Commit 92600e14 authored by Arturo Herrero's avatar Arturo Herrero

Merge branch 'mmj-fix-namespace-traits-for-associations' into 'master'

Fix the nature of FactoryBot traits that create associations of Namespace [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!55160
parents 469fc9e1 94f2ea1d
......@@ -23,15 +23,21 @@ FactoryBot.define do
end
trait :with_aggregation_schedule do
association :aggregation_schedule, factory: :namespace_aggregation_schedules
after(:create) do |namespace|
create(:namespace_aggregation_schedules, namespace: namespace)
end
end
trait :with_root_storage_statistics do
association :root_storage_statistics, factory: :namespace_root_storage_statistics
after(:create) do |namespace|
create(:namespace_root_storage_statistics, namespace: namespace)
end
end
trait :with_namespace_settings do
association :namespace_settings, factory: :namespace_settings
after(:create) do |namespace|
create(:namespace_settings, namespace: namespace)
end
end
trait :shared_runners_disabled do
......
......@@ -134,4 +134,14 @@ RSpec.describe Gitlab::Ci::Status::Factory do
it_behaves_like 'compound decorator factory'
end
end
context 'behaviour of FactoryBot traits that create associations' do
context 'creating a namespace with an associated aggregation_schedule record' do
it 'creates only one Namespace record and one Namespace::AggregationSchedule record' do
expect { create(:namespace, :with_aggregation_schedule) }
.to change { Namespace.count }.by(1)
.and change { Namespace::AggregationSchedule.count }.by(1)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment