diff --git a/app/controllers/aspect_memberships_controller.rb b/app/controllers/aspect_memberships_controller.rb index 3c49cffb9..fc826a654 100644 --- a/app/controllers/aspect_memberships_controller.rb +++ b/app/controllers/aspect_memberships_controller.rb @@ -47,19 +47,23 @@ class AspectMembershipsController < ApplicationController @person = Person.find(params[:person_id]) @aspect = current_user.aspects.where(:id => params[:aspect_id]).first - current_user.share_with(@person, @aspect) + if current_user.share_with(@person, @aspect) - flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success' + flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success' - respond_to do |format| - format.js { render :json => { - :button_html => render_to_string(:partial => 'aspect_memberships/add_to_aspect', - :locals => {:aspect_id => @aspect.id, - :person_id => @person.id}), - :badge_html => render_to_string(:partial => 'aspects/aspect_badge', - :locals => {:aspect => @aspect}) - }} - format.html{ redirect_to aspect_path(@aspect.id)} + respond_to do |format| + format.js { render :json => { + :button_html => render_to_string(:partial => 'aspect_memberships/add_to_aspect', + :locals => {:aspect_id => @aspect.id, + :person_id => @person.id}), + :badge_html => render_to_string(:partial => 'aspects/aspect_badge', + :locals => {:aspect => @aspect}) + }} + format.html{ redirect_to aspect_path(@aspect.id)} + end + else + flash[:error] = I18n.t 'contacts.create.failure' + redirect_to :back end end diff --git a/app/views/contacts/_share_with_list.html.haml b/app/views/contacts/_share_with_list.html.haml index 59957923c..442225ece 100644 --- a/app/views/contacts/_share_with_list.html.haml +++ b/app/views/contacts/_share_with_list.html.haml @@ -31,5 +31,5 @@ .done .right = link_to t('aspects.aspect_contacts.done_editing'), "#", :class => "button", :onClick => '$.facebox.close();' - - if contact + - if contact.persisted? = link_to t('people.profile_sidebar.remove_contact'), contact, :confirm => t('are_you_sure'), :method => :delete diff --git a/features/connects_users.feature b/features/connects_users.feature index 38336cd53..3c493a661 100644 --- a/features/connects_users.feature +++ b/features/connects_users.feature @@ -7,7 +7,6 @@ Feature: sending and receiving requests When I sign in as "bob@bob.bob" And I am on "alice@alice.alice"'s page - And I press the first ".share_with.button" And I wait for the ajax to finish And I add the person to my first aspect diff --git a/lib/postzord/receiver.rb b/lib/postzord/receiver.rb index 0cfcdcbcf..e3cc16d51 100644 --- a/lib/postzord/receiver.rb +++ b/lib/postzord/receiver.rb @@ -60,6 +60,12 @@ module Postzord end def validate_object + #begin similar + unless @object.is_a?(Request) || @user.contact_for(@sender) + Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}") + return false + end + #special casey if @object.is_a?(Request) @object.sender_handle = @sender.diaspora_handle diff --git a/spec/controllers/aspect_memberships_controller_spec.rb b/spec/controllers/aspect_memberships_controller_spec.rb index 6a660f926..338bf4a54 100644 --- a/spec/controllers/aspect_memberships_controller_spec.rb +++ b/spec/controllers/aspect_memberships_controller_spec.rb @@ -8,38 +8,71 @@ describe AspectMembershipsController do render_views before do - @user = alice - @user2 = bob + @aspect0 = alice.aspects.first + @aspect1 = alice.aspects.create(:name => "another aspect") + @aspect2 = bob.aspects.first - @aspect0 = @user.aspects.first - @aspect1 = @user.aspects.create(:name => "another aspect") - @aspect2 = @user2.aspects.first - - @contact = @user.contact_for(@user2.person) - @user.getting_started = false - @user.save - sign_in :user, @user - @controller.stub(:current_user).and_return(@user) + @contact = alice.contact_for(bob.person) + alice.getting_started = false + alice.save + sign_in :user, alice + @controller.stub(:current_user).and_return(alice) request.env["HTTP_REFERER"] = 'http://' + request.host end describe '#create' do - it 'creates an aspect membership' do - @user.should_receive(:add_contact_to_aspect) + before do + @person = eve.person + end + + it 'succeeds' do post :create, :format => 'js', - :person_id => @user2.person.id, + :person_id => bob.person.id, :aspect_id => @aspect1.id response.should be_success end + + it 'creates an aspect membership' do + lambda { + post :create, + :format => 'js', + :person_id => bob.person.id, + :aspect_id => @aspect1.id + }.should change{ + alice.contact_for(bob.person).aspect_memberships.count + }.by(1) + + end + + it 'creates a contact' do + lambda { + post :create, + :format => 'js', + :person_id => @person.id, + :aspect_id => @aspect0.id + }.should change{ + alice.contacts.size + }.by(1) + end + + it 'failure flashes error' do + alice.should_receive(:share_with).and_return(nil) + post :create, + :format => 'js', + :person_id => @person.id, + :aspect_id => @aspect0.id + flash[:error].should_not be_empty + end end + describe "#destroy" do it 'removes contacts from an aspect' do - @user.add_contact_to_aspect(@contact, @aspect1) + alice.add_contact_to_aspect(@contact, @aspect1) delete :destroy, :format => 'js', :id => 123, - :person_id => @user2.person.id, + :person_id => bob.person.id, :aspect_id => @aspect0.id response.should be_success @aspect0.reload @@ -59,7 +92,7 @@ describe AspectMembershipsController do it 'contact is not in the aspect' do delete :destroy, :format => 'js', :id => 123, - :person_id => @user2.person.id, + :person_id => bob.person.id, :aspect_id => 2321 response.should_not be_success response.body.should include "Could not find the selected person in that aspect" @@ -69,10 +102,10 @@ describe AspectMembershipsController do describe "#update" do it 'calls the move_contact method' do - @controller.stub!(:current_user).and_return(@user) - @user.should_receive(:move_contact) + @controller.stub!(:current_user).and_return(alice) + alice.should_receive(:move_contact) put :update, :id => 123, - :person_id => @user.person.id, + :person_id => alice.person.id, :aspect_id => @aspect0.id, :to => @aspect1.id end diff --git a/spec/controllers/contacts_controller_spec.rb b/spec/controllers/contacts_controller_spec.rb index 3398329cc..22b9ba6ca 100644 --- a/spec/controllers/contacts_controller_spec.rb +++ b/spec/controllers/contacts_controller_spec.rb @@ -28,29 +28,6 @@ describe ContactsController do end end - describe '#create' do - before do - @person = eve.person - end - - it 'calls share_in_aspect' do - @controller.should_receive(:share_with).with(@aspect, @person) - post :create, - :format => 'js', - :person_id => @person.id, - :aspect_id => @aspect.id - end - - it 'failure flashes error' do - @controller.should_receive(:share_with).and_return(nil) - post :create, - :format => 'js', - :person_id => @person.id, - :aspect_id => @aspect.id - flash[:error].should_not be_empty - end - end - describe '#edit' do it 'assigns a contact' do get :edit, :id => @contact.id diff --git a/spec/integration/receiving_spec.rb b/spec/integration/receiving_spec.rb index ae6ba0686..c218b4a60 100644 --- a/spec/integration/receiving_spec.rb +++ b/spec/integration/receiving_spec.rb @@ -283,6 +283,8 @@ describe 'a user receives a post' do xml = @post.to_diaspora_xml + alice.share_with(eve.person, alice.aspects.first) + receive_with_zord(bob, alice.person, xml) receive_with_zord(eve, alice.person, xml) end @@ -292,7 +294,7 @@ describe 'a user receives a post' do @xml = @comment.to_diaspora_xml lambda { - receive_with_zord(alice, bob.person, @xml) + receive_with_zord(alice, bob.person, @xml) }.should_not raise_exception end end