'How Can I Represent Postgresql Intervals in Ruby On Rails fixtures

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?



Solution 1:[1]

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 %>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mechnicov