thoughtbot/factory_girl — Issue #227: Allow to pass additional options to `.build` or `.create`
Author: dadooda
Created: 2011-10-29 10:02:25+00:00
State: open

Hi

I think that might be a good idea to allow `.build` or `.create` take additional options that are then accessible in the factory block.

For example, I want to specify if the sample attribute samples are fetched from a sequence or are taken randomly.

At the moment I see no way I can do it via arguments.

The usage may be something like:

# General form. Optional second hash is an extension.
FactoryGirl.build(:article, {...}, {...})

# Example of the actual call. `:custom` is the key for user options.
FactoryGirl.build(:article, {...}, {:custom => {:random_samples => true}})

FactoryGirl.define do
factory :article do |f|
p f.custom
# {:random_samples => true}

...
end
end