Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding proper columns to our fake table

  • Loading branch information...
commit 424e39d6883e5ab53a0f2c5d27508b36b1fb5879 1 parent d9d9944
@tenderlove tenderlove authored
View
4 test/support/fake_record.rb
@@ -10,7 +10,9 @@ def initialize
@columns = {
'users' => [
Column.new('id', :integer),
- Column.new('name', :string)
+ Column.new('name', :string),
+ Column.new('bool', :boolean),
+ Column.new('created_at', :date),
]
}
@primary_keys = {
View
11 test/test_insert_manager.rb
@@ -13,11 +13,9 @@ module Arel
table = Table.new(:users)
manager = Arel::InsertManager.new Table.engine
- table[:id].column.extend(Module.new { def type; :boolean; end })
-
- manager.insert [[table[:id], false]]
+ manager.insert [[table[:bool], false]]
manager.to_sql.must_be_like %{
- INSERT INTO "users" ("id") VALUES ('f')
+ INSERT INTO "users" ("bool") VALUES ('f')
}
end
@@ -35,12 +33,11 @@ module Arel
manager = Arel::InsertManager.new Table.engine
time = Time.now
- attribute = table[:id]
- attribute.column.type = :date
+ attribute = table[:created_at]
manager.insert [[attribute, time]]
manager.to_sql.must_be_like %{
- INSERT INTO "users" ("id") VALUES (#{Table.engine.connection.quote time})
+ INSERT INTO "users" ("created_at") VALUES (#{Table.engine.connection.quote time})
}
end
View
4 test/test_table.rb
@@ -150,8 +150,8 @@ module Arel
describe 'columns' do
it 'returns a list of columns' do
columns = @relation.columns
- columns.length.must_equal 2
- columns.map { |x| x.name.to_s }.sort.must_equal %w{ name id }.sort
+ columns.length.must_equal 4
+ columns.map { |x| x.name.to_s }.sort.must_equal %w{ created_at bool name id }.sort
end
end
View
13 test/visitors/test_to_sql.rb
@@ -69,9 +69,8 @@ module Visitors
end
it "should visit_TrueClass" do
- test = @attr.eq(true)
- test.left.column.type = :boolean
- @visitor.accept(test).must_be_like %{ "users"."id" = 't' }
+ test = Table.new(:users)[:bool].eq(true)
+ @visitor.accept(test).must_be_like %{ "users"."bool" = 't' }
end
describe "Nodes::Ordering" do
@@ -113,6 +112,7 @@ module Visitors
end
it 'uses the same column for escaping values' do
+ @attr = Table.new(:users)[:name]
visitor = Class.new(ToSql) do
attr_accessor :expected
@@ -124,16 +124,15 @@ def quote value, column = nil
in_node = Nodes::In.new @attr, %w{ a b c }
visitor = visitor.new(Table.engine)
visitor.expected = @attr.column
- visitor.accept(in_node).must_equal %("users"."id" IN ('a', 'b', 'c'))
+ visitor.accept(in_node).must_equal %("users"."name" IN ('a', 'b', 'c'))
end
end
describe 'Equality' do
it "should escape strings" do
- test = @attr.eq 'Aaron Patterson'
- test.left.column.type = :string
+ test = Table.new(:users)[:name].eq 'Aaron Patterson'
@visitor.accept(test).must_be_like %{
- "users"."id" = 'Aaron Patterson'
+ "users"."name" = 'Aaron Patterson'
}
end
end

0 comments on commit 424e39d

Please sign in to comment.
Something went wrong with that request. Please try again.