Commit 1761e6e43101676fe34f9e7f1138fb446e177044
1 parent
27818a77
Exists in
master
and in
28 other branches
invite-member: fixed inviteMember crash when community is destroyed
AI3054
Showing
2 changed files
with
12 additions
and
3 deletions
Show diff stats
app/models/community.rb
1 | 1 | class Community < Organization |
2 | 2 | |
3 | + after_destroy :check_invite_member_for_destroy | |
4 | + | |
3 | 5 | def self.type_name |
4 | 6 | _('Community') |
5 | 7 | end |
... | ... | @@ -17,6 +19,10 @@ class Community < Organization |
17 | 19 | community.moderated_articles = true if community.environment.enabled?('organizations_are_moderated_by_default') |
18 | 20 | end |
19 | 21 | |
22 | + def check_invite_member_for_destroy | |
23 | + InviteMember.pending.select { |task| task.community_id == self.id }.map(&:destroy) | |
24 | + end | |
25 | + | |
20 | 26 | def self.create_after_moderation(requestor, attributes = {}) |
21 | 27 | community = Community.new(attributes) |
22 | 28 | if community.environment.enabled?('admin_must_approve_new_communities') | ... | ... |
test/unit/invite_member_test.rb
... | ... | @@ -118,13 +118,16 @@ class InviteMemberTest < ActiveSupport::TestCase |
118 | 118 | should 'destroy InviteMember task when the community is destroyed' do |
119 | 119 | p1 = create_user('testuser1').person |
120 | 120 | p2 = create_user('testuser2').person |
121 | + p3 = create_user('testuser3').person | |
121 | 122 | community = fast_create(Community) |
122 | 123 | |
123 | - task = InviteMember.create!(:person => p1, :friend => p2, :friend_email => 'test@test.com', :community_id => community.id) | |
124 | + t1 = InviteMember.create!(:person => p1, :friend => p2, :community_id => community.id) | |
125 | + t2 = InviteMember.create!(:person => p1, :friend => p3, :community_id => community.id) | |
124 | 126 | community.destroy |
125 | 127 | |
126 | - assert_nil task.reload | |
127 | - end | |
128 | + assert_raise ActiveRecord::RecordNotFound do; t1.reload; end | |
129 | + assert_raise ActiveRecord::RecordNotFound do; t2.reload; end | |
130 | + end | |
128 | 131 | |
129 | 132 | end |
130 | 133 | ... | ... |