diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 6de362e3..735cc0a5 100644 --- a/CHANGELOG.rdoc +++ b/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) diff --git a/lib/devise/models/timeoutable.rb b/lib/devise/models/timeoutable.rb index 343b09f0..bd8e8ef0 100644 --- a/lib/devise/models/timeoutable.rb +++ b/lib/devise/models/timeoutable.rb @@ -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? diff --git a/test/models/timeoutable_test.rb b/test/models/timeoutable_test.rb index f9cb9cf8..cb2ee701 100644 --- a/test/models/timeoutable_test.rb +++ b/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