diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 988673fd35ad354a6eeeaf5b5b55da444be6ac88..e8783e149ca13a94461f2bba6fee624a59fa58fc 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -148,14 +148,18 @@ class AspectsController < ApplicationController :person_id => @person_id}), :aspect_id => @aspect_id }} - format.html{ redirect_to aspect_path(@aspect_id)} + format.html{ + redirect_to :back + } end rescue Exception => e flash.now[:error] = I18n.t 'aspects.remove_from_aspect.failure' respond_to do |format| format.js { render :text => e, :status => 403 } - format.html{ redirect_to aspect_path(@aspect_id)} + format.html{ + redirect_to :back + } end end end diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index 3e1f2df51907f69e39787a99a2b2a654c1e81d83..696b37ff1c3383331343dd5076438c6b7b023c6c 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -29,7 +29,7 @@ class RequestsController < ApplicationController def create 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) existing_request = Request.from(person).to(current_user.person).where(:sent => false).first if person if existing_request diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 0175a3eb930df6040085a8e116150f73a2ec0c69..53c6a0e0119cf96ad38197e703b399b894fb49d3 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -221,10 +221,16 @@ describe AspectsController do end 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 @aspect1.reload @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.contacts.include?(@contact).should be_true end @@ -232,13 +238,13 @@ describe AspectsController do describe "#remove_from_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.contacts.include?(@contact).should be true - post 'remove_from_aspect', {:person_id => @user2.person.id, :aspect_id => @aspect1.id} - @aspect1.reload - @aspect1.contacts.include?(@contact).should be false + post 'remove_from_aspect', :format => 'js', :person_id => @user2.person.id, :aspect_id => @aspect.id + response.should be_success + @aspect.reload + @aspect.contacts.include?(@contact).should be false end end end diff --git a/spec/controllers/requests_controller_spec.rb b/spec/controllers/requests_controller_spec.rb index f5c9a52335690f62c50ee670109fdff64034dca3..9544e65ab6764dd163ff456f0af6705a828f6b00 100644 --- a/spec/controllers/requests_controller_spec.rb +++ b/spec/controllers/requests_controller_spec.rb @@ -11,7 +11,7 @@ describe RequestsController do sign_in :user, @user request.env["HTTP_REFERER"] = "http://test.host" - + @user.aspects.create!(:name => "lame-os") @user.reload @@ -38,7 +38,7 @@ describe RequestsController do response.should be_success end it "removes the request object" do - lambda { + lambda { xhr :delete, :destroy, "id" => @friend_request.id.to_s }.should change(Request, 'count').by(-1) end @@ -46,57 +46,77 @@ describe RequestsController do end 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 - #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 + @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 + 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 post(:create, :request => { :to => @user.diaspora_handle, - :into => @user.aspects[0].id - } + :into => @user.aspects[0].id + } ) + flash[:error].should_not be_blank 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 + :into => @user.aspects[0].id } ) flash[:error].should_not be_blank response.should redirect_to :back end - - it "flashes and redirects when requesting an invalid identity with a port number" do + + it "accepts no port numbers" do post(:create, :request => { :to => "johndoe@email.com:3000", - :into => @user.aspects[0].id - } + :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 post(:create, :request => { :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 end end