From b0d98b9ce8343583e4e5936ec841fa6c10e24d63 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Sat, 19 Feb 2011 22:17:45 -0800 Subject: [PATCH] Add people#show specs around showing the right set of posts. --- spec/controllers/people_controller_spec.rb | 27 ++++++++++++++++++---- spec/support/fixture_builder.rb | 3 ++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 2c9393166..da054c135 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -138,21 +138,40 @@ describe PeopleController do get :show, :id => @person.id response.should be_success end + + it "assigns only the posts the current user can see" do + bob.posts.should be_empty + posts_user_can_see = [] + posts_user_can_see << bob.post(:status_message, :message => "to an aspect @user is in", :to => bob.aspects[0].id) + bob.post(:status_message, :message => "to an aspect @user is not in", :to => bob.aspects[1].id) + posts_user_can_see << bob.post(:status_message, :message => "to all aspects", :to => 'all') + posts_user_can_see << bob.post(:status_message, :message => "public", :to => 'all', :public => true) + bob.reload.posts.length.should == 4 + + get :show, :id => @person.id + assigns(:posts).should =~ posts_user_can_see + end end context "when the person is not a contact of the current user" do before do @person = eve.person end + it "succeeds" do get :show, :id => @person.id response.should be_success end - it "shows public posts only" do - status_message = @person.owner.post(:status_message, :message => "hey there", :to => 'all', :public => true) + + it "assigns only public posts" do + eve.posts.should be_empty + eve.post(:status_message, :message => "to an aspect @user is not in", :to => eve.aspects.first.id) + eve.post(:status_message, :message => "to all aspects", :to => 'all') + public_post = eve.post(:status_message, :message => "public", :to => 'all', :public => true) + eve.reload.posts.length.should == 3 + get :show, :id => @person.id - assigns[:posts].should include status_message - response.body.should include status_message.message + assigns[:posts].should =~ [public_post] end end end diff --git a/spec/support/fixture_builder.rb b/spec/support/fixture_builder.rb index e6681b620..79fbf6279 100644 --- a/spec/support/fixture_builder.rb +++ b/spec/support/fixture_builder.rb @@ -6,8 +6,9 @@ FixtureBuilder.configure do |fbuilder| # now declare objects fbuilder.factory do alice = Factory(:user_with_aspect, :username => "alice") - bob = Factory(:user_with_aspect, :username => "bob") eve = Factory(:user_with_aspect, :username => "eve") + bob = Factory(:user_with_aspect, :username => "bob") + Factory(:aspect, :name => "empty", :user => bob) connect_users(bob, bob.aspects.first, alice, alice.aspects.first) connect_users(bob, bob.aspects.first, eve, eve.aspects.first)