Commit 576b270d authored by Manoj M J's avatar Manoj M J

Fix nature of FactoryBot traits that create associations of Namespace

This change fixes the nature of FactoryBot traits
that create associations of Namespace
parent 41b03ea7
......@@ -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
# Construct a hierarchy underneath the namespace.
......
......@@ -1502,4 +1502,30 @@ RSpec.describe Namespace do
it { is_expected.to be(true) }
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
context 'creating a namespace with an associated root_storage_statistics record' do
it 'creates only one Namespace record and one Namespace::RootStorageStatistics record' do
expect { create(:namespace, :with_root_storage_statistics) }
.to change { Namespace.count }.by(1)
.and change { Namespace::RootStorageStatistics.count }.by(1)
end
end
context 'creating a namespace with an associated namespace_settings record' do
it 'creates only one Namespace record and one NamespaceSetting record' do
expect { create(:namespace, :with_namespace_settings) }
.to change { Namespace.count }.by(1)
.and change { NamespaceSetting.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