aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/finder_test.rb
diff options
context:
space:
mode:
authorBrian Christian <brchristian@gmail.com>2018-01-09 11:28:30 -0800
committerBrian Christian <brchristian@gmail.com>2018-01-09 11:28:30 -0800
commitb75a67cdef06cbf0a5a4feb1be9c74f31b89b28a (patch)
treeb58b6b49c5abc95983b1885df1663d63fb44c399 /activerecord/test/cases/finder_test.rb
parentbaa88b8ddff59b10b8e98eeee7503e2416da8abe (diff)
downloadrails-b75a67cdef06cbf0a5a4feb1be9c74f31b89b28a.tar.gz
rails-b75a67cdef06cbf0a5a4feb1be9c74f31b89b28a.tar.bz2
rails-b75a67cdef06cbf0a5a4feb1be9c74f31b89b28a.zip
resolve inconsistencies between first and to_a.first with limit
Diffstat (limited to 'activerecord/test/cases/finder_test.rb')
-rw-r--r--activerecord/test/cases/finder_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index c0485a7be7..95bd987551 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -687,6 +687,24 @@ class FinderTest < ActiveRecord::TestCase
assert_equal comments.limit(2).to_a.last(3), comments.limit(2).last(3)
end
+ def test_first_on_relation_with_limit_and_offset
+ post = posts("sti_comments")
+
+ comments = post.comments.order(id: :asc)
+ assert_equal comments.limit(2).to_a.first, comments.limit(2).first
+ assert_equal comments.limit(2).to_a.first(2), comments.limit(2).first(2)
+ assert_equal comments.limit(2).to_a.first(3), comments.limit(2).first(3)
+
+ assert_equal comments.offset(2).to_a.first, comments.offset(2).first
+ assert_equal comments.offset(2).to_a.first(2), comments.offset(2).first(2)
+ assert_equal comments.offset(2).to_a.first(3), comments.offset(2).first(3)
+
+ comments = comments.offset(1)
+ assert_equal comments.limit(2).to_a.first, comments.limit(2).first
+ assert_equal comments.limit(2).to_a.first(2), comments.limit(2).first(2)
+ assert_equal comments.limit(2).to_a.first(3), comments.limit(2).first(3)
+ end
+
def test_take_and_first_and_last_with_integer_should_return_an_array
assert_kind_of Array, Topic.take(5)
assert_kind_of Array, Topic.first(5)