debian-mirror-gitlab/spec/uploaders/file_uploader_spec.rb

67 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

2016-08-24 12:49:21 +05:30
require 'spec_helper'
describe FileUploader do
2017-09-10 17:25:29 +05:30
let(:uploader) { described_class.new(build_stubbed(:project)) }
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
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
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
describe "#store_dir" do
it "stores in the namespace path" do
2017-09-10 17:25:29 +05:30
project = build_stubbed(:project)
2017-08-17 22:00:37 +05:30
uploader = described_class.new(project)
expect(uploader.store_dir).to include(project.path_with_namespace)
expect(uploader.store_dir).not_to include("system")
end
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
describe 'initialize' do
it 'generates a secret if none is provided' do
expect(SecureRandom).to receive(:hex).and_return('secret')
uploader = described_class.new(double)
expect(uploader.secret).to eq 'secret'
end
it 'accepts a secret parameter' do
expect(SecureRandom).not_to receive(:hex)
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
uploader = described_class.new(double, 'secret')
expect(uploader.secret).to eq 'secret'
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
end
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
describe '#move_to_cache' do
it 'is true' do
expect(uploader.move_to_cache).to eq(true)
end
end
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
describe '#move_to_store' do
it 'is true' do
expect(uploader.move_to_store).to eq(true)
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
end
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
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))
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
expect(uploader.relative_path).to match(/\A\h{32}\/rails_sample.jpg\z/)
2016-08-24 12:49:21 +05:30
end
end
end