Skip to content

Group visibility levels: Apply best practices to visibility helper test

  • Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA

What does this MR do and why?

  • Related to #455668 (closed)
  • This MR applys some best practices to visibility helper test, see individual commits
    • Extract different visibility level in test constants
    • Format table syntax correctly
    • Apply subject approach for testing
    • Use test util stub_application_setting
    • Improve performance of test by using let_it_be
    • Use single quote strings for consistency

🛠️ with ❤️ at Siemens

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

MR Checklist (@gerardo-navarro)

Screenshots or screen recordings

The following console output is generated when running the test specs FPROF=1 bundle exec rspec spec/helpers/visibility_level_helper_spec.rb

Before this MR

Test environment set up in 2.239237 seconds
.........................................................................................................................................................

Finished in 41.25 seconds (files took 19.04 seconds to load)
153 examples, 0 failures

[TEST PROF INFO] Time spent in factories: 00:17.729 (38.41% of total time)
[TEST PROF INFO] Factories usage

 Total: 352
 Total top-level: 189
 Total time: 00:17.729 (out of 00:54.532)
 Total uniq factories: 9

   total   top-level     total time      time per call      top-level time               name

     106          84        3.9321s            0.0371s             2.9957s               user
      58           0        0.3022s            0.0052s             0.0000s namespace_settings
      58           0        0.2016s            0.0035s             0.0000s namespace_ci_cd_settings
      58          58        4.3859s            0.0756s             4.3859s              group
      45          45       10.1673s            0.2259s            10.1673s            project
      24           0        2.0917s            0.0872s             0.0000s          namespace
       1           1        0.1707s            0.1707s             0.1707s            snippet
       1           0        0.0318s            0.0318s             0.0000s             author
       1           1        0.0095s            0.0095s             0.0095s            license

After this MR

Test environment set up in 2.666858 seconds
.........................................................................................................................................................

Finished in 32.46 seconds (files took 18.3 seconds to load)
153 examples, 0 failures

[TEST PROF INFO] Time spent in factories: 00:08.879 (23.53% of total time)
[TEST PROF INFO] Factories usage

 Total: 175
 Total top-level: 88
 Total time: 00:08.879 (out of 00:46.560)
 Total uniq factories: 9

   total   top-level     total time      time per call      top-level time               name

      39           0        0.2191s            0.0056s             0.0000s namespace_settings
      39           0        0.1173s            0.0030s             0.0000s namespace_ci_cd_settings
      39          39        3.0500s            0.0782s             3.0500s              group
      26          26        4.8429s            0.1863s             4.8429s            project
      24          21        0.8875s            0.0370s             0.7991s               user
       5           0        0.7421s            0.1484s             0.0000s          namespace
       1           1        0.1768s            0.1768s             0.1768s            snippet
       1           0        0.0320s            0.0320s             0.0000s             author
       1           1        0.0103s            0.0103s             0.0103s            license

How to set up and validate locally

  1. Run the respective test
FPROF=1 bundle exec rspec spec/helpers/visibility_level_helper_spec.rb
Edited by Gerardo Navarro

Merge request reports

Loading