Commit 7e9273dd authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by Phil Hughes

Test controllers if they allow to keep artifacts

parent 304979f8
class Projects::ArtifactsController < Projects::ApplicationController class Projects::ArtifactsController < Projects::ApplicationController
layout 'project' layout 'project'
before_action :authorize_read_build! before_action :authorize_read_build!
before_action :authorize_update_build!, only: [:keep]
before_action :validate_artifacts! before_action :validate_artifacts!
def download def download
......
...@@ -97,6 +97,48 @@ describe "Builds" do ...@@ -97,6 +97,48 @@ describe "Builds" do
end end
end end
context 'Artifacts expire date' do
before do
@build.update_attributes(artifacts_file: artifacts_file, artifacts_expire_at: expire_at)
visit namespace_project_build_path(@project.namespace, @project, @build)
end
context 'no expire date defined' do
let(:expire_at) { nil }
it 'should not have the Keep button' do
page.within('.artifacts') do
expect(page).not_to have_content 'Keep'
end
end
end
context 'when expire date is defined' do
let(:expire_at) { Time.now + 7.days }
it 'should keep artifacts when Keep button is clicked' do
page.within('.artifacts') do
expect(page).to have_content 'The artifacts will be removed'
click_link 'Keep'
end
expect(page).not_to have_link 'Keep'
expect(page).not_to have_content 'The artifacts will be removed'
end
end
context 'when artifacts expired' do
let(:expire_at) { Time.now - 7.days }
it 'should not have the Keep button' do
page.within('.artifacts') do
expect(page).to have_content 'The artifacts were removed'
expect(page).not_to have_link 'Keep'
end
end
end
end
context 'Build raw trace' do context 'Build raw trace' do
before do before do
@build.run! @build.run!
...@@ -108,6 +150,8 @@ describe "Builds" do ...@@ -108,6 +150,8 @@ describe "Builds" do
expect(page).to have_link 'Raw' expect(page).to have_link 'Raw'
end end
end end
context ''
end end
describe "POST /:project/builds/:id/cancel" do describe "POST /:project/builds/:id/cancel" do
......
...@@ -397,9 +397,32 @@ describe Ci::Build, models: true do ...@@ -397,9 +397,32 @@ describe Ci::Build, models: true do
context 'artifacts archive exists' do context 'artifacts archive exists' do
let(:build) { create(:ci_build, :artifacts) } let(:build) { create(:ci_build, :artifacts) }
it { is_expected.to be_truthy } 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 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 describe '#artifacts_metadata?' do
subject { build.artifacts_metadata? } subject { build.artifacts_metadata? }
...@@ -412,7 +435,6 @@ describe Ci::Build, models: true do ...@@ -412,7 +435,6 @@ describe Ci::Build, models: true do
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
end end
describe '#repo_url' do describe '#repo_url' do
let(:build) { create(:ci_build) } let(:build) { create(:ci_build) }
let(:project) { build.project } let(:project) { build.project }
...@@ -427,6 +449,47 @@ describe Ci::Build, models: true do ...@@ -427,6 +449,47 @@ describe Ci::Build, models: true do
it { is_expected.to include(project.web_url[7..-1]) } it { is_expected.to include(project.web_url[7..-1]) }
end 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 describe '#depends_on_builds' do
let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') } 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') } let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment