summaryrefslogtreecommitdiff
path: root/spec/uploaders
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2017-02-28 13:34:43 -0500
committerRobert Speicher <rspeicher@gmail.com>2017-03-06 14:41:10 -0500
commit5c41338fa30b5795309957c71202b11a71cccef0 (patch)
tree5115c177c3abe55fe1e71208fa46a5cec201291f /spec/uploaders
parentc4c2ac10d0997dd4e7bc958bca6052144a58839e (diff)
downloadgitlab-ce-5c41338fa30b5795309957c71202b11a71cccef0.tar.gz
Handle relative and absolute Upload paths in the Uploaders
Diffstat (limited to 'spec/uploaders')
-rw-r--r--spec/uploaders/file_uploader_spec.rb21
-rw-r--r--spec/uploaders/records_uploads_spec.rb8
2 files changed, 25 insertions, 4 deletions
diff --git a/spec/uploaders/file_uploader_spec.rb b/spec/uploaders/file_uploader_spec.rb
index 396b0abdaef..d9113ef4095 100644
--- a/spec/uploaders/file_uploader_spec.rb
+++ b/spec/uploaders/file_uploader_spec.rb
@@ -3,6 +3,18 @@ require 'spec_helper'
describe FileUploader do
let(:uploader) { described_class.new(build_stubbed(:empty_project)) }
+ describe '.absolute_path' do
+ it 'returns the correct absolute path by building it dynamically' do
+ project = build_stubbed(:project)
+ upload = double(model: project, path: 'secret/foo.jpg')
+
+ dynamic_segment = project.path_with_namespace
+
+ expect(described_class.absolute_path(upload))
+ .to end_with("#{dynamic_segment}/secret/foo.jpg")
+ end
+ end
+
describe 'initialize' do
it 'generates a secret if none is provided' do
expect(SecureRandom).to receive(:hex).and_return('secret')
@@ -32,4 +44,13 @@ describe FileUploader do
expect(uploader.move_to_store).to eq(true)
end
end
+
+ describe '#relative_path' do
+ it 'removes the leading dynamic path segment' do
+ fixture = Rails.root.join('spec', 'fixtures', 'rails_sample.jpg')
+ uploader.store!(fixture_file_upload(fixture))
+
+ expect(uploader.relative_path).to match(/\A\h{32}\/rails_sample.jpg\z/)
+ end
+ end
end
diff --git a/spec/uploaders/records_uploads_spec.rb b/spec/uploaders/records_uploads_spec.rb
index a104dc4257f..5c26e334a6e 100644
--- a/spec/uploaders/records_uploads_spec.rb
+++ b/spec/uploaders/records_uploads_spec.rb
@@ -2,7 +2,7 @@ require 'rails_helper'
describe RecordsUploads do
let(:uploader) do
- example_uploader = Class.new(GitlabUploader) do
+ class RecordsUploadsExampleUploader < GitlabUploader
include RecordsUploads
storage :file
@@ -12,7 +12,7 @@ describe RecordsUploads do
end
end
- example_uploader.new
+ RecordsUploadsExampleUploader.new
end
def upload_fixture(filename)
@@ -59,10 +59,10 @@ describe RecordsUploads do
it 'it destroys Upload records at the same path before recording' do
existing = Upload.create!(
- path: File.join(CarrierWave.root, 'uploads', 'rails_sample.jpg'),
+ path: File.join('uploads', 'rails_sample.jpg'),
size: 512.kilobytes,
model: build_stubbed(:user),
- uploader: described_class.to_s
+ uploader: uploader.class.to_s
)
uploader.store!(upload_fixture('rails_sample.jpg'))