From 4146538dfd7066eb38fff29e73c739912acad13f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 16 Aug 2010 14:43:18 -0700 Subject: [PATCH] IN seems to work --- spec/arel/attributes/attribute_spec.rb | 16 ++++++++++++++-- spec/arel/select_manager_spec.rb | 2 +- spec/arel/table_spec.rb | 8 ++++---- spec/arel/visitors/to_sql_spec.rb | 9 +++++++++ spec/spec_helper.rb | 2 ++ 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/spec/arel/attributes/attribute_spec.rb b/spec/arel/attributes/attribute_spec.rb index ef0e0787fa..e6e6483e64 100644 --- a/spec/arel/attributes/attribute_spec.rb +++ b/spec/arel/attributes/attribute_spec.rb @@ -7,11 +7,23 @@ module Arel it 'should return an equality node' do attribute = Attribute.new nil, nil, nil equality = attribute.eq 1 - equality.left.should == attribute - equality.right.should == 1 + check equality.left.should == attribute + check equality.right.should == 1 equality.should be_kind_of Nodes::Equality end end + + describe '#in' do + it 'can be constructed with a list' do + end + + it 'should return an in node' do + attribute = Attribute.new nil, nil, nil + node = Nodes::In.new attribute, [1,2,3] + check node.left.should == attribute + check node.right.should == [1, 2, 3] + end + end end describe 'equality' do diff --git a/spec/arel/select_manager_spec.rb b/spec/arel/select_manager_spec.rb index e456cabc16..038475bf3d 100644 --- a/spec/arel/select_manager_spec.rb +++ b/spec/arel/select_manager_spec.rb @@ -127,7 +127,7 @@ module Arel it "chains" do table = Table.new :users manager = Arel::SelectManager.new Table.engine - manager.from(table).project(table['id']).should == manager + check manager.from(table).project(table['id']).should == manager manager.to_sql.should be_like 'SELECT "users"."id" FROM "users"' end end diff --git a/spec/arel/table_spec.rb b/spec/arel/table_spec.rb index c2bcd3911a..dbb21d6d69 100644 --- a/spec/arel/table_spec.rb +++ b/spec/arel/table_spec.rb @@ -9,12 +9,12 @@ module Arel describe 'new' do it 'should accept an engine' do rel = Table.new :users, 'foo' - rel.engine.should == 'foo' + check rel.engine.should == 'foo' end it 'should accept a hash' do rel = Table.new :users, :engine => 'foo' - rel.engine.should == 'foo' + check rel.engine.should == 'foo' end end @@ -44,7 +44,7 @@ module Arel describe 'columns' do it 'returns a list of columns' do columns = @relation.columns - columns.length.should == 2 + check columns.length.should == 2 columns.map { |x| x.name }.sort.should == %w{ name id }.sort end end @@ -61,7 +61,7 @@ module Arel describe 'when given a', Symbol do it "manufactures an attribute if the symbol names an attribute within the relation" do column = @relation[:id] - column.name.should == 'id' + check column.name.should == 'id' column.should be_kind_of Attributes::Integer end end diff --git a/spec/arel/visitors/to_sql_spec.rb b/spec/arel/visitors/to_sql_spec.rb index a266e87d22..1d78395b2f 100644 --- a/spec/arel/visitors/to_sql_spec.rb +++ b/spec/arel/visitors/to_sql_spec.rb @@ -13,6 +13,15 @@ module Arel @visitor.accept attr end + describe "Nodes::In" do + it "should know how to visit" do + node = @attr.in [1, 2, 3] + @visitor.accept(node).should be_like %{ + "users"."id" IN (1, 2, 3) + } + end + end + describe 'Equality' do it "should escape strings" do test = @attr.eq 'Aaron Patterson' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 797fe0a028..12cbe0170e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ require 'fileutils' require 'arel' require 'support/matchers/be_like' +require 'support/check' if adapter = ENV['ADAPTER'] require "support/connections/#{adapter}_connection.rb" @@ -11,6 +12,7 @@ end Spec::Runner.configure do |config| config.include Matchers + config.include Check if defined?(ActiveRecord::Base) tmp = File.expand_path('../../tmp', __FILE__)