Commit fd3ac0d828fc2f33e6aa0f81b7de3e249c06b019
Committed by
Antonio Terceiro
1 parent
2108a3c4
Exists in
master
and in
28 other branches
Not crashing when inviting a friend in the environment
* Granting that the attribute 'task_args' isn't nil before trying to merge. (ActionItem1411)
Showing
2 changed files
with
20 additions
and
6 deletions
Show diff stats
app/models/invitation.rb
@@ -60,12 +60,14 @@ class Invitation < Task | @@ -60,12 +60,14 @@ class Invitation < Task | ||
60 | {:person => person, :target => user.person} | 60 | {:person => person, :target => user.person} |
61 | end | 61 | end |
62 | 62 | ||
63 | - if profile.person? | ||
64 | - InviteFriend.create(task_args) | ||
65 | - elsif profile.community? | ||
66 | - InviteMember.create(task_args.merge(:community_id => profile.id)) | ||
67 | - else | ||
68 | - raise NotImplementedError, 'Don\'t know how to invite people to a %s' % profile.class.to_s | 63 | + if !task_args.nil? |
64 | + if profile.person? | ||
65 | + InviteFriend.create(task_args) | ||
66 | + elsif profile.community? | ||
67 | + InviteMember.create(task_args.merge(:community_id => profile.id)) | ||
68 | + else | ||
69 | + raise NotImplementedError, 'Don\'t know how to invite people to a %s' % profile.class.to_s | ||
70 | + end | ||
69 | end | 71 | end |
70 | end | 72 | end |
71 | end | 73 | end |
test/unit/invitation_test.rb
@@ -59,4 +59,16 @@ class InvitationTest < ActiveSupport::TestCase | @@ -59,4 +59,16 @@ class InvitationTest < ActiveSupport::TestCase | ||
59 | end | 59 | end |
60 | end | 60 | end |
61 | 61 | ||
62 | + should 'not crash if the invited friend is already your friend in the environment' do | ||
63 | + person = create_user('person').person | ||
64 | + invited_friend = create_user('invited_friend').person | ||
65 | + community = fast_create(Community) | ||
66 | + | ||
67 | + invited_friend.add_friend(person) | ||
68 | + | ||
69 | + assert_nothing_raised NoMethodError do | ||
70 | + Invitation.invite( person, [invited_friend.user.email], "", community ) | ||
71 | + end | ||
72 | + end | ||
73 | + | ||
62 | end | 74 | end |