Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bulk_insert/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialize(connection, table_name, primary_key, column_names, set_size=500,
column_map = columns.inject({}) { |h, c| h.update(c.name => c) }

@primary_key = primary_key
@columns = column_names.map { |name| column_map[name.to_s] }
@columns = column_names.map { |name| column_map.fetch(name.to_s) }
@table_name = connection.quote_table_name(table_name)
@column_names = column_names.map { |name| connection.quote_column_name(name) }.join(",")

Expand Down
11 changes: 11 additions & 0 deletions test/bulk_insert/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ class BulkInsertWorkerTest < ActiveSupport::TestCase
assert_nil hello
end

test "meaningful error is raised when specifying non existent columns" do
assert_raises(KeyError) {
BulkInsert::Worker.new(
Testing.connection,
Testing.table_name,
'id',
%w(no_such_column)
)
}
end

test "adapter dependent SQLite methods" do
connection = Testing.connection
stub_connection_if_needed(connection, 'SQLite') do
Expand Down