Skip to content

Commit

Permalink
expose get_follow_for on followable through the public api, get_follo…
Browse files Browse the repository at this point in the history
…w was already exposed in follower, this standardizes what can be accessed through each module
  • Loading branch information
tcocca committed Oct 16, 2011
1 parent 2f6857d commit 7ba0a8d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
4 changes: 1 addition & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'"
Expand All @@ -35,5 +34,4 @@ namespace :rcov do
task :clobber do
sh "rm -rdf coverage"
end

end
end
13 changes: 6 additions & 7 deletions lib/acts_as_follower/followable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/acts_as_followable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7ba0a8d

Please sign in to comment.