Using FactoryGirl 4.7.0, I have a factory that I want to specify the updated_at attribute to a date in the past.
factory :living_arrangement do
trait :expired do
updated_at Date.new(2012, 3, 6)
# or
updated_at { Date.new(2012, 3, 6) }
end
end
However these are not working. The factory updated_at attribute keeps getting set back to Date.now
.
How do I get this to work?
Turns out I had to use a callback for when the factory gets created, like so
factory :living_arrangement do
trait :expired do
after :create do |living|
living.updated_at = Date.new(2012, 3, 6)
end
end
end