From 930b324c15ab54f3682cb6d78405e46b24d25ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 11 Dec 2011 20:18:02 +0100 Subject: [PATCH] Usage of confirm_within was deprecated in favor allow_unconfirmed_access_for --- CHANGELOG.rdoc | 10 ++++++---- lib/devise.rb | 10 +++++++--- lib/devise/models/confirmable.rb | 16 ++++++++-------- lib/generators/templates/devise.rb | 2 +- test/devise_test.rb | 4 ++-- test/integration/confirmable_test.rb | 6 +++--- test/integration/trackable_test.rb | 2 +- test/models/confirmable_test.rb | 10 +++++----- test/models_test.rb | 6 +++--- test/rails_app/config/initializers/devise.rb | 4 ++-- test/rails_app/lib/shared_admin.rb | 2 +- test/test_helpers_test.rb | 4 ++-- 12 files changed, 41 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 54d45c9c..8a1ceb9a 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -6,15 +6,17 @@ * deprecation * Devise.apply_schema is deprecated - * Usage of rememberable with remember_token is deprecated - * Usage of recoverable without reset_password_sent_at is deprecated - * Usage of remember_across_browsers is deprecated + * Usage of remember_across_browsers was deprecated + * Usage of confirm_within was deprecated in favor allow_unconfirmed_access_for + * Usage of rememberable with remember_token was removed + * Usage of recoverable without reset_password_sent_at was removed + * Usage of case_insensitive_keys equals to false was removed == 1.5.2 * enhancements * Add support for Rails 3.1 new mass assignment conventions (by github.com/kirs) - * Add timeout_in method to Timeoutable, it can be overriden in a model (by github.com/lest) + * Add timeout_in method to Timeoutable, it can be overridden 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.rb b/lib/devise.rb index a2e4d10f..c13139bd 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -125,8 +125,8 @@ module Devise @@extend_remember_period = false # Time interval you can access your account before confirming your account. - mattr_accessor :confirm_within - @@confirm_within = 0.days + mattr_accessor :allow_unconfirmed_access_for + @@allow_unconfirmed_access_for = 0.days # Defines which key will be used when confirming an account. mattr_accessor :confirmation_keys @@ -230,6 +230,10 @@ module Devise puts "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it." end + def self.confirm_within=(value) + puts "\n[DEVISE] Devise.confirm_within= is deprecated. Please set Devise.allow_unconfirmed_access_for= instead." + end + # PRIVATE CONFIGURATION # Store scopes mappings. @@ -369,7 +373,7 @@ module Devise # initialization. # # Devise.initialize do |config| - # config.confirm_within = 2.days + # config.allow_unconfirmed_access_for = 2.days # # config.warden do |manager| # # Configure warden to use other strategies, like oauth. diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb index 5525c6d7..d1d64a30 100644 --- a/lib/devise/models/confirmable.rb +++ b/lib/devise/models/confirmable.rb @@ -9,11 +9,11 @@ module Devise # # Confirmable adds the following options to devise_for: # - # * +confirm_within+: the time you want to allow the user to access his account + # * +allow_unconfirmed_access_for+: the time you want to allow the user to access his account # before confirming it. After this period, the user access is denied. You can # use this to let your user access some features of your application without # confirming the account, but blocking it after a certain period (ie 7 days). - # By default confirm_within is zero, it means users always have to confirm to sign in. + # By default allow_unconfirmed_access_for is zero, it means users always have to confirm to sign in. # * +reconfirmable+: requires any email changes to be confirmed (exactly the same way as # initial account confirmation) to be applied. Requires additional unconfirmed_email # db field to be setup (t.reconfirmable in migrations). Until confirmed new email is @@ -117,20 +117,20 @@ module Devise # # Example: # - # # confirm_within = 1.day and confirmation_sent_at = today + # # allow_unconfirmed_access_for = 1.day and confirmation_sent_at = today # confirmation_period_valid? # returns true # - # # confirm_within = 5.days and confirmation_sent_at = 4.days.ago + # # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 4.days.ago # confirmation_period_valid? # returns true # - # # confirm_within = 5.days and confirmation_sent_at = 5.days.ago + # # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 5.days.ago # confirmation_period_valid? # returns false # - # # confirm_within = 0.days + # # allow_unconfirmed_access_for = 0.days # confirmation_period_valid? # will always return false # def confirmation_period_valid? - confirmation_sent_at && confirmation_sent_at.utc >= self.class.confirm_within.ago + confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago end # Checks whether the record is confirmed or not or a new email has been added, yielding to the block @@ -213,7 +213,7 @@ module Devise find_or_initialize_with_errors(unconfirmed_required_attributes, unconfirmed_attributes, :not_found) end - Devise::Models.config(self, :confirm_within, :confirmation_keys, :reconfirmable) + Devise::Models.config(self, :allow_unconfirmed_access_for, :confirmation_keys, :reconfirmable) end end end diff --git a/lib/generators/templates/devise.rb b/lib/generators/templates/devise.rb index 64874eea..4122dec3 100644 --- a/lib/generators/templates/devise.rb +++ b/lib/generators/templates/devise.rb @@ -80,7 +80,7 @@ Devise.setup do |config| # able to access the website for two days without confirming his account, # access will be blocked just in the third day. Default is 0.days, meaning # the user cannot access the website without confirming his account. - # config.confirm_within = 2.days + # config.allow_unconfirmed_access_for = 2.days # If true, requires any email changes to be confirmed (exctly the same way as # initial account confirmation) to be applied. Requires additional unconfirmed_email diff --git a/test/devise_test.rb b/test/devise_test.rb index 56c73ca9..1b0746d7 100644 --- a/test/devise_test.rb +++ b/test/devise_test.rb @@ -12,8 +12,8 @@ end class DeviseTest < ActiveSupport::TestCase test 'model options can be configured through Devise' do - swap Devise, :confirm_within => 113, :pepper => "foo" do - assert_equal 113, Devise.confirm_within + swap Devise, :allow_unconfirmed_access_for => 113, :pepper => "foo" do + assert_equal 113, Devise.allow_unconfirmed_access_for assert_equal "foo", Devise.pepper end end diff --git a/test/integration/confirmable_test.rb b/test/integration/confirmable_test.rb index 2c0a034a..831ac0a5 100644 --- a/test/integration/confirmable_test.rb +++ b/test/integration/confirmable_test.rb @@ -98,7 +98,7 @@ class ConfirmationTest < ActionController::IntegrationTest end test 'not confirmed user with setup to block without confirmation should not be able to sign in' do - swap Devise, :confirm_within => 0.days do + swap Devise, :allow_unconfirmed_access_for => 0.days do sign_in_as_user(:confirm => false) assert_contain 'You have to confirm your account before continuing' @@ -107,7 +107,7 @@ class ConfirmationTest < ActionController::IntegrationTest end test 'not confirmed user should not see confirmation message if invalid credentials are given' do - swap Devise, :confirm_within => 0.days do + swap Devise, :allow_unconfirmed_access_for => 0.days do sign_in_as_user(:confirm => false) do fill_in 'password', :with => 'invalid' end @@ -118,7 +118,7 @@ class ConfirmationTest < ActionController::IntegrationTest end test 'not confirmed user but configured with some days to confirm should be able to sign in' do - swap Devise, :confirm_within => 1.day do + swap Devise, :allow_unconfirmed_access_for => 1.day do sign_in_as_user(:confirm => false) assert_response :success diff --git a/test/integration/trackable_test.rb b/test/integration/trackable_test.rb index 6559c576..d3aef96b 100644 --- a/test/integration/trackable_test.rb +++ b/test/integration/trackable_test.rb @@ -63,7 +63,7 @@ class TrackableHooksTest < ActionController::IntegrationTest end test "does not update anything if user has signed out along the way" do - swap Devise, :confirm_within => 0 do + swap Devise, :allow_unconfirmed_access_for => 0 do user = create_user(:confirm => false) sign_in_as_user diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index 93e2c5dc..71fbe1c8 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -164,19 +164,19 @@ class ConfirmableTest < ActiveSupport::TestCase end test 'confirm time should fallback to devise confirm in default configuration' do - swap Devise, :confirm_within => 1.day do + swap Devise, :allow_unconfirmed_access_for => 1.day do user = new_user user.confirmation_sent_at = 2.days.ago assert_not user.active_for_authentication? - Devise.confirm_within = 3.days + Devise.allow_unconfirmed_access_for = 3.days assert user.active_for_authentication? end end test 'should be active when confirmation sent at is not overpast' do - swap Devise, :confirm_within => 5.days do - Devise.confirm_within = 5.days + swap Devise, :allow_unconfirmed_access_for => 5.days do + Devise.allow_unconfirmed_access_for = 5.days user = create_user user.confirmation_sent_at = 4.days.ago @@ -198,7 +198,7 @@ class ConfirmableTest < ActiveSupport::TestCase end test 'should not be active when confirm in is zero' do - Devise.confirm_within = 0.days + Devise.allow_unconfirmed_access_for = 0.days user = create_user user.confirmation_sent_at = Date.today assert_not user.active_for_authentication? diff --git a/test/models_test.rb b/test/models_test.rb index bc60ba17..0a1da72a 100644 --- a/test/models_test.rb +++ b/test/models_test.rb @@ -2,7 +2,7 @@ require 'test_helper' class Configurable < User devise :database_authenticatable, :encryptable, :confirmable, :rememberable, :timeoutable, :lockable, - :stretches => 15, :pepper => 'abcdef', :confirm_within => 5.days, + :stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days, :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days end @@ -87,8 +87,8 @@ class ActiveRecordTest < ActiveSupport::TestCase assert_equal 'abcdef', Configurable.pepper end - test 'set a default value for confirm_within' do - assert_equal 5.days, Configurable.confirm_within + test 'set a default value for allow_unconfirmed_access_for' do + assert_equal 5.days, Configurable.allow_unconfirmed_access_for end test 'set a default value for remember_for' do diff --git a/test/rails_app/config/initializers/devise.rb b/test/rails_app/config/initializers/devise.rb index 0ae9b35d..a317c828 100644 --- a/test/rails_app/config/initializers/devise.rb +++ b/test/rails_app/config/initializers/devise.rb @@ -68,11 +68,11 @@ Devise.setup do |config| # ==> Configuration for :confirmable # The time you want to give your user to confirm his account. During this time # he will be able to access your application without confirming. Default is nil. - # When confirm_within is zero, the user won't be able to sign in without confirming. + # When allow_unconfirmed_access_for is zero, the user won't be able to sign in without confirming. # You can use this to let your user access some features of your application # without confirming the account, but blocking it after a certain period # (ie 2 days). - # config.confirm_within = 2.days + # config.allow_unconfirmed_access_for = 2.days # Defines which key will be used when confirming an account # config.confirmation_keys = [ :email ] diff --git a/test/rails_app/lib/shared_admin.rb b/test/rails_app/lib/shared_admin.rb index 7282b56c..36fb5f8b 100644 --- a/test/rails_app/lib/shared_admin.rb +++ b/test/rails_app/lib/shared_admin.rb @@ -5,7 +5,7 @@ module SharedAdmin devise :database_authenticatable, :encryptable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable, :unlock_strategy => :time, :lock_strategy => :none, - :confirm_within => 2.weeks, :reconfirmable => true + :allow_unconfirmed_access_for => 2.weeks, :reconfirmable => true validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed? end diff --git a/test/test_helpers_test.rb b/test/test_helpers_test.rb index c4dd91f3..b3905c1e 100644 --- a/test/test_helpers_test.rb +++ b/test/test_helpers_test.rb @@ -17,7 +17,7 @@ class TestHelpersTest < ActionController::TestCase end test "redirects if attempting to access a page with an unconfirmed account" do - swap Devise, :confirm_within => 0 do + swap Devise, :allow_unconfirmed_access_for => 0 do user = create_user assert !user.active_for_authentication? @@ -28,7 +28,7 @@ class TestHelpersTest < ActionController::TestCase end test "returns nil if accessing current_user with an unconfirmed account" do - swap Devise, :confirm_within => 0 do + swap Devise, :allow_unconfirmed_access_for => 0 do user = create_user assert !user.active_for_authentication?