Skip to content
Extraits de code Groupes Projets
aspect_memberships_controller_spec.rb 3,15 ko
Newer Older
  • Learn to ignore specific revisions
  • danielgrippi's avatar
    danielgrippi a validé
    #   Copyright (c) 2010-2011, 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, :type => :controller 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
    
        allow(@controller).to receive(:current_user).and_return(alice)
    
        request.env["HTTP_REFERER"] = 'http://' + request.host
      end
    
    
    maxwell's avatar
    maxwell a validé
      describe '#create' do
    
        before do
          @person = eve.person
        end
    
        it 'succeeds' do
    
    maxwell's avatar
    maxwell a validé
          post :create,
    
    maxwell's avatar
    maxwell a validé
            :aspect_id => @aspect1.id
    
          expect(response).to be_success
    
    maxwell's avatar
    maxwell a validé
        end
    
    
        it 'creates an aspect membership' do
    
              :person_id => bob.person.id,
              :aspect_id => @aspect1.id
    
          }.to change{
    
            alice.contact_for(bob.person).aspect_memberships.count
          }.by(1)
        end
    
        it 'creates a contact' do
    
          #argggg why?
          alice.contacts.reload
    
              :person_id => @person.id,
              :aspect_id => @aspect0.id
    
          }.to change{
    
            alice.contacts.size
          }.by(1)
        end
    
        it 'failure flashes error' do
    
          expect(alice).to receive(:share_with).and_return(nil)
    
            :person_id => @person.id,
            :aspect_id => @aspect0.id
    
          expect(flash[:error]).not_to be_blank
    
    maxwell's avatar
    maxwell a validé
    
    
        it 'does not 500 on a duplicate key error' do
    
          params = {:format => :json, :person_id => @person.id, :aspect_id => @aspect0.id}
    
          post :create, params
          post :create, params
    
          expect(response.status).to eq(400)
    
          it 'returns the aspect membership' do
    
            :person_id => @person.id,
            :aspect_id => @aspect0.id
    
            contact = @controller.current_user.contact_for(@person)
    
            expect(response.body).to eq(AspectMembershipPresenter.new(contact.aspect_memberships.first).base_hash.to_json)
    
      describe "#destroy" do
        it 'removes contacts from an aspect' do
    
          membership = alice.add_contact_to_aspect(@contact, @aspect1)
          delete :destroy, :format => :json, :id => membership.id
    
          expect(response).to be_success
    
          expect(@aspect1.contacts.to_a).not_to include @contact
    
          membership = alice.add_contact_to_aspect(@contact, @aspect1)
          delete :destroy, :id => membership.id
    
          expect(response).to redirect_to :back
    
          expect(@aspect1.contacts.to_a).not_to include @contact
    
        it 'aspect membership does not exist' do
          delete :destroy, :format => :json, :id => 123
    
          expect(response).not_to be_success
          expect(response.body).to include "Could not find the selected person in that aspect"