diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-09-05 05:41:46 -0700 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-09-05 05:41:46 -0700 |
commit | e221108c141fa564b7da6378478b762b356e0084 (patch) | |
tree | 9988d58da2e27c67a6de9e01137f81b3dc9a6c9b /activerecord/test/cases | |
parent | 24ee573d6ce8bb11f7eb62224feca5a87fdd2a69 (diff) | |
parent | 5f5527c726841cdefb82965a645d554767c5a6a9 (diff) | |
download | rails-e221108c141fa564b7da6378478b762b356e0084.tar.gz rails-e221108c141fa564b7da6378478b762b356e0084.tar.bz2 rails-e221108c141fa564b7da6378478b762b356e0084.zip |
Merge pull request #2789 from dmathieu/limit_first_last
Use LIMIT SQL word in first - Closes #2783
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 5dc5f99582..d840d38678 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -243,6 +243,32 @@ class FinderTest < ActiveRecord::TestCase end end + def test_first_and_last_with_integer_should_use_sql_limit + assert_sql(/LIMIT 2/) { Topic.first(2).entries } + assert_sql(/LIMIT 5/) { Topic.last(5).entries } + end + + def test_last_with_integer_and_order_should_keep_the_order + assert_equal Topic.order("title").to_a.last(2), Topic.order("title").last(2) + end + + def test_last_with_integer_and_order_should_not_use_sql_limit + query = assert_sql { Topic.order("title").last(5).entries } + assert_equal 1, query.length + assert_no_match(/LIMIT/, query.first) + end + + def test_last_with_integer_and_reorder_should_not_use_sql_limit + query = assert_sql { Topic.reorder("title").last(5).entries } + assert_equal 1, query.length + assert_no_match(/LIMIT/, query.first) + end + + def test_first_and_last_with_integer_should_return_an_array + assert_kind_of Array, Topic.first(5) + assert_kind_of Array, Topic.last(5) + end + def test_unexisting_record_exception_handling assert_raise(ActiveRecord::RecordNotFound) { Topic.find(1).parent |