made service#invite redirect to the right place

This commit is contained in:
zhitomirskiyi 2011-01-26 12:16:00 -08:00
parent 3392f11b64
commit 89a8817ce6
3 changed files with 13 additions and 11 deletions

View file

@ -53,11 +53,15 @@ class ServicesController < ApplicationController
def inviter def inviter
@uid = params[:uid] @uid = params[:uid]
@subject = "Join me on DIASPORA*" @subject = "Join me on DIASPORA*"
@message = ""
current_user.invite_user(aspect_id, :service => params[:provider], invited_user = current_user.invite_user(params[:aspect_id], params[:provider], params[:uid])
:identifier => params[:uid])
@message = <<MSG
redirect_to "http://facebook.com" Diaspora* is the social network that puts you in control of your information. You decide what you'd like to share, and with whom. You retain full ownership of all your information, including friend lists, messages, photos, and profile details.
Click here to accept your invitation:
#{accept_invitation_url(invited_user, :invitation_token => invited_user.invitation_token)}
MSG
redirect_to "https://www.facebook.com/?compose=1&id=#{@uid}&subject=#{@subject}&message=#{@message}&sk=messages"
end end
end end

View file

@ -50,7 +50,7 @@ class Invitation < ActiveRecord::Base
def self.create_invitee(opts = {}) def self.create_invitee(opts = {})
invitee = new_or_existing_user_by_service_and_identifier(opts[:service], opts[:identifier]) 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 invitee.invites = opts[:invites] || 0
if invitee.new_record? if invitee.new_record?
invitee.errors.clear invitee.errors.clear

View file

@ -96,7 +96,6 @@ describe ServicesController do
describe '#invite' do describe '#invite' do
before do before do
pending
@service1 = Services::Facebook.create(:provider => 'facebook') @service1 = Services::Facebook.create(:provider => 'facebook')
@uid = "abc" @uid = "abc"
@invite_params = {:provider => @service1.provider, :uid => @uid, :aspect_id => @user.aspects.first.id} @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 it 'sets the subject' do
put :inviter, @invite_params put :inviter, @invite_params
assigns[:@subject].should_not be_nil assigns[:subject].should_not be_nil
end end
it 'sets a message containing the invitation link' do it 'sets a message containing the invitation link' do
put :inviter, @invite_params put :inviter, @invite_params
assigns[:@message].should include(User.last.invitation_token) assigns[:message].should include(User.last.invitation_token)
end end
it 'redirects to a prefilled facebook message url' do it 'redirects to a prefilled facebook message url' do
put :inviter, @invite_params put :inviter, @invite_params
response.should be_redirect response.location.should match(/https:\/\/www\.facebook\.com\/\?compose=1&id=.*&subject=.*&message=.*&sk=messages/)
response.should have_text(/http:\/\/www\.facebook\.com\/\?compose=1&id=.*&subject=.*&message=.*&sk=messages/)
end end
end end