From e30b82dd45374155cd9d4510bf4882b13682e6b6 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Tue, 12 Jul 2011 15:07:29 -0700 Subject: [PATCH] Fix resend links in inviter --- app/models/invitation.rb | 8 ++++++++ app/views/invitations/new.html.haml | 5 +++-- spec/models/invitation_spec.rb | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/models/invitation.rb b/app/models/invitation.rb index bb86f6116c6..078b18d5636 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -92,4 +92,12 @@ def share_with! destroy if contact contact end + + def recipient_identifier + if recipient.invitation_service == 'email' + recipient.invitation_identifier + elsif recipient.invitation_service == 'facebook' + ServiceUser.where(:uid => recipient.invitation_identifier).first.name + end + end end diff --git a/app/views/invitations/new.html.haml b/app/views/invitations/new.html.haml index 89a086c7e96..5977375c786 100644 --- a/app/views/invitations/new.html.haml +++ b/app/views/invitations/new.html.haml @@ -36,11 +36,12 @@ %p = invite.submit t('.send_an_invitation') - - if !@sent_invitations.empty? + - unless @sent_invitations.empty? .span-6.last #already_invited_pane %h4 = t('.already_invited') - for invitation in @sent_invitations - = invitation.recipient.email + = invitation.recipient_identifier = link_to t('.resend'), invitation_resend_path(invitation), :confirm => t('are_you_sure') + %br diff --git a/spec/models/invitation_spec.rb b/spec/models/invitation_spec.rb index 65629c2ec75..929868ad6df 100644 --- a/spec/models/invitation_spec.rb +++ b/spec/models/invitation_spec.rb @@ -21,7 +21,7 @@ end it 'is valid' do @invitation.sender.should == user - @invitation.recipient.should == eve + @invitation.recipient.should == eve @invitation.aspect.should == aspect @invitation.should be_valid end @@ -323,5 +323,20 @@ }.should change(Contact, :count).by(2) end end + + describe '#recipient_identifier' do + it 'calls email if the invitation_service is email' do + alice.invite_user(aspect.id, 'email', "a@a.com", "") + invitation = alice.reload.invitations_from_me.first + invitation.recipient_identifier.should == 'a@a.com' + end + it 'gets the name if the invitation_service is facebook' do + alice.services << Services::Facebook.new(:uid => "13234895") + alice.reload.services(true).first.service_users.create(:uid => "23526464", :photo_url => 'url', :name => "Remote User") + alice.invite_user(aspect.id, 'facebook', "23526464", '') + invitation = alice.reload.invitations_from_me.first + invitation.recipient_identifier.should == "Remote User" + end + end end