Optimize factory usage for ci variable presenter

What does this MR do and why?

This MR replaces create with build_stubbed in spec/presenters/ci/variable_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 spec/presenters/ci/variable_presenter_spec.rb.

Factory Usage Optimization Results

Before optimization:

  • Factory time: 3.209s (15.75% of total time)

After optimization:

  • Factory time: 0.087s (0.52% of total time)

🚀 Improvement:

  • Factory time reduced by: 3.122s
  • Factory time percentage reduced by: 15.23%
  • Overall factory usage improvement: 97.3%

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.1947110000037355 seconds
........[TEST PROF INFO] FactoryDoctor report

Total (potentially) bad examples: 7
Total wasted time: 00:03.058

Ci::VariablePresenter (./spec/presenters/ci/variable_presenter_spec.rb:5) (28 records created, 00:03.058)
  takes a variable and optional params (./spec/presenters/ci/variable_presenter_spec.rb:20)  4 records created, 00:01.464
  exposes variable (./spec/presenters/ci/variable_presenter_spec.rb:24)  4 records created, 00:00.260
  forwards missing methods to variable (./spec/presenters/ci/variable_presenter_spec.rb:28)  4 records created, 00:00.222
  is expected to eq "/namespace4/project-4/-/variables" (./spec/presenters/ci/variable_presenter_spec.rb:54)  4 records created, 00:00.228
  is expected to eq "/namespace5/project-5/-/variables" (./spec/presenters/ci/variable_presenter_spec.rb:48)  4 records created, 00:00.433
  is expected to eq "PROJECT_VARIABLE" (./spec/presenters/ci/variable_presenter_spec.rb:36)  4 records created, 00:00.230
  is expected to eq "/namespace7/project-7/-/settings/ci_cd" (./spec/presenters/ci/variable_presenter_spec.rb:42)  4 records created, 00:00.219




Finished in 16.04 seconds (files took 13.86 seconds to load)
8 examples, 0 failures

Randomized with seed 50767

[TEST PROF INFO] Time spent in factories: 00:03.065 (15.56% of total time)

Factory time after update

[TEST PROF INFO] Time spent in factories: 00:00.087 (0.52% 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.

Merge request reports

Loading