diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-11-13 17:26:55 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-11-19 17:40:21 +0100 |
commit | f83c9b10b4c92b0d8deacb30d6fdfa2b1252d6dd (patch) | |
tree | 2320f2867a13a1f30faddadb92eb65c98bec8597 /activerecord/test/cases | |
parent | a7afceec3e491bbf505c690b3019445593c04f68 (diff) | |
download | rails-f83c9b10b4c92b0d8deacb30d6fdfa2b1252d6dd.tar.gz rails-f83c9b10b4c92b0d8deacb30d6fdfa2b1252d6dd.tar.bz2 rails-f83c9b10b4c92b0d8deacb30d6fdfa2b1252d6dd.zip |
use arel nodes to represent non-string `order_values`.
This fixes a bug when merging relations of different classes.
```
Given:
Post.joins(:author).merge(Author.order(name: :desc)).to_sql
Before:
SELECT "posts".* FROM "posts"
INNER JOIN "authors" ON "authors"."id" = "posts"."author_id"
ORDER BY "posts"."name" DESC
After:
SELECT "posts".* FROM "posts"
INNER JOIN "authors" ON "authors"."id" = "posts"."author_id"
ORDER BY "authors"."name" DESC
```
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/relation/merging_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/cases/relation/mutation_test.rb | 6 |
2 files changed, 13 insertions, 5 deletions
diff --git a/activerecord/test/cases/relation/merging_test.rb b/activerecord/test/cases/relation/merging_test.rb index 9f9244f9b2..23500bf5d8 100644 --- a/activerecord/test/cases/relation/merging_test.rb +++ b/activerecord/test/cases/relation/merging_test.rb @@ -146,5 +146,17 @@ class MergingDifferentRelationsTest < ActiveRecord::TestCase merge(Author.order(:name)).pluck("authors.name") assert_equal ["Bob", "Bob", "David"], posts_by_author_name + + posts_by_author_name = Post.limit(3).joins(:author). + merge(Author.order("name")).pluck("authors.name") + + assert_equal ["Bob", "Bob", "David"], posts_by_author_name + end + + test "merging order relations (using a hash argument)" do + posts_by_author_name = Post.limit(4).joins(:author). + merge(Author.order(name: :desc)).pluck("authors.name") + + assert_equal ["Mary", "Mary", "Mary", "David"], posts_by_author_name end end diff --git a/activerecord/test/cases/relation/mutation_test.rb b/activerecord/test/cases/relation/mutation_test.rb index 020fb24afa..a70f979442 100644 --- a/activerecord/test/cases/relation/mutation_test.rb +++ b/activerecord/test/cases/relation/mutation_test.rb @@ -7,10 +7,6 @@ module ActiveRecord extend ActiveRecord::Delegation::DelegateCache inherited self - def arel_table - Post.arel_table - end - def connection Post.connection end @@ -21,7 +17,7 @@ module ActiveRecord end def relation - @relation ||= Relation.new FakeKlass.new('posts'), :b + @relation ||= Relation.new FakeKlass.new('posts'), Post.arel_table end (Relation::MULTI_VALUE_METHODS - [:references, :extending, :order]).each do |method| |