diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index f368e6748..c9a332399 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -70,6 +70,11 @@ class ServicesController < ApplicationController #{accept_invitation_url(invited_user, :invitation_token => invited_user.invitation_token)} MSG + service = current_user.services.where(:type => "Services::Facebook").first + su = ServiceUser.where(:service_id => service.id, :uid => @uid).first + su.attach_local_models + su.save + url = "https://www.facebook.com/?compose=1&id=#{@uid}&subject=#{@subject}&message=#{@message}&sk=messages" respond_to do |format| format.html{ redirect_to url } diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 80edbc208..11d161dd0 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -38,7 +38,7 @@ describe ServicesController do end describe '#create' do - it 'creates a new OmniauthService' do + it 'creates a new OmniauthService' do request.env['omniauth.auth'] = omniauth_auth lambda{ post :create, :provider => 'twitter' @@ -105,9 +105,12 @@ describe ServicesController do end end - describe '#invite' do + describe '#inviter' do before do @uid = "abc" + fb = Factory(:service, :type => "Services::Facebook", :user => @user) + fb = Services::Facebook.find(fb.id) + @su = Factory(:service_user, :service => fb, :uid => @uid) @invite_params = {:provider => 'facebook', :uid => @uid, :aspect_id => @user.aspects.first.id} end @@ -132,6 +135,11 @@ describe ServicesController do }.should change(Invitation, :count).by(1) end + it 'sets the invitation_id on the service_user' do + post :inviter, @invite_params + @su.reload.invitation.should_not be_nil + end + it 'does not create a duplicate invitation' do inv = Invitation.create!(:sender_id => @user.id, :recipient_id => eve.id, :aspect_id => @user.aspects.first.id) @invite_params[:invitation_id] = inv.id