2010-03-26 11:27:19 +01:00
|
|
|
require 'test_helper'
|
2009-11-22 22:19:29 -02:00
|
|
|
|
|
|
|
class TimeoutableTest < ActiveSupport::TestCase
|
|
|
|
|
2009-11-22 22:33:19 -02:00
|
|
|
test 'should be expired' do
|
2010-01-14 15:47:14 +01:00
|
|
|
assert new_user.timedout?(31.minutes.ago)
|
2009-11-22 22:33:19 -02:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should not be expired' do
|
2010-01-14 15:47:14 +01:00
|
|
|
assert_not new_user.timedout?(29.minutes.ago)
|
2009-11-22 22:33:19 -02:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should not be expired when params is nil' do
|
2010-01-14 15:47:14 +01:00
|
|
|
assert_not new_user.timedout?(nil)
|
2009-11-22 22:33:19 -02:00
|
|
|
end
|
|
|
|
|
2011-11-25 10:57:36 +03:00
|
|
|
test 'should use timeout_in method' do
|
2011-11-24 21:42:58 +03:00
|
|
|
user = new_user
|
2011-11-25 10:57:36 +03:00
|
|
|
user.instance_eval { def timeout_in; 10.minutes end }
|
2011-11-24 21:42:58 +03:00
|
|
|
|
2011-11-25 10:57:36 +03:00
|
|
|
assert user.timedout?(12.minutes.ago)
|
|
|
|
assert_not user.timedout?(8.minutes.ago)
|
2011-11-24 21:42:58 +03:00
|
|
|
end
|
|
|
|
|
2011-11-25 10:57:36 +03:00
|
|
|
test 'should not be expired when timeout_in method returns nil' do
|
|
|
|
user = new_user
|
|
|
|
user.instance_eval { def timeout_in; nil end }
|
|
|
|
assert_not user.timedout?(10.hours.ago)
|
2011-11-24 21:42:58 +03:00
|
|
|
end
|
|
|
|
|
2009-11-22 22:33:19 -02:00
|
|
|
test 'fallback to Devise config option' do
|
2009-11-25 00:11:49 -02:00
|
|
|
swap Devise, :timeout_in => 1.minute do
|
2009-11-22 22:33:19 -02:00
|
|
|
user = new_user
|
2010-01-14 15:47:14 +01:00
|
|
|
assert user.timedout?(2.minutes.ago)
|
|
|
|
assert_not user.timedout?(30.seconds.ago)
|
2009-11-24 23:19:12 -02:00
|
|
|
|
2009-11-25 00:11:49 -02:00
|
|
|
Devise.timeout_in = 5.minutes
|
2010-01-14 15:47:14 +01:00
|
|
|
assert_not user.timedout?(2.minutes.ago)
|
|
|
|
assert user.timedout?(6.minutes.ago)
|
2009-11-22 22:33:19 -02:00
|
|
|
end
|
|
|
|
end
|
2012-02-24 20:56:04 -02:00
|
|
|
|
|
|
|
test 'required_fields should contain the fields that Devise uses' do
|
|
|
|
assert_same_content Devise::Models::Timeoutable.required_fields(User), []
|
|
|
|
end
|
2009-11-22 22:19:29 -02:00
|
|
|
end
|