Once run bulk_insert with non constant attributes count
records = [
{ :name => "Foo", :age => 30 },
{ :name => "Bar" }
]
expect {SampleRecord.bulk_insert(records)}.to change{SampleRecord.count}.by(records.size)
It fails
ActiveRecord::StatementInvalid:
SQLite3::SQLException: all VALUES must have the same number of terms: INSERT INTO "sample_records"
(name, age, created_at, updated_at)
VALUES
('Foo', 30, '2017-05-04 12:44:57.825195', '2017-05-04 12:44:57.825195'),('Bar', '2017-05-04 12:44:57.825351', '2017-05-04 12:44:57.825351')
# ./lib/active_record_bulk_insert.rb:40:in `bulk_insert'
# ./spec/sample_record_spec.rb:24:in `block (4 levels) in <top (required)>'
# ./spec/sample_record_spec.rb:24:in `block (3 levels) in <top (required)>'
As you can see it does not fill gap
INSERT INTO "sample_records"
(name, age, created_at, updated_at)
VALUES
('Foo', 30, '2017-05-04 12:44:57.825195', '2017-05-04 12:44:57.825195'),
('Bar', '2017-05-04 12:44:57.825351', '2017-05-04 12:44:57.825351')
^^^ here
Once run
bulk_insertwith non constant attributes countIt fails
As you can see it does not fill gap