Optimize factory usage for import issue csv email
What does this MR do and why?
This MR replaces create with build_stubbed in spec/views/notify/import_issues_csv_email.html.haml_spec.rb to optimize the factory usage as recommended in our handbook.
This spec is part of the list .rubocop_todo/rspec/factory_bot/avoid_create.yml.
It was verified that database persistence is not needed using the factory doctor command FDOC=1 bin/rspec spec/views/notify/import_issues_csv_email.html.haml_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 2.358s (11.41% of total time)
After optimization:
- Factory time: 0.055s (0.31% of total time)
- Factory time reduced by: 2.303s
- Factory time percentage reduced by: 11.1%
- Overall factory usage improvement: 97.7%
Factory Doctor Output
[TEST PROF INFO] FactoryDoctor enabled (event: "sql.active_record", threshold: 0.01)
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
==> Using precompiled Gitaly binaries from cache
Test environment set up in 1.1167169999680482 seconds
.....[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 5
Total wasted time: 00:02.127
notify/import_issues_csv_email.html.haml (./spec/views/notify/import_issues_csv_email.html.haml_spec.rb:5) (22 records created, 00:02.127)
renders with project name error (./spec/views/notify/import_issues_csv_email.html.haml_spec.rb:71) – 5 records created, 00:01.394
renders with group clause error (./spec/views/notify/import_issues_csv_email.html.haml_spec.rb:82) – 2 records created, 00:00.036
renders correctly (./spec/views/notify/import_issues_csv_email.html.haml_spec.rb:43) – 5 records created, 00:00.235
renders with parse error (./spec/views/notify/import_issues_csv_email.html.haml_spec.rb:58) – 5 records created, 00:00.234
renders correctly (./spec/views/notify/import_issues_csv_email.html.haml_spec.rb:26) – 5 records created, 00:00.225
Finished in 15.25 seconds (files took 14.3 seconds to load)
5 examples, 0 failures
Randomized with seed 32672
[TEST PROF INFO] Time spent in factories: 00:02.370 (11.98% of total time)
Factory time before the update
[TEST PROF INFO] Time spent in factories: 00:02.358 (11.41% of total time)Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.055 (0.31% of total time)This MR also adds the missing feature category in this spec.
References
Relates to: #378910.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.