Commit 358e1f31c396944ed8689f70a493e076f295164a
Exists in
master
and in
21 other branches
Merge branch 'fix_task_invitation' into 'master'
Fix invitation tasks Fix creation of tasks to invite already registered users See merge request !399
Showing
2 changed files
with
20 additions
and
9 deletions
Show diff stats
app/models/invitation.rb
| ... | ... | @@ -65,18 +65,16 @@ class Invitation < Task |
| 65 | 65 | |
| 66 | 66 | task_args = if user.nil? |
| 67 | 67 | {:person => person, :friend_name => friend_name, :friend_email => friend_email, :message => message} |
| 68 | - elsif !user.person.is_a_friend?(person) | |
| 68 | + else | |
| 69 | 69 | {:person => person, :target => user.person} |
| 70 | 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 | 78 | end |
| 81 | 79 | end |
| 82 | 80 | end | ... | ... |
test/unit/invitation_test.rb
| ... | ... | @@ -60,6 +60,19 @@ class InvitationTest < ActiveSupport::TestCase |
| 60 | 60 | end |
| 61 | 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 | 76 | should 'not crash if the invited friend is already your friend in the environment' do |
| 64 | 77 | person = create_user('person').person |
| 65 | 78 | invited_friend = create_user('invited_friend').person | ... | ... |