diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-03-17 13:22:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-17 13:22:20 -0400 |
commit | bac40b9cc8bae5a88743dba01bdee24ef8a2d579 (patch) | |
tree | 1e3d1103798ee613bc877a06b8076fd616c20fee /activerecord/test/cases | |
parent | 6f7e7aadfdc76990176a5f3c4d0024aa665ef173 (diff) | |
parent | 6cf4835b743cbce2536d53ae0a4a998f4f0f1e24 (diff) | |
download | rails-bac40b9cc8bae5a88743dba01bdee24ef8a2d579.tar.gz rails-bac40b9cc8bae5a88743dba01bdee24ef8a2d579.tar.bz2 rails-bac40b9cc8bae5a88743dba01bdee24ef8a2d579.zip |
Merge pull request #28191 from eugeneius/string_assoc_order
Allow order to be given expressions as hash keys
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 0c94e891eb..b7c3406fbb 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -218,17 +218,34 @@ class RelationTest < ActiveRecord::TestCase assert_equal topics(:fifth).title, topics.first.title end - def test_finding_with_reverted_assoc_order + def test_finding_with_arel_assoc_order + topics = Topic.order(Arel.sql("id") => :desc) + assert_equal 5, topics.to_a.size + assert_equal topics(:fifth).title, topics.first.title + end + + def test_finding_with_reversed_assoc_order topics = Topic.order(id: :asc).reverse_order assert_equal 5, topics.to_a.size assert_equal topics(:fifth).title, topics.first.title end + def test_finding_with_reversed_arel_assoc_order + topics = Topic.order(Arel.sql("id") => :asc).reverse_order + assert_equal 5, topics.to_a.size + assert_equal topics(:fifth).title, topics.first.title + end + def test_reverse_order_with_function topics = Topic.order("length(title)").reverse_order assert_equal topics(:second).title, topics.first.title end + def test_reverse_arel_assoc_order_with_function + topics = Topic.order(Arel.sql("length(title)") => :asc).reverse_order + assert_equal topics(:second).title, topics.first.title + end + def test_reverse_order_with_function_other_predicates topics = Topic.order("author_name, length(title), id").reverse_order assert_equal topics(:second).title, topics.first.title @@ -251,6 +268,12 @@ class RelationTest < ActiveRecord::TestCase end end + def test_reverse_arel_assoc_order_with_multiargument_function + assert_nothing_raised do + Topic.order(Arel.sql("REPLACE(title, '', '')") => :asc).reverse_order + end + end + def test_reverse_order_with_nulls_first_or_last assert_raises(ActiveRecord::IrreversibleOrderError) do Topic.order("title NULLS FIRST").reverse_order |