From 1a6a3a1c6aa2f75333edef9100951407c4f76f1f Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sun, 16 Mar 2008 15:40:15 -0700 Subject: properly quoting array values --- .../active_relation/unit/predicates/binary_spec.rb | 28 ++++++++++++---------- .../unit/relations/compound_spec.rb | 6 +++++ spec/active_relation/unit/relations/join_spec.rb | 9 ++++++- 3 files changed, 29 insertions(+), 14 deletions(-) (limited to 'spec/active_relation') diff --git a/spec/active_relation/unit/predicates/binary_spec.rb b/spec/active_relation/unit/predicates/binary_spec.rb index 13b3f10a8c..62d894b0fa 100644 --- a/spec/active_relation/unit/predicates/binary_spec.rb +++ b/spec/active_relation/unit/predicates/binary_spec.rb @@ -54,20 +54,22 @@ module ActiveRelation end describe 'when relating to an array' do - it 'manufactures sql with a list' do - pending - array = [1, 2, 3] - ConcreteBinary.new(@attribute1, array).to_sql.should be_like(" - `users`.`id` <=> (1,2,3) - ") + describe 'when given an arry of elements of the same type of the attribute' do + it 'manufactures sql with a list' do + array = [1, 2, 3] + ConcreteBinary.new(@attribute1, array.bind(@relation)).to_sql.should be_like(" + `users`.`id` <=> (1, 2, 3) + ") + end end - - it 'formats values in the array in the type of the attribute' do - pending - array = ['1-asdf', 2, 3] - ConcreteBinary.new(@attribute1, array).to_sql.should be_like(" - `users`.`id` <=> (1,2,3) - ") + + describe 'when given an array, the elements of which are not the same type as the attribute' do + it 'formats values in the array in the type of the attribute' do + array = ['1-asdf', 2, 3] + ConcreteBinary.new(@attribute1, array.bind(@relation)).to_sql.should be_like(" + `users`.`id` <=> (1, 2, 3) + ") + end end end diff --git a/spec/active_relation/unit/relations/compound_spec.rb b/spec/active_relation/unit/relations/compound_spec.rb index e8fcd12e2c..54a89f3f57 100644 --- a/spec/active_relation/unit/relations/compound_spec.rb +++ b/spec/active_relation/unit/relations/compound_spec.rb @@ -21,5 +21,11 @@ module ActiveRelation @compound_relation.attributes.should == @relation.attributes.collect { |a| a.bind(@compound_relation) } end end + + describe 'hashing' do + it 'implements hash equality' do + ConcreteCompound.new(@relation).should hash_the_same_as(ConcreteCompound.new(@relation)) + end + end end end \ No newline at end of file diff --git a/spec/active_relation/unit/relations/join_spec.rb b/spec/active_relation/unit/relations/join_spec.rb index fefe069d7b..a0e94a5b65 100644 --- a/spec/active_relation/unit/relations/join_spec.rb +++ b/spec/active_relation/unit/relations/join_spec.rb @@ -24,6 +24,13 @@ module ActiveRelation Join.new("INNER JOIN", @relation1, @relation2, @predicate).should == Join.new("INNER JOIN", @relation2, @relation1, @predicate) end end + + describe 'hashing' do + it 'implements hash equality' do + Join.new("INNER JOIN", @relation1, @relation2, @predicate) \ + .should hash_the_same_as(Join.new("INNER JOIN", @relation1, @relation2, @predicate)) + end + end describe '#qualify' do it 'descends' do @@ -150,6 +157,6 @@ module ActiveRelation ") end end - end + end end end \ No newline at end of file -- cgit v1.2.3