diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-24 15:21:54 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-24 15:21:54 -0700 |
commit | 6b86ae4f9f2fb8cd145f958753fedf16aae3a0d4 (patch) | |
tree | fff66461830df50e3211d8ced131584e6d75f9d4 /spec/update_manager_spec.rb | |
parent | 245d797a8ccab3ed2de9a0eedf455d3094a091ce (diff) | |
download | rails-6b86ae4f9f2fb8cd145f958753fedf16aae3a0d4.tar.gz rails-6b86ae4f9f2fb8cd145f958753fedf16aae3a0d4.tar.bz2 rails-6b86ae4f9f2fb8cd145f958753fedf16aae3a0d4.zip |
shuffling around the spec directory
Diffstat (limited to 'spec/update_manager_spec.rb')
-rw-r--r-- | spec/update_manager_spec.rb | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/spec/update_manager_spec.rb b/spec/update_manager_spec.rb new file mode 100644 index 0000000000..016b6f69b1 --- /dev/null +++ b/spec/update_manager_spec.rb @@ -0,0 +1,89 @@ +require 'spec_helper' + +module Arel + describe 'update manager' do + describe 'new' do + it 'takes an engine' do + Arel::UpdateManager.new Table.engine + end + end + + describe 'set' do + it "updates with null" do + table = Table.new(:users) + um = Arel::UpdateManager.new Table.engine + um.table table + um.set [[table[:name], nil]] + um.to_sql.should be_like %{ UPDATE "users" SET "name" = NULL } + end + + it 'takes a string' do + table = Table.new(:users) + um = Arel::UpdateManager.new Table.engine + um.table table + um.set Nodes::SqlLiteral.new "foo = bar" + um.to_sql.should be_like %{ UPDATE "users" SET foo = bar } + end + + it 'takes a list of lists' do + table = Table.new(:users) + um = Arel::UpdateManager.new Table.engine + um.table table + um.set [[table[:id], 1], [table[:name], 'hello']] + um.to_sql.should be_like %{ + UPDATE "users" SET "id" = 1, "name" = 'hello' + } + end + + it 'chains' do + table = Table.new(:users) + um = Arel::UpdateManager.new Table.engine + um.set([[table[:id], 1], [table[:name], 'hello']]).should == um + end + end + + describe 'table' do + it 'generates an update statement' do + um = Arel::UpdateManager.new Table.engine + um.table Table.new(:users) + um.to_sql.should be_like %{ UPDATE "users" } + end + + it 'chains' do + um = Arel::UpdateManager.new Table.engine + um.table(Table.new(:users)).should == um + end + end + + describe 'where' do + it 'generates a where clause' do + table = Table.new :users + um = Arel::UpdateManager.new Table.engine + um.table table + um.where table[:id].eq(1) + um.to_sql.should be_like %{ + UPDATE "users" WHERE "users"."id" = 1 + } + end + + it 'chains' do + table = Table.new :users + um = Arel::UpdateManager.new Table.engine + um.table table + um.where(table[:id].eq(1)).should == um + end + end + + describe "TreeManager" do + subject do + table = Table.new :users + Arel::UpdateManager.new(Table.engine).tap do |manager| + manager.table table + manager.where table[:id].eq(1) + end + end + + it_should_behave_like "TreeManager" + end + end +end |