diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/factories_spec.rb | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/factories_spec.rb')
-rw-r--r-- | spec/factories_spec.rb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/spec/factories_spec.rb b/spec/factories_spec.rb index f89aeb1c93d..7241af6e8c0 100644 --- a/spec/factories_spec.rb +++ b/spec/factories_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe 'factories' do - FactoryBot.factories.each do |factory| + shared_examples 'factory' do |factory| describe "#{factory.name} factory" do it 'does not raise error when built' do expect { build(factory.name) }.not_to raise_error @@ -22,4 +22,32 @@ RSpec.describe 'factories' do end end end + + # FactoryDefault speed up specs by creating associations only once + # and reuse them in other factories. + # + # However, for some factories we cannot use FactoryDefault because the + # associations must be unique and cannot be reused. + skip_factory_defaults = %i[ + fork_network_member + ].to_set.freeze + + without_fd, with_fd = FactoryBot.factories + .partition { |factory| skip_factory_defaults.include?(factory.name) } + + context 'with factory defaults', factory_default: :keep do + let_it_be(:namespace) { create_default(:namespace) } + let_it_be(:project) { create_default(:project, :repository) } + let_it_be(:user) { create_default(:user) } + + with_fd.each do |factory| + it_behaves_like 'factory', factory + end + end + + context 'without factory defaults' do + without_fd.each do |factory| + it_behaves_like 'factory', factory + end + end end |