From 60e0137c864e26fee0120dc4447bb95acc46ce51 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 14 Jun 2016 11:38:34 +0200 Subject: Fix specs --- lib/api/builds.rb | 2 +- spec/features/builds_spec.rb | 16 ++++--------- spec/models/build_spec.rb | 6 +++-- spec/workers/expire_build_artifacts_worker_spec.rb | 28 ++++++++++++++-------- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lib/api/builds.rb b/lib/api/builds.rb index 644e5a2a99d..645e2dda0b7 100644 --- a/lib/api/builds.rb +++ b/lib/api/builds.rb @@ -184,7 +184,7 @@ module API status 200 present build, with: Entities::Build, - user_can_download_artifacts: can?(current_user, :read_build, user_project) + user_can_download_artifacts: can?(current_user, :read_build, user_project) end end diff --git a/spec/features/builds_spec.rb b/spec/features/builds_spec.rb index 0fd95295388..16832c297ac 100644 --- a/spec/features/builds_spec.rb +++ b/spec/features/builds_spec.rb @@ -107,9 +107,7 @@ describe "Builds" do let(:expire_at) { nil } it 'does not have the Keep button' do - page.within('.artifacts') do - expect(page).not_to have_content 'Keep' - end + expect(page).not_to have_content 'Keep' end end @@ -117,10 +115,8 @@ describe "Builds" do let(:expire_at) { Time.now + 7.days } it 'keeps 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).to have_content 'The artifacts will be removed' + click_link 'Keep' expect(page).not_to have_link 'Keep' expect(page).not_to have_content 'The artifacts will be removed' @@ -131,10 +127,8 @@ describe "Builds" do let(:expire_at) { Time.now - 7.days } it 'does 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 + expect(page).to have_content 'The artifacts were removed' + expect(page).not_to have_link 'Keep' end end end diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index c07832a4b5f..35554e1e0c0 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -415,12 +415,14 @@ describe Ci::Build, models: true do context 'is expired' do before { build.update(artifacts_expire_at: Time.now - 7.days) } - it { is_expected.to be_falsy } + + it { is_expected.to be_truthy } end context 'is not expired' do before { build.update(artifacts_expire_at: Time.now + 7.days) } - it { is_expected.to be_truthy } + + it { is_expected.to be_falsey } end end diff --git a/spec/workers/expire_build_artifacts_worker_spec.rb b/spec/workers/expire_build_artifacts_worker_spec.rb index eb8afb20275..e3827cae9a6 100644 --- a/spec/workers/expire_build_artifacts_worker_spec.rb +++ b/spec/workers/expire_build_artifacts_worker_spec.rb @@ -11,37 +11,45 @@ describe ExpireBuildArtifactsWorker do subject! { worker.perform } context 'with expired artifacts' do - let!(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now - 7.days) } + let(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now - 7.days) } it 'does expire' do expect(build.reload.artifacts_expired?).to be_truthy end + + it 'does remove files' do + expect(build.reload.artifacts_file.exists?).to be_falsey + end end context 'with not yet expired artifacts' do - let!(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now + 7.days) } + let(:build) { create(:ci_build, :artifacts, artifacts_expire_at: Time.now + 7.days) } it 'does not expire' do - expect(build.reload.artifacts_expired?).to be_truthy + expect(build.reload.artifacts_expired?).to be_falsey + end + + it 'does not remove files' do + expect(build.reload.artifacts_file.exists?).to be_truthy end end context 'without expire date' do - let!(:build) { create(:ci_build, :artifacts) } + let(:build) { create(:ci_build, :artifacts) } it 'does not expire' do expect(build.reload.artifacts_expired?).to be_falsey end + + it 'does not remove files' do + expect(build.reload.artifacts_file.exists?).to be_truthy + end end context 'for expired artifacts' do - let!(:build) { create(:ci_build, artifacts_expire_at: Time.now - 7.days) } + let(:build) { create(:ci_build, artifacts_expire_at: Time.now - 7.days) } - it 'does not erase artifacts' do - expect_any_instance_of(Ci::Build).not_to have_received(:erase_artifacts!) - end - - it 'does expire' do + it 'is still expired' do expect(build.reload.artifacts_expired?).to be_truthy end end -- cgit v1.2.1