Skip to content
Extraits de code Groupes Projets
  • danielgrippi's avatar
    60a60733
    Merge branch 'master' into follow · 60a60733
    danielgrippi a rédigé
    Conflicts:
    	app/controllers/aspects_controller.rb
    	app/controllers/contacts_controller.rb
    	app/controllers/people_controller.rb
    	app/controllers/photos_controller.rb
    	app/controllers/tags_controller.rb
    	app/helpers/notifications_helper.rb
    	app/models/notifications/new_request.rb
    	app/models/user_preference.rb
    	public/javascripts/view.js
    	spec/controllers/aspects_controller_spec.rb
    	spec/controllers/contacts_controller_spec.rb
    	spec/controllers/home_controller_spec.rb
    	spec/controllers/post_visibilities_controller_spec.rb
    	spec/controllers/requests_controller_spec.rb
    	spec/mailers/notifier_spec.rb
    	spec/models/user_spec.rb
    60a60733
    Historique
    Merge branch 'master' into follow
    danielgrippi a rédigé
    Conflicts:
    	app/controllers/aspects_controller.rb
    	app/controllers/contacts_controller.rb
    	app/controllers/people_controller.rb
    	app/controllers/photos_controller.rb
    	app/controllers/tags_controller.rb
    	app/helpers/notifications_helper.rb
    	app/models/notifications/new_request.rb
    	app/models/user_preference.rb
    	public/javascripts/view.js
    	spec/controllers/aspects_controller_spec.rb
    	spec/controllers/contacts_controller_spec.rb
    	spec/controllers/home_controller_spec.rb
    	spec/controllers/post_visibilities_controller_spec.rb
    	spec/controllers/requests_controller_spec.rb
    	spec/mailers/notifier_spec.rb
    	spec/models/user_spec.rb
aspect_memberships_controller_spec.rb 2,98 Kio
#   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