Fix timeout tests.
This commit is contained in:
parent
15ba859454
commit
691055cf06
|
@ -100,8 +100,7 @@ module Devise
|
|||
# confirmation_period_valid? # will always return false
|
||||
#
|
||||
def confirmation_period_valid?
|
||||
confirmation_sent_at &&
|
||||
((Time.now.utc - confirmation_sent_at.utc) < self.class.confirm_within)
|
||||
confirmation_sent_at && confirmation_sent_at.utc >= self.class.confirm_within.ago
|
||||
end
|
||||
|
||||
# Checks whether the record is confirmed or not, yielding to the block
|
||||
|
|
|
@ -19,7 +19,7 @@ module Devise
|
|||
|
||||
# Checks whether the user session has expired based on configured time.
|
||||
def timeout?(last_access)
|
||||
last_access && last_access <= self.class.timeout.ago.utc
|
||||
last_access && last_access <= self.class.timeout.ago
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
|
|
@ -10,6 +10,7 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|||
sign_in_as_user
|
||||
old_last_request = last_request_at
|
||||
assert_not_nil last_request_at
|
||||
|
||||
get users_path
|
||||
assert_not_nil last_request_at
|
||||
assert_not_equal old_last_request, last_request_at
|
||||
|
@ -62,8 +63,10 @@ class SessionTimeoutTest < ActionController::IntegrationTest
|
|||
:sessions => { :user => { :timeout => 'Session expired!' } }
|
||||
} do
|
||||
sign_in_as_user
|
||||
|
||||
# Setup last_request_at to timeout
|
||||
get new_user_path
|
||||
|
||||
get users_path
|
||||
follow_redirect!
|
||||
assert_contain 'Session expired!'
|
||||
|
|
|
@ -3,11 +3,11 @@ require 'test/test_helper'
|
|||
class TimeoutableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should be expired' do
|
||||
assert new_user.timeout?(11.minutes.ago)
|
||||
assert new_user.timeout?(31.minutes.ago)
|
||||
end
|
||||
|
||||
test 'should not be expired' do
|
||||
assert_not new_user.timeout?(9.minutes.ago)
|
||||
assert_not new_user.timeout?(29.minutes.ago)
|
||||
end
|
||||
|
||||
test 'should not be expired when params is nil' do
|
||||
|
|
|
@ -6,12 +6,12 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
user_session['last_request_at'] = 11.minutes.ago.utc
|
||||
user_session['last_request_at'] = 31.minutes.ago.utc
|
||||
render :text => 'New user!'
|
||||
end
|
||||
|
||||
def edit
|
||||
user_session['last_request_at'] = 9.minutes.ago.utc
|
||||
user_session['last_request_at'] = 29.minutes.ago.utc
|
||||
render :text => 'Edit user!'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue