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/insertion_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/insertion_spec.rb')
-rw-r--r-- | spec/active_relation/unit/relations/insertion_spec.rb | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/spec/active_relation/unit/relations/insertion_spec.rb b/spec/active_relation/unit/relations/insertion_spec.rb index f081743c50..b74ec6c7cb 100644 --- a/spec/active_relation/unit/relations/insertion_spec.rb +++ b/spec/active_relation/unit/relations/insertion_spec.rb @@ -4,20 +4,57 @@ module ActiveRelation describe Insertion do before do @relation = Table.new(:users) - @insertion = Insertion.new(@relation, @relation[:name] => "nick".bind(@relation)) end describe '#to_sql' do - it 'manufactures sql inserting the data for one item' do - @insertion.to_sql.should be_like(" - INSERT - INTO `users` - (`users`.`name`) VALUES ('nick') - ") + describe 'when given values whose types correspond to the types of the attributes' do + before do + @insertion = Insertion.new(@relation, @relation[:name] => "nick".bind(@relation)) + end + + it 'manufactures sql inserting data' do + @insertion.to_sql.should be_like(" + INSERT + INTO `users` + (`users`.`name`) VALUES ('nick') + ") + end + end + + describe 'when given values whose types differ from from the types of the attributes' do + before do + @insertion = Insertion.new(@relation, @relation[:id] => '1-asdf'.bind(@relation)) + end + + it 'manufactures sql inserting data' do + @insertion.to_sql.should be_like(" + INSERT + INTO `users` + (`users`.`id`) VALUES (1) + ") + end + end + + describe 'when given values whose types correspond to the type of the attribtues' do + before do + @insertion = Insertion.new(@relation, @relation[:name] => "nick".bind(@relation)) + end + + it 'manufactures sql inserting data' do + @insertion.to_sql.should be_like(" + INSERT + INTO `users` + (`users`.`name`) VALUES ('nick') + ") + end end end describe '#call' do + before do + @insertion = Insertion.new(@relation, @relation[:name] => "nick".bind(@relation)) + end + it 'executes an insert on the connection' do mock(connection = Object.new).insert(@insertion.to_sql) @insertion.call(connection) |