Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implement dynamic value for timeout_in as a model method instead of a…

… proc
  • Loading branch information...
commit 37dad2172b9d1f3a35132a384103a28fd41acfca 1 parent c8c471a
@lest lest authored
View
2  CHANGELOG.rdoc
@@ -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)
View
7 lib/devise/models/timeoutable.rb
@@ -24,12 +24,13 @@ module Timeoutable
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?
View
22 test/models/timeoutable_test.rb
@@ -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
+ assert user.timedout?(12.minutes.ago)
+ assert_not user.timedout?(8.minutes.ago)
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
Please sign in to comment.
Something went wrong with that request. Please try again.