diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2016-01-27 12:53:51 +0200 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2016-01-27 12:53:51 +0200 |
commit | 14efb42a906aa8079adff2b1e56d6444d147a386 (patch) | |
tree | 07bde2d9fd6609d597b00892ca621bb4493e43eb /activerecord/test | |
parent | 5262bf544abacb10828abcfeb046d8146bef4c14 (diff) | |
download | rails-14efb42a906aa8079adff2b1e56d6444d147a386.tar.gz rails-14efb42a906aa8079adff2b1e56d6444d147a386.tar.bz2 rails-14efb42a906aa8079adff2b1e56d6444d147a386.zip |
Introduce ActiveRecord::IrreversibleOrderError
Raises when #reverse_order can not process SQL order instead of making
invalid SQL before this patch
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 0638edacbd..090b885dd5 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -19,6 +19,7 @@ require 'models/aircraft' require "models/possession" require "models/reader" require "models/categorization" +require "models/edge" class RelationTest < ActiveRecord::TestCase fixtures :authors, :topics, :entrants, :developers, :companies, :developers_projects, :accounts, :categories, :categorizations, :posts, :comments, @@ -223,6 +224,39 @@ class RelationTest < ActiveRecord::TestCase 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_order_with_function_other_predicates + topics = Topic.order("author_name, length(title), id").reverse_order + assert_equal topics(:second).title, topics.first.title + topics = Topic.order("length(author_name), id, length(title)").reverse_order + assert_equal topics(:fifth).title, topics.first.title + end + + def test_reverse_order_with_multiargument_function + assert_raises(ActiveRecord::IrreversibleOrderError) do + Topic.order("concat(author_name, title)").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 + end + assert_raises(ActiveRecord::IrreversibleOrderError) do + Topic.order("title nulls last").reverse_order + end + end + + def test_default_reverse_order_on_table_without_primary_key + assert_raises(ActiveRecord::IrreversibleOrderError) do + Edge.all.reverse_order + end + end + def test_order_with_hash_and_symbol_generates_the_same_sql assert_equal Topic.order(:id).to_sql, Topic.order(:id => :asc).to_sql end |