1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

adding crazy code to fix the last two AR tests

This commit is contained in:
Aaron Patterson 2010-09-20 13:29:12 -07:00
parent 6f9f83e474
commit d8de55cee1
3 changed files with 40 additions and 3 deletions

View file

@ -12,6 +12,9 @@ module Arel
end
def in other
if Arel::SelectManager === other
other = other.to_a.map { |x| x.id }
end
Nodes::In.new self, other
end

View file

@ -1,6 +1,10 @@
module Arel
module Nodes
class In < Equality
def initialize left, right
raise if Arel::SelectManager === right
super
end
end
end
end

View file

@ -12,13 +12,17 @@ module Arel
@head.limit
end
def constraints
@ctx.wheres
end
def skip amount
@head.offset = Nodes::Offset.new(amount)
self
end
def where_clauses
warn "where_clauses is deprecated" if $VERBOSE
#warn "where_clauses is deprecated" if $VERBOSE
to_sql = Visitors::ToSql.new @engine
@ctx.wheres.map { |c| to_sql.accept c }
end
@ -52,6 +56,18 @@ module Arel
def from table
table = Nodes::SqlLiteral.new(table) if String === table
# FIXME: this is a hack to support
# test_with_two_tables_in_from_without_getting_double_quoted
# from the AR tests.
unless @ctx.froms.empty?
source = @ctx.froms.first
if Nodes::SqlLiteral === table && Nodes::Join === source
source.left = table
table = source
end
end
@ctx.froms = [table]
self
end
@ -125,8 +141,22 @@ module Arel
manager.join_sql
end
def to_a
raise NotImplementedError
class Row < Struct.new(:data) # :nodoc:
def id
data['id']
end
def method_missing(name, *args)
name = name.to_s
return data[name] if data.key?(name)
super
end
end
def to_a # :nodoc:
warn "to_a is deprecated. Please remove it from #{caller[0]}"
# FIXME: I think `select` should be made public...
@engine.connection.send(:select, to_sql, 'AREL').map { |x| Row.new(x) }
end
# FIXME: this method should go away