aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichiaki Ariga <chezou+github@gmail.com>2016-02-18 17:49:57 +0900
committerMichiaki Ariga <chezou+github@gmail.com>2016-02-18 18:35:30 +0900
commit25dbfba26343f04f0eb978852ad0dc80a18aedc5 (patch)
tree74a5a49c12dea3ec210eeac193456a6321de7645
parent00b62719b4ff4fe4e60b00ba46c03cc6209b1f40 (diff)
downloadrails-25dbfba26343f04f0eb978852ad0dc80a18aedc5.tar.gz
rails-25dbfba26343f04f0eb978852ad0dc80a18aedc5.tar.bz2
rails-25dbfba26343f04f0eb978852ad0dc80a18aedc5.zip
Add assertions order by field with empty data
Add assertions to MySQL `ORDER BY FIELD()` with empty data. These tests examine to sanitize `ORDER BY FIELD()` with empty data appropriately. ```ruby Tag.order(['field(id, ?)', []]).to_sql # => SELECT "tags".* FROM "tags" ORDER BY field(id, NULL) Tag.order(['field(id, ?)', nil]).to_sql # => SELECT "tags".* FROM "tags" ORDER BY field(id, NULL) ```
-rw-r--r--activerecord/test/cases/relations_test.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 090b885dd5..b860d8975d 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -358,6 +358,12 @@ class RelationTest < ActiveRecord::TestCase
def test_finding_with_sanitized_order
query = Tag.order(["field(id, ?)", [1,3,2]]).to_sql
assert_match(/field\(id, 1,3,2\)/, query)
+
+ query = Tag.order(["field(id, ?)", []]).to_sql
+ assert_match(/field\(id, NULL\)/, query)
+
+ query = Tag.order(["field(id, ?)", nil]).to_sql
+ assert_match(/field\(id, NULL\)/, query)
end
def test_finding_with_order_limit_and_offset