Load EE factories in Rails console and verify them in specs
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)
Closes #335714 (closed).
How to set up and validate locally
- To test
production
env add this toconfig/database.yml
:
production:
<<: *test

EE factories are missing
$ 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)

EE factories are available
$ 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.
-
I have evaluated the MR acceptance checklist for this MR.
Merge request reports
Activity
assigned to @splattael
marked the checklist item I have evaluated the MR acceptance checklist for this MR. as completed
Suggested Reviewers (beta)
The individuals below may be good candidates to participate in the review based on various factors.
You can use slash commands in comments to quickly assign
/assign_reviewer @user1
.Suggested Reviewers @rspeicher
,@tigerwnz
,@pslaughter
,@marin
,@abrandl
If you do not believe these suggestions are useful, please apply the label Bad Suggested Reviewer. You can also provide feedback for this feature on this issue:
https://gitlab.com/gitlab-org/gitlab/-/issues/357923
.Automatically generated by Suggested Reviewers Bot - an experimental ML-based recommendation engine created by ~"group::applied ml".
Edited by GitLab Reviewer-Recommender Botchanged milestone to %15.4
added backend devopsmonitor grouprespond maintenancerefactor typemaintenance labels
- A deleted user
added documentation label
Reviewer roulette
Changes that require review have been detected!
Please refer to the table below for assigning reviewers and maintainers suggested by Danger in the specified category:
Category Reviewer Maintainer backend Smriti Garg ( @sgarg_gitlab
) (UTC+5.5, 3.5 hours ahead of@splattael
)Vasilii Iakliushin ( @vyaklushin
) (UTC+2, same timezone as@splattael
)To spread load more evenly across eligible reviewers, Danger has picked a candidate for each review slot, based on their timezone. Feel free to override these selections if you think someone else would be better-suited or use the GitLab Review Workload Dashboard to find other available reviewers.
To read more on how to use the reviewer roulette, please take a look at the Engineering workflow and code review guidelines. Please consider assigning a reviewer or maintainer who is a domain expert in the area of the merge request.
Once you've decided who will review this merge request, assign them as a reviewer! Danger does not automatically notify them for you.
If needed, you can retry the
danger-review
job that generated this comment.Generated by
Dangermentioned in issue #369851 (closed)
- Resolved by Vasilii Iakliushin
Can you review this MR?
requested review from @Quintasan
added pipeline:run-as-if-foss label
removed review request for @Quintasan
added pipeline:run-all-rspec label
added 25 commits
-
5f5ad3c3...b9f53e1b - 22 commits from branch
master
- e9820154 - Define FactoryBot file paths only once
- 046c5649 - Drop _spec suffix for EE LFS Object factory
- 89b35d8b - Fix traits of factory lfs_object
Toggle commit list-
5f5ad3c3...b9f53e1b - 22 commits from branch
added sectionops label
mentioned in issue #341253
added 132 commits
-
89b35d8b...7ed859d2 - 129 commits from branch
master
- 87cda6d5 - Define FactoryBot file paths only once
- 8e79da6e - Drop _spec suffix for EE LFS Object factory
- db93930f - More factory fixes
Toggle commit list-
89b35d8b...7ed859d2 - 129 commits from branch
Allure report
allure-report-publisher
generated test report!review-qa-blocking:
test report for db93930fexpand test summary
+-----------------------------------------------------------------------------------------+ | suites summary | +------------------------------------+--------+--------+---------+-------+-------+--------+ | | passed | failed | skipped | flaky | total | result | +------------------------------------+--------+--------+---------+-------+-------+--------+ | Manage | 46 | 0 | 3 | 11 | 49 | ❗ | | Plan | 47 | 0 | 1 | 0 | 48 | ✅ | | Verify | 12 | 0 | 1 | 2 | 13 | ❗ | | Create | 28 | 0 | 1 | 3 | 29 | ❗ | | Secure | 2 | 0 | 0 | 0 | 2 | ✅ | | Package | 0 | 0 | 1 | 0 | 1 | ➖ | | Version sanity check | 0 | 0 | 1 | 0 | 1 | ➖ | | Feature flag handler sanity checks | 9 | 0 | 0 | 0 | 9 | ✅ | | Protect | 2 | 0 | 0 | 0 | 2 | ✅ | | Configure | 0 | 0 | 1 | 0 | 1 | ➖ | +------------------------------------+--------+--------+---------+-------+-------+--------+ | Total | 146 | 0 | 9 | 16 | 155 | ❗ | +------------------------------------+--------+--------+---------+-------+-------+--------+
changed milestone to %15.5
added missed:15.4 label
added 6951 commits
-
db93930f...eb58e0b6 - 6947 commits from branch
master
- c2f25098 - Define FactoryBot file paths only once
- 59b34403 - Drop _spec suffix for EE LFS Object factory
- feadf38b - More factory fixes
- 97a2ad9e - Reference GraphQL during runtime not load time
Toggle commit list-
db93930f...eb58e0b6 - 6947 commits from branch
changed milestone to %15.6
- Resolved by Vasilii Iakliushin
added 390 commits
-
97a2ad9e...4988912e - 382 commits from branch
master
- 4d83cbda - Define FactoryBot file paths only once
- 58391997 - Drop _spec suffix for EE LFS Object factory
- 1703e5f1 - More factory fixes
- 4e60907c - Reference GraphQL during runtime not load time
- bb1c0cea - Fix project_security_setting
- 37da0d78 - Stub licences
- 942aed1b - Fix protected_environment_approval_rule
- 99abdff2 - Disable some more geo_ factories
Toggle commit list-
97a2ad9e...4988912e - 382 commits from branch
added 1 commit
- ad1f36a2 - Use skip instead of pending when verifying FactoryBot.build
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
Toggle commit list-
ad1f36a2...3612de75 - 286 commits from branch
- Resolved by Vasilii Iakliushin
- Resolved by Vasilii Iakliushin
- Resolved by Peter Leitzen
mentioned in issue #378383
requested review from @serenafang
@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:
requested review from @vyaklushin and removed review request for @serenafang
mentioned in issue #378478 (closed)
enabled an automatic merge when the pipeline for c046bb54 succeeds
mentioned in commit d6cc8715
added workflowstaging-canary label
added workflowcanary label and removed workflowstaging-canary label
added workflowstaging label and removed workflowcanary label
mentioned in merge request !101900 (merged)
added workflowpost-deploy-db-staging label and removed workflowstaging label
added workflowpost-deploy-db-production label and removed workflowpost-deploy-db-staging label
added releasedcandidate label
added releasedpublished label and removed releasedcandidate label
mentioned in merge request !110361 (merged)
mentioned in issue #397700 (closed)
mentioned in issue gitlab-org/monitor/respond#217 (closed)
mentioned in issue gitlab-org/monitor/respond#225 (closed)
mentioned in issue gitlab-org/monitor/respond#226 (closed)
mentioned in issue gitlab-org/monitor/respond#230 (closed)
mentioned in merge request !120277 (merged)
added devopsservice management sectionseg labels and removed devopsmonitor sectionops labels
mentioned in issue #335714 (closed)