From 7e9273dd946f46b2b2bcc0a751316dc704089a16 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 10 Jun 2016 16:20:11 +0200 Subject: Test controllers if they allow to keep artifacts --- spec/models/build_spec.rb | 65 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 2beb6cc598d..a2e4639dbf7 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -397,9 +397,32 @@ describe Ci::Build, models: true do context 'artifacts archive exists' do let(:build) { create(:ci_build, :artifacts) } it { is_expected.to be_truthy } + + context 'is expired' do + before { build.update(artifacts_expire_at: Time.now - 7.days) } + it { is_expected.to be_falsy } + end + + context 'is not expired' do + before { build.update(artifacts_expire_at: Time.now + 7.days) } + it { is_expected.to be_truthy } + end end end + describe '#artifacts_expired?' do + subject { build.artifacts_expired? } + + context 'is expired' do + before { build.update(artifacts_expire_at: Time.now - 7.days) } + it { is_expected.to be_falsy } + end + + context 'is not expired' do + before { build.update(artifacts_expire_at: Time.now + 7.days) } + it { is_expected.to be_truthy } + end + end describe '#artifacts_metadata?' do subject { build.artifacts_metadata? } @@ -412,7 +435,6 @@ describe Ci::Build, models: true do it { is_expected.to be_truthy } end end - describe '#repo_url' do let(:build) { create(:ci_build) } let(:project) { build.project } @@ -427,6 +449,47 @@ describe Ci::Build, models: true do it { is_expected.to include(project.web_url[7..-1]) } end + describe '#artifacts_expire_in' do + subject { build.artifacts_expire_in } + it { is_expected.to be_nil } + + context 'when artifacts_expire_at is specified' do + let(:expire_at) { Time.now + 7.days } + + before { build.artifacts_expire_at = expire_at } + + it { is_expected.to be_within(5).of(expire_at - Time.now) } + end + end + + describe '#artifacts_expire_in=' do + subject { build.artifacts_expire_in } + + it 'when assigning valid duration' do + build.artifacts_expire_in = '7 days' + is_expected.to be_within(10).of(7.days.to_i) + end + + it 'when assigning invalid duration' do + expect{ build.artifacts_expire_in = '7 elephants' }.not_to raise_error + is_expected.to be_nil + end + + it 'when resseting value' do + build.artifacts_expire_in = nil + is_expected.to be_nil + end + end + + describe '#keep_artifacts!' do + let(:build) { create(:ci_build, artifacts_expire_at: Time.now + 7.days) } + + it 'to reset expire_at' do + build.keep_artifacts! + expect(build.artifacts_expire_at).to be_nil + end + end + describe '#depends_on_builds' do let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') } let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') } -- cgit v1.2.1 From 421be01dabb13cd1f45d0118b4e1be9d33baef61 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 10 Jun 2016 21:45:06 +0200 Subject: Improve design based on review --- spec/models/build_spec.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'spec/models') diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index a2e4639dbf7..f25b676651e 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -467,6 +467,7 @@ describe Ci::Build, models: true do it 'when assigning valid duration' do build.artifacts_expire_in = '7 days' + is_expected.to be_within(10).of(7.days.to_i) end @@ -477,6 +478,7 @@ describe Ci::Build, models: true do it 'when resseting value' do build.artifacts_expire_in = nil + is_expected.to be_nil end end @@ -486,6 +488,7 @@ describe Ci::Build, models: true do it 'to reset expire_at' do build.keep_artifacts! + expect(build.artifacts_expire_at).to be_nil end end -- cgit v1.2.1 From c534d2e89ed00ff98c83a197674b5ac66a8aca93 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 13 Jun 2016 16:05:23 +0200 Subject: Improve tests --- spec/models/build_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index f25b676651e..c07832a4b5f 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -472,7 +472,7 @@ describe Ci::Build, models: true do end it 'when assigning invalid duration' do - expect{ build.artifacts_expire_in = '7 elephants' }.not_to raise_error + expect { build.artifacts_expire_in = '7 elephants' }.not_to raise_error is_expected.to be_nil end -- cgit v1.2.1 From 60e0137c864e26fee0120dc4447bb95acc46ce51 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 14 Jun 2016 11:38:34 +0200 Subject: Fix specs --- spec/models/build_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec/models') diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index c07832a4b5f..35554e1e0c0 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -415,12 +415,14 @@ describe Ci::Build, models: true do context 'is expired' do before { build.update(artifacts_expire_at: Time.now - 7.days) } - it { is_expected.to be_falsy } + + it { is_expected.to be_truthy } end context 'is not expired' do before { build.update(artifacts_expire_at: Time.now + 7.days) } - it { is_expected.to be_truthy } + + it { is_expected.to be_falsey } end end -- cgit v1.2.1 From 2b5449b96d1c08eafc3e874f28dd9f85a6b09535 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 14 Jun 2016 14:51:09 +0200 Subject: Fix Ci::Build#artifacts_expire_in= when assigning invalid duration --- spec/models/build_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 35554e1e0c0..5d1fa8226e5 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -474,7 +474,7 @@ describe Ci::Build, models: true do end it 'when assigning invalid duration' do - expect { build.artifacts_expire_in = '7 elephants' }.not_to raise_error + expect { build.artifacts_expire_in = '7 elephants' }.to raise_error(ChronicDuration::DurationParseError) is_expected.to be_nil end -- cgit v1.2.1