Rocky
Rocky

Reputation: 57

How do you test models that depend on Date.current?

My model will have logic that uses Date.current like this:

if(date_three && date_three != Date.current.yesterday)
  ...
end

How do I change the system's current date on my specs so I can test my model with different dates?

Upvotes: 1

Views: 664

Answers (1)

Marek Příhoda
Marek Příhoda

Reputation: 11198

There is a gem for just this kind of tasks - the timecop gem.

Upvotes: 5

Related Questions