Fix filename method of GitlabUploader to return always real filename

This commit is contained in:
Kamil Trzcinski 2017-06-12 23:42:11 +02:00
parent 652eb0118b
commit 05683f313b
3 changed files with 43 additions and 2 deletions

View file

@ -61,6 +61,10 @@ class GitlabUploader < CarrierWave::Uploader::Base
CarrierWave.tmp_path CarrierWave.tmp_path
end end
def filename
super || file&.filename
end
private private
# To prevent files from moving across filesystems, override the default # To prevent files from moving across filesystems, override the default

View file

@ -431,11 +431,32 @@ describe API::Runner do
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
expect(json_response['id']).to eq(test_job.id) expect(json_response['id']).to eq(test_job.id)
expect(json_response['dependencies'].count).to eq(2) expect(json_response['dependencies'].count).to eq(2)
expect(json_response['dependencies']).to include({ 'id' => job.id, 'name' => job.name, 'token' => job.token }, expect(json_response['dependencies']).to include(
{ 'id' => job.id, 'name' => job.name, 'token' => job.token },
{ 'id' => job2.id, 'name' => job2.name, 'token' => job2.token }) { 'id' => job2.id, 'name' => job2.name, 'token' => job2.token })
end end
end end
context 'when pipeline have jobs with artifacts' do
let!(:job) { create(:ci_build_tag, :artifacts, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) }
let!(:test_job) { create(:ci_build, pipeline: pipeline, name: 'deploy', stage: 'deploy', stage_idx: 1) }
before do
job.success
end
it 'returns dependent jobs' do
request_job
expect(response).to have_http_status(201)
expect(json_response['id']).to eq(test_job.id)
expect(json_response['dependencies'].count).to eq(1)
expect(json_response['dependencies']).to include(
{ 'id' => job.id, 'name' => job.name, 'token' => job.token,
'artifacts_file' => { 'filename' => 'ci_build_artifacts.zip', 'size' => 106365 } })
end
end
context 'when explicit dependencies are defined' do context 'when explicit dependencies are defined' do
let!(:job) { create(:ci_build_tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } let!(:job) { create(:ci_build_tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) }
let!(:job2) { create(:ci_build_tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) } let!(:job2) { create(:ci_build_tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) }

View file

@ -42,4 +42,20 @@ describe ArtifactUploader do
it { is_expected.to start_with(path) } it { is_expected.to start_with(path) }
it { is_expected.to end_with('/tmp/work') } it { is_expected.to end_with('/tmp/work') }
end end
describe '#filename' do
# we need to use uploader, as this makes to use mounter
# which initialises uploader.file object
let(:uploader) { job.artifacts_file }
subject { uploader.filename }
it { is_expected.to be_nil }
context 'with artifacts' do
let(:job) { create(:ci_build, :artifacts) }
it { is_expected.not_to be_nil }
end
end
end end