Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Devise session timeout with RSpec

I'd like to customize the time period after which my Rails app will automatically end a user's session.

I found this question to give me exactly what I need, but I'd like to approach this through TDD. I've got a relatively solid test suite for the application, I'm just a little lost when it comes to testing if a user's session has expired, other than having a test sit there and wait for the session to expire after x.minutes have elapsed. Surely there's a better way.

I checked the Devise and Warden documentation for test helpers dealing with this and came up dry. Anyone have any tips?

like image 938
Brad Rice Avatar asked Sep 16 '25 04:09

Brad Rice


1 Answers

How about stubbing user.timedout? to return true? Or, you could pass a custom time in your test that exceeds your custom timeout value, like user.timed_out?(31.minutes.ago).

like image 62
stereoscott Avatar answered Sep 19 '25 12:09

stereoscott