Skip to content

Commit

Permalink
Merge pull request #291 from jkowens/clone_input_array
Browse files Browse the repository at this point in the history
Prevent modification of input array
  • Loading branch information
zdennis committed Jun 24, 2016
2 parents d8b7ed4 + caf838a commit 196f053
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/activerecord-import/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ def import_helper( *args )
# supports 2-element array and array
elsif args.size == 2 && args.first.is_a?( Array ) && args.last.is_a?( Array )
column_names, array_of_attributes = args
array_of_attributes = array_of_attributes.map(&:dup)
else
raise ArgumentError, "Invalid arguments!"
end

# dup the passed in array so we don't modify it unintentionally
column_names = column_names.dup
array_of_attributes = array_of_attributes.dup

# Force the primary key col into the insert if it's not
# on the list and we are using a sequence and stuff a nil
Expand Down
3 changes: 2 additions & 1 deletion test/import_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

it "should not modify the passed in values array" do
assert_nothing_raised do
values = [%w(foo bar)].freeze
record = %w(foo bar).freeze
values = [record].freeze
Topic.import %w(title author_name), values
end
end
Expand Down

0 comments on commit 196f053

Please sign in to comment.