Permalink
Browse files

Prevent :on_duplicate_key_update args from being modified

  • Loading branch information...
jkowens committed Sep 15, 2017
1 parent ca3f5f0 commit 28617dedb19f72e505f1a9706ece3c53124d12b5
@@ -415,8 +415,13 @@ def import_helper( *args )
options[:primary_key] = primary_key
# Don't modify incoming arguments
if options[:on_duplicate_key_update] && options[:on_duplicate_key_update].duplicable?
options[:on_duplicate_key_update] = options[:on_duplicate_key_update].dup
on_duplicate_key_update = options[:on_duplicate_key_update]
if on_duplicate_key_update && on_duplicate_key_update.duplicable?
options[:on_duplicate_key_update] = if on_duplicate_key_update.is_a?(Hash)
on_duplicate_key_update.each { |k, v| on_duplicate_key_update[k] = v.dup if v.duplicable? }
else
on_duplicate_key_update.dup
end
end
is_validating = options[:validate]
@@ -309,6 +309,13 @@ def should_support_postgresql_upsert_functionality
@topic = Topic.find 99
end
it "should not modify the passed in :on_duplicate_key_update columns array" do
assert_nothing_raised do
columns = %w(title author_name).freeze
Topic.import columns, [%w(foo, bar)], on_duplicate_key_update: { columns: columns }
end
end
context "using string hash map" do
let(:update_columns) { { "title" => "title", "author_email_address" => "author_email_address", "parent_id" => "parent_id" } }
should_support_on_duplicate_key_update
@@ -7,7 +7,7 @@ def should_support_basic_on_duplicate_key_update
context "with :on_duplicate_key_update" do
describe "argument safety" do
it "should not modify the passed in :on_duplicate_key_update columns array" do
it "should not modify the passed in :on_duplicate_key_update array" do
assert_nothing_raised do
columns = %w(title author_name).freeze
Topic.import columns, [%w(foo, bar)], on_duplicate_key_update: columns

0 comments on commit 28617de

Please sign in to comment.