Optimize factory usage for award emoji helper
What does this MR do and why?
This MR replaces create with build_stubbed in spec/helpers/award_emoji_helper_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/helpers/award_emoji_helper_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 4.497s (22.46% of total time)
After optimization:
- Factory time: 0.063s (0.39% of total time)
- Factory time reduced by: 4.434s
- Factory time percentage reduced by: 22.07%
- Overall factory usage improvement: 98.6%
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.2168739999997342 seconds
.....[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 5
Total wasted time: 00:04.352
AwardEmojiHelper (./spec/helpers/award_emoji_helper_spec.rb:5) (26 records created, 00:04.352)
returns correct url (./spec/helpers/award_emoji_helper_spec.rb:16) – 8 records created, 00:00.841
returns correct url (./spec/helpers/award_emoji_helper_spec.rb:27) – 5 records created, 00:00.921
returns correct url (./spec/helpers/award_emoji_helper_spec.rb:40) – 4 records created, 00:00.072
returns correct url (./spec/helpers/award_emoji_helper_spec.rb:51) – 4 records created, 00:02.157
returns correct url (./spec/helpers/award_emoji_helper_spec.rb:64) – 5 records created, 00:00.360
Finished in 17.71 seconds (files took 14.3 seconds to load)
5 examples, 0 failures
[TEST PROF INFO] Time spent in factories: 00:04.359 (20.42% of total time)
Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.063 (0.39% 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.