diff options
author | Eugene Kalenkovich <rubify@softover.com> | 2013-08-21 14:39:39 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-09-12 14:08:02 -0300 |
commit | c9642e31b1a9f764fbf1ce85b38fa225ec5e6b42 (patch) | |
tree | 196df21f7b56022a9ff9dda7adf8163778eb236c /activerecord/test/cases/finder_test.rb | |
parent | cff8d1d24da1237a2f4d44e46f5ec486cd6ba32d (diff) | |
download | rails-c9642e31b1a9f764fbf1ce85b38fa225ec5e6b42.tar.gz rails-c9642e31b1a9f764fbf1ce85b38fa225ec5e6b42.tar.bz2 rails-c9642e31b1a9f764fbf1ce85b38fa225ec5e6b42.zip |
Fix FinderMethods#last unscoped primary key
Fixes table.joins(:relation).last(N) breaking on sqlite
Conflicts:
activerecord/CHANGELOG.md
activerecord/test/cases/finder_test.rb
Diffstat (limited to 'activerecord/test/cases/finder_test.rb')
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 2efafe5c24..89e17643f6 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -305,10 +305,24 @@ class FinderTest < ActiveRecord::TestCase assert_sql(/LIMIT 5|ROWNUM <= 5/) { Topic.last(5).entries } end + def test_last_should_use_default_order + assert_sql(/ORDER BY .topics.\..id. DESC/) { Topic.last } + end + + def test_last_with_integer_should_use_default_order + assert_sql(/ORDER BY .topics.\..id. DESC/) { 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_should_work_with_joins + assert_nothing_raised do + Post.joins(:comments).last(2) + end + 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 |