aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/active_relation/relations/insertion.rb4
-rw-r--r--spec/active_relation/unit/relations/insertion_spec.rb33
-rw-r--r--spec/spec_helper.rb1
3 files changed, 18 insertions, 20 deletions
diff --git a/lib/active_relation/relations/insertion.rb b/lib/active_relation/relations/insertion.rb
index 30de6819f1..58defe4b01 100644
--- a/lib/active_relation/relations/insertion.rb
+++ b/lib/active_relation/relations/insertion.rb
@@ -10,8 +10,8 @@ module ActiveRelation
[
"INSERT",
"INTO #{table_sql}",
- "(#{record.keys.collect(&:to_sql)})",
- "VALUES (#{record.collect { |key, value| key.format(value) }})"
+ "(#{record.keys.collect(&:to_sql).join(', ')})",
+ "VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})"
].join("\n")
end
diff --git a/spec/active_relation/unit/relations/insertion_spec.rb b/spec/active_relation/unit/relations/insertion_spec.rb
index e1718e3b25..543e2d51a9 100644
--- a/spec/active_relation/unit/relations/insertion_spec.rb
+++ b/spec/active_relation/unit/relations/insertion_spec.rb
@@ -8,27 +8,24 @@ module ActiveRelation
describe '#to_sql' do
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
+ pending 'it should insert multiple rows'
+ @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
it 'manufactures sql inserting data when given multiple values' do
- pending do
- @insertion = Insertion.new(@relation, @relation[:id] => "1", @relation[:name] => "nick")
-
- @insertion.to_sql.should be_like("
- INSERT
- INTO `users`
- (`users`.`name`, `users`.`id`) VALUES ('nick', 1)
- ")
- end
+ @insertion = Insertion.new(@relation, @relation[:id] => "1", @relation[:name] => "nick")
+
+ @insertion.to_sql.should be_like("
+ INSERT
+ INTO `users`
+ (`users`.`id`, `users`.`name`) VALUES (1, 'nick')
+ ")
end
describe 'when given values whose types correspond to the types of the attributes' do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index b633d17257..0d1613e223 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,6 +1,7 @@
require 'rubygems'
require 'spec'
require 'pp'
+require 'fileutils'
dir = File.dirname(__FILE__)
$LOAD_PATH.unshift "#{dir}/../lib"
Dir["#{dir}/matchers/*"].each { |m| require "#{dir}/matchers/#{File.basename(m)}" }