From 0eb33b371b2c39dcef019d7b8cea770b64ec1017 Mon Sep 17 00:00:00 2001 From: Dan Hansen & Maxwell Salzberg Date: Tue, 1 Nov 2011 19:12:45 -0500 Subject: [PATCH] blocked users works for multi stream, cuke passes fixed scoping stuff --- app/helpers/stream_element_helper.rb | 2 +- app/models/post.rb | 6 +++++- features/blocks_user.feature | 21 +++++++++------------ features/step_definitions/posts_steps.rb | 8 ++++++-- lib/stream/multi.rb | 2 +- spec/models/post_spec.rb | 4 ++++ 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app/helpers/stream_element_helper.rb b/app/helpers/stream_element_helper.rb index 67856a182..a023ea04b 100644 --- a/app/helpers/stream_element_helper.rb +++ b/app/helpers/stream_element_helper.rb @@ -1,7 +1,7 @@ module StreamElementHelper def block_user_control(author) if user_signed_in? - link_to block_path(author), :class => "block_button" + button_to "block a mofo", blocks_path(:block => {:person_id => author.id}), :class => "block_button" end end end \ No newline at end of file diff --git a/app/models/post.rb b/app/models/post.rb index feb1f7504..0948ffc0b 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -26,7 +26,11 @@ class Post < ActiveRecord::Base def self.excluding_blocks(user) people = user.blocks.map { |x| x.person_id } - where("posts.author_id NOT IN (?)", people) + if people.present? + where("posts.author_id NOT IN (?)", people) + else + scoped + end end def self.for_a_stream(max_time, order, user=nil) diff --git a/features/blocks_user.feature b/features/blocks_user.feature index fd47a4f93..19b5c7e4a 100644 --- a/features/blocks_user.feature +++ b/features/blocks_user.feature @@ -1,20 +1,17 @@ @javascript Feature: Blocking a user from the stream Background: - Given a user with username "bob" - And a user with username "alice" - And a user with username "alice" is connected with "bob" - - When I sign in as "bob@bob.bob" - And I post a status with the text "I am da #boss" - And I am on the home page - When I go to the destroy user session page + Given a user named "Bob Jones" with email "bob@bob.bob" + And a user named "Alice Smith" with email "alice@alice.alice" + And a user with email "bob@bob.bob" is connected with "alice@alice.alice" + And Alice has a post mentioning Bob Scenario: Blocking a user - When I sign in as "alice@alice.alice" + When I sign in as "bob@bob.bob" And I am on the home page - Then I should see "I am da #boss" - When I click on bob's block button + And I wait for the ajax to finish + When I click on the first block button And I am on the home page - Then I should not see "I am da #boss" \ No newline at end of file + And I wait for the ajax to finish + Then I should not see any posts in my stream \ No newline at end of file diff --git a/features/step_definitions/posts_steps.rb b/features/step_definitions/posts_steps.rb index bdf830c8a..e0c1b9efe 100644 --- a/features/step_definitions/posts_steps.rb +++ b/features/step_definitions/posts_steps.rb @@ -13,6 +13,10 @@ Then /^I should not see an uploaded image within the photo drop zone$/ do find("#photodropzone img").should be_nil end +Then /^I should not see any posts in my stream$/ do + find(".stream_element").should be_nil +end + Given /^"([^"]*)" has a public post with text "([^"]*)"$/ do |email, text| user = User.find_by_email(email) user.post(:status_message, :text => text, :public => true, :to => user.aspects) @@ -27,6 +31,6 @@ When /^The user deletes their first post$/ do @me.posts.first.destroy end -When /^I click on bob's block button/ do - find(".block_button").first.click +When /^I click on the first block button/ do + find(".block_button").click end \ No newline at end of file diff --git a/lib/stream/multi.rb b/lib/stream/multi.rb index f02277617..235990c9a 100644 --- a/lib/stream/multi.rb +++ b/lib/stream/multi.rb @@ -19,7 +19,7 @@ class Stream::Multi < Stream::Base @posts ||= lambda do post_ids = aspects_post_ids + followed_tags_post_ids + mentioned_post_ids post_ids += community_spotlight_post_ids if include_community_spotlight? - Post.where(:id => post_ids).for_a_stream(max_time, order) + Post.where(:id => post_ids).for_a_stream(max_time, order, user) end.call end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 0804064db..55f9b3430 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -81,6 +81,10 @@ describe Post do it 'includes not blocked users posts' do Post.excluding_blocks(bob).should include(@other_post) end + + it 'returns posts if you dont have any blocks' do + Post.excluding_blocks(alice).count.should == 2 + end end context 'having some posts' do