Commit 737f856ef88a810583886ab402e1267e098c54d8
1 parent
a19e1c86
Exists in
master
and in
21 other branches
cancel other invitations to same community when finishes task
If a user is successfully added to a community when performing a community invitation task, cancel all other pending tasks the user might have with invitations for the same community. (ActionItem3100)
Showing
2 changed files
with
15 additions
and
1 deletions
Show diff stats
app/models/invite_member.rb
| @@ -12,7 +12,7 @@ class InviteMember < Invitation | @@ -12,7 +12,7 @@ class InviteMember < Invitation | ||
| 12 | end | 12 | end |
| 13 | 13 | ||
| 14 | def perform | 14 | def perform |
| 15 | - community.add_member(friend) | 15 | + community.add_member(friend) and friend.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == community_id }.each { |invite| invite.cancel } |
| 16 | end | 16 | end |
| 17 | 17 | ||
| 18 | def title | 18 | def title |
test/unit/invite_member_test.rb
| @@ -22,6 +22,20 @@ class InviteMemberTest < ActiveSupport::TestCase | @@ -22,6 +22,20 @@ class InviteMemberTest < ActiveSupport::TestCase | ||
| 22 | ok('friend is member of community') { community.members.include?(friend) } | 22 | ok('friend is member of community') { community.members.include?(friend) } |
| 23 | end | 23 | end |
| 24 | 24 | ||
| 25 | + should 'cancel other invitations for same community when confirmed' do | ||
| 26 | + friend = create_user('friend').person | ||
| 27 | + p1 = create_user('testuser1').person | ||
| 28 | + p2 = create_user('testuser2').person | ||
| 29 | + community = fast_create(Community) | ||
| 30 | + | ||
| 31 | + task = InviteMember.create!(:person => p1, :friend => friend, :community_id => community.id) | ||
| 32 | + InviteMember.create!(:person => p2, :friend => friend, :community_id => community.id) | ||
| 33 | + | ||
| 34 | + assert_difference friend.tasks.pending, :count, -2 do | ||
| 35 | + task.finish | ||
| 36 | + end | ||
| 37 | + end | ||
| 38 | + | ||
| 25 | should 'require community (person inviting other to be a member)' do | 39 | should 'require community (person inviting other to be a member)' do |
| 26 | task = InviteMember.new | 40 | task = InviteMember.new |
| 27 | task.valid? | 41 | task.valid? |