Skip to content

Commit

Permalink
Add assertions order by field with empty data
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
chezou committed Feb 18, 2016
1 parent 00b6271 commit 25dbfba
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 25dbfba

Please sign in to comment.