Permalink
Browse files

to_sql on nodes may be passed an engine

  • Loading branch information...
1 parent ec998ae commit 77fa5fa5f7cc21824edb5b1c1ebccd58f92e982b @tenderlove tenderlove committed Sep 27, 2010
View
@@ -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
@@ -1,6 +1,6 @@
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
View
@@ -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
View
@@ -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
View
@@ -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

0 comments on commit 77fa5fa

Please sign in to comment.