Q:

Skip validation on date field but still run before_validate callback

I've ended up with a little dilemma and I'm curious to hear what your general thoughts on this are and where I need to think different.
I have a model called Post which has a published_date. In certain tests I use FactoryGirl create to push this date back for statistics calculations etc. Now I would like to have a constraint so that can not push this date back at all. I've added the validation and the obvious problem is that I get a validation error on the tests I mentioned as well.
You could say that I could skip validation in the tests by doing a save(validation: false) but that results in the before_validation callback not running which in my case is important to set data correctly and make sure fields are filled in with data etc.
What are your takes on this?

A:

Check the timecop gem it allows you to manipulate time, so if you have a validation that doesn't allow past dates, you could travel back in time and then the Time.now would return the old time, and the validations would work fine
here's a silly sample of what you could do
Timecop.freeze(30.days.ago) do
  object = FactoryGirl.create(:some_object)
end

expect(object.created_at).to be <= 30.days.ago

