gitlab-org--gitlab-foss/spec/lib/gitlab/background_migration/populate_untracked_uploads_...

525 lines
19 KiB
Ruby
Raw Normal View History

2017-11-08 03:08:02 +00:00
require 'spec_helper'
# This migration is using UploadService, which sets uploads.secret that is only
# added to the DB schema in 20180129193323. Since the test isn't isolated, we
# just use the latest schema when testing this migration.
# Ideally, the test should not use factories nor UploadService, and rely on the
# `table` helper instead.
describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :sidekiq, :migration, schema: 20180129193323 do
2017-11-15 07:15:30 +00:00
include TrackUntrackedUploadsHelpers
subject { described_class.new }
let!(:untracked_files_for_uploads) { described_class::UntrackedFile }
let!(:uploads) { described_class::Upload }
2017-11-08 03:08:02 +00:00
before do
2017-12-06 20:20:06 +00:00
DatabaseCleaner.clean
drop_temp_table_if_exists
ensure_temporary_tracking_table_exists
2017-12-06 20:20:06 +00:00
uploads.delete_all
end
after(:all) do
drop_temp_table_if_exists
end
context 'with untracked files and tracked files in untracked_files_for_uploads' do
let!(:appearance) { create_or_update_appearance(logo: uploaded_file, header_logo: uploaded_file) }
2017-11-15 07:15:30 +00:00
let!(:user1) { create(:user, :with_avatar) }
let!(:user2) { create(:user, :with_avatar) }
2017-12-01 13:58:49 +00:00
let!(:project1) { create(:project, :legacy_storage, :with_avatar) }
let!(:project2) { create(:project, :legacy_storage, :with_avatar) }
2017-11-08 03:08:02 +00:00
2017-11-15 07:15:30 +00:00
before do
2017-11-08 03:08:02 +00:00
UploadService.new(project1, uploaded_file, FileUploader).execute # Markdown upload
UploadService.new(project2, uploaded_file, FileUploader).execute # Markdown upload
# File records created by PrepareUntrackedUploads
2017-11-15 07:15:30 +00:00
untracked_files_for_uploads.create!(path: appearance.uploads.first.path)
untracked_files_for_uploads.create!(path: appearance.uploads.last.path)
untracked_files_for_uploads.create!(path: user1.uploads.first.path)
untracked_files_for_uploads.create!(path: user2.uploads.first.path)
untracked_files_for_uploads.create!(path: project1.uploads.first.path)
untracked_files_for_uploads.create!(path: project2.uploads.first.path)
untracked_files_for_uploads.create!(path: "#{Gitlab::BackgroundMigration::PrepareUntrackedUploads::RELATIVE_UPLOAD_DIR}/#{project1.full_path}/#{project1.uploads.last.path}")
untracked_files_for_uploads.create!(path: "#{Gitlab::BackgroundMigration::PrepareUntrackedUploads::RELATIVE_UPLOAD_DIR}/#{project2.full_path}/#{project2.uploads.last.path}")
2017-11-08 03:08:02 +00:00
2017-11-15 07:15:30 +00:00
# Untrack 4 files
2017-11-08 03:08:02 +00:00
user2.uploads.delete_all
2017-11-15 07:15:30 +00:00
project2.uploads.delete_all # 2 files: avatar and a Markdown upload
appearance.uploads.where("path like '%header_logo%'").delete_all
2017-11-08 03:08:02 +00:00
end
it 'adds untracked files to the uploads table' do
expect do
2017-12-01 13:58:49 +00:00
subject.perform(1, untracked_files_for_uploads.reorder(:id).last.id)
2017-11-08 03:08:02 +00:00
end.to change { uploads.count }.from(4).to(8)
expect(user2.uploads.count).to eq(1)
expect(project2.uploads.count).to eq(2)
expect(appearance.uploads.count).to eq(2)
end
it 'deletes rows after processing them' do
expect(subject).to receive(:drop_temp_table_if_finished) # Don't drop the table so we can look at it
2017-11-08 04:38:17 +00:00
expect do
2017-12-05 18:43:08 +00:00
subject.perform(1, untracked_files_for_uploads.last.id)
end.to change { untracked_files_for_uploads.count }.from(8).to(0)
2017-11-08 04:38:17 +00:00
end
2017-11-08 03:08:02 +00:00
it 'does not create duplicate uploads of already tracked files' do
2017-12-05 18:43:08 +00:00
subject.perform(1, untracked_files_for_uploads.last.id)
2017-11-08 03:08:02 +00:00
expect(user1.uploads.count).to eq(1)
expect(project1.uploads.count).to eq(2)
expect(appearance.uploads.count).to eq(2)
end
2017-11-08 04:38:17 +00:00
it 'uses the start and end batch ids [only 1st half]' do
2017-11-27 04:57:51 +00:00
ids = untracked_files_for_uploads.all.order(:id).pluck(:id)
start_id = ids[0]
end_id = ids[3]
2017-11-08 04:38:17 +00:00
expect do
subject.perform(start_id, end_id)
2017-11-08 04:38:17 +00:00
end.to change { uploads.count }.from(4).to(6)
expect(user1.uploads.count).to eq(1)
expect(user2.uploads.count).to eq(1)
expect(appearance.uploads.count).to eq(2)
expect(project1.uploads.count).to eq(2)
expect(project2.uploads.count).to eq(0)
# Only 4 have been either confirmed or added to uploads
expect(untracked_files_for_uploads.count).to eq(4)
2017-11-08 04:38:17 +00:00
end
it 'uses the start and end batch ids [only 2nd half]' do
2017-11-27 04:57:51 +00:00
ids = untracked_files_for_uploads.all.order(:id).pluck(:id)
start_id = ids[4]
end_id = ids[7]
2017-11-08 04:38:17 +00:00
expect do
subject.perform(start_id, end_id)
2017-11-08 04:38:17 +00:00
end.to change { uploads.count }.from(4).to(6)
expect(user1.uploads.count).to eq(1)
expect(user2.uploads.count).to eq(0)
expect(appearance.uploads.count).to eq(1)
expect(project1.uploads.count).to eq(2)
expect(project2.uploads.count).to eq(2)
# Only 4 have been either confirmed or added to uploads
expect(untracked_files_for_uploads.count).to eq(4)
2017-11-08 04:38:17 +00:00
end
it 'does not drop the temporary tracking table after processing the batch, if there are still untracked rows' do
subject.perform(1, untracked_files_for_uploads.last.id - 1)
expect(ActiveRecord::Base.connection.table_exists?(:untracked_files_for_uploads)).to be_truthy
end
it 'drops the temporary tracking table after processing the batch, if there are no untracked rows left' do
subject.perform(1, untracked_files_for_uploads.last.id)
expect(ActiveRecord::Base.connection.table_exists?(:untracked_files_for_uploads)).to be_falsey
end
it 'does not block a whole batch because of one bad path' do
untracked_files_for_uploads.create!(path: "#{Gitlab::BackgroundMigration::PrepareUntrackedUploads::RELATIVE_UPLOAD_DIR}/#{project2.full_path}/._7d37bf4c747916390e596744117d5d1a")
expect(untracked_files_for_uploads.count).to eq(9)
expect(uploads.count).to eq(4)
subject.perform(1, untracked_files_for_uploads.last.id)
expect(untracked_files_for_uploads.count).to eq(1)
expect(uploads.count).to eq(8)
end
it 'an unparseable path is shown in error output' do
bad_path = "#{Gitlab::BackgroundMigration::PrepareUntrackedUploads::RELATIVE_UPLOAD_DIR}/#{project2.full_path}/._7d37bf4c747916390e596744117d5d1a"
untracked_files_for_uploads.create!(path: bad_path)
expect(Rails.logger).to receive(:error).with(/Error parsing path "#{bad_path}":/)
subject.perform(1, untracked_files_for_uploads.last.id)
end
2017-11-08 03:08:02 +00:00
end
context 'with no untracked files' do
it 'does not add to the uploads table (and does not raise error)' do
expect do
subject.perform(1, 1000)
2017-11-08 03:08:02 +00:00
end.not_to change { uploads.count }.from(0)
end
end
2017-11-24 07:12:24 +00:00
describe 'upload outcomes for each path pattern' do
shared_examples_for 'non_markdown_file' do
2017-11-15 07:15:30 +00:00
let!(:expected_upload_attrs) { model.uploads.first.attributes.slice('path', 'uploader', 'size', 'checksum') }
2017-11-24 07:12:24 +00:00
let!(:untracked_file) { untracked_files_for_uploads.create!(path: expected_upload_attrs['path']) }
2017-11-08 03:08:02 +00:00
before do
model.uploads.delete_all
2017-11-08 03:08:02 +00:00
end
it 'creates an Upload record' do
expect do
2017-12-05 18:43:08 +00:00
subject.perform(1, untracked_files_for_uploads.last.id)
end.to change { model.reload.uploads.count }.from(0).to(1)
2017-11-08 03:08:02 +00:00
2017-11-15 07:15:30 +00:00
expect(model.uploads.first.attributes).to include(expected_upload_attrs)
2017-11-08 03:08:02 +00:00
end
end
2017-11-15 07:15:30 +00:00
context 'for an appearance logo file path' do
let(:model) { create_or_update_appearance(logo: uploaded_file) }
2017-11-08 03:08:02 +00:00
2017-11-24 07:12:24 +00:00
it_behaves_like 'non_markdown_file'
2017-11-15 07:15:30 +00:00
end
2017-11-08 03:08:02 +00:00
2017-11-15 07:15:30 +00:00
context 'for an appearance header_logo file path' do
let(:model) { create_or_update_appearance(header_logo: uploaded_file) }
2017-11-08 03:08:02 +00:00
2017-11-24 07:12:24 +00:00
it_behaves_like 'non_markdown_file'
2017-11-08 03:08:02 +00:00
end
context 'for a pre-Markdown Note attachment file path' do
2017-12-12 21:13:07 +00:00
let(:model) { create(:note, :with_attachment) }
let!(:expected_upload_attrs) { Upload.where(model_type: 'Note', model_id: model.id).first.attributes.slice('path', 'uploader', 'size', 'checksum') }
let!(:untracked_file) { untracked_files_for_uploads.create!(path: expected_upload_attrs['path']) }
before do
Upload.where(model_type: 'Note', model_id: model.id).delete_all
2017-11-08 03:08:02 +00:00
end
2017-12-12 21:13:07 +00:00
# Can't use the shared example because Note doesn't have an `uploads` association
it 'creates an Upload record' do
expect do
subject.perform(1, untracked_files_for_uploads.last.id)
end.to change { Upload.where(model_type: 'Note', model_id: model.id).count }.from(0).to(1)
2017-11-08 03:08:02 +00:00
2017-12-12 21:13:07 +00:00
expect(Upload.where(model_type: 'Note', model_id: model.id).first.attributes).to include(expected_upload_attrs)
end
2017-11-08 03:08:02 +00:00
end
context 'for a user avatar file path' do
2017-11-15 07:15:30 +00:00
let(:model) { create(:user, :with_avatar) }
2017-11-08 03:08:02 +00:00
2017-11-24 07:12:24 +00:00
it_behaves_like 'non_markdown_file'
2017-11-08 03:08:02 +00:00
end
context 'for a group avatar file path' do
2017-11-15 07:15:30 +00:00
let(:model) { create(:group, :with_avatar) }
2017-11-08 03:08:02 +00:00
2017-11-24 07:12:24 +00:00
it_behaves_like 'non_markdown_file'
2017-11-08 03:08:02 +00:00
end
context 'for a project avatar file path' do
2017-12-01 13:58:49 +00:00
let(:model) { create(:project, :legacy_storage, :with_avatar) }
2017-11-08 03:08:02 +00:00
2017-11-24 07:12:24 +00:00
it_behaves_like 'non_markdown_file'
2017-11-08 03:08:02 +00:00
end
context 'for a project Markdown attachment (notes, issues, MR descriptions) file path' do
2017-12-01 13:58:49 +00:00
let(:model) { create(:project, :legacy_storage) }
2017-11-15 07:15:30 +00:00
2017-11-08 03:08:02 +00:00
before do
2017-11-15 07:15:30 +00:00
# Upload the file
UploadService.new(model, uploaded_file, FileUploader).execute
# Create the untracked_files_for_uploads record
2017-11-24 07:12:24 +00:00
untracked_files_for_uploads.create!(path: "#{Gitlab::BackgroundMigration::PrepareUntrackedUploads::RELATIVE_UPLOAD_DIR}/#{model.full_path}/#{model.uploads.first.path}")
2017-11-15 07:15:30 +00:00
# Save the expected upload attributes
2017-11-15 11:01:35 +00:00
@expected_upload_attrs = model.reload.uploads.first.attributes.slice('path', 'uploader', 'size', 'checksum')
2017-11-15 07:15:30 +00:00
# Untrack the file
model.reload.uploads.delete_all
2017-11-08 03:08:02 +00:00
end
it 'creates an Upload record' do
expect do
2017-12-05 18:43:08 +00:00
subject.perform(1, untracked_files_for_uploads.last.id)
end.to change { model.reload.uploads.count }.from(0).to(1)
2017-11-08 03:08:02 +00:00
2017-11-15 11:01:35 +00:00
expect(model.uploads.first.attributes).to include(@expected_upload_attrs)
2017-11-08 03:08:02 +00:00
end
end
end
2017-11-24 07:12:24 +00:00
end
describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UntrackedFile do
include TrackUntrackedUploadsHelpers
let(:upload_class) { Gitlab::BackgroundMigration::PopulateUntrackedUploads::Upload }
before(:all) do
ensure_temporary_tracking_table_exists
end
after(:all) do
drop_temp_table_if_exists
end
2017-11-08 03:08:02 +00:00
describe '#upload_path' do
2017-11-15 07:15:30 +00:00
def assert_upload_path(file_path, expected_upload_path)
untracked_file = create_untracked_file(file_path)
2017-11-08 03:08:02 +00:00
2017-11-15 07:15:30 +00:00
expect(untracked_file.upload_path).to eq(expected_upload_path)
end
context 'for an appearance logo file path' do
2017-11-08 03:08:02 +00:00
it 'returns the file path relative to the CarrierWave root' do
2017-11-15 07:15:30 +00:00
assert_upload_path('/-/system/appearance/logo/1/some_logo.jpg', 'uploads/-/system/appearance/logo/1/some_logo.jpg')
2017-11-08 03:08:02 +00:00
end
end
context 'for an appearance header_logo file path' do
it 'returns the file path relative to the CarrierWave root' do
2017-11-15 07:15:30 +00:00
assert_upload_path('/-/system/appearance/header_logo/1/some_logo.jpg', 'uploads/-/system/appearance/header_logo/1/some_logo.jpg')
2017-11-08 03:08:02 +00:00
end
end
context 'for a pre-Markdown Note attachment file path' do
it 'returns the file path relative to the CarrierWave root' do
2017-11-15 07:15:30 +00:00
assert_upload_path('/-/system/note/attachment/1234/some_attachment.pdf', 'uploads/-/system/note/attachment/1234/some_attachment.pdf')
2017-11-08 03:08:02 +00:00
end
end
context 'for a user avatar file path' do
it 'returns the file path relative to the CarrierWave root' do
2017-11-15 07:15:30 +00:00
assert_upload_path('/-/system/user/avatar/1234/avatar.jpg', 'uploads/-/system/user/avatar/1234/avatar.jpg')
2017-11-08 03:08:02 +00:00
end
end
context 'for a group avatar file path' do
it 'returns the file path relative to the CarrierWave root' do
2017-11-15 07:15:30 +00:00
assert_upload_path('/-/system/group/avatar/1234/avatar.jpg', 'uploads/-/system/group/avatar/1234/avatar.jpg')
2017-11-08 03:08:02 +00:00
end
end
context 'for a project avatar file path' do
it 'returns the file path relative to the CarrierWave root' do
2017-11-15 07:15:30 +00:00
assert_upload_path('/-/system/project/avatar/1234/avatar.jpg', 'uploads/-/system/project/avatar/1234/avatar.jpg')
2017-11-08 03:08:02 +00:00
end
end
context 'for a project Markdown attachment (notes, issues, MR descriptions) file path' do
it 'returns the file path relative to the project directory in uploads' do
2017-12-01 13:58:49 +00:00
project = create(:project, :legacy_storage)
2017-11-15 07:15:30 +00:00
random_hex = SecureRandom.hex
assert_upload_path("/#{project.full_path}/#{random_hex}/Some file.jpg", "#{random_hex}/Some file.jpg")
2017-11-08 03:08:02 +00:00
end
end
end
describe '#uploader' do
2017-11-15 07:15:30 +00:00
def assert_uploader(file_path, expected_uploader)
untracked_file = create_untracked_file(file_path)
expect(untracked_file.uploader).to eq(expected_uploader)
end
2017-11-08 03:08:02 +00:00
2017-11-15 07:15:30 +00:00
context 'for an appearance logo file path' do
2017-11-08 03:08:02 +00:00
it 'returns AttachmentUploader as a string' do
2017-11-15 07:15:30 +00:00
assert_uploader('/-/system/appearance/logo/1/some_logo.jpg', 'AttachmentUploader')
2017-11-08 03:08:02 +00:00
end
end
context 'for an appearance header_logo file path' do
it 'returns AttachmentUploader as a string' do
2017-11-15 07:15:30 +00:00
assert_uploader('/-/system/appearance/header_logo/1/some_logo.jpg', 'AttachmentUploader')
2017-11-08 03:08:02 +00:00
end
end
context 'for a pre-Markdown Note attachment file path' do
it 'returns AttachmentUploader as a string' do
2017-11-15 07:15:30 +00:00
assert_uploader('/-/system/note/attachment/1234/some_attachment.pdf', 'AttachmentUploader')
2017-11-08 03:08:02 +00:00
end
end
context 'for a user avatar file path' do
it 'returns AvatarUploader as a string' do
2017-11-15 07:15:30 +00:00
assert_uploader('/-/system/user/avatar/1234/avatar.jpg', 'AvatarUploader')
2017-11-08 03:08:02 +00:00
end
end
context 'for a group avatar file path' do
it 'returns AvatarUploader as a string' do
2017-11-15 07:15:30 +00:00
assert_uploader('/-/system/group/avatar/1234/avatar.jpg', 'AvatarUploader')
2017-11-08 03:08:02 +00:00
end
end
context 'for a project avatar file path' do
it 'returns AvatarUploader as a string' do
2017-11-15 07:15:30 +00:00
assert_uploader('/-/system/project/avatar/1234/avatar.jpg', 'AvatarUploader')
2017-11-08 03:08:02 +00:00
end
end
context 'for a project Markdown attachment (notes, issues, MR descriptions) file path' do
it 'returns FileUploader as a string' do
2017-12-01 13:58:49 +00:00
project = create(:project, :legacy_storage)
2017-11-15 07:15:30 +00:00
assert_uploader("/#{project.full_path}/#{SecureRandom.hex}/Some file.jpg", 'FileUploader')
2017-11-08 03:08:02 +00:00
end
end
end
describe '#model_type' do
2017-11-15 07:15:30 +00:00
def assert_model_type(file_path, expected_model_type)
untracked_file = create_untracked_file(file_path)
2017-11-08 03:08:02 +00:00
2017-11-15 07:15:30 +00:00
expect(untracked_file.model_type).to eq(expected_model_type)
end
context 'for an appearance logo file path' do
2017-11-08 03:08:02 +00:00
it 'returns Appearance as a string' do
2017-11-15 07:15:30 +00:00
assert_model_type('/-/system/appearance/logo/1/some_logo.jpg', 'Appearance')
2017-11-08 03:08:02 +00:00
end
end
context 'for an appearance header_logo file path' do
it 'returns Appearance as a string' do
2017-11-15 07:15:30 +00:00
assert_model_type('/-/system/appearance/header_logo/1/some_logo.jpg', 'Appearance')
2017-11-08 03:08:02 +00:00
end
end
context 'for a pre-Markdown Note attachment file path' do
it 'returns Note as a string' do
2017-11-15 07:15:30 +00:00
assert_model_type('/-/system/note/attachment/1234/some_attachment.pdf', 'Note')
2017-11-08 03:08:02 +00:00
end
end
context 'for a user avatar file path' do
it 'returns User as a string' do
2017-11-15 07:15:30 +00:00
assert_model_type('/-/system/user/avatar/1234/avatar.jpg', 'User')
2017-11-08 03:08:02 +00:00
end
end
context 'for a group avatar file path' do
it 'returns Namespace as a string' do
2017-11-15 07:15:30 +00:00
assert_model_type('/-/system/group/avatar/1234/avatar.jpg', 'Namespace')
2017-11-08 03:08:02 +00:00
end
end
context 'for a project avatar file path' do
it 'returns Project as a string' do
2017-11-15 07:15:30 +00:00
assert_model_type('/-/system/project/avatar/1234/avatar.jpg', 'Project')
2017-11-08 03:08:02 +00:00
end
end
context 'for a project Markdown attachment (notes, issues, MR descriptions) file path' do
it 'returns Project as a string' do
2017-12-01 13:58:49 +00:00
project = create(:project, :legacy_storage)
2017-11-15 07:15:30 +00:00
assert_model_type("/#{project.full_path}/#{SecureRandom.hex}/Some file.jpg", 'Project')
2017-11-08 03:08:02 +00:00
end
end
end
describe '#model_id' do
2017-11-15 07:15:30 +00:00
def assert_model_id(file_path, expected_model_id)
untracked_file = create_untracked_file(file_path)
expect(untracked_file.model_id).to eq(expected_model_id)
end
2017-11-08 03:08:02 +00:00
2017-11-15 07:15:30 +00:00
context 'for an appearance logo file path' do
2017-11-08 03:08:02 +00:00
it 'returns the ID as a string' do
2017-11-24 08:49:04 +00:00
assert_model_id('/-/system/appearance/logo/1/some_logo.jpg', 1)
2017-11-08 03:08:02 +00:00
end
end
context 'for an appearance header_logo file path' do
it 'returns the ID as a string' do
2017-11-24 08:49:04 +00:00
assert_model_id('/-/system/appearance/header_logo/1/some_logo.jpg', 1)
2017-11-08 03:08:02 +00:00
end
end
context 'for a pre-Markdown Note attachment file path' do
it 'returns the ID as a string' do
2017-11-24 08:49:04 +00:00
assert_model_id('/-/system/note/attachment/1234/some_attachment.pdf', 1234)
2017-11-08 03:08:02 +00:00
end
end
context 'for a user avatar file path' do
it 'returns the ID as a string' do
2017-11-24 08:49:04 +00:00
assert_model_id('/-/system/user/avatar/1234/avatar.jpg', 1234)
2017-11-08 03:08:02 +00:00
end
end
context 'for a group avatar file path' do
it 'returns the ID as a string' do
2017-11-24 08:49:04 +00:00
assert_model_id('/-/system/group/avatar/1234/avatar.jpg', 1234)
2017-11-08 03:08:02 +00:00
end
end
context 'for a project avatar file path' do
it 'returns the ID as a string' do
2017-11-24 08:49:04 +00:00
assert_model_id('/-/system/project/avatar/1234/avatar.jpg', 1234)
2017-11-08 03:08:02 +00:00
end
end
context 'for a project Markdown attachment (notes, issues, MR descriptions) file path' do
it 'returns the ID as a string' do
2017-12-01 13:58:49 +00:00
project = create(:project, :legacy_storage)
2017-11-15 07:15:30 +00:00
2017-11-24 08:49:04 +00:00
assert_model_id("/#{project.full_path}/#{SecureRandom.hex}/Some file.jpg", project.id)
2017-11-08 03:08:02 +00:00
end
end
end
describe '#file_size' do
context 'for an appearance logo file path' do
let(:appearance) { create_or_update_appearance(logo: uploaded_file) }
2017-11-15 07:15:30 +00:00
let(:untracked_file) { described_class.create!(path: appearance.uploads.first.path) }
2017-11-08 03:08:02 +00:00
it 'returns the file size' do
expect(untracked_file.file_size).to eq(35255)
2017-11-08 03:08:02 +00:00
end
it 'returns the same thing that CarrierWave would return' do
expect(untracked_file.file_size).to eq(appearance.logo.size)
2017-11-08 03:08:02 +00:00
end
end
context 'for a project avatar file path' do
2017-12-01 13:58:49 +00:00
let(:project) { create(:project, :legacy_storage, avatar: uploaded_file) }
2017-11-15 07:15:30 +00:00
let(:untracked_file) { described_class.create!(path: project.uploads.first.path) }
2017-11-08 03:08:02 +00:00
it 'returns the file size' do
expect(untracked_file.file_size).to eq(35255)
2017-11-08 03:08:02 +00:00
end
it 'returns the same thing that CarrierWave would return' do
expect(untracked_file.file_size).to eq(project.avatar.size)
2017-11-08 03:08:02 +00:00
end
end
context 'for a project Markdown attachment (notes, issues, MR descriptions) file path' do
2017-12-01 13:58:49 +00:00
let(:project) { create(:project, :legacy_storage) }
2017-11-15 07:15:30 +00:00
let(:untracked_file) { create_untracked_file("/#{project.full_path}/#{project.uploads.first.path}") }
2017-11-08 03:08:02 +00:00
before do
UploadService.new(project, uploaded_file, FileUploader).execute
end
it 'returns the file size' do
expect(untracked_file.file_size).to eq(35255)
2017-11-08 03:08:02 +00:00
end
it 'returns the same thing that CarrierWave would return' do
expect(untracked_file.file_size).to eq(project.uploads.first.size)
2017-11-08 03:08:02 +00:00
end
end
end
2017-11-15 07:15:30 +00:00
def create_untracked_file(path_relative_to_upload_dir)
described_class.create!(path: "#{Gitlab::BackgroundMigration::PrepareUntrackedUploads::RELATIVE_UPLOAD_DIR}#{path_relative_to_upload_dir}")
end
end