Optimize factory usage for more actions dropdown
What does this MR do and why?
This MR replaces create with build_stubbed in spec/views/projects/notes/_more_actions_dropdown.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/projects/notes/_more_actions_dropdown.html.haml_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 4.211s (18.66% of total time)
After optimization:
- Factory time: 0.111s (0.62% of total time)
- Factory time reduced by: 4.1s
- Factory time percentage reduced by: 18.04%
- Overall factory usage improvement: 97.4%
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.319508999993559 seconds
......[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 6
Total wasted time: 00:04.066
projects/notes/_more_actions_dropdown (./spec/views/projects/notes/_more_actions_dropdown.html.haml_spec.rb:5) (54 records created, 00:04.066)
shows Report abuse to admin button if not editable and not current users comment (./spec/views/projects/notes/_more_actions_dropdown.html.haml_spec.rb:17) – 10 records created, 00:02.313
does not show the More actions button if not editable and current users comment (./spec/views/projects/notes/_more_actions_dropdown.html.haml_spec.rb:23) – 8 records created, 00:00.335
does not show Edit button if not editable and not current users comment (./spec/views/projects/notes/_more_actions_dropdown.html.haml_spec.rb:51) – 10 records created, 00:00.526
shows Edit button if editable and current users comment (./spec/views/projects/notes/_more_actions_dropdown.html.haml_spec.rb:43) – 8 records created, 00:00.314
shows Delete button if editable and current users comment (./spec/views/projects/notes/_more_actions_dropdown.html.haml_spec.rb:37) – 8 records created, 00:00.277
shows Report abuse and Delete buttons if editable and not current users comment (./spec/views/projects/notes/_more_actions_dropdown.html.haml_spec.rb:29) – 10 records created, 00:00.298
Finished in 17.32 seconds (files took 14.44 seconds to load)
6 examples, 0 failures
Randomized with seed 31436
[TEST PROF INFO] Time spent in factories: 00:04.074 (18.66% of total time)
Factory time before the update
[TEST PROF INFO] Time spent in factories: 00:04.211 (18.66% of total time)
Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.111 (0.62% 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.