2015-11-03 15:28:07 -05:00
|
|
|
require "spec_helper"
|
|
|
|
|
2016-01-15 06:21:52 -05:00
|
|
|
describe Projects::UpdatePagesService do
|
2015-11-03 15:28:07 -05:00
|
|
|
let(:project) { create :project }
|
2016-06-07 10:40:15 -04:00
|
|
|
let(:pipeline) { create :ci_pipeline, project: project, sha: project.commit('HEAD').sha }
|
|
|
|
let(:build) { create :ci_build, pipeline: pipeline, ref: 'HEAD' }
|
2016-01-20 15:49:26 -05:00
|
|
|
let(:invalid_file) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png') }
|
2016-05-13 06:51:52 -04:00
|
|
|
|
2016-01-15 06:21:52 -05:00
|
|
|
subject { described_class.new(project, build) }
|
2015-11-03 15:28:07 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.remove_pages
|
|
|
|
end
|
|
|
|
|
2016-01-20 15:49:26 -05:00
|
|
|
%w(tar.gz zip).each do |format|
|
|
|
|
context "for valid #{format}" do
|
|
|
|
let(:file) { fixture_file_upload(Rails.root + "spec/fixtures/pages.#{format}") }
|
|
|
|
let(:empty_file) { fixture_file_upload(Rails.root + "spec/fixtures/pages_empty.#{format}") }
|
|
|
|
let(:metadata) do
|
|
|
|
filename = Rails.root + "spec/fixtures/pages.#{format}.meta"
|
2016-05-13 06:51:52 -04:00
|
|
|
fixture_file_upload(filename) if File.exist?(filename)
|
2016-01-20 15:49:26 -05:00
|
|
|
end
|
2015-11-03 15:28:07 -05:00
|
|
|
|
2016-01-20 15:49:26 -05:00
|
|
|
before do
|
|
|
|
build.update_attributes(artifacts_file: file)
|
|
|
|
build.update_attributes(artifacts_metadata: metadata)
|
|
|
|
end
|
2015-11-03 15:28:07 -05:00
|
|
|
|
2017-03-06 03:49:38 -05:00
|
|
|
describe 'pages artifacts' do
|
2017-03-05 17:14:02 -05:00
|
|
|
context 'with expiry date' do
|
|
|
|
before do
|
|
|
|
build.artifacts_expire_in = "2 days"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't delete artifacts" do
|
|
|
|
expect(execute).to eq(:success)
|
2017-03-06 03:49:38 -05:00
|
|
|
|
2017-03-05 17:14:02 -05:00
|
|
|
expect(build.reload.artifacts_file?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without expiry date' do
|
|
|
|
it "does delete artifacts" do
|
|
|
|
expect(execute).to eq(:success)
|
2017-03-06 03:49:38 -05:00
|
|
|
|
2017-03-05 17:14:02 -05:00
|
|
|
expect(build.reload.artifacts_file?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-20 15:49:26 -05:00
|
|
|
it 'succeeds' do
|
2016-02-19 14:12:56 -05:00
|
|
|
expect(project.pages_deployed?).to be_falsey
|
2016-01-20 15:49:26 -05:00
|
|
|
expect(execute).to eq(:success)
|
2016-02-19 14:12:56 -05:00
|
|
|
expect(project.pages_deployed?).to be_truthy
|
2016-01-20 15:49:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'limits pages size' do
|
|
|
|
stub_application_setting(max_pages_size: 1)
|
2016-05-30 04:11:46 -04:00
|
|
|
expect(execute).not_to eq(:success)
|
2016-01-20 15:49:26 -05:00
|
|
|
end
|
2015-11-03 15:28:07 -05:00
|
|
|
|
2016-01-20 15:49:26 -05:00
|
|
|
it 'removes pages after destroy' do
|
|
|
|
expect(PagesWorker).to receive(:perform_in)
|
2016-02-19 14:12:56 -05:00
|
|
|
expect(project.pages_deployed?).to be_falsey
|
2016-01-20 15:49:26 -05:00
|
|
|
expect(execute).to eq(:success)
|
2016-02-19 14:12:56 -05:00
|
|
|
expect(project.pages_deployed?).to be_truthy
|
2016-01-20 15:49:26 -05:00
|
|
|
project.destroy
|
2016-02-19 14:12:56 -05:00
|
|
|
expect(project.pages_deployed?).to be_falsey
|
2016-01-20 15:49:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails if sha on branch is not latest' do
|
2016-06-07 10:40:15 -04:00
|
|
|
pipeline.update_attributes(sha: 'old_sha')
|
2016-01-20 15:49:26 -05:00
|
|
|
build.update_attributes(artifacts_file: file)
|
2016-05-30 04:11:46 -04:00
|
|
|
expect(execute).not_to eq(:success)
|
2016-01-20 15:49:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails for empty file fails' do
|
|
|
|
build.update_attributes(artifacts_file: empty_file)
|
2016-05-30 04:11:46 -04:00
|
|
|
expect(execute).not_to eq(:success)
|
2016-01-20 15:49:26 -05:00
|
|
|
end
|
2015-11-03 15:28:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-18 07:07:53 -05:00
|
|
|
it 'fails to remove project pages when no pages is deployed' do
|
2016-05-30 04:11:46 -04:00
|
|
|
expect(PagesWorker).not_to receive(:perform_in)
|
2016-02-19 14:12:56 -05:00
|
|
|
expect(project.pages_deployed?).to be_falsey
|
2015-12-18 07:07:53 -05:00
|
|
|
project.destroy
|
|
|
|
end
|
|
|
|
|
2015-11-03 15:28:07 -05:00
|
|
|
it 'fails if no artifacts' do
|
2016-05-30 04:11:46 -04:00
|
|
|
expect(execute).not_to eq(:success)
|
2015-11-03 15:28:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails for invalid archive' do
|
|
|
|
build.update_attributes(artifacts_file: invalid_file)
|
2016-05-30 04:11:46 -04:00
|
|
|
expect(execute).not_to eq(:success)
|
2015-11-03 15:28:07 -05:00
|
|
|
end
|
2016-05-13 06:51:52 -04:00
|
|
|
|
2016-01-15 06:21:52 -05:00
|
|
|
def execute
|
|
|
|
subject.execute[:status]
|
2015-11-03 15:28:07 -05:00
|
|
|
end
|
|
|
|
end
|