debian-mirror-gitlab/spec/migrations/update_upload_paths_to_system_spec.rb

60 lines
2.3 KiB
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170317162059_update_upload_paths_to_system.rb')
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
describe UpdateUploadPathsToSystem, :migration do
2017-08-17 22:00:37 +05:30
let(:migration) { described_class.new }
2018-03-17 18:26:18 +05:30
let(:uploads_table) { table(:uploads) }
let(:base_upload_attributes) { { size: 42, uploader: 'John Doe' } }
2017-08-17 22:00:37 +05:30
before do
allow(migration).to receive(:say)
end
2018-03-17 18:26:18 +05:30
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')
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(uploads_table.where(migration.uploads_to_switch_to_new_path)).to contain_exactly(old_upload, group_upload)
2017-08-17 22:00:37 +05:30
end
end
2018-03-17 18:26:18 +05:30
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')
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
expect(uploads_table.where(migration.uploads_to_switch_to_old_path)).to contain_exactly(upload_with_system_path)
2017-08-17 22:00:37 +05:30
end
end
2018-03-17 18:26:18 +05:30
describe '#up' do
it 'updates old upload records to the new path' do
old_upload = create_upload('Project', 'uploads/project/avatar.jpg')
2017-08-17 22:00:37 +05:30
migration.up
2018-03-17 18:26:18 +05:30
expect(old_upload.reload.path).to eq('uploads/-/system/project/avatar.jpg')
2017-08-17 22:00:37 +05:30
end
end
2018-03-17 18:26:18 +05:30
describe '#down' do
it 'updates the new system patsh to the old paths' do
new_upload = create_upload('Project', 'uploads/-/system/project/avatar.jpg')
2017-08-17 22:00:37 +05:30
migration.down
2018-03-17 18:26:18 +05:30
expect(new_upload.reload.path).to eq('uploads/project/avatar.jpg')
2017-08-17 22:00:37 +05:30
end
end
2018-03-17 18:26:18 +05:30
def create_upload(type, path)
uploads_table.create(base_upload_attributes.merge(model_type: type, path: path))
end
2017-08-17 22:00:37 +05:30
end