diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-13 18:49:04 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-13 18:49:04 -0700 |
commit | 84507c03f49092387b6c57129d350bc5c8463b40 (patch) | |
tree | ad9dfb7e883b818b525db230bbecca71fc3bf0dc | |
parent | 04c8e48311231d0b8332a7050a48defc9d7b075e (diff) | |
parent | 968271f718929311797342e211f5ca29506463b9 (diff) | |
download | rails-84507c03f49092387b6c57129d350bc5c8463b40.tar.gz rails-84507c03f49092387b6c57129d350bc5c8463b40.tar.bz2 rails-84507c03f49092387b6c57129d350bc5c8463b40.zip |
Merge branch 'master' of git://github.com/brynary/arel into brynary/master
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | config/database.yml.example | 6 | ||||
-rw-r--r-- | spec/active_relation/unit/relations/deletion_spec.rb | 10 | ||||
-rw-r--r-- | spec/active_relation/unit/relations/insertion_spec.rb | 32 | ||||
-rw-r--r-- | spec/active_relation/unit/relations/update_spec.rb | 19 | ||||
-rw-r--r-- | spec/spec_helper.rb | 12 |
6 files changed, 60 insertions, 20 deletions
diff --git a/.gitignore b/.gitignore index d6355b45d0..2bab52ab21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ coverage/* +config/database.yml *.DS_Store diff --git a/config/database.yml.example b/config/database.yml.example new file mode 100644 index 0000000000..2230912f7d --- /dev/null +++ b/config/database.yml.example @@ -0,0 +1,6 @@ +test: + adapter: mysql + username: root + password: password + encoding: utf8 + database: sql_algebra_test diff --git a/spec/active_relation/unit/relations/deletion_spec.rb b/spec/active_relation/unit/relations/deletion_spec.rb index 71ddd8d820..72f3f81b2a 100644 --- a/spec/active_relation/unit/relations/deletion_spec.rb +++ b/spec/active_relation/unit/relations/deletion_spec.rb @@ -21,6 +21,16 @@ module ActiveRelation WHERE `users`.`id` = 1 ") end + + it "manufactures sql deleting a ranged relation" do + pending do + Deletion.new(@relation[0..0]).to_sql.should be_like(" + DELETE + FROM `users` + LIMIT 1 + ") + end + end end describe '#call' do diff --git a/spec/active_relation/unit/relations/insertion_spec.rb b/spec/active_relation/unit/relations/insertion_spec.rb index e01e7792e2..e1718e3b25 100644 --- a/spec/active_relation/unit/relations/insertion_spec.rb +++ b/spec/active_relation/unit/relations/insertion_spec.rb @@ -7,44 +7,54 @@ module ActiveRelation end describe '#to_sql' do - describe 'when given values whose types correspond to the types of the attributes' do - before do - @insertion = Insertion.new(@relation, @relation[:name] => "nick") + it 'manufactures sql inserting data when given multiple rows' do + pending do + @insertion = Insertion.new(@relation, [@relation[:name] => "nick", @relation[:name] => "bryan"]) + + @insertion.to_sql.should be_like(" + INSERT + INTO `users` + (`users`.`name`) VALUES ('nick'), ('bryan') + ") end + end + + it 'manufactures sql inserting data when given multiple values' do + pending do + @insertion = Insertion.new(@relation, @relation[:id] => "1", @relation[:name] => "nick") - it 'manufactures sql inserting data' do @insertion.to_sql.should be_like(" INSERT INTO `users` - (`users`.`name`) VALUES ('nick') + (`users`.`name`, `users`.`id`) VALUES ('nick', 1) ") end end - describe 'when given values whose types differ from from the types of the attributes' do + describe 'when given values whose types correspond to the types of the attributes' do before do - @insertion = Insertion.new(@relation, @relation[:id] => '1-asdf') + @insertion = Insertion.new(@relation, @relation[:name] => "nick") end it 'manufactures sql inserting data' do @insertion.to_sql.should be_like(" INSERT INTO `users` - (`users`.`id`) VALUES (1) + (`users`.`name`) VALUES ('nick') ") end end - describe 'when given values whose types correspond to the type of the attribtues' do + describe 'when given values whose types differ from from the types of the attributes' do before do - @insertion = Insertion.new(@relation, @relation[:name] => "nick") + @insertion = Insertion.new(@relation, @relation[:id] => '1-asdf') end it 'manufactures sql inserting data' do @insertion.to_sql.should be_like(" INSERT INTO `users` - (`users`.`name`) VALUES ('nick') + (`users`.`id`) VALUES (1) ") end end diff --git a/spec/active_relation/unit/relations/update_spec.rb b/spec/active_relation/unit/relations/update_spec.rb index 5c234fe759..6634dc67d1 100644 --- a/spec/active_relation/unit/relations/update_spec.rb +++ b/spec/active_relation/unit/relations/update_spec.rb @@ -7,6 +7,25 @@ module ActiveRelation end describe '#to_sql' do + it "manufactures sql updating attributes when given multiple attributes" do + pending do + Update.new(@relation, @relation[:id] => 1, @relation[:name] => "nick").to_sql.should be_like(" + UPDATE `users` + SET `users`.`name` = 'nick', `users`.`id` = 1 + ") + end + end + + it "manufactures sql updating attributes when given a ranged relation" do + pending do + Update.new(@relation[0..0], @relation[:name] => "nick").to_sql.should be_like(" + UPDATE `users` + SET `users`.`name` = 'nick' + LIMIT 1 + ") + end + end + describe 'when given values whose types correspond to the types of the attributes' do before do @update = Update.new(@relation, @relation[:name] => "nick") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4b61ae8ca8..b633d17257 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,15 +6,9 @@ $LOAD_PATH.unshift "#{dir}/../lib" Dir["#{dir}/matchers/*"].each { |m| require "#{dir}/matchers/#{File.basename(m)}" } require 'active_relation' -ActiveRecord::Base.configurations = { - 'test' => { - :adapter => 'mysql', - :username => 'root', - :password => 'password', - :encoding => 'utf8', - :database => 'sql_algebra_test', - }, -} +FileUtils.cp("#{dir}/../config/database.yml.example", "#{dir}/../config/database.yml") unless File.exist?("#{dir}/../config/database.yml") + +ActiveRecord::Base.configurations = YAML::load(IO.read("#{dir}/../config/database.yml")) ActiveRecord::Base.establish_connection 'test' class Hash |