Home > Software engineering >  How Can I Represent Postgresql Intervals in Ruby On Rails fixtures
How Can I Represent Postgresql Intervals in Ruby On Rails fixtures

Time:04-11

I'm trying to create fixtures for my tests and I have an “Interval” field in the one of my models.

How can I represent this “interval” field in my fixtures file?

CodePudding user response:

You can use ERB syntax in your fixtures files

For example you have events table with duration column type interval

In console you can create new record as

Event.create(duration: 2.days)

And in events.yml fixtures as

two_days:
  duration: <%= 2.days %>

three_days:
  duration: <%= 3.days %>
  • Related