diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-01-18 16:51:08 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-01-18 16:51:08 +0300 |
commit | 624092bf7a80028b3192ee0980e2cb08de6b810c (patch) | |
tree | f7c42f7c75fa0020fad42fe73f7fb31c54ba1c98 /spec | |
parent | 50a649530a53a04d2044f9e4c5502586a7ed0c59 (diff) | |
parent | 779ed1cccfc9ed4041b58495146f93f226d620aa (diff) |
Merge branch 'rc/fix-update_upload_paths_to_system_spec' into 'master'
Fix spec/migrations/update_upload_paths_to_system_spec.rb to use the :migration metadata
See merge request gitlab-org/gitlab-ce!16546
Diffstat (limited to 'spec')
-rw-r--r-- | spec/migrations/update_upload_paths_to_system_spec.rb | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/spec/migrations/update_upload_paths_to_system_spec.rb b/spec/migrations/update_upload_paths_to_system_spec.rb index d4a1553fb0e..984b428a020 100644 --- a/spec/migrations/update_upload_paths_to_system_spec.rb +++ b/spec/migrations/update_upload_paths_to_system_spec.rb @@ -1,53 +1,59 @@ -require "spec_helper" -require Rails.root.join("db", "post_migrate", "20170317162059_update_upload_paths_to_system.rb") +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20170317162059_update_upload_paths_to_system.rb') -describe UpdateUploadPathsToSystem do +describe UpdateUploadPathsToSystem, :migration do let(:migration) { described_class.new } + let(:uploads_table) { table(:uploads) } + let(:base_upload_attributes) { { size: 42, uploader: 'John Doe' } } before do allow(migration).to receive(:say) end - describe "#uploads_to_switch_to_new_path" do - it "contains only uploads with the old path for the correct models" do - _upload_for_other_type = create(:upload, model: create(:ci_pipeline), path: "uploads/ci_pipeline/avatar.jpg") - _upload_with_system_path = create(:upload, model: create(:project), path: "uploads/-/system/project/avatar.jpg") - _upload_with_other_path = create(:upload, model: create(:project), path: "thelongsecretforafileupload/avatar.jpg") - old_upload = create(:upload, model: create(:project), path: "uploads/project/avatar.jpg") - group_upload = create(:upload, model: create(:group), path: "uploads/group/avatar.jpg") + describe '#uploads_to_switch_to_new_path' do + it 'contains only uploads with the old path for the correct models' do + _upload_for_other_type = create_upload('Pipeline', 'uploads/ci_pipeline/avatar.jpg') + _upload_with_system_path = create_upload('Project', 'uploads/-/system/project/avatar.jpg') + _upload_with_other_path = create_upload('Project', 'thelongsecretforafileupload/avatar.jpg') + old_upload = create_upload('Project', 'uploads/project/avatar.jpg') + group_upload = create_upload('Namespace', 'uploads/group/avatar.jpg') - expect(Upload.where(migration.uploads_to_switch_to_new_path)).to contain_exactly(old_upload, group_upload) + expect(uploads_table.where(migration.uploads_to_switch_to_new_path)).to contain_exactly(old_upload, group_upload) end end - describe "#uploads_to_switch_to_old_path" do - it "contains only uploads with the new path for the correct models" do - _upload_for_other_type = create(:upload, model: create(:ci_pipeline), path: "uploads/ci_pipeline/avatar.jpg") - upload_with_system_path = create(:upload, model: create(:project), path: "uploads/-/system/project/avatar.jpg") - _upload_with_other_path = create(:upload, model: create(:project), path: "thelongsecretforafileupload/avatar.jpg") - _old_upload = create(:upload, model: create(:project), path: "uploads/project/avatar.jpg") + describe '#uploads_to_switch_to_old_path' do + it 'contains only uploads with the new path for the correct models' do + _upload_for_other_type = create_upload('Pipeline', 'uploads/ci_pipeline/avatar.jpg') + upload_with_system_path = create_upload('Project', 'uploads/-/system/project/avatar.jpg') + _upload_with_other_path = create_upload('Project', 'thelongsecretforafileupload/avatar.jpg') + _old_upload = create_upload('Project', 'uploads/project/avatar.jpg') - expect(Upload.where(migration.uploads_to_switch_to_old_path)).to contain_exactly(upload_with_system_path) + expect(uploads_table.where(migration.uploads_to_switch_to_old_path)).to contain_exactly(upload_with_system_path) end end - describe "#up", :truncate do - it "updates old upload records to the new path" do - old_upload = create(:upload, model: create(:project), path: "uploads/project/avatar.jpg") + describe '#up' do + it 'updates old upload records to the new path' do + old_upload = create_upload('Project', 'uploads/project/avatar.jpg') migration.up - expect(old_upload.reload.path).to eq("uploads/-/system/project/avatar.jpg") + expect(old_upload.reload.path).to eq('uploads/-/system/project/avatar.jpg') end end - describe "#down", :truncate do - it "updates the new system patsh to the old paths" do - new_upload = create(:upload, model: create(:project), path: "uploads/-/system/project/avatar.jpg") + describe '#down' do + it 'updates the new system patsh to the old paths' do + new_upload = create_upload('Project', 'uploads/-/system/project/avatar.jpg') migration.down - expect(new_upload.reload.path).to eq("uploads/project/avatar.jpg") + expect(new_upload.reload.path).to eq('uploads/project/avatar.jpg') end end + + def create_upload(type, path) + uploads_table.create(base_upload_attributes.merge(model_type: type, path: path)) + end end |