Dates and times in fixtures

Just a micro tip. If you’re inserting dates and/or times into your database via fixtures whether for testing or to load initial data, it’s not enough just to specify the date. This won’t work:

some_fixture:
  id: 1
  created_at: <%= 2.days.ago %>

You need to coorce the data into the appropriate format like so:

some_fixture:
  id: 1
  created_at: <%= 2.days.ago.to_s :db %>

Comments

Leave a Reply