Commit 0c739683 authored by James Lopez's avatar James Lopez

Merge branch 'write_out_without_container_expiration_policy' into 'master'

Set container_expiration_policy for project first

See merge request gitlab-org/gitlab!22962
parents 1b223e92 4db2395e
......@@ -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