diff --git a/app/models/invitation.rb b/app/models/invitation.rb index e48ff5c..090239c 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -60,12 +60,14 @@ class Invitation < Task {:person => person, :target => user.person} end - if profile.person? - InviteFriend.create(task_args) - elsif profile.community? - InviteMember.create(task_args.merge(:community_id => profile.id)) - else - raise NotImplementedError, 'Don\'t know how to invite people to a %s' % profile.class.to_s + if !task_args.nil? + if profile.person? + InviteFriend.create(task_args) + elsif profile.community? + InviteMember.create(task_args.merge(:community_id => profile.id)) + else + raise NotImplementedError, 'Don\'t know how to invite people to a %s' % profile.class.to_s + end end end end diff --git a/test/unit/invitation_test.rb b/test/unit/invitation_test.rb index 0f35ebd..5f9499c 100644 --- a/test/unit/invitation_test.rb +++ b/test/unit/invitation_test.rb @@ -59,4 +59,16 @@ class InvitationTest < ActiveSupport::TestCase end end + should 'not crash if the invited friend is already your friend in the environment' do + person = create_user('person').person + invited_friend = create_user('invited_friend').person + community = fast_create(Community) + + invited_friend.add_friend(person) + + assert_nothing_raised NoMethodError do + Invitation.invite( person, [invited_friend.user.email], "", community ) + end + end + end -- libgit2 0.21.2