Time travel with Rails fixtures

If you need to test date- and time-dependend data (for example - "posts that were published yesterday") in your application, use ERB to always obtain correct dates and times in your objects relative to the time the tests are being run:

booking:
  id: 2
  client_id: 2
  device_id: 1
  confirmed: 1
  starts: <%= (1.month.from_now).iso8601 %>
  ends: <%= (40.days.from_now).iso8601 %>



Don't forget to do proper casting ( to_date for datetime fields and to_time.to_s(:db) for time fields).

You need to create an account or log in to post comments to this site.