File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
lib/active_record/relation Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ def first!
147
147
def last ( limit = nil )
148
148
return find_last ( limit ) if loaded? || limit_value
149
149
150
- result = limit ( limit || 1 )
150
+ result = limit ( limit )
151
151
result . order! ( arel_attribute ( primary_key ) ) if order_values . empty? && primary_key
152
152
result = result . reverse_order!
153
153
@@ -536,8 +536,12 @@ def find_nth_with_limit(index, limit)
536
536
self
537
537
end
538
538
539
- relation = relation . offset ( offset_index + index ) unless index . zero?
540
- relation . limit ( limit ) . to_a
539
+ if limit_value . nil? || index < limit_value
540
+ relation = relation . offset ( offset_index + index ) unless index . zero?
541
+ relation . limit ( limit ) . to_a
542
+ else
543
+ [ ]
544
+ end
541
545
end
542
546
end
543
547
Original file line number Diff line number Diff line change @@ -497,7 +497,7 @@ def test_second_to_last
497
497
assert_nil Topic . offset ( 5 ) . second_to_last
498
498
499
499
#test with limit
500
- # assert_nil Topic.limit(1).second # TODO: currently failing
500
+ assert_nil Topic . limit ( 1 ) . second
501
501
assert_nil Topic . limit ( 1 ) . second_to_last
502
502
end
503
503
@@ -526,9 +526,9 @@ def test_third_to_last
526
526
assert_nil Topic . offset ( 5 ) . third_to_last
527
527
528
528
# test with limit
529
- # assert_nil Topic.limit(1).third # TODO: currently failing
529
+ assert_nil Topic . limit ( 1 ) . third
530
530
assert_nil Topic . limit ( 1 ) . third_to_last
531
- # assert_nil Topic.limit(2).third # TODO: currently failing
531
+ assert_nil Topic . limit ( 2 ) . third
532
532
assert_nil Topic . limit ( 2 ) . third_to_last
533
533
end
534
534
You can’t perform that action at this time.
0 commit comments