specs green after moving ContactController#new to AspectsMembership#new

This commit is contained in:
danielgrippi 2011-04-08 11:44:09 -07:00
parent aeda5a4e39
commit c128cae4ec
7 changed files with 78 additions and 57 deletions

View file

@ -47,7 +47,7 @@ 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'
@ -61,6 +61,10 @@ class AspectMembershipsController < ApplicationController
}}
format.html{ redirect_to aspect_path(@aspect.id)}
end
else
flash[:error] = I18n.t 'contacts.create.failure'
redirect_to :back
end
end
def update

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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