Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2017-02-28 21:34:43 +0300
committerRobert Speicher <rspeicher@gmail.com>2017-03-06 22:41:10 +0300
commit5c41338fa30b5795309957c71202b11a71cccef0 (patch)
tree5115c177c3abe55fe1e71208fa46a5cec201291f /spec/uploaders/file_uploader_spec.rb
parentc4c2ac10d0997dd4e7bc958bca6052144a58839e (diff)
Handle relative and absolute Upload paths in the Uploaders
Diffstat (limited to 'spec/uploaders/file_uploader_spec.rb')
-rw-r--r--spec/uploaders/file_uploader_spec.rb21
1 files changed, 21 insertions, 0 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