Skip to content
Snippets Groups Projects

Load EE factories in Rails console and verify them in specs

Merged Peter Leitzen requested to merge pl-factory-bot-reload into master
All threads resolved!

What does this MR do and why?

Previously, factories defined in ee/spec/factories/**/*.rb were not loaded in rails console.

Moreover, they were not verified via spec/models/factories_spec.rb. Some EE factories have been fixed to pass the specs (skip_create was added to play nice with create(...) for non-DB factories).

This MR defines file paths via application configuration instead of overriding definition_file_paths in multiple places.

This allows factories for EE and JH to be loaded also in Rails console if available and make them available in spec/models/factories_spec.rb.

This MR might help to resolve #369851 (closed) :fingers_crossed: (no reproduction/evidence though)

Closes #335714 (closed).

How to set up and validate locally

  • To test production env add this to config/database.yml:
production:
  <<: *test

Before :x:

EE factories are missing :x:

$ bin/rails  console
WARNING: This version of GitLab depends on gitlab-shell 14.10.0, but you're running 14.7.4. Please update gitlab-shell.
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       15.4.0-pre (25e0d649a8c) EE
 GitLab Shell: 14.7.4
 PostgreSQL:   12.10
-------------------------------------------------------------[ booted in 4.64s ]
Loading development environment (Rails 6.1.6.1)
[1] pry(main)> FactoryBot.definition_file_paths
=> [#<Pathname:/home/peter/devel/gitlab/gdk/gitlab/factories>, #<Pathname:/home/peter/devel/gitlab/gdk/gitlab/test/factories>, #<Pathname:/home/peter/devel/gitlab/gdk/gitlab/spec/factories>]
[2] pry(main)> FactoryBot.reload
=> ["/home/peter/devel/gitlab/gdk/gitlab/factories", "/home/peter/devel/gitlab/gdk/gitlab/test/factories", "/home/peter/devel/gitlab/gdk/gitlab/spec/factories"]

$ bin/rails  console -e production
WARNING: This version of GitLab depends on gitlab-shell 14.10.0, but you're running 14.7.4. Please update gitlab-shell.
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       15.4.0-pre (25e0d649a8c) EE
 GitLab Shell: 14.7.4
 PostgreSQL:   12.10
-------------------------------------------------------------[ booted in 9.44s ]
Loading production environment (Rails 6.1.6.1)
>> FactoryBot
Traceback (most recent call last):
        1: from (irb):1
NameError (uninitialized constant FactoryBot)

After :white_check_mark:

EE factories are available :white_check_mark:

$ bin/rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       15.4.0-pre (ac4f1ac2435) EE
 GitLab Shell: Unknown
 PostgreSQL:   12.10
-------------------------------------------------------------[ booted in 0.00s ]
Loading test environment (Rails 6.1.6.1)

[1] pry(main)> FactoryBot.definition_file_paths
=> [#<Pathname:/home/peter/devel/gitlab/gdk/gitlab/factories>,
 #<Pathname:/home/peter/devel/gitlab/gdk/gitlab/test/factories>,
 #<Pathname:/home/peter/devel/gitlab/gdk/gitlab/spec/factories>,
 #<Pathname:/home/peter/devel/gitlab/gdk/gitlab/ee/spec/factories>]

[2] pry(main)> FactoryBot.definition_file_paths
=> [#<Pathname:/home/peter/devel/gitlab/gdk/gitlab/factories>,
 #<Pathname:/home/peter/devel/gitlab/gdk/gitlab/test/factories>,
 #<Pathname:/home/peter/devel/gitlab/gdk/gitlab/spec/factories>,
 #<Pathname:/home/peter/devel/gitlab/gdk/gitlab/ee/spec/factories>]
[2] pry(main)> FactoryBot.reload
=> ["/home/peter/devel/gitlab/gdk/gitlab/factories", "/home/peter/devel/gitlab/gdk/gitlab/test/factories", "/home/peter/devel/gitlab/gdk/gitlab/spec/factories", "/home/peter/devel/gitlab/gdk/gitlab/ee/spec/factories"]

# same for 
$ bin/rails console -e test


# Still works in FOSS

$ FOSS_ONLY=1 bin/rails  console
WARNING: This version of GitLab depends on gitlab-shell 14.10.0, but you're running 14.7.4. Please update gitlab-shell.
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       15.4.0-pre (5f5ad3c3a12) FOSS
 GitLab Shell: 14.7.4
 PostgreSQL:   12.10
-------------------------------------------------------------[ booted in 4.21s ]
Loading development environment (Rails 6.1.6.1)
[1] pry(main)> FactoryBot.definition_file_paths
=> [#<Pathname:/home/peter/devel/gitlab/gdk/gitlab/factories>, #<Pathname:/home/peter/devel/gitlab/gdk/gitlab/test/factories>, #<Pathname:/home/peter/devel/gitlab/gdk/gitlab/spec/factories>]
[2] pry(main)>


$ bin/rails  console -e production
WARNING: This version of GitLab depends on gitlab-shell 14.10.0, but you're running 14.7.4. Please update gitlab-shell.
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       15.4.0-pre (25e0d649a8c) EE
 GitLab Shell: 14.7.4
 PostgreSQL:   12.10
-------------------------------------------------------------[ booted in 9.44s ]
Loading production environment (Rails 6.1.6.1)
>> FactoryBot
Traceback (most recent call last):
        1: from (irb):1
NameError (uninitialized constant FactoryBot)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Peter Leitzen added 390 commits

    added 390 commits

    Compare with previous version

  • Peter Leitzen added 1 commit

    added 1 commit

    • ad1f36a2 - Use skip instead of pending when verifying FactoryBot.build

    Compare with previous version

  • Peter Leitzen added 290 commits

    added 290 commits

    • ad1f36a2...3612de75 - 286 commits from branch master
    • 4cbbeeeb - Define FactoryBot file paths only once
    • 7a354db6 - Drop _spec suffix for EE LFS Object factory
    • 1ba5beee - Reference GraphQL during runtime not load time
    • e69c430b - Fix some EE factories to pass specs and exclude the rest

    Compare with previous version

  • Peter Leitzen
  • Peter Leitzen changed the description

    changed the description

  • Peter Leitzen
  • Peter Leitzen
  • Peter Leitzen mentioned in issue #378383

    mentioned in issue #378383

  • Peter Leitzen requested review from @serenafang

    requested review from @serenafang

  • Serena Fang approved this merge request

    approved this merge request

  • :wave: @serenafang, thanks for approving this merge request.

    This is the first time the merge request is approved. To ensure full test coverage, a new pipeline will be started shortly.

    For more info, please refer to the following links:

  • 🤖 GitLab Bot 🤖 added 1 deleted label

    added 1 deleted label

  • Peter Leitzen requested review from @vyaklushin and removed review request for @serenafang

    requested review from @vyaklushin and removed review request for @serenafang

  • mentioned in issue #378478 (closed)

  • Vasilii Iakliushin resolved all threads

    resolved all threads

  • Vasilii Iakliushin approved this merge request

    approved this merge request

  • Vasilii Iakliushin enabled an automatic merge when the pipeline for c046bb54 succeeds

    enabled an automatic merge when the pipeline for c046bb54 succeeds

  • mentioned in commit d6cc8715

  • added workflowstaging label and removed workflowcanary label

  • MAO Chao mentioned in merge request !101900 (merged)

    mentioned in merge request !101900 (merged)

  • Peter Leitzen mentioned in merge request !110361 (merged)

    mentioned in merge request !110361 (merged)

  • mentioned in issue #397700 (closed)

  • Peter Leitzen mentioned in merge request !120277 (merged)

    mentioned in merge request !120277 (merged)

  • Peter Leitzen changed the description

    changed the description

  • mentioned in issue #335714 (closed)

  • Please register or sign in to reply
    Loading