# Copyright (c) 2010, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. require 'spec_helper' describe AspectMembershipsController do before do @aspect0 = alice.aspects.first @aspect1 = alice.aspects.create(:name => "another aspect") @aspect2 = bob.aspects.first @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 before do @person = eve.person end it 'succeeds' do post :create, :format => 'js', :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 alice.add_contact_to_aspect(@contact, @aspect1) delete :destroy, :format => 'js', :id => 123, :person_id => bob.person.id, :aspect_id => @aspect0.id response.should be_success @aspect0.reload @aspect0.contacts.include?(@contact).should be false end context 'aspect membership does not exist' do it 'person does not exist' do delete :destroy, :format => 'js', :id => 123, :person_id => 4324525, :id => @aspect0.id response.should_not be_success response.body.should include "Could not find the selected person in that aspect" end it 'contact is not in the aspect' do delete :destroy, :format => 'js', :id => 123, :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" end end end describe "#update" do it 'calls the move_contact method' do @controller.stub!(:current_user).and_return(alice) alice.should_receive(:move_contact) put :update, :id => 123, :person_id => alice.person.id, :aspect_id => @aspect0.id, :to => @aspect1.id end end end