Optimize factory usage for subscription_presenter_spec
What does this MR do and why?
This MR replaces create with build_stubbed in ee/spec/presenters/subscription_presenter_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 ee/spec/presenters/subscription_presenter_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 2.297s (3.59% of total time)
After optimization:
- Factory time: 0.011s (0.06% of total time)
- Factory time reduced by: 2.286s
- Factory time percentage reduced by: 3.53%
- Overall factory usage improvement: 99.5%
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
==> Go projects set up in 0.809 seconds...
Test environment set up in 2.3303089999826625 seconds
..................[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 18
Total wasted time: 00:02.355
SubscriptionPresenter (./ee/spec/presenters/subscription_presenter_spec.rb:5) (90 records created, 00:02.355)
is expected to eq "ultimate" (./ee/spec/presenters/subscription_presenter_spec.rb:14) – 5 records created, 00:00.662
is nil when end_date is nil (./ee/spec/presenters/subscription_presenter_spec.rb:126) – 5 records created, 00:00.095
returns the number of days between end_date and today (./ee/spec/presenters/subscription_presenter_spec.rb:132) – 5 records created, 00:00.085
is 0 if expired (./ee/spec/presenters/subscription_presenter_spec.rb:140) – 5 records created, 00:00.079
is expected to equal true (./ee/spec/presenters/subscription_presenter_spec.rb:109) – 5 records created, 00:00.088
is false (./ee/spec/presenters/subscription_presenter_spec.rb:113) – 5 records created, 00:00.079
is expected to equal false (./ee/spec/presenters/subscription_presenter_spec.rb:40) – 5 records created, 00:00.231
is expected to eq Tue, 06 Apr 2027 (./ee/spec/presenters/subscription_presenter_spec.rb:46) – 5 records created, 00:00.079
is nil (./ee/spec/presenters/subscription_presenter_spec.rb:49) – 5 records created, 00:00.076
is expected to equal false (./ee/spec/presenters/subscription_presenter_spec.rb:69) – 5 records created, 00:00.079
is false (./ee/spec/presenters/subscription_presenter_spec.rb:75) – 5 records created, 00:00.077
is false (./ee/spec/presenters/subscription_presenter_spec.rb:86) – 5 records created, 00:00.080
is true (./ee/spec/presenters/subscription_presenter_spec.rb:96) – 5 records created, 00:00.068
is expected to equal false (./ee/spec/presenters/subscription_presenter_spec.rb:33) – 5 records created, 00:00.074
is expected to equal true (./ee/spec/presenters/subscription_presenter_spec.rb:33) – 5 records created, 00:00.067
is expected to equal true (./ee/spec/presenters/subscription_presenter_spec.rb:33) – 5 records created, 00:00.273
is expected to equal true (./ee/spec/presenters/subscription_presenter_spec.rb:33) – 5 records created, 00:00.076
is expected to equal false (./ee/spec/presenters/subscription_presenter_spec.rb:33) – 5 records created, 00:00.081
Finished in 14.62 seconds (files took 15.72 seconds to load)
18 examples, 0 failures
Randomized with seed 16762
[TEST PROF INFO] Time spent in factories: 00:02.365 (12.62% of total time)
Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.011 (0.06% 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.