diff options
author | Stan Hu <stanhu@gmail.com> | 2017-12-12 23:44:48 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-12-12 23:44:48 +0000 |
commit | 31fa9313991881258b4697cb507cfc8ab205b7dc (patch) | |
tree | 035b560c87dc6d5040d998bbb23bdfdf5dd493f0 | |
parent | 7ed6a651598ea0658674f2fab15d5f7c8dc187ad (diff) | |
parent | acde0e3f5cee3a9a1bff4aadbf276b91f7c7272d (diff) | |
download | gitlab-ce-31fa9313991881258b4697cb507cfc8ab205b7dc.tar.gz |
Merge branch 'mk-fix-leaky-spec' into 'master'
CE Backport - Fix order-dependent spec failure by avoiding monkeypatching
See merge request gitlab-org/gitlab-ce!15893
-rw-r--r-- | spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb | 17 |
1 files changed, 13 insertions, 4 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 b80df6956b0..be45c00dfe6 100644 --- a/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb +++ b/spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb @@ -182,13 +182,22 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :sidekiq do end context 'for a pre-Markdown Note attachment file path' do - class Note < ActiveRecord::Base - has_many :uploads, as: :model, dependent: :destroy + 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 end - let(:model) { create(:note, :with_attachment) } + # 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) - it_behaves_like 'non_markdown_file' + expect(Upload.where(model_type: 'Note', model_id: model.id).first.attributes).to include(expected_upload_attrs) + end end context 'for a user avatar file path' do |