diff options
Diffstat (limited to 'spec/models/pages_deployment_spec.rb')
-rw-r--r-- | spec/models/pages_deployment_spec.rb | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/spec/models/pages_deployment_spec.rb b/spec/models/pages_deployment_spec.rb index e74c7ee8612..1e6f8b33a86 100644 --- a/spec/models/pages_deployment_spec.rb +++ b/spec/models/pages_deployment_spec.rb @@ -71,54 +71,62 @@ RSpec.describe PagesDeployment, feature_category: :pages do end end - describe '.deactivate_deployments_older_than', :freeze_time do - let!(:other_project_deployment) do - create(:pages_deployment) - end + describe '.deactivate_all', :freeze_time do + let!(:deployment) { create(:pages_deployment, project: project, updated_at: 5.minutes.ago) } + let!(:nil_path_prefix_deployment) { create(:pages_deployment, project: project, path_prefix: nil) } + let!(:empty_path_prefix_deployment) { create(:pages_deployment, project: project, path_prefix: '') } - let!(:other_path_prefix_deployment) do - create(:pages_deployment, project: project, path_prefix: 'other') - end + let!(:other_project_deployment) { create(:pages_deployment) } + let!(:deactivated_deployment) { create(:pages_deployment, project: project, deleted_at: 5.minutes.ago) } - let!(:deactivated_deployment) do - create(:pages_deployment, project: project, deleted_at: 5.minutes.ago) + it 'updates only older deployments for the same project and path prefix' do + expect { described_class.deactivate_all(project) } + .to change { deployment.reload.deleted_at }.from(nil).to(Time.zone.now) + .and change { deployment.reload.updated_at }.to(Time.zone.now) + .and change { nil_path_prefix_deployment.reload.deleted_at }.from(nil).to(Time.zone.now) + .and change { empty_path_prefix_deployment.reload.deleted_at }.from(nil).to(Time.zone.now) + .and not_change { other_project_deployment.reload.deleted_at } + .and not_change { deactivated_deployment.reload.deleted_at } end + end + + describe '.deactivate_deployments_older_than', :freeze_time do + let!(:nil_path_prefix_deployment) { create(:pages_deployment, project: project, path_prefix: nil) } + let!(:empty_path_prefix_deployment) { create(:pages_deployment, project: project, path_prefix: '') } + let!(:older_deployment) { create(:pages_deployment, project: project, updated_at: 5.minutes.ago) } + let!(:reference_deployment) { create(:pages_deployment, project: project, updated_at: 5.minutes.ago) } + let!(:newer_deployment) { create(:pages_deployment, project: project, updated_at: 5.minutes.ago) } + + let!(:other_project_deployment) { create(:pages_deployment) } + let!(:other_path_prefix_deployment) { create(:pages_deployment, project: project, path_prefix: 'other') } + let!(:deactivated_deployment) { create(:pages_deployment, project: project, deleted_at: 5.minutes.ago) } it 'updates only older deployments for the same project and path prefix' do - deployment1 = create(:pages_deployment, project: project, updated_at: 5.minutes.ago) - deployment2 = create(:pages_deployment, project: project, updated_at: 5.minutes.ago) - deployment3 = create(:pages_deployment, project: project, updated_at: 5.minutes.ago) - - expect { described_class.deactivate_deployments_older_than(deployment2) } - .to change { deployment1.reload.deleted_at } - .from(nil).to(Time.zone.now) - .and change { deployment1.reload.updated_at } - .to(Time.zone.now) - - expect(deployment2.reload.deleted_at).to be_nil - expect(deployment3.reload.deleted_at).to be_nil - expect(other_project_deployment.deleted_at).to be_nil - expect(other_path_prefix_deployment.reload.deleted_at).to be_nil - expect(deactivated_deployment.reload.deleted_at).to eq(5.minutes.ago) + expect { described_class.deactivate_deployments_older_than(reference_deployment) } + .to change { older_deployment.reload.deleted_at }.from(nil).to(Time.zone.now) + .and change { older_deployment.reload.updated_at }.to(Time.zone.now) + .and change { nil_path_prefix_deployment.reload.deleted_at }.from(nil).to(Time.zone.now) + .and change { empty_path_prefix_deployment.reload.deleted_at }.from(nil).to(Time.zone.now) + .and not_change { reference_deployment.reload.deleted_at } + .and not_change { newer_deployment.reload.deleted_at } + .and not_change { other_project_deployment.reload.deleted_at } + .and not_change { other_path_prefix_deployment.reload.deleted_at } + .and not_change { deactivated_deployment.reload.deleted_at } end it 'updates only older deployments for the same project with the given time' do - deployment1 = create(:pages_deployment, project: project, updated_at: 5.minutes.ago) - deployment2 = create(:pages_deployment, project: project, updated_at: 5.minutes.ago) - deployment3 = create(:pages_deployment, project: project, updated_at: 5.minutes.ago) time = 30.minutes.from_now - expect { described_class.deactivate_deployments_older_than(deployment2, time: time) } - .to change { deployment1.reload.deleted_at } - .from(nil).to(time) - .and change { deployment1.reload.updated_at } - .to(Time.zone.now) - - expect(deployment2.reload.deleted_at).to be_nil - expect(deployment3.reload.deleted_at).to be_nil - expect(other_project_deployment.deleted_at).to be_nil - expect(other_path_prefix_deployment.reload.deleted_at).to be_nil - expect(deactivated_deployment.reload.deleted_at).to eq(5.minutes.ago) + expect { described_class.deactivate_deployments_older_than(reference_deployment, time: time) } + .to change { older_deployment.reload.deleted_at }.from(nil).to(time) + .and change { older_deployment.reload.updated_at }.to(Time.zone.now) + .and change { nil_path_prefix_deployment.reload.deleted_at }.from(nil).to(time) + .and change { empty_path_prefix_deployment.reload.deleted_at }.from(nil).to(time) + .and not_change { reference_deployment.reload.deleted_at } + .and not_change { newer_deployment.reload.deleted_at } + .and not_change { other_project_deployment.reload.deleted_at } + .and not_change { other_path_prefix_deployment.reload.deleted_at } + .and not_change { deactivated_deployment.reload.deleted_at } end end |