diff --git a/app/helpers/stream_element_helper.rb b/app/helpers/stream_element_helper.rb index 67856a18270c6464dbec208e0de925d7ff1e8af1..a023ea04b9793dd7e53e70a5761a3104d3928a93 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 feb1f7504420e079fb63ba169d9724d01c4b637d..0948ffc0b0045107c68efac6c71f85938bd64d5b 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 fd47a4f93dc7737feef75605c5919cf02ac98f35..19b5c7e4a89979f31ec2d0465e4cecad9e642484 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 bdf830c8a9a9e674d1fd614650ac178aebcfb86b..e0c1b9efe8dcacc3d17fde16fe1d6087e01a98b5 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 f022776170ee8972fda50f5f96ea93fd44dd2a5a..235990c9a8e9347aae2426cb5b7d9094c91c2718 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 0804064db4e3a9f739195a55cbc45460cb42a327..55f9b34302a036fe50a5764eae5de7855e70ee12 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