Sending a request to someone who requested you autoaccepts the request
This commit is contained in:
parent
c7ac90538a
commit
1519fd46bf
4 changed files with 45 additions and 35 deletions
|
|
@ -32,19 +32,25 @@ class RequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
aspect = current_user.aspect_by_id(params[:request][:into])
|
aspect = current_user.aspect_by_id(params[:request][:into])
|
||||||
account = params[:request][:to].strip
|
account = params[:request][:to].strip
|
||||||
person = Person.by_account_identifier(account)
|
person = Person.by_account_identifier(account)
|
||||||
@request = Request.instantiate(:to => person,
|
existing_request = Request.from(person).to(current_user.person).where(:sent => false).first if person
|
||||||
:from => current_user.person,
|
if existing_request
|
||||||
:into => aspect)
|
current_user.accept_and_respond(existing_request.id, aspect.id)
|
||||||
if @request.save
|
redirect_to :back
|
||||||
current_user.dispatch_request(@request)
|
else
|
||||||
flash.now[:notice] = I18n.t('requests.create.sent')
|
@request = Request.instantiate(:to => person,
|
||||||
redirect_to :back
|
:from => current_user.person,
|
||||||
else
|
:into => aspect)
|
||||||
flash.now[:error] = @request.errors.full_messages.join(', ')
|
if @request.save
|
||||||
redirect_to :back
|
current_user.dispatch_request(@request)
|
||||||
end
|
flash.now[:notice] = I18n.t('requests.create.sent')
|
||||||
|
redirect_to :back
|
||||||
|
else
|
||||||
|
flash.now[:error] = @request.errors.full_messages.join(', ')
|
||||||
|
redirect_to :back
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ module Diaspora
|
||||||
module UserModules
|
module UserModules
|
||||||
module Connecting
|
module Connecting
|
||||||
def send_contact_request_to(desired_contact, aspect)
|
def send_contact_request_to(desired_contact, aspect)
|
||||||
|
##THIS METHOD IS ONLY USED IN TEST HELPERS
|
||||||
request = Request.instantiate(:to => desired_contact,
|
request = Request.instantiate(:to => desired_contact,
|
||||||
:from => self.person,
|
:from => self.person,
|
||||||
:into => aspect)
|
:into => aspect)
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,16 @@ describe RequestsController do
|
||||||
|
|
||||||
@user.aspects.create!(:name => "lame-os")
|
@user.aspects.create!(:name => "lame-os")
|
||||||
@user.reload
|
@user.reload
|
||||||
|
|
||||||
|
@other_user = make_user
|
||||||
|
@other_user.aspects.create!(:name => "meh")
|
||||||
|
@other_user.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#destroy' do
|
describe '#destroy' do
|
||||||
before do
|
before do
|
||||||
@other_user = make_user
|
|
||||||
@other_user.aspects.create!(:name => "meh")
|
|
||||||
@other_user.reload
|
|
||||||
|
|
||||||
@other_user.send_contact_request_to(@user.person, @other_user.aspects.first)
|
@other_user.send_contact_request_to(@user.person, @other_user.aspects.first)
|
||||||
@user.reload # so it can find its pending requests.
|
@user.reload # so it can find its pending requests.
|
||||||
@friend_request = @user.pending_requests.first
|
@friend_request = @user.pending_requests.first
|
||||||
|
|
@ -46,6 +48,22 @@ describe RequestsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#create' do
|
describe '#create' do
|
||||||
|
it 'autoaccepts and when sending a request to someone who sent me a request' do
|
||||||
|
#pending "When a user sends a request to person who requested them the request should be auto accepted"
|
||||||
|
@other_user.send_contact_request_to(@user.person, @other_user.aspects[0])
|
||||||
|
@user.reload.pending_requests.count.should == 1
|
||||||
|
@user.contact_for(@other_user.person).should be_nil
|
||||||
|
|
||||||
|
post(:create, :request => {
|
||||||
|
:to => @other_user.diaspora_handle,
|
||||||
|
:into => @user.aspects[0].id
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@user.reload.pending_requests.count.should == 0
|
||||||
|
@user.contact_for(@other_user.person).should_not be_nil
|
||||||
|
@user.aspects[0].contacts.all(:person_id => @other_user.person.id).should_not be_nil
|
||||||
|
end
|
||||||
|
|
||||||
it "redirects when requesting to be contacts with yourself" do
|
it "redirects when requesting to be contacts with yourself" do
|
||||||
post(:create, :request => {
|
post(:create, :request => {
|
||||||
:to => @user.diaspora_handle,
|
:to => @user.diaspora_handle,
|
||||||
|
|
|
||||||
|
|
@ -59,21 +59,6 @@ describe Diaspora::UserModules::Connecting do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'requests that cross paths' do
|
|
||||||
it 'autoaccepts and when sending a request to someone who sent me a request' do
|
|
||||||
pending "When a user sends a request to person who requested them the request should be auto accepted"
|
|
||||||
user.send_contact_request_to(user2.person, aspect)
|
|
||||||
user2.reload.pending_requests.count.should == 1
|
|
||||||
user2.contact_for(user.person).should be_nil
|
|
||||||
|
|
||||||
user2.send_contact_request_to(user.person, aspect2)
|
|
||||||
user2.reload.pending_requests.count.should == 0
|
|
||||||
user2.contact_for(user.person).should_not be_nil
|
|
||||||
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'received a contact request' do
|
context 'received a contact request' do
|
||||||
|
|
||||||
let(:request_for_user) {Request.instantiate(:to => user.person, :from => person)}
|
let(:request_for_user) {Request.instantiate(:to => user.person, :from => person)}
|
||||||
|
|
@ -117,7 +102,7 @@ describe Diaspora::UserModules::Connecting do
|
||||||
}.should raise_error(MongoMapper::DocumentNotValid, /already connected/)
|
}.should raise_error(MongoMapper::DocumentNotValid, /already connected/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be able to contact request yourself' do
|
it 'should not be able to contact request no-one' do
|
||||||
proc { user.send_contact_request_to(nil, aspect)
|
proc { user.send_contact_request_to(nil, aspect)
|
||||||
}.should raise_error(MongoMapper::DocumentNotValid)
|
}.should raise_error(MongoMapper::DocumentNotValid)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue