Optimize factory usage for lazy image tag helper

What does this MR do and why?

This MR replaces create with build_stubbed in spec/helpers/lazy_image_tag_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/lazy_image_tag_helper_spec.rb.

Factory Usage Optimization Results

Before optimization:

  • Factory time: 0.671s (3.36% of total time)

After optimization:

  • Factory time: 0.006s (0.04% of total time)

🚀 Improvement:

  • Factory time reduced by: 0.665s
  • Factory time percentage reduced by: 3.32%
  • Overall factory usage improvement: 99.1%

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

Total (potentially) bad examples: 5
Total wasted time: 00:00.676

LazyImageTagHelper (./spec/helpers/lazy_image_tag_helper_spec.rb:5) (10 records created, 00:00.676)
  adds an auto dark mode class from gitlab-ui (./spec/helpers/lazy_image_tag_helper_spec.rb:38)  2 records created, 00:00.501
  uses dark variant as a source (./spec/helpers/lazy_image_tag_helper_spec.rb:58)  2 records created, 00:00.047
  does not add a dark mode class from gitlab-ui (./spec/helpers/lazy_image_tag_helper_spec.rb:72)  2 records created, 00:00.043
  does nothing (./spec/helpers/lazy_image_tag_helper_spec.rb:82)  2 records created, 00:00.045
  uses original image as a source (./spec/helpers/lazy_image_tag_helper_spec.rb:92)  2 records created, 00:00.038




Finished in 14.46 seconds (files took 15.6 seconds to load)
9 examples, 0 failures

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

Factory time after update

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