diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-16 16:14:02 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-16 16:14:02 -0700 |
commit | af3d7c5193eee90ad17b1ba8aaf5d76a2874c0a5 (patch) | |
tree | c3eaf1cfdc0ed1f1d977937fb04848566e964c32 /spec/active_relation/unit/relations/update_spec.rb | |
parent | ed9c8d4d828fe4e28c1e37ed8921acbee54450f2 (diff) | |
download | rails-af3d7c5193eee90ad17b1ba8aaf5d76a2874c0a5.tar.gz rails-af3d7c5193eee90ad17b1ba8aaf5d76a2874c0a5.tar.bz2 rails-af3d7c5193eee90ad17b1ba8aaf5d76a2874c0a5.zip |
formatting insert and update statements
- values need to be coerced to the type corresponding to the column
Diffstat (limited to 'spec/active_relation/unit/relations/update_spec.rb')
-rw-r--r-- | spec/active_relation/unit/relations/update_spec.rb | 61 |
1 files changed, 46 insertions, 15 deletions
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 |