Module: FactoryGirl::Syntax::Methods

Included in:
Default, FactoryGirl::SyntaxRunner
Defined in:
lib/factory_girl/syntax/methods.rb

Instance Method Summary collapse

Instance Method Details

#build_list(name, amount, *traits_and_overrides) ⇒ Object

Builds and returns multiple instances from this factory as an array. Attributes can be individually overridden by passing in a Hash of attribute => value pairs.

Arguments:

  • name: Symbol or String The name of the factory to be used.

  • amount: Integer number of instances to be built.

  • 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.



19
20
21
# File 'lib/factory_girl/syntax/methods.rb', line 19

def build_list(name, amount, *traits_and_overrides)
  amount.times.map { build(name, *traits_and_overrides) }
end

#create_list(name, amount, *traits_and_overrides) ⇒ Object

Creates and returns multiple instances from this factory as an array. Attributes can be individually overridden by passing in a Hash of attribute => value pairs.

Arguments:

  • name: Symbol or String The name of the factory to be used.

  • amount: Integer number of instances to be created.

  • 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.



38
39
40
# File 'lib/factory_girl/syntax/methods.rb', line 38

def create_list(name, amount, *traits_and_overrides)
  amount.times.map { create(name, *traits_and_overrides) }
end

#generate(name) ⇒ Object

Generates and returns the next value in a sequence.

Arguments:

name: (Symbol)
  The name of the sequence that a value should be generated for.

Returns:

The next value in the sequence. (Object)


50
51
52
# File 'lib/factory_girl/syntax/methods.rb', line 50

def generate(name)
  FactoryGirl.sequence_by_name(name).next
end