diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2017-04-05 10:20:53 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2017-04-06 16:28:57 +0300 |
commit | 72580f07af5a2c1e4df6bbc339ad804b5f5bb9ed (patch) | |
tree | a80a44687563e69aab8636c03c62e7d5e9b95230 /spec/support | |
parent | fa65b65b0f5e7095e2ec7c4ca0c269a4fe4baab1 (diff) |
Move a user's merge requests to the ghost user.
1. When the user is deleted.
2. Refactor out code relating to "migrating records to the ghost user" into a
`MigrateToGhostUser` concern, which is tested using a shared example.
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/services/user_destroy_service_migrate_to_ghost_user_shared_examples.rb | 53 |
1 files changed, 53 insertions, 0 deletions
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 new file mode 100644 index 00000000000..8996e3420e6 --- /dev/null +++ b/spec/support/services/user_destroy_service_migrate_to_ghost_user_shared_examples.rb @@ -0,0 +1,53 @@ +require "spec_helper" + +shared_examples "migrating a deleted user's associated records to the ghost user" do |record_class| + record_class_name = record_class.to_s.titleize.downcase + + let(:project) { create(:project) } + + before do + project.add_developer(user) + end + + context "for a #{record_class_name} the user has created" do + let!(:record) { created_record } + + it "does not delete the #{record_class_name}" do + service.execute(user) + + expect(record_class.find_by_id(record.id)).to be_present + end + + it "migrates the #{record_class_name} so that the 'Ghost User' is the #{record_class_name} owner" do + service.execute(user) + + migrated_record = record_class.find_by_id(record.id) + + expect(migrated_record.author).to eq(User.ghost) + end + + it "blocks the user before migrating #{record_class_name}s to the 'Ghost User'" do + service.execute(user) + + expect(user).to be_blocked + end + end + + context "for a #{record_class_name} the user was assigned to" do + let!(:record) { assigned_record } + + 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 "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 + end + end +end |