diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-06-10 16:20:11 +0200 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-06-13 11:07:23 +0100 |
commit | 7e9273dd946f46b2b2bcc0a751316dc704089a16 (patch) | |
tree | 574e3db48d3797384fad50a710e00b4a54f88898 /spec/models | |
parent | 304979f89777f4aca52b382fdbe3a593dc7e50f3 (diff) | |
download | gitlab-ce-7e9273dd946f46b2b2bcc0a751316dc704089a16.tar.gz |
Test controllers if they allow to keep artifacts
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/build_spec.rb | 65 |
1 files changed, 64 insertions, 1 deletions
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') } |