aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2016-08-17 00:28:56 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2016-08-17 00:28:56 -0300
commit8debad2a18ff497d7410ffe2ceb7eec2bc13f454 (patch)
tree30d7c5c99c0dc7262866340cd49ac1e95c1d6b0b /activerecord
parent5fe02881b11b3e7ade089df1b46fff249137fdf8 (diff)
parentd929a218c47b7a5ffc3f8989676a99edb992e2aa (diff)
downloadrails-8debad2a18ff497d7410ffe2ceb7eec2bc13f454.tar.gz
rails-8debad2a18ff497d7410ffe2ceb7eec2bc13f454.tar.bz2
rails-8debad2a18ff497d7410ffe2ceb7eec2bc13f454.zip
Merge pull request #25987 from aquajach/master
Fix does_not_support_reverse? to find sql functions with commas in nested brackets
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb2
-rw-r--r--activerecord/test/cases/relations_test.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 1a59b3a146..47976fa735 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -1137,7 +1137,7 @@ module ActiveRecord
def does_not_support_reverse?(order)
# Uses SQL function with multiple arguments.
- /\([^()]*,[^()]*\)/.match?(order) ||
+ (order.include?(',') && order.split(',').find { |section| section.count('(') != section.count(')')}) ||
# Uses "nulls first" like construction.
/nulls (first|last)\Z/i.match?(order)
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index a5bb6e1c51..3efaace69d 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -240,6 +240,15 @@ class RelationTest < ActiveRecord::TestCase
assert_raises(ActiveRecord::IrreversibleOrderError) do
Topic.order("concat(author_name, title)").reverse_order
end
+ assert_raises(ActiveRecord::IrreversibleOrderError) do
+ Topic.order("concat(lower(author_name), title)").reverse_order
+ end
+ assert_raises(ActiveRecord::IrreversibleOrderError) do
+ Topic.order("concat(author_name, lower(title))").reverse_order
+ end
+ assert_raises(ActiveRecord::IrreversibleOrderError) do
+ Topic.order("concat(lower(author_name), title, length(title)").reverse_order
+ end
end
def test_reverse_order_with_nulls_first_or_last