the invitations add requests which are now correctly auto accepted
This commit is contained in:
parent
d06c6ced38
commit
9727b356e1
9 changed files with 62 additions and 11 deletions
|
|
@ -122,6 +122,7 @@ GEM
|
||||||
selenium-webdriver (>= 0.0.3)
|
selenium-webdriver (>= 0.0.3)
|
||||||
childprocess (0.0.7)
|
childprocess (0.0.7)
|
||||||
ffi (~> 0.6.3)
|
ffi (~> 0.6.3)
|
||||||
|
columnize (0.3.1)
|
||||||
crack (0.1.8)
|
crack (0.1.8)
|
||||||
cucumber (0.9.2)
|
cucumber (0.9.2)
|
||||||
builder (~> 2.1.2)
|
builder (~> 2.1.2)
|
||||||
|
|
@ -162,6 +163,7 @@ GEM
|
||||||
i18n (0.4.1)
|
i18n (0.4.1)
|
||||||
json (1.4.6)
|
json (1.4.6)
|
||||||
json_pure (1.4.6)
|
json_pure (1.4.6)
|
||||||
|
linecache (0.43)
|
||||||
mail (2.2.7)
|
mail (2.2.7)
|
||||||
activesupport (>= 2.3.6)
|
activesupport (>= 2.3.6)
|
||||||
mime-types
|
mime-types
|
||||||
|
|
@ -223,6 +225,11 @@ GEM
|
||||||
rspec-expectations (= 2.0.0)
|
rspec-expectations (= 2.0.0)
|
||||||
rspec-rails (2.0.0)
|
rspec-rails (2.0.0)
|
||||||
rspec (= 2.0.0)
|
rspec (= 2.0.0)
|
||||||
|
ruby-debug (0.10.3)
|
||||||
|
columnize (>= 0.1)
|
||||||
|
ruby-debug-base (~> 0.10.3.0)
|
||||||
|
ruby-debug-base (0.10.3)
|
||||||
|
linecache (>= 0.3)
|
||||||
rubyzip (0.9.4)
|
rubyzip (0.9.4)
|
||||||
selenium-webdriver (0.0.29)
|
selenium-webdriver (0.0.29)
|
||||||
childprocess (>= 0.0.7)
|
childprocess (>= 0.0.7)
|
||||||
|
|
@ -280,6 +287,7 @@ DEPENDENCIES
|
||||||
roxml!
|
roxml!
|
||||||
rspec (>= 2.0.0)
|
rspec (>= 2.0.0)
|
||||||
rspec-rails (>= 2.0.0)
|
rspec-rails (>= 2.0.0)
|
||||||
|
ruby-debug
|
||||||
sprinkle!
|
sprinkle!
|
||||||
thin
|
thin
|
||||||
webmock
|
webmock
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def count_requests
|
def count_requests
|
||||||
@request_count = Request.for_user(current_user).size if current_user
|
@request_count = current_user.requests_for_me.size if current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_invites
|
def set_invites
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class AspectsController < ApplicationController
|
||||||
|
|
||||||
def manage
|
def manage
|
||||||
@aspect = :manage
|
@aspect = :manage
|
||||||
@remote_requests = Request.for_user(current_user).all
|
@remote_requests = current_user.requests_for_me
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,9 @@ class InvitationsController < Devise::InvitationsController
|
||||||
|
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
puts params.inspect
|
||||||
begin
|
begin
|
||||||
params[:aspect_id] = params.delete(:aspects)
|
params[:user][:aspect_id] = params[:user].delete(:aspects)
|
||||||
self.resource = current_user.invite_user(params[resource_name])
|
self.resource = current_user.invite_user(params[resource_name])
|
||||||
flash[:notice] = I18n.t 'invitations.create.sent'
|
flash[:notice] = I18n.t 'invitations.create.sent'
|
||||||
rescue RuntimeError => e
|
rescue RuntimeError => e
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,5 @@
|
||||||
- if @aspect == :all
|
- if @aspect == :all
|
||||||
= f.select(:aspects, @aspects_dropdown_array)
|
= f.select(:aspects, @aspects_dropdown_array)
|
||||||
- else
|
- else
|
||||||
= f.select(:aspects, @aspects_dropdown_array, :selected => [@aspect.to_s, @aspect.id])
|
= f.select(:aspects, @aspects_dropdown_array, :selected => [@aspect.to_s, @aspect_id])
|
||||||
%p= f.submit "Send an invitation"
|
%p= f.submit "Send an invitation"
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,11 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_from_me?(request)
|
def request_from_me?(request)
|
||||||
pending_requests.detect{|req| (req.callback_url == person.receive_url) && (req.destination_url == person.receive_url)}
|
(pending_request_ids.include?(request.id.to_id)) && (request.callback_url == person.receive_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
def requests_for_me
|
||||||
|
pending_requests.select{|req| req.person != self.person }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,10 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Request do
|
describe Request do
|
||||||
let(:user) { Factory(:user) }
|
let(:user) { Factory(:user) }
|
||||||
ler(:person) {Factory :person}
|
let(:user2) { Factory :user}
|
||||||
|
let(:person) {Factory :person}
|
||||||
let(:aspect) { user.aspect(:name => "dudes") }
|
let(:aspect) { user.aspect(:name => "dudes") }
|
||||||
let(:request){ user.send_friend_request_to person, aspect }
|
let(:request){ user.send_friend_request_to user2.person, aspect }
|
||||||
|
|
||||||
it 'should require a destination and callback url' do
|
it 'should require a destination and callback url' do
|
||||||
person_request = Request.new
|
person_request = Request.new
|
||||||
|
|
@ -19,6 +20,8 @@ describe Request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate xml for the User as a Person' do
|
it 'should generate xml for the User as a Person' do
|
||||||
|
|
||||||
|
request = user.send_friend_request_to person, aspect
|
||||||
xml = request.to_xml.to_s
|
xml = request.to_xml.to_s
|
||||||
|
|
||||||
xml.should include user.person.diaspora_handle
|
xml.should include user.person.diaspora_handle
|
||||||
|
|
@ -45,10 +48,25 @@ describe Request do
|
||||||
person_request.destination_url.should == "http://google.com/"
|
person_request.destination_url.should == "http://google.com/"
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'quering request through user' do
|
describe '#request_from_me' do
|
||||||
it 'finds requests the user sent' do
|
it 'recognizes requests from me' do
|
||||||
request
|
request
|
||||||
user.requests_for_me.include?(request).should be true
|
user.reload
|
||||||
|
user.request_from_me?(request).should be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'recognized when a request is not from me' do
|
||||||
|
user2.receive_salmon(user.salmon(request).xml_for(user2.person))
|
||||||
|
user2.reload
|
||||||
|
user2.request_from_me?(request).should == false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'quering request through user' do
|
||||||
|
it 'finds requests for that user' do
|
||||||
|
user2.receive_salmon(user.salmon(request).xml_for(user2.person))
|
||||||
|
user2.reload
|
||||||
|
user2.requests_for_me.include?(request).should == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ describe User do
|
||||||
let(:inviter_with_3_invites) {Factory.create :user, :invites => 3}
|
let(:inviter_with_3_invites) {Factory.create :user, :invites => 3}
|
||||||
let(:aspect2) {inviter_with_3_invites.aspect(:name => "Jersey Girls")}
|
let(:aspect2) {inviter_with_3_invites.aspect(:name => "Jersey Girls")}
|
||||||
let!(:invited_user1) { create_user_with_invitation("abc", :email => "email@example.com", :inviter => inviter)}
|
let!(:invited_user1) { create_user_with_invitation("abc", :email => "email@example.com", :inviter => inviter)}
|
||||||
|
let!(:invited_user2) { inviter.invite_user(:email => "jane@example.com", :aspect_id => aspect.id) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
deliverable = Object.new
|
deliverable = Object.new
|
||||||
|
|
@ -39,6 +40,7 @@ describe User do
|
||||||
it 'sends email to the invited user' do
|
it 'sends email to the invited user' do
|
||||||
::Devise.mailer.should_receive(:invitation).once
|
::Devise.mailer.should_receive(:invitation).once
|
||||||
inviter.invite_user(:email => "ian@example.com", :aspect_id => aspect.id)
|
inviter.invite_user(:email => "ian@example.com", :aspect_id => aspect.id)
|
||||||
|
inviter.invite_user(:email => "ian@example.com", :aspect_id => aspect.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds the inviter to the invited_user' do
|
it 'adds the inviter to the invited_user' do
|
||||||
|
|
@ -87,6 +89,24 @@ describe User do
|
||||||
Person.count.should be person_count + 1
|
Person.count.should be person_count + 1
|
||||||
u.person.profile.first_name.should == "Bob"
|
u.person.profile.first_name.should == "Bob"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should auto accept the request for the sender into the right aspect' do
|
||||||
|
u = invited_user2.accept_invitation!(:invitation_token => invited_user2.invitation_token,
|
||||||
|
:username => "user",
|
||||||
|
:password => "secret",
|
||||||
|
:password_confirmation => "secret",
|
||||||
|
:person => {:profile => {:first_name => "Bob",
|
||||||
|
:last_name => "Smith"}} )
|
||||||
|
u.reload
|
||||||
|
u.pending_requests
|
||||||
|
u.pending_requests.count.should == 1
|
||||||
|
request = u.pending_requests.first
|
||||||
|
aspect2 = u.aspect(:name => "dudes")
|
||||||
|
u.reload
|
||||||
|
inviter
|
||||||
|
inviter.receive_salmon(u.salmon(u.accept_friend_request(request.id, aspect2.id)).xml_for(inviter.person))
|
||||||
|
inviter.friends.include?(u.person).should be true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ require 'database_cleaner'
|
||||||
require 'webmock/rspec'
|
require 'webmock/rspec'
|
||||||
|
|
||||||
include Devise::TestHelpers
|
include Devise::TestHelpers
|
||||||
include WebMock
|
include WebMock::API
|
||||||
|
|
||||||
# Requires supporting files with custom matchers and macros, etc,
|
# Requires supporting files with custom matchers and macros, etc,
|
||||||
# in ./support/ and its subdirectories.
|
# in ./support/ and its subdirectories.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue