Commit 97cbf7c2 authored by Timothy Andrew's avatar Timothy Andrew

Move a user's notes to the ghost user

... when the user is destroyed.
parent 72580f07
...@@ -21,6 +21,7 @@ module Users::MigrateToGhostUser ...@@ -21,6 +21,7 @@ module Users::MigrateToGhostUser
move_issues_to_ghost_user(user) move_issues_to_ghost_user(user)
move_merge_requests_to_ghost_user(user) move_merge_requests_to_ghost_user(user)
move_notes_to_ghost_user(user)
end end
user.reload user.reload
...@@ -35,4 +36,8 @@ module Users::MigrateToGhostUser ...@@ -35,4 +36,8 @@ module Users::MigrateToGhostUser
def move_merge_requests_to_ghost_user(user) def move_merge_requests_to_ghost_user(user)
user.merge_requests.update_all(author_id: ghost_user.id) user.merge_requests.update_all(author_id: ghost_user.id)
end end
def move_notes_to_ghost_user(user)
user.notes.update_all(author_id: ghost_user.id)
end
end end
...@@ -144,18 +144,24 @@ describe Users::DestroyService, services: true do ...@@ -144,18 +144,24 @@ describe Users::DestroyService, services: true do
context 'migrating associated records to the ghost user' do context 'migrating associated records to the ghost user' do
context 'issues' do context 'issues' do
include_examples "migrating a deleted user's associated records to the ghost user", Issue do include_examples "migrating a deleted user's associated records to the ghost user", Issue, {} do
let(:created_record) { create(:issue, project: project, author: user) } let(:created_record) { create(:issue, project: project, author: user) }
let(:assigned_record) { create(:issue, project: project, assignee: user) } let(:assigned_record) { create(:issue, project: project, assignee: user) }
end end
end end
context 'merge requests' do context 'merge requests' do
include_examples "migrating a deleted user's associated records to the ghost user", MergeRequest do include_examples "migrating a deleted user's associated records to the ghost user", MergeRequest, {} do
let(:created_record) { create(:merge_request, source_project: project, author: user, target_branch: "first") } let(:created_record) { create(:merge_request, source_project: project, author: user, target_branch: "first") }
let(:assigned_record) { create(:merge_request, source_project: project, assignee: user, target_branch: 'second') } let(:assigned_record) { create(:merge_request, source_project: project, assignee: user, target_branch: 'second') }
end end
end end
context 'notes' do
include_examples "migrating a deleted user's associated records to the ghost user", Note, { skip_assignee_specs: true } do
let(:created_record) { create(:note, project: project, author: user) }
end
end
end end
end end
end end
require "spec_helper" require "spec_helper"
shared_examples "migrating a deleted user's associated records to the ghost user" do |record_class| shared_examples "migrating a deleted user's associated records to the ghost user" do |record_class, options|
record_class_name = record_class.to_s.titleize.downcase record_class_name = record_class.to_s.titleize.downcase
let(:project) { create(:project) } let(:project) { create(:project) }
...@@ -33,21 +33,23 @@ shared_examples "migrating a deleted user's associated records to the ghost user ...@@ -33,21 +33,23 @@ shared_examples "migrating a deleted user's associated records to the ghost user
end end
end end
context "for a #{record_class_name} the user was assigned to" do unless options[:skip_assignee_specs]
let!(:record) { assigned_record } context "for a #{record_class_name} the user was assigned to" do
let!(:record) { assigned_record }
before do before do
service.execute(user) service.execute(user)
end end
it "does not delete #{record_class_name}s the user is assigned to" do it "does not delete #{record_class_name}s the user is assigned to" do
expect(record_class.find_by_id(record.id)).to be_present expect(record_class.find_by_id(record.id)).to be_present
end end
it "migrates the #{record_class_name} so that it is 'Unassigned'" do it "migrates the #{record_class_name} so that it is 'Unassigned'" do
migrated_record = record_class.find_by_id(record.id) migrated_record = record_class.find_by_id(record.id)
expect(migrated_record.assignee).to be_nil expect(migrated_record.assignee).to be_nil
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment