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

View file

@ -31,5 +31,5 @@
.done .done
.right .right
= link_to t('aspects.aspect_contacts.done_editing'), "#", :class => "button", :onClick => '$.facebox.close();' = 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 = 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" When I sign in as "bob@bob.bob"
And I am on "alice@alice.alice"'s page And I am on "alice@alice.alice"'s page
And I press the first ".share_with.button" And I press the first ".share_with.button"
And I wait for the ajax to finish And I wait for the ajax to finish
And I add the person to my first aspect And I add the person to my first aspect

View file

@ -60,6 +60,12 @@ module Postzord
end end
def validate_object 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 #special casey
if @object.is_a?(Request) if @object.is_a?(Request)
@object.sender_handle = @sender.diaspora_handle @object.sender_handle = @sender.diaspora_handle

View file

@ -8,38 +8,71 @@ describe AspectMembershipsController do
render_views render_views
before do before do
@user = alice @aspect0 = alice.aspects.first
@user2 = bob @aspect1 = alice.aspects.create(:name => "another aspect")
@aspect2 = bob.aspects.first
@aspect0 = @user.aspects.first @contact = alice.contact_for(bob.person)
@aspect1 = @user.aspects.create(:name => "another aspect") alice.getting_started = false
@aspect2 = @user2.aspects.first alice.save
sign_in :user, alice
@contact = @user.contact_for(@user2.person) @controller.stub(:current_user).and_return(alice)
@user.getting_started = false
@user.save
sign_in :user, @user
@controller.stub(:current_user).and_return(@user)
request.env["HTTP_REFERER"] = 'http://' + request.host request.env["HTTP_REFERER"] = 'http://' + request.host
end end
describe '#create' do describe '#create' do
it 'creates an aspect membership' do before do
@user.should_receive(:add_contact_to_aspect) @person = eve.person
end
it 'succeeds' do
post :create, post :create,
:format => 'js', :format => 'js',
:person_id => @user2.person.id, :person_id => bob.person.id,
:aspect_id => @aspect1.id :aspect_id => @aspect1.id
response.should be_success response.should be_success
end 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 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 describe "#destroy" do
it 'removes contacts from an aspect' do it 'removes contacts from an aspect' do
@user.add_contact_to_aspect(@contact, @aspect1) alice.add_contact_to_aspect(@contact, @aspect1)
delete :destroy, delete :destroy,
:format => 'js', :id => 123, :format => 'js', :id => 123,
:person_id => @user2.person.id, :person_id => bob.person.id,
:aspect_id => @aspect0.id :aspect_id => @aspect0.id
response.should be_success response.should be_success
@aspect0.reload @aspect0.reload
@ -59,7 +92,7 @@ describe AspectMembershipsController do
it 'contact is not in the aspect' do it 'contact is not in the aspect' do
delete :destroy, delete :destroy,
:format => 'js', :id => 123, :format => 'js', :id => 123,
:person_id => @user2.person.id, :person_id => bob.person.id,
:aspect_id => 2321 :aspect_id => 2321
response.should_not be_success response.should_not be_success
response.body.should include "Could not find the selected person in that aspect" response.body.should include "Could not find the selected person in that aspect"
@ -69,10 +102,10 @@ describe AspectMembershipsController do
describe "#update" do describe "#update" do
it 'calls the move_contact method' do it 'calls the move_contact method' do
@controller.stub!(:current_user).and_return(@user) @controller.stub!(:current_user).and_return(alice)
@user.should_receive(:move_contact) alice.should_receive(:move_contact)
put :update, :id => 123, put :update, :id => 123,
:person_id => @user.person.id, :person_id => alice.person.id,
:aspect_id => @aspect0.id, :aspect_id => @aspect0.id,
:to => @aspect1.id :to => @aspect1.id
end end

View file

@ -28,29 +28,6 @@ describe ContactsController do
end end
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 describe '#edit' do
it 'assigns a contact' do it 'assigns a contact' do
get :edit, :id => @contact.id get :edit, :id => @contact.id

View file

@ -283,6 +283,8 @@ describe 'a user receives a post' do
xml = @post.to_diaspora_xml xml = @post.to_diaspora_xml
alice.share_with(eve.person, alice.aspects.first)
receive_with_zord(bob, alice.person, xml) receive_with_zord(bob, alice.person, xml)
receive_with_zord(eve, alice.person, xml) receive_with_zord(eve, alice.person, xml)
end end