TIL: Use Rails travel functions instead of timecop or time-warp

If you were using timecop or time-warp gems like me before, you will be happy to hear that Ruby on Rails provides its own travel and travel_to methods that allow you move in time and test time sensitive methods.

It’s great to see that you don’t need an external gem for this!

test 'creates a post in the past' do
  travel_to(5.days.ago) do
    @post = Post.create
  assert_equal 5.days.ago, @post.created_at

Read more at OmniRef.

Last modified: 14-May-24