Move a user's notes to the ghost user

... when the user is destroyed.
上级 72580f07
......@@ -21,6 +21,7 @@ module Users::MigrateToGhostUser
move_issues_to_ghost_user(user)
move_merge_requests_to_ghost_user(user)
move_notes_to_ghost_user(user)
end
user.reload
......@@ -35,4 +36,8 @@ module Users::MigrateToGhostUser
def move_merge_requests_to_ghost_user(user)
user.merge_requests.update_all(author_id: ghost_user.id)
end
def move_notes_to_ghost_user(user)
user.notes.update_all(author_id: ghost_user.id)
end
end
......@@ -144,18 +144,24 @@ describe Users::DestroyService, services: true do
context 'migrating associated records to the ghost user' 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(:assigned_record) { create(:issue, project: project, assignee: user) }
end
end
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(:assigned_record) { create(:merge_request, source_project: project, assignee: user, target_branch: 'second') }
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
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
let(:project) { create(:project) }
......@@ -33,21 +33,23 @@ shared_examples "migrating a deleted user's associated records to the ghost user
end
end
context "for a #{record_class_name} the user was assigned to" do
let!(:record) { assigned_record }
unless options[:skip_assignee_specs]
context "for a #{record_class_name} the user was assigned to" do
let!(:record) { assigned_record }
before do
service.execute(user)
end
before do
service.execute(user)
end
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
end
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
end
it "migrates the #{record_class_name} so that it is 'Unassigned'" do
migrated_record = record_class.find_by_id(record.id)
it "migrates the #{record_class_name} so that it is 'Unassigned'" do
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册