diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-01-20 23:49:26 +0300 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-02-01 01:53:57 +0300 |
commit | c4c8ca04052aaf7d37c2335066381b536df68427 (patch) | |
tree | 1f0187a87053be2390670548e96050f65496ee6f /spec/services | |
parent | 6e70870a2e80ea092f8528f727753184eb3265fb (diff) |
Added support for zip archives in pages
The ZIP archive size is calculated from artifacts metadata that should get uploaded for new artifacts
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/projects/update_pages_worker_spec.rb | 74 |
1 files changed, 42 insertions, 32 deletions
diff --git a/spec/services/projects/update_pages_worker_spec.rb b/spec/services/projects/update_pages_worker_spec.rb index 0607c025b9e..68e66866340 100644 --- a/spec/services/projects/update_pages_worker_spec.rb +++ b/spec/services/projects/update_pages_worker_spec.rb @@ -4,9 +4,7 @@ describe Projects::UpdatePagesService do let(:project) { create :project } let(:commit) { create :ci_commit, project: project, sha: project.commit('HEAD').sha } let(:build) { create :ci_build, commit: commit, ref: 'HEAD' } - let(:file) { fixture_file_upload(Rails.root + 'spec/fixtures/pages.tar.gz', 'application/octet-stream') } - let(:empty_file) { fixture_file_upload(Rails.root + 'spec/fixtures/pages_empty.tar.gz', 'application/octet-stream') } - let(:invalid_file) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'application/octet-stream') } + let(:invalid_file) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png') } subject { described_class.new(project, build) } @@ -14,27 +12,50 @@ describe Projects::UpdatePagesService do project.remove_pages end - context 'for valid file' do - before { build.update_attributes(artifacts_file: file) } + %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" + fixture_file_upload(filename) if File.exists?(filename) + end - it 'succeeds' do - expect(project.pages_url).to be_nil - expect(execute).to eq(:success) - expect(project.pages_url).to_not be_nil - end + before do + build.update_attributes(artifacts_file: file) + build.update_attributes(artifacts_metadata: metadata) + end - it 'limits pages size' do - stub_application_setting(max_pages_size: 1) - expect(execute).to_not eq(:success) - end + it 'succeeds' do + expect(project.pages_url).to be_nil + expect(execute).to eq(:success) + expect(project.pages_url).to_not be_nil + end + + it 'limits pages size' do + stub_application_setting(max_pages_size: 1) + expect(execute).to_not eq(:success) + end - it 'removes pages after destroy' do - expect(PagesWorker).to receive(:perform_in) - expect(project.pages_url).to be_nil - expect(execute).to eq(:success) - expect(project.pages_url).to_not be_nil - project.destroy - expect(Dir.exist?(project.public_pages_path)).to be_falsey + it 'removes pages after destroy' do + expect(PagesWorker).to receive(:perform_in) + expect(project.pages_url).to be_nil + expect(execute).to eq(:success) + expect(project.pages_url).to_not be_nil + project.destroy + expect(Dir.exist?(project.public_pages_path)).to be_falsey + end + + it 'fails if sha on branch is not latest' do + commit.update_attributes(sha: 'old_sha') + build.update_attributes(artifacts_file: file) + expect(execute).to_not eq(:success) + end + + it 'fails for empty file fails' do + build.update_attributes(artifacts_file: empty_file) + expect(execute).to_not eq(:success) + end end end @@ -48,21 +69,10 @@ describe Projects::UpdatePagesService do expect(execute).to_not eq(:success) end - it 'fails for empty file fails' do - build.update_attributes(artifacts_file: empty_file) - expect(execute).to_not eq(:success) - end - it 'fails for invalid archive' do build.update_attributes(artifacts_file: invalid_file) expect(execute).to_not eq(:success) end - - it 'fails if sha on branch is not latest' do - commit.update_attributes(sha: 'old_sha') - build.update_attributes(artifacts_file: file) - expect(execute).to_not eq(:success) - end def execute subject.execute[:status] |