diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-11-09 16:51:33 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-11-09 16:51:33 -0800 |
commit | 3718cdab13696a7c60921803349f63f9c9478db2 (patch) | |
tree | 5e0f8ea0d613a3968db8b52c32860bf36cb5ef7e | |
parent | 567a14205d5a17e7cffc012bcc8c1132da99124c (diff) | |
parent | 4dcfe6786e5fe72c27cadc5c0ee18aa6a67ba2bd (diff) | |
download | rails-3718cdab13696a7c60921803349f63f9c9478db2.tar.gz rails-3718cdab13696a7c60921803349f63f9c9478db2.tar.bz2 rails-3718cdab13696a7c60921803349f63f9c9478db2.zip |
Merge commit 'brynary/master'
-rw-r--r-- | Rakefile | 2 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/writes.rb | 22 | ||||
-rw-r--r-- | spec/arel/algebra/unit/predicates/binary_spec.rb | 2 | ||||
-rw-r--r-- | spec/arel/algebra/unit/predicates/equality_spec.rb | 4 | ||||
-rw-r--r-- | spec/arel/algebra/unit/relations/relation_spec.rb | 10 | ||||
-rw-r--r-- | spec/arel/algebra/unit/session/session_spec.rb | 10 | ||||
-rw-r--r-- | spec/arel/engines/sql/unit/predicates/binary_spec.rb | 2 | ||||
-rw-r--r-- | spec/arel/engines/sql/unit/predicates/equality_spec.rb | 4 | ||||
-rw-r--r-- | spec/arel/engines/sql/unit/predicates/in_spec.rb | 2 | ||||
-rw-r--r-- | spec/arel/engines/sql/unit/predicates/predicates_spec.rb | 6 | ||||
-rw-r--r-- | spec/arel/engines/sql/unit/relations/table_spec.rb | 4 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 |
12 files changed, 43 insertions, 27 deletions
@@ -36,7 +36,7 @@ else end desc "Run specs with mysql and sqlite3 database adapters (default)" - task :spec => ["check_dependencies", "spec:sqlite3", "spec:mysql", "spec:postgresql"] + task :spec => ["spec:sqlite3", "spec:mysql", "spec:postgresql"] desc "Default task is to run specs" task :default => :spec diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index 42496ef735..50fcb8e07e 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -14,8 +14,19 @@ module Arel insertion_attributes_values_sql = if record.is_a?(Value) record.value else - build_query "(#{record.keys.collect { |key| engine.quote_column_name(key.name) }.join(', ')})", - "VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})" + attributes = record.keys.sort_by do |attribute| + attribute.name.to_s + end + + first = attributes.collect do |key| + engine.quote_column_name(key.name) + end.join(', ') + + second = attributes.collect do |key| + key.format(record[key]) + end.join(', ') + + build_query "(#{first})", "VALUES (#{second})" end build_query \ @@ -37,7 +48,12 @@ module Arel def assignment_sql if assignments.respond_to?(:collect) - assignments.collect do |attribute, value| + attributes = assignments.keys.sort_by do |attribute| + attribute.name.to_s + end + + attributes.map do |attribute| + value = assignments[attribute] "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}" end.join(",\n") else diff --git a/spec/arel/algebra/unit/predicates/binary_spec.rb b/spec/arel/algebra/unit/predicates/binary_spec.rb index be4c1ac738..051aeeeb6e 100644 --- a/spec/arel/algebra/unit/predicates/binary_spec.rb +++ b/spec/arel/algebra/unit/predicates/binary_spec.rb @@ -4,7 +4,7 @@ module Arel module Predicates describe Binary do before do - @relation = Table.new(:users) + @relation = Arel::Table.new(:users) @attribute1 = @relation[:id] @attribute2 = @relation[:name] class ConcreteBinary < Binary diff --git a/spec/arel/algebra/unit/predicates/equality_spec.rb b/spec/arel/algebra/unit/predicates/equality_spec.rb index cfd04cd90c..7d1d79ff35 100644 --- a/spec/arel/algebra/unit/predicates/equality_spec.rb +++ b/spec/arel/algebra/unit/predicates/equality_spec.rb @@ -4,8 +4,8 @@ module Arel module Predicates describe Equality do before do - @relation1 = Table.new(:users) - @relation2 = Table.new(:photos) + @relation1 = Arel::Table.new(:users) + @relation2 = Arel::Table.new(:photos) @attribute1 = @relation1[:id] @attribute2 = @relation2[:user_id] end diff --git a/spec/arel/algebra/unit/relations/relation_spec.rb b/spec/arel/algebra/unit/relations/relation_spec.rb index 35ce8bf1fb..cf6509fe6a 100644 --- a/spec/arel/algebra/unit/relations/relation_spec.rb +++ b/spec/arel/algebra/unit/relations/relation_spec.rb @@ -150,7 +150,7 @@ module Arel describe '#delete' do it 'manufactures a deletion relation' do Session.start do - mock(Session.new).delete(Deletion.new(@relation)) + Session.new.should_receive(:delete).with(Deletion.new(@relation)) @relation.delete end end @@ -160,7 +160,7 @@ module Arel it 'manufactures an insertion relation' do Session.start do record = { @relation[:name] => 'carl' } - mock(Session.new).create(Insert.new(@relation, record)) + Session.new.should_receive(:create).with(Insert.new(@relation, record)) @relation.insert(record) end end @@ -170,7 +170,7 @@ module Arel it 'manufactures an update relation' do Session.start do assignments = { @relation[:name] => Value.new('bob', @relation) } - mock(Session.new).update(Update.new(@relation, assignments)) + Session.new.should_receive(:update).with(Update.new(@relation, assignments)) @relation.update(assignments) end end @@ -180,8 +180,8 @@ module Arel describe Relation::Enumerable do it "implements enumerable" do - check @relation.collect.should == @relation.session.read(@relation).collect - @relation.first.should == @relation.session.read(@relation).first + @relation.map { |value| value }.should == + @relation.session.read(@relation).map { |value| value } end end end diff --git a/spec/arel/algebra/unit/session/session_spec.rb b/spec/arel/algebra/unit/session/session_spec.rb index 03aab6a03f..0553a140ec 100644 --- a/spec/arel/algebra/unit/session/session_spec.rb +++ b/spec/arel/algebra/unit/session/session_spec.rb @@ -40,19 +40,19 @@ module Arel describe '#create' do it "executes an insertion on the connection" do - mock(@insert).call + @insert.should_receive(:call) @session.create(@insert) end end describe '#read' do it "executes an selection on the connection" do - mock(@read).call + @read.should_receive(:call) @session.read(@read) end it "is memoized" do - mock(@read).call.once + @read.should_receive(:call).once @session.read(@read) @session.read(@read) end @@ -60,14 +60,14 @@ module Arel describe '#update' do it "executes an update on the connection" do - mock(@update).call + @update.should_receive(:call) @session.update(@update) end end describe '#delete' do it "executes a delete on the connection" do - mock(@delete).call + @delete.should_receive(:call) @session.delete(@delete) end end diff --git a/spec/arel/engines/sql/unit/predicates/binary_spec.rb b/spec/arel/engines/sql/unit/predicates/binary_spec.rb index 23bce54792..08f3310f8e 100644 --- a/spec/arel/engines/sql/unit/predicates/binary_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/binary_spec.rb @@ -10,7 +10,7 @@ module Arel end before do - @relation = Table.new(:users) + @relation = Arel::Table.new(:users) @attribute1 = @relation[:id] @attribute2 = @relation[:name] end diff --git a/spec/arel/engines/sql/unit/predicates/equality_spec.rb b/spec/arel/engines/sql/unit/predicates/equality_spec.rb index 4004bb5881..7a5cb42c85 100644 --- a/spec/arel/engines/sql/unit/predicates/equality_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/equality_spec.rb @@ -4,8 +4,8 @@ module Arel module Predicates describe Equality do before do - @relation1 = Table.new(:users) - @relation2 = Table.new(:photos) + @relation1 = Arel::Table.new(:users) + @relation2 = Arel::Table.new(:photos) @attribute1 = @relation1[:id] @attribute2 = @relation2[:user_id] end diff --git a/spec/arel/engines/sql/unit/predicates/in_spec.rb b/spec/arel/engines/sql/unit/predicates/in_spec.rb index bb00733e60..691abcb2d2 100644 --- a/spec/arel/engines/sql/unit/predicates/in_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/in_spec.rb @@ -4,7 +4,7 @@ module Arel module Predicates describe In do before do - @relation = Table.new(:users) + @relation = Arel::Table.new(:users) @attribute = @relation[:id] end diff --git a/spec/arel/engines/sql/unit/predicates/predicates_spec.rb b/spec/arel/engines/sql/unit/predicates/predicates_spec.rb index 7d53351546..81c348357c 100644 --- a/spec/arel/engines/sql/unit/predicates/predicates_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/predicates_spec.rb @@ -4,11 +4,11 @@ module Arel module Predicates describe Predicate do before do - @relation = Table.new(:users) + @relation = Arel::Table.new(:users) @attribute1 = @relation[:id] @attribute2 = @relation[:name] - @operand1 = Equality.new(@attribute1, 1) - @operand2 = Equality.new(@attribute2, "name") + @operand1 = Arel::Predicates::Equality.new(@attribute1, 1) + @operand2 = Arel::Predicates::Equality.new(@attribute2, "name") end describe "when being combined with another predicate with AND logic" do diff --git a/spec/arel/engines/sql/unit/relations/table_spec.rb b/spec/arel/engines/sql/unit/relations/table_spec.rb index 26b9364929..92e4549028 100644 --- a/spec/arel/engines/sql/unit/relations/table_spec.rb +++ b/spec/arel/engines/sql/unit/relations/table_spec.rb @@ -42,8 +42,8 @@ module Arel describe '#reset' do it "reloads columns from the database" do - lambda { stub(@relation.engine).columns { [] } }.should_not change { @relation.attributes } - lambda { @relation.reset }.should change { @relation.attributes } + lambda { @relation.engine.stub!(:columns => []) }.should_not change { @relation.attributes } + lambda { @relation.reset }.should change { @relation.attributes } end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7d61fc9120..6d99fa4038 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -48,7 +48,7 @@ Spec::Runner.configure do |config| config.include BeLikeMatcher, HashTheSameAsMatcher, DisambiguateAttributesMatcher config.include AdapterGuards config.include Check - config.mock_with :rr + config.before do Arel::Table.engine = Arel::Sql::Engine.new(ActiveRecord::Base) end |