Make And and Case into expression nodes

Allows aliasing, predications, ordering, and various other functions on `And` and `Case` nodes. This brings them in line with other nodes like `Binary` and `Unary`.
This commit is contained in:
Kevin Deisz 2019-01-24 14:35:52 -05:00
parent 1e25dfde03
commit 5cf36e2ea2
No known key found for this signature in database
GPG Key ID: D78C2D8FB232C59C
3 changed files with 11 additions and 4 deletions

@ -2,7 +2,7 @@
module Arel # :nodoc: all
module Nodes
class And < Arel::Nodes::Node
class And < Arel::Nodes::NodeExpression
attr_reader :children
def initialize(children)

@ -2,9 +2,7 @@
module Arel # :nodoc: all
module Nodes
class Case < Arel::Nodes::Node
include Arel::AliasPredication
class Case < Arel::Nodes::NodeExpression
attr_accessor :case, :conditions, :default
def initialize(expression = nil, default = nil)

@ -16,6 +16,15 @@ module Nodes
assert_equal 2, array.uniq.size
end
end
describe "functions as node expression" do
it "allows aliasing" do
aliased = And.new(["foo", "bar"]).as("baz")
assert_kind_of As, aliased
assert_kind_of SqlLiteral, aliased.right
end
end
end
end
end