2017-08-25 07:37:21 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('db', 'migrate', '20170825104051_migrate_issues_to_ghost_user.rb')
|
|
|
|
|
|
|
|
describe MigrateIssuesToGhostUser, :migration do
|
|
|
|
describe '#up' do
|
|
|
|
let(:projects) { table(:projects) }
|
|
|
|
let(:issues) { table(:issues) }
|
|
|
|
let(:users) { table(:users) }
|
|
|
|
|
|
|
|
before do
|
2018-03-01 09:09:09 -05:00
|
|
|
project = projects.create!(name: 'gitlab', namespace_id: 1)
|
2017-08-25 07:37:21 -04:00
|
|
|
user = users.create(email: 'test@example.com')
|
2018-01-17 06:30:25 -05:00
|
|
|
issues.create(title: 'Issue 1', author_id: nil, project_id: project.id)
|
|
|
|
issues.create(title: 'Issue 2', author_id: user.id, project_id: project.id)
|
2017-08-25 07:37:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when ghost user exists' do
|
|
|
|
let!(:ghost) { users.create(ghost: true, email: 'ghost@example.com') }
|
|
|
|
|
|
|
|
it 'does not create a new user' do
|
2018-10-15 04:58:13 -04:00
|
|
|
expect { migrate! }.not_to change { User.count }
|
2017-08-25 07:37:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'migrates issues where author = nil to the ghost user' do
|
2018-10-15 04:58:13 -04:00
|
|
|
migrate!
|
2017-08-25 07:37:21 -04:00
|
|
|
|
|
|
|
expect(issues.first.reload.author_id).to eq(ghost.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change issues authored by an existing user' do
|
2018-10-15 04:58:13 -04:00
|
|
|
expect { migrate! }.not_to change { issues.second.reload.author_id}
|
2017-08-25 07:37:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when ghost user does not exist' do
|
|
|
|
it 'creates a new user' do
|
2018-10-15 04:58:13 -04:00
|
|
|
expect { migrate! }.to change { User.count }.by(1)
|
2017-08-25 07:37:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'migrates issues where author = nil to the ghost user' do
|
2018-10-15 04:58:13 -04:00
|
|
|
migrate!
|
2017-08-25 07:37:21 -04:00
|
|
|
|
|
|
|
expect(issues.first.reload.author_id).to eq(User.ghost.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change issues authored by an existing user' do
|
2018-10-15 04:58:13 -04:00
|
|
|
expect { migrate! }.not_to change { issues.second.reload.author_id}
|
2017-08-25 07:37:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|