diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 1b03a3660..452cc0319 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -53,11 +53,15 @@ class ServicesController < ApplicationController def inviter @uid = params[:uid] @subject = "Join me on DIASPORA*" - @message = "" - current_user.invite_user(aspect_id, :service => params[:provider], - :identifier => params[:uid]) - - redirect_to "http://facebook.com" + invited_user = current_user.invite_user(params[:aspect_id], params[:provider], params[:uid]) + + @message = < invited_user.invitation_token)} +MSG + redirect_to "https://www.facebook.com/?compose=1&id=#{@uid}&subject=#{@subject}&message=#{@message}&sk=messages" end end diff --git a/app/models/invitation.rb b/app/models/invitation.rb index 79a6364cb..4cbe2e774 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -50,7 +50,7 @@ class Invitation < ActiveRecord::Base def self.create_invitee(opts = {}) invitee = new_or_existing_user_by_service_and_identifier(opts[:service], opts[:identifier]) - return invitee unless opts[:service] == 'email' && opts[:identifier].match(Devise.email_regexp) + return invitee if opts[:service] == 'email' && !opts[:identifier].match(Devise.email_regexp) invitee.invites = opts[:invites] || 0 if invitee.new_record? invitee.errors.clear diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 75eebd895..c62feb4c0 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -96,7 +96,6 @@ describe ServicesController do describe '#invite' do before do - pending @service1 = Services::Facebook.create(:provider => 'facebook') @uid = "abc" @invite_params = {:provider => @service1.provider, :uid => @uid, :aspect_id => @user.aspects.first.id} @@ -110,18 +109,17 @@ describe ServicesController do it 'sets the subject' do put :inviter, @invite_params - assigns[:@subject].should_not be_nil + assigns[:subject].should_not be_nil end it 'sets a message containing the invitation link' do put :inviter, @invite_params - assigns[:@message].should include(User.last.invitation_token) + assigns[:message].should include(User.last.invitation_token) end it 'redirects to a prefilled facebook message url' do put :inviter, @invite_params - response.should be_redirect - response.should have_text(/http:\/\/www\.facebook\.com\/\?compose=1&id=.*&subject=.*&message=.*&sk=messages/) + response.location.should match(/https:\/\/www\.facebook\.com\/\?compose=1&id=.*&subject=.*&message=.*&sk=messages/) end end