Commit 4db2395e authored by Thong Kuah's avatar Thong Kuah

Set container_expiration_policy for project first

This means we don't need the without_container_expiration_policy trait
anymore (which was globally modifying callbacks)

Add comment explaining why we need this and also comment on how
developers can assign existing projects.
parent 933ab919
......@@ -2,7 +2,18 @@
FactoryBot.define do
factory :container_expiration_policy, class: 'ContainerExpirationPolicy' do
association :project, factory: [:project, :without_container_expiration_policy]
# Note: because of the project_id primary_key on
# container_expiration_policies, and the create_container_expiration_policy
# callback on Project, we need to build the project first before assigning
# it to a container_expiration_policy.
#
# Also, if you wish to assign an existing project to a
# container_expiration_policy, you will then have to destroy the project's
# container_expiration_policy first.
before(:create) do |container_expiration_policy|
container_expiration_policy.project = build(:project) unless container_expiration_policy.project
end
cadence { '1d' }
enabled { true }
......
......@@ -140,12 +140,6 @@ FactoryBot.define do
end
end
trait :without_container_expiration_policy do
after(:build) do |project|
project.class.skip_callback(:create, :after, :create_container_expiration_policy, raise: false)
end
end
# Build a custom repository by specifying a hash of `filename => content` in
# the transient `files` attribute. Each file will be created in its own
# commit, operating against the master branch. So, the following call:
......
......@@ -153,6 +153,16 @@ describe Project do
expect(project.container_expiration_policy).to be_persisted
end
it 'does not create another container expiration policy if there is already one' do
project = build(:project)
expect do
container_expiration_policy = create(:container_expiration_policy, project: project)
expect(project.container_expiration_policy).to eq(container_expiration_policy)
end.to change { ContainerExpirationPolicy.count }.by(1)
end
it 'automatically creates a Pages metadata row' do
expect(project.pages_metadatum).to be_an_instance_of(ProjectPagesMetadatum)
expect(project.pages_metadatum).to be_persisted
......
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