diff --git a/lib/factory_girl/syntax/methods.rb b/lib/factory_girl/syntax/methods.rb index 25989a457..025dcb2fb 100644 --- a/lib/factory_girl/syntax/methods.rb +++ b/lib/factory_girl/syntax/methods.rb @@ -90,14 +90,15 @@ def build_stubbed(name, *traits_and_overrides, &block) # The name of the factory to be used. # * amount: +Integer+ # number of instances to be built. - # * overrides: +Hash+ - # Attributes to overwrite for each instance. + # * traits_and_overrides: +Array+ + # [+*Array+] Traits to be applied + # [+Hash+] Attributes to overwrite for this instance. # # Returns: +Array+ # An array of instances of the class this factory generates, with generated attributes # assigned. - def build_list(name, amount, overrides = {}) - amount.times.map { build(name, overrides) } + def build_list(name, amount, *traits_and_overrides) + amount.times.map { build(name, *traits_and_overrides) } end # Creates and returns multiple instances from this factory as an array. Attributes can be @@ -108,14 +109,15 @@ def build_list(name, amount, overrides = {}) # The name of the factory to be used. # * amount: +Integer+ # number of instances to be created. - # * overrides: +Hash+ - # Attributes to overwrite for each instance. + # * traits_and_overrides: +Array+ + # [+*Array+] Traits to be applied + # [+Hash+] Attributes to overwrite for this instance. # # Returns: +Array+ # An array of instances of the class this factory generates, with generated attributes # assigned. - def create_list(name, amount, overrides = {}) - amount.times.map { create(name, overrides) } + def create_list(name, amount, *traits_and_overrides) + amount.times.map { create(name, *traits_and_overrides) } end # Generates and returns the next value in a sequence. diff --git a/spec/acceptance/traits_spec.rb b/spec/acceptance/traits_spec.rb index 3735602ff..0fced44b2 100644 --- a/spec/acceptance/traits_spec.rb +++ b/spec/acceptance/traits_spec.rb @@ -262,6 +262,32 @@ its(:admin) { should be_true } its(:name) { should == "Jack" } end + + context "adding traits in create_list" do + subject { FactoryGirl.create_list(:user, 2, :admin, :great, :name => "Joe") } + + its(:length) { should == 2 } + + it "creates all the records" do + subject.each do |record| + record.admin.should be_true + record.name.should == "JOE" + end + end + end + + context "adding traits in build_list" do + subject { FactoryGirl.build_list(:user, 2, :admin, :great, :name => "Joe") } + + its(:length) { should == 2 } + + it "builds all the records" do + subject.each do |record| + record.admin.should be_true + record.name.should == "Joe" + end + end + end end describe "traits and dynamic attributes that are applied simultaneously" do