Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2017-04-05 10:57:46 +0300
committerTimothy Andrew <mail@timothyandrew.net>2017-04-06 16:28:59 +0300
commit97cbf7c223ec772e4747bab5083904d4053e2e63 (patch)
treee956aac6644a42485095939f3b11aaa59a40b5b5
parent72580f07af5a2c1e4df6bbc339ad804b5f5bb9ed (diff)
Move a user's notes to the ghost user
... when the user is destroyed.
-rw-r--r--app/services/concerns/users/migrate_to_ghost_user.rb5
-rw-r--r--spec/services/users/destroy_service_spec.rb10
-rw-r--r--spec/support/services/user_destroy_service_migrate_to_ghost_user_shared_examples.rb26
3 files changed, 27 insertions, 14 deletions
diff --git a/app/services/concerns/users/migrate_to_ghost_user.rb b/app/services/concerns/users/migrate_to_ghost_user.rb
index ecbbf3026a0..0779d12cd3a 100644
--- a/app/services/concerns/users/migrate_to_ghost_user.rb
+++ b/app/services/concerns/users/migrate_to_ghost_user.rb
@@ -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
diff --git a/spec/services/users/destroy_service_spec.rb b/spec/services/users/destroy_service_spec.rb
index a5b69e6ddf4..3efa7c196dc 100644
--- a/spec/services/users/destroy_service_spec.rb
+++ b/spec/services/users/destroy_service_spec.rb
@@ -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
diff --git a/spec/support/services/user_destroy_service_migrate_to_ghost_user_shared_examples.rb b/spec/support/services/user_destroy_service_migrate_to_ghost_user_shared_examples.rb
index 8996e3420e6..add3dd3d5bc 100644
--- a/spec/support/services/user_destroy_service_migrate_to_ghost_user_shared_examples.rb
+++ b/spec/support/services/user_destroy_service_migrate_to_ghost_user_shared_examples.rb
@@ -1,6 +1,6 @@
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