From af3d7c5193eee90ad17b1ba8aaf5d76a2874c0a5 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sun, 16 Mar 2008 16:14:02 -0700 Subject: formatting insert and update statements - values need to be coerced to the type corresponding to the column --- spec/active_relation/unit/relations/update_spec.rb | 61 ++++++++++++++++------ 1 file changed, 46 insertions(+), 15 deletions(-) (limited to 'spec/active_relation/unit/relations/update_spec.rb') diff --git a/spec/active_relation/unit/relations/update_spec.rb b/spec/active_relation/unit/relations/update_spec.rb index 848760de83..485c86372d 100644 --- a/spec/active_relation/unit/relations/update_spec.rb +++ b/spec/active_relation/unit/relations/update_spec.rb @@ -7,27 +7,58 @@ module ActiveRelation end describe '#to_sql' do - it 'manufactures sql updating attributes' do - Update.new(@relation, @relation[:name] => "nick".bind(@relation)).to_sql.should be_like(" - UPDATE `users` - SET `users`.`name` = 'nick' - ") + describe 'when given values whose types correspond to the types of the attributes' do + before do + @update = Update.new(@relation, @relation[:name] => "nick".bind(@relation)) + end + + it 'manufactures sql updating attributes' do + @update.to_sql.should be_like(" + UPDATE `users` + SET `users`.`name` = 'nick' + ") + end end - - it 'manufactures sql updating a selection relation' do - Update.new(@relation.select(@relation[:id].equals(1)), @relation[:name] => "nick".bind(@relation)).to_sql.should be_like(" - UPDATE `users` - SET `users`.`name` = 'nick' - WHERE `users`.`id` = 1 - ") + + describe 'when given values whose types differ from from the types of the attributes' do + before do + @update = Update.new(@relation, @relation[:id] => '1-asdf'.bind(@relation)) + end + + it 'manufactures sql updating attributes' do + @update.to_sql.should be_like(" + UPDATE `users` + SET `users`.`id` = 1 + ") + end + end + + describe 'when the relation is a selection' do + before do + @update = Update.new( + @relation.select(@relation[:id].equals(1)), + @relation[:name] => "nick".bind(@relation) + ) + end + + it 'manufactures sql updating a selection relation' do + @update.to_sql.should be_like(" + UPDATE `users` + SET `users`.`name` = 'nick' + WHERE `users`.`id` = 1 + ") + end end end describe '#call' do + before do + @update = Update.new(@relation, @relation[:name] => "nick".bind(@relation)) + end + it 'executes an update on the connection' do - update = Update.new(@relation, @relation[:name] => "nick".bind(@relation)) - mock(connection = Object.new).update(update.to_sql) - update.call(connection) + mock(connection = Object.new).update(@update.to_sql) + @update.call(connection) end end -- cgit v1.2.3