diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2017-09-19 10:14:06 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-12-03 14:04:47 +0300 |
commit | 25df666156279e5b392b429519b4f4ba01eefaac (patch) | |
tree | 6c1283d937cebb3ee4542e5d7bfc974939eff657 /spec | |
parent | 8ac7f29726989bc0a20ee32780aa18625159f8b4 (diff) |
Create Ci::Artifacts
To allow jobs/builds to have multiple artifacts, and to start seperating
concerns from Ci::Build a new model is created: Ci::Artifact.
Changes include the updating of the ArtifactUploader to adapt to a
slightly different interface. The uploader expects to be initialized
with a `Ci::Build`.
Futher a migration with the minimal fields, the needed foreign keys and
an index.
Last, the way this works is by prepending a module to Ci::Build so we
can basically override behaviour but if needed use `super` to get the
original behaviour.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/artifacts.rb | 22 | ||||
-rw-r--r-- | spec/factories/ci/builds.rb | 27 | ||||
-rw-r--r-- | spec/models/ci/artifact_spec.rb | 60 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 17 |
4 files changed, 89 insertions, 37 deletions
diff --git a/spec/factories/ci/artifacts.rb b/spec/factories/ci/artifacts.rb new file mode 100644 index 00000000000..085e707d686 --- /dev/null +++ b/spec/factories/ci/artifacts.rb @@ -0,0 +1,22 @@ +include ActionDispatch::TestProcess + +FactoryGirl.define do + factory :artifact, class: Ci::Artifact do + project + build factory: :ci_build + + after :create do |artifact| + artifact.file = fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts.zip'), 'application/zip') + artifact.save + end + + factory :artifact_metadata do + type :metadata + + after :create do |artifact| + artifact.file = fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'), 'application/x-gzip') + artifact.save + end + end + end +end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index cf38066dedc..69d58f367ac 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -156,32 +156,13 @@ FactoryGirl.define do trait :artifacts do after(:create) do |build, _| - build.artifacts_file = - fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts.zip'), - 'application/zip') - - build.artifacts_metadata = - fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'), - 'application/x-gzip') - - build.save! + create(:artifact, build: build) + create(:artifact_metadata, build: build) end end - trait :artifacts_expired do - after(:create) do |build, _| - build.artifacts_file = - fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts.zip'), - 'application/zip') - - build.artifacts_metadata = - fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'), - 'application/x-gzip') - - build.artifacts_expire_at = 1.minute.ago - - build.save! - end + trait :expired do + artifacts_expire_at = 1.minute.ago end trait :with_commit do diff --git a/spec/models/ci/artifact_spec.rb b/spec/models/ci/artifact_spec.rb index 438964fd787..5e39f73763b 100644 --- a/spec/models/ci/artifact_spec.rb +++ b/spec/models/ci/artifact_spec.rb @@ -1,5 +1,59 @@ -require 'rails_helper' +require 'spec_helper' -RSpec.describe Artifact, type: :model do - pending "add some examples to (or delete) #{__FILE__}" +describe Ci::Artifact do + it { is_expected.to belong_to(:project) } + it { is_expected.to belong_to(:build) } + + it { is_expected.to respond_to(:file) } + it { is_expected.to respond_to(:created_at) } + it { is_expected.to respond_to(:updated_at) } + it { is_expected.to respond_to(:type) } + + let(:artifact) { create(:artifact) } + + describe '#type' do + it 'defaults to archive' do + expect(artifact.type).to eq("archive") + end + end + + describe '#set_size' do + it 'sets the size' do + expect(artifact.size).to eq(106365) + end + end + + describe '#file' do + subject { artifact.file } + + context 'the uploader api' do + it { is_expected.to respond_to(:store_dir) } + it { is_expected.to respond_to(:cache_dir) } + it { is_expected.to respond_to(:work_dir) } + end + end + + describe '#remove_file' do + it 'removes the file from the database' do + artifact.remove_file! + + expect(artifact.file.exists?).to be_falsy + end + end + + describe '#exists?' do + context 'when the artifact file is present' do + it 'is returns true' do + expect(artifact.exists?).to be(true) + end + end + + context 'when the file has been removed' do + it 'does not exist' do + artifact.remove_file! + + expect(artifact.exists?).to be_falsy + end + end + end end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 1795ee8e9a4..52a3732d0cd 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -23,6 +23,8 @@ describe Ci::Build do it { is_expected.to respond_to(:has_trace?) } it { is_expected.to respond_to(:trace) } + it { is_expected.to be_a(ArtifactMigratable) } + describe 'callbacks' do context 'when running after_create callback' do it 'triggers asynchronous build hooks worker' do @@ -130,33 +132,26 @@ describe Ci::Build do end describe '#artifacts?' do + let(:build) { create(:ci_build, :artifacts) } + subject { build.artifacts? } context 'artifacts archive does not exist' do - before do - build.update_attributes(artifacts_file: nil) - end + let(:build) { create(:ci_build) } it { is_expected.to be_falsy } end context 'artifacts archive exists' do - let(:build) { create(:ci_build, :artifacts) } it { is_expected.to be_truthy } context 'is expired' do - before do - build.update(artifacts_expire_at: Time.now - 7.days) - end + let(:build) { create(:ci_build, :artifacts, :expired) } it { is_expected.to be_falsy } end context 'is not expired' do - before do - build.update(artifacts_expire_at: Time.now + 7.days) - end - it { is_expected.to be_truthy } end end |