diff --git a/lib/fixturama/seed.rb b/lib/fixturama/seed.rb index d11b564..66ddd22 100644 --- a/lib/fixturama/seed.rb +++ b/lib/fixturama/seed.rb @@ -7,8 +7,9 @@ def call(opts) type = opts[:type].to_sym traits = Utils.symbolize_array opts[:traits] params = Utils.symbolize_hash opts[:params] + count = opts.fetch(:count, 1).to_i - FactoryBot.create(type, *traits, **params) + FactoryBot.create_list(type, count, *traits, **params) if count.positive? end end end diff --git a/spec/fixturama/seed_fixture/_spec.rb b/spec/fixturama/seed_fixture/_spec.rb index dc8b460..458854a 100644 --- a/spec/fixturama/seed_fixture/_spec.rb +++ b/spec/fixturama/seed_fixture/_spec.rb @@ -25,7 +25,8 @@ end it "runs the factory", aggregate_failures: true do - expect(FactoryBot).to receive(:create).and_return(bar: 99, baz: 77, qux: 42) + expect(FactoryBot).to receive(:create_list).with(:foo, 1, :baz, qux: 42) + expect(FactoryBot).to receive(:create_list).with(:foo, 3, :bar, {}) subject end diff --git a/spec/fixturama/seed_fixture/seed.yml b/spec/fixturama/seed_fixture/seed.yml index e117c07..ecf45d7 100644 --- a/spec/fixturama/seed_fixture/seed.yml +++ b/spec/fixturama/seed_fixture/seed.yml @@ -1,7 +1,16 @@ --- - type: foo traits: - - bar - baz params: qux: 42 + +- type: foo + count: 3 + traits: + - bar + +- type: foo + count: 0 + traits: + - baz