diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-07-16 17:55:41 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-07-16 17:55:41 +0900 |
commit | 14821f3babcc210bc52e4e825adc8333752fbc88 (patch) | |
tree | a1e53d138f3e5e01686d38a37d155754cc2e0356 | |
parent | 882faeab57ab39d18f72abd9b65d286db92e1011 (diff) | |
download | gitlab-ce-14821f3babcc210bc52e4e825adc8333752fbc88.tar.gz |
Add spec for file format. Add spec for config_artifacts
-rw-r--r-- | app/presenters/ci/build_presenter.rb | 20 | ||||
-rw-r--r-- | spec/models/ci/job_artifact_spec.rb | 24 | ||||
-rw-r--r-- | spec/presenters/ci/build_presenter_spec.rb | 36 |
3 files changed, 70 insertions, 10 deletions
diff --git a/app/presenters/ci/build_presenter.rb b/app/presenters/ci/build_presenter.rb index 690380cbfaf..a83135ed3f9 100644 --- a/app/presenters/ci/build_presenter.rb +++ b/app/presenters/ci/build_presenter.rb @@ -44,6 +44,16 @@ module Ci list.flatten end + private + + def tooltip_for_badge + detailed_status.badge_tooltip.capitalize + end + + def detailed_status + @detailed_status ||= subject.detailed_status(user) + end + def config_artifacts_archive(artifacts) artifacts.merge(type: :archive, format: :zip) end @@ -59,15 +69,5 @@ module Ci def config_artifacts_reports_junit(junit) { paths: junit, type: :junit, format: :gzip } end - - private - - def tooltip_for_badge - detailed_status.badge_tooltip.capitalize - end - - def detailed_status - @detailed_status ||= subject.detailed_status(user) - end end end diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb index 0fd7612c011..594211c288f 100644 --- a/spec/models/ci/job_artifact_spec.rb +++ b/spec/models/ci/job_artifact_spec.rb @@ -87,6 +87,30 @@ describe Ci::JobArtifact do end end + describe 'validates file format' do + subject { artifact.valid? } + + let(:artifact) { build(:ci_job_artifact, file_format: file_format) } + + context 'when file format is present' do + let(:file_format) { :raw } + + it { is_expected.to be_truthy } + end + + context 'when file format is not defined' do + let(:file_format) { :new_format } + + it { expect { subject }.to raise_error(ArgumentError) } + end + + context 'when file format is not present' do + let(:file_format) { nil } + + it { is_expected.to be_falsy } + end + end + describe '#file' do subject { artifact.file } diff --git a/spec/presenters/ci/build_presenter_spec.rb b/spec/presenters/ci/build_presenter_spec.rb index 6dfaa3b72f7..78d00c4e14a 100644 --- a/spec/presenters/ci/build_presenter_spec.rb +++ b/spec/presenters/ci/build_presenter_spec.rb @@ -252,4 +252,40 @@ describe Ci::BuildPresenter do end end end + + describe '#config_artifacts' do + context "when config has 'artifacts' keyword" do + let(:build) { create(:ci_build, options: { artifacts: { paths: ['sample.txt'] } } ) } + + it 'presents artifacts hash' do + expect(presenter.config_artifacts).to include({ type: :archive, format: :zip, paths: ['sample.txt'] }) + end + end + + context "when config has 'junit' keyword" do + let(:build) { create(:ci_build, options: { artifacts: { reports: { junit: ['junit.xml'] } } } ) } + + it 'presents artifacts hash' do + expect(presenter.config_artifacts).to include({ type: :junit, format: :gzip, paths: ['junit.xml'] }) + end + end + + context "when config has all artifact keywords" do + let(:build) { create(:ci_build, options: { script: 'echo', artifacts: { paths: ['sample.txt'], reports: { junit: ['junit.xml'] } } } ) } + + it 'presents artifacts hash' do + expect(presenter.config_artifacts).to include( + { type: :junit, format: :gzip, paths: ['junit.xml'] }, + { type: :archive, format: :zip, paths: ['sample.txt'] }) + end + end + + context "when config has no artifact keywords" do + let(:build) { create(:ci_build, :no_options) } + + it 'presents empty artifacts hash' do + expect(presenter.config_artifacts).to eq([]) + end + end + end end |