From 25dbfba26343f04f0eb978852ad0dc80a18aedc5 Mon Sep 17 00:00:00 2001 From: Michiaki Ariga Date: Thu, 18 Feb 2016 17:49:57 +0900 Subject: [PATCH] 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) ``` --- activerecord/test/cases/relations_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 090b885dd5f15..b860d8975d6c6 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -358,6 +358,12 @@ def test_finding_with_complex_order 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