2019-10-14 23:06:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-18 10:31:44 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AvatarUploader do
|
2018-02-02 08:59:43 -05:00
|
|
|
let(:model) { build_stubbed(:user) }
|
|
|
|
let(:uploader) { described_class.new(model, :avatar) }
|
|
|
|
let(:upload) { create(:upload, model: model) }
|
2016-08-18 10:31:44 -04:00
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
subject { uploader }
|
2017-06-07 23:32:38 -04:00
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
it_behaves_like 'builds correct paths',
|
|
|
|
store_dir: %r[uploads/-/system/user/avatar/],
|
|
|
|
upload_path: %r[uploads/-/system/user/avatar/],
|
|
|
|
absolute_path: %r[#{CarrierWave.root}/uploads/-/system/user/avatar/]
|
2017-06-07 23:32:38 -04:00
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
context "object_store is REMOTE" do
|
|
|
|
before do
|
|
|
|
stub_uploads_object_storage
|
2016-08-18 10:31:44 -04:00
|
|
|
end
|
2018-02-02 08:59:43 -05:00
|
|
|
|
|
|
|
include_context 'with storage', described_class::Store::REMOTE
|
|
|
|
|
|
|
|
it_behaves_like 'builds correct paths',
|
|
|
|
store_dir: %r[user/avatar/],
|
|
|
|
upload_path: %r[user/avatar/]
|
2016-08-18 10:31:44 -04:00
|
|
|
end
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
context "with a file" do
|
|
|
|
let(:project) { create(:project, :with_avatar) }
|
|
|
|
let(:uploader) { project.avatar }
|
|
|
|
let(:upload) { uploader.upload }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_uploads_object_storage
|
2016-08-18 10:31:44 -04:00
|
|
|
end
|
2018-02-02 08:59:43 -05:00
|
|
|
|
|
|
|
it_behaves_like "migrates", to_store: described_class::Store::REMOTE
|
|
|
|
it_behaves_like "migrates", from_store: described_class::Store::REMOTE, to_store: described_class::Store::LOCAL
|
2018-09-10 11:41:51 -04:00
|
|
|
|
|
|
|
it 'sets the right absolute path' do
|
|
|
|
storage_path = Gitlab.config.uploads.storage_path
|
|
|
|
absolute_path = File.join(storage_path, upload.path)
|
|
|
|
|
|
|
|
expect(uploader.absolute_path.scan(storage_path).size).to eq(1)
|
|
|
|
expect(uploader.absolute_path).to eq(absolute_path)
|
|
|
|
end
|
2016-08-18 10:31:44 -04:00
|
|
|
end
|
2020-01-02 16:07:38 -05:00
|
|
|
|
|
|
|
context 'upload type check' do
|
|
|
|
AvatarUploader::SAFE_IMAGE_EXT.each do |ext|
|
|
|
|
context "#{ext} extension" do
|
|
|
|
it_behaves_like 'type checked uploads', filenames: "image.#{ext}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'skip image/svg+xml integrity check' do
|
|
|
|
it_behaves_like 'skipped type checked uploads', filenames: 'image.svg'
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 10:31:44 -04:00
|
|
|
end
|