提交 77fa5fa5 编写于 作者: A Aaron Patterson

to_sql on nodes may be passed an engine

上级 ec998ae9
......@@ -7,16 +7,6 @@ def initialize left, right
@left = left
@right = right
end
# FIXME: this method should go away. I don't like people calling
# to_sql on non-head nodes. This forces us to walk the AST until we
# can find a node that has a "relation" member.
#
# Maybe we should just use `Table.engine`? :'(
def to_sql
viz = Visitors::ToSql.new Table.engine
viz.accept self
end
end
end
end
module Arel
module Nodes
class Function
class Function < Arel::Nodes::Node
include Arel::Expression
attr_accessor :expressions, :alias
......@@ -13,11 +13,6 @@ def as aliaz
self.alias = SqlLiteral.new(aliaz)
self
end
def to_sql
viz = Visitors::ToSql.new Table.engine
viz.accept self
end
end
end
end
......@@ -6,16 +6,6 @@ class Grouping < Arel::Nodes::Node
def initialize expression
@expr = expression
end
# FIXME: this method should go away. I don't like people calling
# to_sql on non-head nodes. This forces us to walk the AST until we
# can find a node that has a "relation" member.
#
# Maybe we should just use `Table.engine`? :'(
def to_sql
viz = Visitors::ToSql.new Table.engine
viz.accept self
end
end
end
end
......@@ -15,6 +15,16 @@ def or right
def and right
Nodes::And.new self, right
end
# FIXME: this method should go away. I don't like people calling
# to_sql on non-head nodes. This forces us to walk the AST until we
# can find a node that has a "relation" member.
#
# Maybe we should just use `Table.engine`? :'(
def to_sql engine = Table.engine
viz = Visitors::ToSql.new engine
viz.accept self
end
end
end
end
......@@ -26,6 +26,24 @@ module Nodes
check left.right.should == left.operand2
end
end
describe 'to_sql' do
it 'takes an engine' do
engine = FakeRecord::Base.new
engine.connection.extend Module.new {
attr_accessor :quote_count
def quote(*args) @quote_count += 1; super; end
def quote_column_name(*args) @quote_count += 1; super; end
def quote_table_name(*args) @quote_count += 1; super; end
}
engine.connection.quote_count = 0
attr = Table.new(:users)[:id]
test = attr.eq(10)
test.to_sql engine
check engine.connection.quote_count.should == 2
end
end
end
describe 'or' do
......
......@@ -13,6 +13,6 @@
config.include Check
config.before do
Arel::Table.engine = Arel::Sql::Engine.new(FakeRecord::Base)
Arel::Table.engine = Arel::Sql::Engine.new(FakeRecord::Base.new)
end
end
......@@ -63,14 +63,11 @@ class ConnectionPool
class Spec < Struct.new(:config)
end
attr_reader :spec
attr_reader :spec, :connection
def initialize
@spec = Spec.new('sqlite3')
end
def connection
Connection.new
@connection = Connection.new
end
def with_connection
......@@ -79,11 +76,13 @@ def with_connection
end
class Base
def self.connection_pool
ConnectionPool.new
attr_accessor :connection_pool
def initialize
@connection_pool = ConnectionPool.new
end
def self.connection
def connection
connection_pool.connection
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册