diff options
author | Jarka Kadlecova <jarka@gitlab.com> | 2017-08-25 13:37:21 +0200 |
---|---|---|
committer | Jarka Kadlecova <jarka@gitlab.com> | 2017-09-05 16:25:26 +0200 |
commit | b0e30189a0cb82a03d6b6b25c04fa1498da85b0b (patch) | |
tree | 0d12298788e5af2534d522875516f2a285a9a1b1 /spec/migrations | |
parent | 597bc29260c4be3a1527a1c5307bec40004bac4d (diff) | |
download | gitlab-ce-b0e30189a0cb82a03d6b6b25c04fa1498da85b0b.tar.gz |
Migrate issues authored by deleted user to the Ghost user
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/migrate_issues_to_ghost_user_spec.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/migrations/migrate_issues_to_ghost_user_spec.rb b/spec/migrations/migrate_issues_to_ghost_user_spec.rb new file mode 100644 index 00000000000..cfd4021fbac --- /dev/null +++ b/spec/migrations/migrate_issues_to_ghost_user_spec.rb @@ -0,0 +1,51 @@ +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 + projects.create!(name: 'gitlab') + user = users.create(email: 'test@example.com') + issues.create(title: 'Issue 1', author_id: nil, project_id: 1) + issues.create(title: 'Issue 2', author_id: user.id, project_id: 1) + 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 + expect { schema_migrate_up! }.not_to change { User.count } + end + + it 'migrates issues where author = nil to the ghost user' do + schema_migrate_up! + + expect(issues.first.reload.author_id).to eq(ghost.id) + end + + it 'does not change issues authored by an existing user' do + expect { schema_migrate_up! }.not_to change { issues.second.reload.author_id} + end + end + + context 'when ghost user does not exist' do + it 'creates a new user' do + expect { schema_migrate_up! }.to change { User.count }.by(1) + end + + it 'migrates issues where author = nil to the ghost user' do + schema_migrate_up! + + expect(issues.first.reload.author_id).to eq(User.ghost.id) + end + + it 'does not change issues authored by an existing user' do + expect { schema_migrate_up! }.not_to change { issues.second.reload.author_id} + end + end + end +end |