From 7ba0a8d7409170f98dbeb07984f36cd4a0d38b43 Mon Sep 17 00:00:00 2001 From: Tom Cocca Date: Sun, 16 Oct 2011 17:54:27 -0400 Subject: [PATCH] expose get_follow_for on followable through the public api, get_follow was already exposed in follower, this standardizes what can be accessed through each module --- Rakefile | 4 +--- lib/acts_as_follower/followable.rb | 13 ++++++------- test/acts_as_followable_test.rb | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Rakefile b/Rakefile index 27a9cac..e33a737 100644 --- a/Rakefile +++ b/Rakefile @@ -25,7 +25,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc| end namespace :rcov do - desc "Generate a coverage report in coverage/" task :gen do sh "rcov --output coverage test/*_test.rb --exclude 'gems/*'" @@ -35,5 +34,4 @@ namespace :rcov do task :clobber do sh "rm -rdf coverage" end - -end \ No newline at end of file +end diff --git a/lib/acts_as_follower/followable.rb b/lib/acts_as_follower/followable.rb index 3bd564a..e7e02ba 100644 --- a/lib/acts_as_follower/followable.rb +++ b/lib/acts_as_follower/followable.rb @@ -24,11 +24,10 @@ def followers_count def followers_by_type(follower_type, options={}) follows = follower_type.constantize. includes(:follows). - where('blocked = ?', false). - where( - "follows.followable_id = ? AND follows.followable_type = ? AND follows.follower_type = ?", - self.id, parent_class_name(self), follower_type - ) + where('follows.blocked' => false, + 'follows.followable_id' => self.id, + 'follows.followable_type' => parent_class_name(self), + 'follows.follower_type' => follower_type) if options.has_key?(:limit) follows = follows.limit(options[:limit]) end @@ -80,12 +79,12 @@ def unblock(follower) get_follow_for(follower).try(:delete) end - private - def get_follow_for(follower) self.followings.for_follower(follower).first end + private + def block_future_follow(follower) follows.create(:followable => self, :follower => follower, :blocked => true) end diff --git a/test/acts_as_followable_test.rb b/test/acts_as_followable_test.rb index 4ba1d94..8b9364d 100644 --- a/test/acts_as_followable_test.rb +++ b/test/acts_as_followable_test.rb @@ -84,6 +84,21 @@ class ActsAsFollowableTest < ActiveSupport::TestCase should_change("@sam.all_following.size", :by => -1) { @sam.all_following.size } end + context "get follow record" do + setup do + @bob = Factory(:bob) + @follow = @bob.follow(@sam) + end + + should "return follow record" do + assert_equal @follow, @sam.get_follow_for(@bob) + end + + should "return nil" do + assert_nil @sam.get_follow_for(@jon) + end + end + context "blocks" do setup do @bob = Factory(:bob)