Commit d9d687b0 authored by Matthias Kaeppler's avatar Matthias Kaeppler

Simplify test that checks IDs are set on insertion

parent 43131110
...@@ -57,16 +57,12 @@ describe BulkInsertableAssociations do ...@@ -57,16 +57,12 @@ describe BulkInsertableAssociations do
end end
end end
before do
ActiveRecord::Base.connection.execute('TRUNCATE bulk_foos RESTART IDENTITY')
end
context 'saving bulk insertable associations' do context 'saving bulk insertable associations' do
let(:parent) { BulkParent.new(name: 'parent') } let(:parent) { BulkParent.new(name: 'parent') }
context 'when items already have IDs' do context 'when items already have IDs' do
it 'stores nothing and raises an error' do it 'stores nothing and raises an error' do
build_items(parent: parent) { |n, item| item.id = 100 + n } build_items(parent: parent) { |n, item| item.id = n }
expect { save_with_bulk_inserts(parent) }.to raise_error(BulkInsertSafe::PrimaryKeySetError) expect { save_with_bulk_inserts(parent) }.to raise_error(BulkInsertSafe::PrimaryKeySetError)
expect(BulkFoo.count).to eq(0) expect(BulkFoo.count).to eq(0)
...@@ -79,7 +75,7 @@ describe BulkInsertableAssociations do ...@@ -79,7 +75,7 @@ describe BulkInsertableAssociations do
expect(BulkFoo).to receive(:bulk_insert!).once.and_call_original expect(BulkFoo).to receive(:bulk_insert!).once.and_call_original
expect { save_with_bulk_inserts(parent) }.to change { BulkFoo.count }.from(0).to(items.size) expect { save_with_bulk_inserts(parent) }.to change { BulkFoo.count }.from(0).to(items.size)
expect(parent.bulk_foos.pluck(:id)).to contain_exactly(*(1..10)) expect(parent.bulk_foos.pluck(:id)).to all(be_a Integer)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment