mercredi 13 avril 2016

How to test Devise's 'timeoutable' module?

I am trying to test a session timeout in my Rails 4.2 app using Devise. I have added :timeoutable in the relevant model. I have Devise::TestHelpers included, and I use sign_in and sign_out in my tests.

Here are the three things I have tried, none of which work. I know that if I do a sign_out explicitly instead of any of these, the test succeeds (basically, assert a redirect to the sign in page.)

What am I doing wrong?

With ActiveSupport::Testing::TimeHelper # before stuff travel_to(later) do # after stuff end

With Timecop # before stuff Timecop.travel(later) # after stuff

With stubbing t = Time.now + later.minutes # before stuff Time.stubs(:now).returns t # after stuff

Aucun commentaire:

Enregistrer un commentaire