diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-09-06 06:24:53 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-09-06 06:24:53 +0000 |
commit | 745bc35666ce7e6cc3fbdb08596e4e18a35f8e04 (patch) | |
tree | ee1c9196ff30cfe5105e5299ff644c350e0f87fe /spec | |
parent | d68ff7f50a93ebbff537b5e795cf6bf80bd66a6e (diff) | |
parent | 4c6898bdcf0bff6a0a3b288215271be4e916b27c (diff) | |
download | gitlab-ce-745bc35666ce7e6cc3fbdb08596e4e18a35f8e04.tar.gz |
Merge branch '36860-migrate-issues-author' into 'master'
Migrate old issues without author to the ghost user
Closes #36860
See merge request !13860
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/issues/issue_detail_spec.rb | 14 | ||||
-rw-r--r-- | spec/migrations/migrate_issues_to_ghost_user_spec.rb | 51 |
2 files changed, 51 insertions, 14 deletions
diff --git a/spec/features/issues/issue_detail_spec.rb b/spec/features/issues/issue_detail_spec.rb index c470cb7c716..28b636f9359 100644 --- a/spec/features/issues/issue_detail_spec.rb +++ b/spec/features/issues/issue_detail_spec.rb @@ -40,18 +40,4 @@ feature 'Issue Detail', :js do end end end - - context 'when authored by a user who is later deleted' do - before do - issue.update_attribute(:author_id, nil) - sign_in(user) - visit project_issue_path(project, issue) - end - - it 'shows the issue' do - page.within('.issuable-details') do - expect(find('h2')).to have_content(issue.title) - end - end - end end 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 |