diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2017-04-06 13:06:36 +0300 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2017-04-06 16:29:17 +0300 |
commit | 3e1a1242c67781fb52940433c5ad1bbefd346216 (patch) | |
tree | 5f45e1f2dfee8ac69c0ee6340e2cc01ac5273817 /spec/services/users | |
parent | 682987547a932c011f84c6455f0fd32bb500b308 (diff) |
Move a user's award emoji to the ghost user
... when the user is destroyed.
1. Normally, for a given awardable and award emoji name, a user is only allowed
to create a single award emoji.
2. This validation needs to be removed for ghost users, since:
- User A and User B have created award emoji - with the same name and against
the same awardable
- User A is deleted. Their award emoji is moved to the ghost user
- User B is deleted. Their award emoji needs to be moved to the ghost user.
However, this breaks the uniqueness validation, since the ghost user is
only allowed to have one award emoji of a given name for a given awardable
Diffstat (limited to 'spec/services/users')
-rw-r--r-- | spec/services/users/destroy_service_spec.rb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/spec/services/users/destroy_service_spec.rb b/spec/services/users/destroy_service_spec.rb index 028de62e4ca..d3463185ebe 100644 --- a/spec/services/users/destroy_service_spec.rb +++ b/spec/services/users/destroy_service_spec.rb @@ -166,7 +166,35 @@ describe Users::DestroyService, services: true do context 'abuse reports' do include_examples "migrating a deleted user's associated records to the ghost user", AbuseReport, { skip_assignee_specs: true } do let(:created_record) { create(:abuse_report, reporter: user, user: create(:user)) } - let(:author_method) { :reporter } + end + end + + context 'award emoji' do + include_examples "migrating a deleted user's associated records to the ghost user", AwardEmoji, { skip_assignee_specs: true } do + let(:created_record) { create(:award_emoji, user: user) } + let(:author_alias) { :user } + + context "when the awardable already has an award emoji of the same name assigned to the ghost user" do + let(:awardable) { create(:issue) } + let!(:existing_award_emoji) { create(:award_emoji, user: User.ghost, name: "thumbsup", awardable: awardable) } + let!(:award_emoji) { create(:award_emoji, user: user, name: "thumbsup", awardable: awardable) } + + it "migrates the award emoji regardless" do + service.execute(user) + + migrated_record = AwardEmoji.find_by_id(award_emoji.id) + + expect(migrated_record.user).to eq(User.ghost) + end + + it "does not leave the migrated award emoji in an invalid state" do + service.execute(user) + + migrated_record = AwardEmoji.find_by_id(award_emoji.id) + + expect(migrated_record).to be_valid + end + end end end end |