WIP pending contacts

This commit is contained in:
Raphael 2010-12-13 18:51:00 -08:00 committed by danielvincent
parent 251cdec2ec
commit 06b7b1c99a
4 changed files with 71 additions and 41 deletions

View file

@ -148,14 +148,18 @@ class AspectsController < ApplicationController
:person_id => @person_id}), :person_id => @person_id}),
:aspect_id => @aspect_id :aspect_id => @aspect_id
}} }}
format.html{ redirect_to aspect_path(@aspect_id)} format.html{
redirect_to :back
}
end end
rescue Exception => e rescue Exception => e
flash.now[:error] = I18n.t 'aspects.remove_from_aspect.failure' flash.now[:error] = I18n.t 'aspects.remove_from_aspect.failure'
respond_to do |format| respond_to do |format|
format.js { render :text => e, :status => 403 } format.js { render :text => e, :status => 403 }
format.html{ redirect_to aspect_path(@aspect_id)} format.html{
redirect_to :back
}
end end
end end
end end

View file

@ -29,7 +29,7 @@ class RequestsController < ApplicationController
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)
existing_request = Request.from(person).to(current_user.person).where(:sent => false).first if person existing_request = Request.from(person).to(current_user.person).where(:sent => false).first if person
if existing_request if existing_request

View file

@ -221,10 +221,16 @@ describe AspectsController do
end end
describe "#add_to_aspect" do describe "#add_to_aspect" do
context 'with a non-contact' do
it 'creates a pending contact' do
pending
end
end
it 'adds the users to the aspect' do it 'adds the users to the aspect' do
@aspect1.reload @aspect1.reload
@aspect1.contacts.include?(@contact).should be_false @aspect1.contacts.include?(@contact).should be_false
post 'add_to_aspect', {:person_id => @user2.person.id, :aspect_id => @aspect1.id} post 'add_to_aspect', :format => 'js', :person_id => @user2.person.id, :aspect_id => @aspect1.id
response.should be_success
@aspect1.reload @aspect1.reload
@aspect1.contacts.include?(@contact).should be_true @aspect1.contacts.include?(@contact).should be_true
end end
@ -232,13 +238,13 @@ describe AspectsController do
describe "#remove_from_aspect" do describe "#remove_from_aspect" do
it 'removes contacts from an aspect' do it 'removes contacts from an aspect' do
pending 'this needs to test with another aspect present' @user.add_person_to_aspect( @user2.person.id, @aspect1.id)
@aspect.reload @aspect.reload
@aspect.contacts.include?(@contact).should be true @aspect.contacts.include?(@contact).should be true
post 'remove_from_aspect', {:person_id => @user2.person.id, :aspect_id => @aspect1.id} post 'remove_from_aspect', :format => 'js', :person_id => @user2.person.id, :aspect_id => @aspect.id
@aspect1.reload response.should be_success
@aspect1.contacts.include?(@contact).should be false @aspect.reload
@aspect.contacts.include?(@contact).should be false
end end
end end
end end

View file

@ -11,7 +11,7 @@ describe RequestsController do
sign_in :user, @user sign_in :user, @user
request.env["HTTP_REFERER"] = "http://test.host" request.env["HTTP_REFERER"] = "http://test.host"
@user.aspects.create!(:name => "lame-os") @user.aspects.create!(:name => "lame-os")
@user.reload @user.reload
@ -38,7 +38,7 @@ describe RequestsController do
response.should be_success response.should be_success
end end
it "removes the request object" do it "removes the request object" do
lambda { lambda {
xhr :delete, :destroy, "id" => @friend_request.id.to_s xhr :delete, :destroy, "id" => @friend_request.id.to_s
}.should change(Request, 'count').by(-1) }.should change(Request, 'count').by(-1)
end end
@ -46,57 +46,77 @@ describe RequestsController do
end end
describe '#create' do describe '#create' do
context 'valid new request' do
before do
@params = {:request => {:to => @other_user.diaspora_handle,
:into => @user.aspects[0].id}}
end
it 'creates a contact' do
@user.contact_for(@other_user).should be_nil
lambda {
post :create, @params
}.should change(Contact,:count).by(1)
new_contact = @user.reload.contact_for(@other_user)
new_contact.should_not be_nil
new_contact.should be_pending
end
it 'does not persist a Request' do
lambda {
post :create, @params
}.should_not change(Request,:count)
end
end
it 'autoaccepts and when sending a request to someone who sent me a request' 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])
@other_user.send_contact_request_to(@user.person, @other_user.aspects[0]) @user.reload.pending_requests.count.should == 1
@user.reload.pending_requests.count.should == 1 @user.contact_for(@other_user.person).should be_nil
@user.contact_for(@other_user.person).should be_nil
post(:create, :request => { post(:create, :request => {
:to => @other_user.diaspora_handle, :to => @other_user.diaspora_handle,
:into => @user.aspects[0].id :into => @user.aspects[0].id}
} )
) @user.reload.pending_requests.count.should == 0
@user.reload.pending_requests.count.should == 0 @user.contact_for(@other_user.person).should_not be_nil
@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
@user.aspects[0].contacts.all(:person_id => @other_user.person.id).should_not be_nil
end 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,
:into => @user.aspects[0].id :into => @user.aspects[0].id
}
)
response.should redirect_to :back
end
it "flashes and redirects when requesting an invalid identity" do
post(:create, :request => {
:to => "not_a_@valid_email",
:into => @user.aspects[0].id
} }
) )
flash[:error].should_not be_blank flash[:error].should_not be_blank
response.should redirect_to :back response.should redirect_to :back
end end
it "flashes and redirects when requesting an invalid identity with a port number" do it "flashes and redirects when requesting an invalid identity" do
post(:create, :request => { post(:create, :request => {
:to => "johndoe@email.com:3000", :to => "not_a_@valid_email",
:into => @user.aspects[0].id :into => @user.aspects[0].id
} }
) )
flash[:error].should_not be_blank flash[:error].should_not be_blank
response.should redirect_to :back response.should redirect_to :back
end end
it "accepts no port numbers" do
post(:create, :request => {
:to => "johndoe@email.com:3000",
:into => @user.aspects[0].id
}
)
flash[:error].should_not be_blank
response.should redirect_to :back
end
it "redirects when requesting an identity from an invalid server" do it "redirects when requesting an identity from an invalid server" do
post(:create, :request => { post(:create, :request => {
:to => "johndoe@notadiasporaserver.com", :to => "johndoe@notadiasporaserver.com",
:into => @user.aspects[0].id :into => @user.aspects[0].id
} }
) )
flash[:error].should_not be_blank
response.should redirect_to :back response.should redirect_to :back
end end
end end