diff options
Diffstat (limited to 'spec/models/ci/job_artifact_spec.rb')
-rw-r--r-- | spec/models/ci/job_artifact_spec.rb | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb index 4cdc74d7a41..17e00533ac3 100644 --- a/spec/models/ci/job_artifact_spec.rb +++ b/spec/models/ci/job_artifact_spec.rb @@ -23,6 +23,14 @@ describe Ci::JobArtifact do subject { build(:ci_job_artifact, :archive, size: 107464) } end + describe '.not_expired' do + it 'returns artifacts that have not expired' do + _expired_artifact = create(:ci_job_artifact, :expired) + + expect(described_class.not_expired).to contain_exactly(artifact) + end + end + describe '.with_reports' do let!(:artifact) { create(:ci_job_artifact, :archive) } @@ -118,6 +126,17 @@ describe Ci::JobArtifact do end end + describe '.downloadable' do + subject { described_class.downloadable } + + it 'filters for downloadable artifacts' do + downloadable_artifact = create(:ci_job_artifact, :codequality) + _not_downloadable_artifact = create(:ci_job_artifact, :trace) + + expect(subject).to contain_exactly(downloadable_artifact) + end + end + describe '.archived_trace_exists_for?' do subject { described_class.archived_trace_exists_for?(job_id) } @@ -357,19 +376,75 @@ describe Ci::JobArtifact do end end + describe 'expired?' do + subject { artifact.expired? } + + context 'when expire_at is nil' do + let(:artifact) { build(:ci_job_artifact, expire_at: nil) } + + it 'returns false' do + is_expected.to be_falsy + end + end + + context 'when expire_at is in the past' do + let(:artifact) { build(:ci_job_artifact, expire_at: Date.yesterday) } + + it 'returns true' do + is_expected.to be_truthy + end + end + + context 'when expire_at is in the future' do + let(:artifact) { build(:ci_job_artifact, expire_at: Date.tomorrow) } + + it 'returns false' do + is_expected.to be_falsey + end + end + end + + describe '#expiring?' do + subject { artifact.expiring? } + + context 'when expire_at is nil' do + let(:artifact) { build(:ci_job_artifact, expire_at: nil) } + + it 'returns false' do + is_expected.to be_falsy + end + end + + context 'when expire_at is in the past' do + let(:artifact) { build(:ci_job_artifact, expire_at: Date.yesterday) } + + it 'returns false' do + is_expected.to be_falsy + end + end + + context 'when expire_at is in the future' do + let(:artifact) { build(:ci_job_artifact, expire_at: Date.tomorrow) } + + it 'returns true' do + is_expected.to be_truthy + end + end + end + describe '#expire_in' do subject { artifact.expire_in } it { is_expected.to be_nil } context 'when expire_at is specified' do - let(:expire_at) { Time.now + 7.days } + let(:expire_at) { Time.current + 7.days } before do artifact.expire_at = expire_at end - it { is_expected.to be_within(5).of(expire_at - Time.now) } + it { is_expected.to be_within(5).of(expire_at - Time.current) } end end |