Commit c3e00f211dcdd62e8036a354f73377e12d8b4ccc
Committed by
GitHub
Exists in
master
Merge pull request #66 from joshsoftware/method_short_description
Add short description for ActsAsFollower::FollowScopes methods
Showing
3 changed files
with
12 additions
and
4 deletions
Show diff stats
lib/acts_as_follower/follow_scopes.rb
1 | module ActsAsFollower #:nodoc: | 1 | module ActsAsFollower #:nodoc: |
2 | module FollowScopes | 2 | module FollowScopes |
3 | 3 | ||
4 | + # returns Follow records where follower is the record passed in. | ||
4 | def for_follower(follower) | 5 | def for_follower(follower) |
5 | where(:follower_id => follower.id, | 6 | where(:follower_id => follower.id, |
6 | :follower_type => parent_class_name(follower)) | 7 | :follower_type => parent_class_name(follower)) |
7 | end | 8 | end |
8 | 9 | ||
10 | + # returns Follow records where followable is the record passed in. | ||
9 | def for_followable(followable) | 11 | def for_followable(followable) |
10 | where(:followable_id => followable.id, :followable_type => parent_class_name(followable)) | 12 | where(:followable_id => followable.id, :followable_type => parent_class_name(followable)) |
11 | end | 13 | end |
12 | 14 | ||
15 | + # returns Follow records where follower_type is the record passed in. | ||
13 | def for_follower_type(follower_type) | 16 | def for_follower_type(follower_type) |
14 | where(:follower_type => follower_type) | 17 | where(:follower_type => follower_type) |
15 | end | 18 | end |
16 | 19 | ||
20 | + # returns Follow records where followeable_type is the record passed in. | ||
17 | def for_followable_type(followable_type) | 21 | def for_followable_type(followable_type) |
18 | where(:followable_type => followable_type) | 22 | where(:followable_type => followable_type) |
19 | end | 23 | end |
20 | 24 | ||
25 | + # returns Follow records from past 2 weeks with default parameter. | ||
21 | def recent(from) | 26 | def recent(from) |
22 | where(["created_at > ?", (from || 2.weeks.ago).to_s(:db)]) | 27 | where(["created_at > ?", (from || 2.weeks.ago).to_s(:db)]) |
23 | end | 28 | end |
24 | 29 | ||
30 | + # returns Follow records in descending order. | ||
25 | def descending | 31 | def descending |
26 | order("follows.created_at DESC") | 32 | order("follows.created_at DESC") |
27 | end | 33 | end |
28 | 34 | ||
35 | + # returns unblocked Follow records. | ||
29 | def unblocked | 36 | def unblocked |
30 | where(:blocked => false) | 37 | where(:blocked => false) |
31 | end | 38 | end |
32 | 39 | ||
40 | + # returns blocked Follow records. | ||
33 | def blocked | 41 | def blocked |
34 | where(:blocked => true) | 42 | where(:blocked => true) |
35 | end | 43 | end |
lib/generators/templates/model.rb
@@ -3,7 +3,7 @@ class Follow < ActiveRecord::Base | @@ -3,7 +3,7 @@ class Follow < ActiveRecord::Base | ||
3 | extend ActsAsFollower::FollowerLib | 3 | extend ActsAsFollower::FollowerLib |
4 | extend ActsAsFollower::FollowScopes | 4 | extend ActsAsFollower::FollowScopes |
5 | 5 | ||
6 | - # NOTE: Follows belong to the "followable" interface, and also to followers | 6 | + # NOTE: Follows belong to the "followable" and "follower" interface |
7 | belongs_to :followable, :polymorphic => true | 7 | belongs_to :followable, :polymorphic => true |
8 | belongs_to :follower, :polymorphic => true | 8 | belongs_to :follower, :polymorphic => true |
9 | 9 |
test/acts_as_followable_test.rb
@@ -189,7 +189,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase | @@ -189,7 +189,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase | ||
189 | assert_equal [], @jon.followers | 189 | assert_equal [], @jon.followers |
190 | end | 190 | end |
191 | 191 | ||
192 | - should "not be in the blockked followers count" do | 192 | + should "not be in the blocked followers count" do |
193 | assert_equal 0, @jon.blocked_followers_count | 193 | assert_equal 0, @jon.blocked_followers_count |
194 | end | 194 | end |
195 | 195 | ||
@@ -206,7 +206,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase | @@ -206,7 +206,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase | ||
206 | 206 | ||
207 | should "return the followers for given type" do | 207 | should "return the followers for given type" do |
208 | assert_equal [@sam], @jon.followers_by_type('User') | 208 | assert_equal [@sam], @jon.followers_by_type('User') |
209 | - assert_equal [@sam,@jon], @oasis.followers_by_type('User') | 209 | + assert_equal [@sam, @jon], @oasis.followers_by_type('User') |
210 | end | 210 | end |
211 | 211 | ||
212 | should "not return block followers in the followers for a given type" do | 212 | should "not return block followers in the followers for a given type" do |
@@ -233,7 +233,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase | @@ -233,7 +233,7 @@ class ActsAsFollowableTest < ActiveSupport::TestCase | ||
233 | 233 | ||
234 | should "return the followers for given type" do | 234 | should "return the followers for given type" do |
235 | assert_equal [@sam], @jon.user_followers | 235 | assert_equal [@sam], @jon.user_followers |
236 | - assert_equal [@sam,@jon], @oasis.user_followers | 236 | + assert_equal [@sam, @jon], @oasis.user_followers |
237 | end | 237 | end |
238 | 238 | ||
239 | should "not return block followers in the followers for a given type" do | 239 | should "not return block followers in the followers for a given type" do |