mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Merge pull request #1462 from lest/timeout-in-method
implement dynamic value for timeout_in as a model method instead of a proc
This commit is contained in:
commit
ede004169c
3 changed files with 13 additions and 18 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
* enhancements
|
||||
* Add support for rails 3.1 new mass assignment conventions (by github.com/kirs)
|
||||
* timeout_in option can be a Proc object (by github.com/lest)
|
||||
* Add timeout_in method to Timeoutable, it can be overriden in a model (by github.com/lest)
|
||||
|
||||
* bug fix
|
||||
* OmniAuth error message now shows the proper option (:strategy_class instead of :klass)
|
||||
|
|
|
@ -24,12 +24,13 @@ module Devise
|
|||
def timedout?(last_access)
|
||||
return false if remember_exists_and_not_expired?
|
||||
|
||||
timeout_in = self.class.timeout_in
|
||||
timeout_in = timeout_in.call(self) if timeout_in.respond_to?(:call)
|
||||
|
||||
!timeout_in.nil? && last_access && last_access <= timeout_in.ago
|
||||
end
|
||||
|
||||
def timeout_in
|
||||
self.class.timeout_in
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remember_exists_and_not_expired?
|
||||
|
|
|
@ -14,24 +14,18 @@ class TimeoutableTest < ActiveSupport::TestCase
|
|||
assert_not new_user.timedout?(nil)
|
||||
end
|
||||
|
||||
test 'should accept timeout_in proc and provide user as argument' do
|
||||
test 'should use timeout_in method' do
|
||||
user = new_user
|
||||
user.instance_eval { def timeout_in; 10.minutes end }
|
||||
|
||||
timeout_in = proc do |obj|
|
||||
assert_equal user, obj
|
||||
10.minutes
|
||||
end
|
||||
|
||||
swap Devise, :timeout_in => timeout_in do
|
||||
assert user.timedout?(12.minutes.ago)
|
||||
assert_not user.timedout?(8.minutes.ago)
|
||||
end
|
||||
end
|
||||
|
||||
test 'should not be expired when timeout_in proc returns nil' do
|
||||
swap Devise, :timeout_in => proc { nil } do
|
||||
assert_not new_user.timedout?(10.hours.ago)
|
||||
end
|
||||
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)
|
||||
end
|
||||
|
||||
test 'fallback to Devise config option' do
|
||||
|
|
Loading…
Add table
Reference in a new issue