I have a table with one of the field named end
. How do I write the factory for that table:
I try to use quote but it's not working:
FactoryGirl.define do
factory :open_hour do
location
day { Date::DAYNAMES.sample.downcase }
start { Time.now.strftime('%H:%M') }
'end' { Time.now.strftime('%H:%M') }
end
end
From FactoryGirl docs:
factory :user do name 'Billy Idol' end
and:
factory :user do add_attribute :name, 'Billy Idol' end
are equivalent.
Having had some awful issues in the past when trying to do this, I'd advise that you rename those fields to 'start_time' and 'end_time'. There may be other unanticipated issues caused by having fields/methods named 'end', and tracking them down can be extremely annoying. 'end_time' also has the virtue of more clearly explaining what it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With