Skip to content

Commit

Permalink
Fixed Follow.recent method for default parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Amol Udage authored and jrasanen committed Mar 18, 2016
1 parent 0ce6aee commit c376bfa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/acts_as_follower/follow_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def for_followable_type(followable_type)
where(:followable_type => followable_type)
end

def recent(from)
where(["created_at > ?", (from || 2.weeks.ago).to_s(:db)])
def recent(from = 2.weeks.ago)
where(["created_at > ?", (from).to_s(:db)])
end

def descending
Expand Down
19 changes: 19 additions & 0 deletions test/acts_as_followable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ class ActsAsFollowableTest < ActiveSupport::TestCase
end
end

context "Follow recent" do
setup do
@sam = FactoryGirl.create(:sam)
@jon = FactoryGirl.create(:jon)
Follow.create(followable_id: @jon.id, follower_id: @sam.id, follower_type: 'User',
followable_type: 'User', created_at: 4.weeks.ago)
@jon.follow(@sam)
end

should "default returns records from last 2 weeks" do
assert_equal 1, Follow.recent.count
end

should "returns records from 4 weeks" do
assert_equal 2, Follow.recent(4.weeks.ago).count
end
end


context "acts_as_followable" do
setup do
@sam = FactoryGirl.create(:sam)
Expand Down

0 comments on commit c376bfa

Please sign in to comment.