I read this from Thoughtbot but it's still confusing to me.
This is their example:
factory :user do
transient do
rockstar true
upcased false
end
name { "John Doe#{" - Rockstar" if rockstar}" }
email { "#{name.downcase}@example.com" }
after(:create) do |user, evaluator|
user.name.upcase! if evaluator.upcased
end
end
create(:user, upcased: true).name
#=> "JOHN DOE - ROCKSTAR"
So,
- Is
.upcased
a real attribute on the model? - What is the
transient
block really doing? Setting variables that can then be used in the factory? - What is
evaluator
? Does it always need to be passed last? What if yourcreate
function uses traits, transients, and has multiple values?