By setting:
FactoryGirl.duplicate_attribute_assignment_from_initialize_with =
false
This turns off duplicate assignment of attributes accessed from
initialize_with. This means any attributes accessed from the factory and
assigned in the initialize_with block won't be subsequently set after
the object has been instantiated.
This will be the default functionality in 4.0.
Closes#345
This fixes a bug where assignment occurs multiple times; in the case of
nested attributes, assignment mutates the instance, meaning that it
occurring multiple times will cause issues.
Closes#314
Factory Girl now allows factories to override object instantiation. This
means factories can use factory methods (e.g. methods other than new) as
well as pass arguments explicitly.
factory :user do
ignore do
things { ["thing 1", "thing 2"] }
end
initialize_with { User.construct_with_things(things) }
end
factory :report_generator do
ignore do
name { "Generic Report" }
data { {:foo => "bar", :baz => "buzz"} }
end
initialize_with { ReportGenerator.new(name, data) }
end
Whitespace
Code recommendations