Commit 9e22f4a6 authored by zhitomirskiyi's avatar zhitomirskiyi

checks if you already invited the person

parent 1a911a8b
......@@ -25,6 +25,14 @@ class Services::Facebook < Service
data_h[d['id']] = {:name => d['name']}
end
invitation_objects = Invitation.joins(:recipient).where(:sender_id => self.user_id,
:users => {:invitation_service => 'facebook',
:invitation_identifier => data_h.keys})
invitation_objects.each do |inv|
data_h[inv.recipient.invitation_identifier][:invitation] = true
end
service_objects = Services::Facebook.where(:uid => data_h.keys).includes(:user => :person)
service_objects.each do |s|
data_h[s.uid][:person] = s.user.person
......
......@@ -28,6 +28,8 @@
:id => friend[:person].id},
:class => 'button',
:rel => 'facebox'
- elsif friend[:invitation]
= t('invitations.new.already_invited')
- else
= form_tag service_inviter_path do
= select_tag(:aspect_id, options_from_collection_for_select(@all_aspects, 'id', 'name'))
......
......@@ -74,7 +74,24 @@ JSON
connect_users(@user, @user.aspects.first, @user2, @user2.aspects.first)
@service.finder.values.first[:contact].should == @user.reload.contact_for(@user2.person)
end
end
context 'already invited' do
before do
@user2.invitation_service = 'facebook'
@user2.invitation_identifier = @user2_fb_id
@user2.save!
end
it 'contains an invitation if invited' do
@inv = Invitation.create(:sender => @user, :recipient => @user2, :aspect => @user.aspects.first)
@service.finder.values.first[:invitation].should be_true
end
it 'does not find the user with a wrong identifier' do
@user2.invitation_identifier = 'dsaofhnadsoifnsdanf'
@user2.save
@inv = Invitation.create(:sender => @user, :recipient => @user2, :aspect => @user.aspects.first)
@service.finder.values.first[:invitation].should be_nil
end
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment