aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorBrian Christian <brchristian@gmail.com>2016-10-03 10:08:04 -0700
committerBrian Christian <brchristian@gmail.com>2018-07-19 21:32:54 -0700
commit83f755ff66b9152eb0c66b279757310040b23d18 (patch)
tree3973f612fa67e26ad7fbbafcfa28ef1b714dd07f /activerecord
parent1a0bcc3b49e05eba852912f609a20c36a9656857 (diff)
downloadrails-83f755ff66b9152eb0c66b279757310040b23d18.tar.gz
rails-83f755ff66b9152eb0c66b279757310040b23d18.tar.bz2
rails-83f755ff66b9152eb0c66b279757310040b23d18.zip
tests for use of primary_key with limit
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/finder_test.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 39ffe12ec6..2f256dd36a 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -1265,6 +1265,21 @@ class FinderTest < ActiveRecord::TestCase
end
end
+ def test_first_and_last_with_limit_for_order_without_primary_key
+ # While Topic.first should impose an ordering by primary key,
+ # Topic.limit(n).first should not
+
+ Topic.first.touch # PostgreSQL changes the default order if no order clause is used
+
+ assert_equal Topic.limit(1).to_a.first, Topic.limit(1).first
+ assert_equal Topic.limit(2).to_a.first, Topic.limit(2).first
+ assert_equal Topic.limit(2).to_a.first(2), Topic.limit(2).first(2)
+
+ assert_equal Topic.limit(1).to_a.last, Topic.limit(1).last
+ assert_equal Topic.limit(2).to_a.last, Topic.limit(2).last
+ assert_equal Topic.limit(2).to_a.last(2), Topic.limit(2).last(2)
+ end
+
def test_finder_with_offset_string
assert_nothing_raised { Topic.offset("3").to_a }
end