thoughtbot/factory_girl — Issue #257: Passing an argument to attribute block definition skips block evaluation
Author: maca
Created: 2011-12-19 22:53:02+00:00
State: open

FactoryGirl.define do
factory :question do
text { Faker::Lorem.words(5).join(' ') }
answers_attributes { 1.upto(4).map { Factory.attributes_for(:answer) } } # works OK
end
end

FactoryGirl.define do
factory :question do
text { Faker::Lorem.words(5).join(' ') }
answers_attributes { |question| 1.upto(4).map { Factory.attributes_for(:answer) } } # Is not evaluated at all
end
end

If I remember correctly in previous versions I could access the instantiated model within an attribute definition block, but now the block is not even evaluated if arity is 1.