summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-11-23 23:12:24 -0800
committerMichael Kozono <mkozono@gmail.com>2017-12-01 15:26:42 -0800
commit908aacddda571bc82c722798f399fd5a68ebe1da (patch)
tree1a072420766c29efe93578e7b91933fb330e2b3a /spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
parent7549d17f721b3be84f83c1dfa491d6a2ebf4ec28 (diff)
downloadgitlab-ce-908aacddda571bc82c722798f399fd5a68ebe1da.tar.gz
Filter existing uploads with one query
Diffstat (limited to 'spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb')
-rw-r--r--spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb80
1 files changed, 26 insertions, 54 deletions
diff --git a/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb b/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
index 72243ff98a4..623725bffca 100644
--- a/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
+++ b/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
@@ -126,50 +126,11 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid
end.not_to change { uploads.count }.from(0)
end
end
-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
- describe '#ensure_tracked!' do
- let!(:user1) { create(:user, :with_avatar) }
- let!(:untracked_file) { described_class.create!(path: user1.uploads.first.path) }
-
- context 'when the file is already in the uploads table' do
- it 'does not add an upload' do
- expect do
- untracked_file.ensure_tracked!
- end.not_to change { upload_class.count }.from(1)
- end
- end
-
- context 'when the file is not already in the uploads table' do
- before do
- user1.uploads.delete_all
- end
-
- it 'adds an upload' do
- expect do
- untracked_file.ensure_tracked!
- end.to change { upload_class.count }.from(0).to(1)
- end
- end
- end
-
- describe '#add_to_uploads_if_needed' do
- shared_examples_for 'add_to_uploads_non_markdown_files' do
+ describe 'upload outcomes for each path pattern' do
+ shared_examples_for 'non_markdown_file' do
let!(:expected_upload_attrs) { model.uploads.first.attributes.slice('path', 'uploader', 'size', 'checksum') }
- let!(:untracked_file) { described_class.create!(path: expected_upload_attrs['path']) }
+ let!(:untracked_file) { untracked_files_for_uploads.create!(path: expected_upload_attrs['path']) }
before do
model.uploads.delete_all
@@ -177,7 +138,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UntrackedFile do
it 'creates an Upload record' do
expect do
- untracked_file.add_to_uploads_if_needed
+ subject.perform(1, 1000)
end.to change { model.reload.uploads.count }.from(0).to(1)
expect(model.uploads.first.attributes).to include(expected_upload_attrs)
@@ -187,13 +148,13 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UntrackedFile do
context 'for an appearance logo file path' do
let(:model) { create(:appearance, logo: uploaded_file) }
- it_behaves_like 'add_to_uploads_non_markdown_files'
+ it_behaves_like 'non_markdown_file'
end
context 'for an appearance header_logo file path' do
let(:model) { create(:appearance, header_logo: uploaded_file) }
- it_behaves_like 'add_to_uploads_non_markdown_files'
+ it_behaves_like 'non_markdown_file'
end
context 'for a pre-Markdown Note attachment file path' do
@@ -203,39 +164,36 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UntrackedFile do
let(:model) { create(:note, :with_attachment) }
- it_behaves_like 'add_to_uploads_non_markdown_files'
+ it_behaves_like 'non_markdown_file'
end
context 'for a user avatar file path' do
let(:model) { create(:user, :with_avatar) }
- it_behaves_like 'add_to_uploads_non_markdown_files'
+ it_behaves_like 'non_markdown_file'
end
context 'for a group avatar file path' do
let(:model) { create(:group, :with_avatar) }
- it_behaves_like 'add_to_uploads_non_markdown_files'
+ it_behaves_like 'non_markdown_file'
end
context 'for a project avatar file path' do
let(:model) { create(:project, :with_avatar) }
- it_behaves_like 'add_to_uploads_non_markdown_files'
+ it_behaves_like 'non_markdown_file'
end
context 'for a project Markdown attachment (notes, issues, MR descriptions) file path' do
let(:model) { create(:project) }
- # UntrackedFile.path is different than Upload.path
- let(:untracked_file) { create_untracked_file("/#{model.full_path}/#{model.uploads.first.path}") }
-
before do
# Upload the file
UploadService.new(model, uploaded_file, FileUploader).execute
# Create the untracked_files_for_uploads record
- untracked_file
+ untracked_files_for_uploads.create!(path: "#{Gitlab::BackgroundMigration::PrepareUntrackedUploads::RELATIVE_UPLOAD_DIR}/#{model.full_path}/#{model.uploads.first.path}")
# Save the expected upload attributes
@expected_upload_attrs = model.reload.uploads.first.attributes.slice('path', 'uploader', 'size', 'checksum')
@@ -246,13 +204,27 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UntrackedFile do
it 'creates an Upload record' do
expect do
- untracked_file.add_to_uploads_if_needed
+ subject.perform(1, 1000)
end.to change { model.reload.uploads.count }.from(0).to(1)
expect(model.uploads.first.attributes).to include(@expected_upload_attrs)
end
end
end
+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
describe '#upload_path' do
def assert_upload_path(file_path, expected_upload_path)