Commit a9370dcb04ca27493190f748a9a576b5b7fc0ea7

Authored by Victor Costa
2 parents c11afdc5 2006ce6e

Merge branch 'fix_task_invitation' into stable

app/models/invitation.rb
@@ -65,18 +65,16 @@ class Invitation < Task @@ -65,18 +65,16 @@ class Invitation < Task
65 65
66 task_args = if user.nil? 66 task_args = if user.nil?
67 {:person => person, :friend_name => friend_name, :friend_email => friend_email, :message => message} 67 {:person => person, :friend_name => friend_name, :friend_email => friend_email, :message => message}
68 - elsif !user.person.is_a_friend?(person) 68 + else
69 {:person => person, :target => user.person} 69 {:person => person, :target => user.person}
70 end 70 end
71 71
72 - if !task_args.nil?  
73 - if profile.person?  
74 - InviteFriend.create(task_args)  
75 - elsif profile.community?  
76 - InviteMember.create(task_args.merge(:community_id => profile.id))  
77 - else  
78 - raise NotImplementedError, 'Don\'t know how to invite people to a %s' % profile.class.to_s  
79 - end 72 + if profile.person?
  73 + InviteFriend.create(task_args) if user.nil? || !user.person.is_a_friend?(person)
  74 + elsif profile.community?
  75 + InviteMember.create(task_args.merge(:community_id => profile.id)) if user.nil? || !user.person.is_member_of?(profile)
  76 + else
  77 + raise NotImplementedError, 'Don\'t know how to invite people to a %s' % profile.class.to_s
80 end 78 end
81 end 79 end
82 end 80 end
test/unit/invitation_test.rb
@@ -60,6 +60,19 @@ class InvitationTest < ActiveSupport::TestCase @@ -60,6 +60,19 @@ class InvitationTest < ActiveSupport::TestCase
60 end 60 end
61 end 61 end
62 62
  63 + should 'not create task if the invited member is already a member of the community' do
  64 + person = fast_create(Person)
  65 + person.user = User.new(:email => 'current_user@email.invalid')
  66 + community = fast_create(Community)
  67 + user_to_invite = fast_create(User, :email => 'person_to_invite@email.invalid')
  68 + person_to_invite = fast_create(Person, :user_id => user_to_invite.id)
  69 + community.add_member(person_to_invite)
  70 +
  71 + assert_no_difference 'InviteMember.count' do
  72 + Invitation.invite(person, ['person_to_invite@email.invalid'], 'hello friend <url>', community)
  73 + end
  74 + end
  75 +
63 should 'not crash if the invited friend is already your friend in the environment' do 76 should 'not crash if the invited friend is already your friend in the environment' do
64 person = create_user('person').person 77 person = create_user('person').person
65 invited_friend = create_user('invited_friend').person 78 invited_friend = create_user('invited_friend').person