2016-12-21 12:31:30 -05:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'post_migrate', '20161221153951_rename_reserved_project_names.rb')
|
|
|
|
|
2016-12-27 07:45:44 -05:00
|
|
|
# This migration uses multiple threads, and thus different transactions. This
|
|
|
|
# means data created in this spec may not be visible to some threads. To work
|
|
|
|
# around this we use the TRUNCATE cleaning strategy.
|
|
|
|
describe RenameReservedProjectNames, truncate: true do
|
2016-12-21 12:31:30 -05:00
|
|
|
let(:migration) { described_class.new }
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:project) { create(:project) }
|
2016-12-21 12:31:30 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.path = 'projects'
|
|
|
|
project.save!(validate: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#up' do
|
|
|
|
context 'when project repository exists' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
project.create_repository
|
|
|
|
end
|
2016-12-21 12:31:30 -05:00
|
|
|
|
|
|
|
context 'when no exception is raised' do
|
|
|
|
it 'renames project with reserved names' do
|
|
|
|
migration.up
|
|
|
|
|
|
|
|
expect(project.reload.path).to eq('projects0')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when exception is raised during rename' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:rename_repo).and_raise(StandardError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'captures exception from project rename' do
|
|
|
|
expect { migration.up }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project repository does not exist' do
|
|
|
|
it 'does not raise error' do
|
|
|
|
expect { migration.up }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|