timecop
timecop copied to clipboard
SQL 'NOW()' is not impacted by timecop
I am not sure how to handle this case, or even if it should be handled by Timecop, but I cannot find any documentation about it.
This test fails:
it 'test sql now' do
Timecop.freeze(1.year.ago)
sql_now = ActiveRecord::Base.connection.execute('SELECT now()').first['now']
assert_equal sql_now.to_date.year, Time.current.year
end
Because SQL time is not impacted by Timecop.
There is the same problem with javascript, but we succeeded to synchronize it with rails date with sinon.useFakeTimers
.
Do you have any idea on how to propagate the date to the sql server ?
You cannot fake any functions in MySQL except by using the procedures. timecop is just for the faking the date and times on ruby level, not anywhere else.
I understand that, unfortunately :( Do you think a README warning notice could be helpful?
Probably would be good to add some notice in the readme, that it doesn't mock anything outside ruby runtime.
what about adding this in README?
The PR is closed on this. If @cyrilchampier still wants to contribute to the docs on this please let me know. We'd be happy to include your idea with a few updates to the language.