Skip to content

Commit 84e5769

Browse files
committed
Fix batch_size bugs.
1 parent 32a36dd commit 84e5769

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/seed_dump/dump_methods/enumeration.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def batch_params_from(records, options)
5858

5959
count = records.count
6060

61-
[((count / batch_size) + 1), batch_size, (count % batch_size)]
61+
remainder = count % batch_size
62+
63+
[((count.to_f / batch_size).ceil), batch_size, (remainder == 0 ? batch_size : remainder)]
6264
end
6365

6466
def batch_size_from(records, options)

spec/dump_methods_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,14 @@
8585

8686
context 'with a batch_size parameter' do
8787
it 'should not raise an exception' do
88-
8988
SeedDump.dump(Sample, batch_size: 100)
9089
end
90+
91+
it 'should not cause records to not be dumped' do
92+
SeedDump.dump(Sample, batch_size: 2).should eq(@expected_output)
93+
94+
SeedDump.dump(Sample, batch_size: 1).should eq(@expected_output)
95+
end
9196
end
9297

9398
context 'Array' do

0 commit comments

Comments
 (0)