Skip to content
Browse files

fix `last` for paginated AR 3.0 Relation

  • Loading branch information...
1 parent f30a541 commit d5d117a799ae30efa2e368f84934447797cb7e13 @mislav committed Jan 10, 2013
Showing with 10 additions and 0 deletions.
  1. +9 −0 lib/will_paginate/active_record.rb
  2. +1 −0 spec/finders/active_record_spec.rb
View
9 lib/will_paginate/active_record.rb
@@ -50,6 +50,15 @@ def first(*args)
end
end
+ # fix for Rails 3.0
+ def find_last
+ if !loaded? and offset_value || limit_value
+ @last ||= to_a.last
+ else
+ super
+ end
+ end
+
def offset(value = nil)
if value.nil? then offset_value
else super(value)
View
1 spec/finders/active_record_spec.rb
@@ -101,6 +101,7 @@
it "supports #last" do
rel = Developer.order('id').page(2).per_page(4)
rel.last.should == users(:dev_8)
+ rel.last(2).should == users(:dev_7, :dev_8)
rel.page(3).last.should == users(:poor_jamis)
end

0 comments on commit d5d117a

Please sign in to comment.
Something went wrong with that request. Please try again.