Commit 8decbb488e5bc23448f519da7c7c4ec0eb3a7e70

Authored by Rodrigo Souto
2 parents 5768c140 1761e6e4

Merge branch 'invite-member' into 'stable'

Invite Member

http://noosfero.org/Development/ActionItem3054
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 &lt; 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
... ... @@ -115,5 +115,19 @@ class InviteMemberTest &lt; ActiveSupport::TestCase
115 115 assert_match(/#{task.requestor.name} invited you to join #{community.name}/, email.subject)
116 116 end
117 117  
  118 + should 'destroy InviteMember task when the community is destroyed' do
  119 + p1 = create_user('testuser1').person
  120 + p2 = create_user('testuser2').person
  121 + p3 = create_user('testuser3').person
  122 + community = fast_create(Community)
  123 +
  124 + t1 = InviteMember.create!(:person => p1, :friend => p2, :community_id => community.id)
  125 + t2 = InviteMember.create!(:person => p1, :friend => p3, :community_id => community.id)
  126 + community.destroy
  127 +
  128 + assert_raise ActiveRecord::RecordNotFound do; t1.reload; end
  129 + assert_raise ActiveRecord::RecordNotFound do; t2.reload; end
  130 + end
  131 +
118 132 end
119 133  
... ...