Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions acts_as_follower.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

s.add_development_dependency "sqlite3"
s.add_development_dependency "shoulda"
s.add_development_dependency "factory_girl"
s.add_development_dependency "shoulda", "2.11.3"
s.add_development_dependency "factory_girl", "2.0.5"
s.add_development_dependency "rails", "~>3.0.10"
end
11 changes: 9 additions & 2 deletions lib/acts_as_follower/followable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def acts_as_followable
has_many :followings, :as => :followable, :dependent => :destroy, :class_name => 'Follow'
include ActsAsFollower::Followable::InstanceMethods
include ActsAsFollower::FollowerLib
extend ActsAsFollower::Followable::SingletonMethods
end
end

module SingletonMethods
def unfollowed
self.where("NOT EXISTS (SELECT 1 FROM follows WHERE followable_id = #{self.table_name}.id AND followable_type = '#{self.model_name}')")
end
end

Expand All @@ -25,8 +32,8 @@ def followers_by_type(follower_type, options={})
follows = follower_type.constantize.
joins(:follows).
where('follows.blocked' => false,
'follows.followable_id' => self.id,
'follows.followable_type' => parent_class_name(self),
'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])
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 @@ -2,6 +2,21 @@

class ActsAsFollowableTest < ActiveSupport::TestCase

context "class methods" do
context "unfollowed" do
setup do
@sam = Factory(:sam)
@oasis = Factory(:oasis)
@metallica = Factory(:metallica)
@sam.follow(@oasis)
end

should "return unfollowed bands" do
assert_equal 1, Band.unfollowed.count
end
end
end

context "instance methods" do
setup do
@sam = Factory(:sam)
Expand Down