Within a factory, how do I refer to the value of one of the other fields in the object being created?
Suppose my model Widget has two fields, nickname
and fullname
Inside my factory, I want to use Faker create a different random nickname each time a factory is created. (Finally figured out I have to use sequence(:nickname), otherwise the name is the same for all factories.)
In order to make some of the assertions easier to test for, I want to generate a fullname that is based upon nickname, something like fullname = "Full name for #{nickname}"
FactoryGirl.define do
factory :widget do
sequence(:nickname) { |n| Faker::Lorem.words(2).join(' ') }
sequence(:fullname) { |n| "Full name for " + ????? }
end
end
Whatever I put where the ??? goes, I get #<FactoryGirl::Decl...
instead of whatever the nickname was set to.
I tried name, name.to_s, name.value... nothing seems to work.