fix hash clause handling

This commit is contained in:
Loic Nageleisen 2017-03-01 16:48:09 +01:00
parent d538a9b584
commit 8a9b5804fc
2 changed files with 2 additions and 0 deletions

View file

@ -296,6 +296,7 @@ module Rebel::SQL
def and_clause(*clause) def and_clause(*clause)
clause.map do |e| clause.map do |e|
case e case e
when Hash then and_clause(*e.to_a)
when Array then clause_term(e[0], e[1]) when Array then clause_term(e[0], e[1])
when Raw then e.wants_parens? && clause.count > 1 ? "(#{e})" : e when Raw then e.wants_parens? && clause.count > 1 ? "(#{e})" : e
when String then e when String then e

View file

@ -54,6 +54,7 @@ class TestRaw < Minitest::Test
end end
def test_where def test_where
assert_str_equal(Rebel::SQL.where?(foo: 1, bar: 2, baz: 3), 'WHERE "foo" = 1 AND "bar" = 2 AND "baz" = 3')
assert_str_equal(Rebel::SQL.where?(Rebel::SQL.name(:foo).eq(1).or(Rebel::SQL.name(:bar).eq(2)), Rebel::SQL.name(:baz).eq(3)), 'WHERE ("foo" = 1 OR "bar" = 2) AND "baz" = 3') assert_str_equal(Rebel::SQL.where?(Rebel::SQL.name(:foo).eq(1).or(Rebel::SQL.name(:bar).eq(2)), Rebel::SQL.name(:baz).eq(3)), 'WHERE ("foo" = 1 OR "bar" = 2) AND "baz" = 3')
assert_str_equal(Rebel::SQL.where?(Rebel::SQL.name(:foo).eq(1).or(Rebel::SQL.name(:bar).eq(2))), 'WHERE "foo" = 1 OR "bar" = 2') assert_str_equal(Rebel::SQL.where?(Rebel::SQL.name(:foo).eq(1).or(Rebel::SQL.name(:bar).eq(2))), 'WHERE "foo" = 1 OR "bar" = 2')
end end