Skip to content

Commit

Permalink
Get rid of deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed May 6, 2012
1 parent 7aa93a3 commit 32f20dd
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 296 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

* deprecations
* Deprecations warnings added on Devise 2.0 are now removed with their features
* use_salt_as_remember_token and apply_schema does not have any effect since 2.0 and are now deprecated
* valid_for_authentication? must now return a boolean

* bug fix
* `/users/sign_in` doesn't choke on protected attributes used to select sign in scope (by @Paymium)
Expand Down
41 changes: 8 additions & 33 deletions lib/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ module Strategies
@@request_keys = []

# Keys that should be case-insensitive.
# False by default for backwards compatibility.
mattr_accessor :case_insensitive_keys
@@case_insensitive_keys = false
@@case_insensitive_keys = [ :email ]

# Keys that should have whitespace stripped.
# False by default for backwards compatibility.
mattr_accessor :strip_whitespace_keys
@@strip_whitespace_keys = false
@@strip_whitespace_keys = []

# If http authentication is enabled by default.
mattr_accessor :http_authenticatable
Expand Down Expand Up @@ -182,9 +180,8 @@ module Strategies
@@reset_password_keys = [ :email ]

# Time interval you can reset your password with a reset password key
# Nil by default for backwards compatibility.
mattr_accessor :reset_password_within
@@reset_password_within = nil
@@reset_password_within = 6.hours

# The default scope which is used by warden.
mattr_accessor :default_scope
Expand Down Expand Up @@ -226,36 +223,14 @@ module Strategies
mattr_accessor :router_name
@@router_name = nil

# DEPRECATED CONFIG

# If true, uses salt as remember token and does not create it in the database.
# By default is false for backwards compatibility.
mattr_accessor :use_salt_as_remember_token
@@use_salt_as_remember_token = false

# Tells if devise should apply the schema in ORMs where devise declaration
# and schema belongs to the same class (as Datamapper and Mongoid).
mattr_accessor :apply_schema
@@apply_schema = true

def self.remember_across_browsers=(value)
warn "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it.\n"
end

def self.confirm_within=(value)
warn "\n[DEVISE] Devise.confirm_within= is deprecated. Please set Devise.allow_unconfirmed_access_for= instead.\n"
Devise.allow_unconfirmed_access_for = value
end
# DEPRECATION

def self.cookie_options=(value)
warn "\n[DEVISE] Devise.cookie_options= is deprecated. Please set Devise.rememberable_options= instead.\n"
Devise.rememberable_options = value
def self.use_salt_as_remember_token=(value)
warn "\n[DEVISE] Devise.use_salt_as_remember_token is deprecated and has no effect. Please remove it.\n"
end

def self.stateless_token=(value)
warn "\n[DEVISE] Devise.stateless_token= is deprecated. Please append :token_auth to Devise.skip_session_storage " \
"instead, for example: Devise.skip_session_storage << :token_auth\n"
Devise.skip_session_storage << :token_auth
def self.apply_schema=(value)
warn "\n[DEVISE] Devise.apply_schema is deprecated and has no effect. Please remove it.\n"
end

# PRIVATE CONFIGURATION
Expand Down
5 changes: 0 additions & 5 deletions lib/devise/controllers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,6 @@ def sign_in_and_redirect(resource_or_scope, *args)
redirect_to after_sign_in_path_for(resource)
end

def redirect_location(scope, resource) #:nodoc:
ActiveSupport::Deprecation.warn "redirect_location in Devise is deprecated. Please use after_sign_in_path_for instead.", caller
after_sign_in_path_for(resource)
end

def expire_session_data_after_sign_in!
session.keys.grep(/^devise\./).each { |k| session.delete(k) }
end
Expand Down
8 changes: 5 additions & 3 deletions lib/devise/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def self.check_fields!(klass)
failed_attributes << field unless instance.respond_to?(field)
end
else
ActiveSupport::Deprecation.warn "The module #{mod} doesn't implement self.required_fields(klass). Devise uses required_fields to warn developers of any missing fields in their models. Please implement #{mod}.required_fields(klass) that returns an array of symbols with the required fields."
ActiveSupport::Deprecation.warn "The module #{mod} doesn't implement self.required_fields(klass). " \
"Devise uses required_fields to warn developers of any missing fields in their models. " \
"Please implement #{mod}.required_fields(klass) that returns an array of symbols with the required fields."
end
end

Expand Down Expand Up @@ -110,8 +112,8 @@ def devise(*modules)
end
end

# The hook which is called inside devise. So your ORM can include devise
# compatibility stuff.
# The hook which is called inside devise.
# So your ORM can include devise compatibility stuff.
def devise_modules_hook!
yield
end
Expand Down
4 changes: 2 additions & 2 deletions lib/devise/models/authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ def headers_for(name)
end

def downcase_keys
(self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
self.class.case_insensitive_keys.each { |k| self[k].try(:downcase!) }
end

def strip_whitespace
(self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) }
self.class.strip_whitespace_keys.each { |k| self[k].try(:strip!) }
end

array = %w(serializable_hash)
Expand Down
43 changes: 1 addition & 42 deletions lib/devise/orm/active_record.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
require 'orm_adapter/adapters/active_record'

module Devise
module Orm
# This module contains some helpers and handle schema (migrations):
#
# create_table :accounts do |t|
# t.database_authenticatable
# t.confirmable
# t.recoverable
# t.rememberable
# t.trackable
# t.lockable
# t.timestamps
# end
#
# However this method does not add indexes. If you need them, here is the declaration:
#
# add_index "accounts", ["email"], :name => "email", :unique => true
# add_index "accounts", ["confirmation_token"], :name => "confirmation_token", :unique => true
# add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true
#
module ActiveRecord
module Schema
include Devise::Schema

# Tell how to apply schema methods.
def apply_devise_schema(name, type, options={})
@__devise_warning_raised ||= begin
$stderr.puts "\n[DEVISE] You are using t.database_authenticatable and others in your migration " \
"and this feature is deprecated. Please simply use Rails helpers instead as mentioned here:\n" \
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n\n"
true
end
column name, type.to_s.downcase.to_sym, options
end
end
end
end
end

ActiveRecord::Base.extend Devise::Models
ActiveRecord::ConnectionAdapters::Table.send :include, Devise::Orm::ActiveRecord::Schema
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord::Schema
ActiveRecord::Base.extend Devise::Models
30 changes: 1 addition & 29 deletions lib/devise/orm/mongoid.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
require 'orm_adapter/adapters/mongoid'

module Devise
module Orm
module Mongoid
module Hook
def devise_modules_hook!
extend Schema
yield
return unless Devise.apply_schema
devise_modules.each { |m| send(m) if respond_to?(m, true) }
end
end

module Schema
include Devise::Schema

# Tell how to apply schema methods
def apply_devise_schema(name, type, options={})
type = Time if type == DateTime
field name, { :type => type }.merge!(options)
end
end
end
end
end

Mongoid::Document::ClassMethods.class_eval do
include Devise::Models
include Devise::Orm::Mongoid::Hook
end
Mongoid::Document::ClassMethods.send :include, Devise::Models
59 changes: 1 addition & 58 deletions lib/devise/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,69 +43,12 @@ class Engine < ::Rails::Engine
end

initializer "devise.fix_routes_proxy_missing_respond_to_bug" do
# We can get rid of this once we support Rails > 3.2
# We can get rid of this once we support only Rails > 3.2
ActionDispatch::Routing::RoutesProxy.class_eval do
def respond_to?(method, include_private = false)
super || routes.url_helpers.respond_to?(method)
end
end
end

initializer "devise.deprecations" do
unless defined?(Rails::Generators)
if Devise.case_insensitive_keys == false
warn "\n[DEVISE] Devise.case_insensitive_keys is false which is no longer " \
"supported. Recent Devise versions automatically downcase the e-mail before " \
"saving it to the database but your app isn't using this feature. You can solve " \
"this issue by either:\n\n" \
"1) Setting config.case_insensitive_keys = [:email] in your Devise initializer and " \
"running a migration that will downcase all emails already in the database;\n\n" \
"2) Setting config.case_insensitive_keys = [] (so nothing will be downcased) and " \
"making sure you are not using Devise :validatable (since validatable assumes case" \
"insensitivity)\n"
end

if Devise.apply_schema && defined?(Mongoid)
warn "\n[DEVISE] Devise.apply_schema is true. This means Devise was " \
"automatically configuring your DB. This no longer happens. You should " \
"set Devise.apply_schema to false and manually set the fields used by Devise as shown here: " \
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n"
end

# TODO: Deprecate the true value of this option as well
if Devise.use_salt_as_remember_token == false
warn "\n[DEVISE] Devise.use_salt_as_remember_token is false which is no longer " \
"supported. Devise now only uses the salt as remember token and the remember_token " \
"column can be removed from your models.\n"
end

if Devise.reset_password_within.nil?
warn "\n[DEVISE] Devise.reset_password_within is nil. Please set this value to " \
"an interval (for example, 6.hours) and add a reset_password_sent_at field to " \
"your Devise models (if they don't have one already).\n"
end
end

config.after_initialize do
example = <<-YAML
en:
devise:
registrations:
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
YAML

if I18n.t(:"devise.registrations.reasons", :default => {}).present?
warn "\n[DEVISE] devise.registrations.reasons in yml files is deprecated, " \
"please use devise.registrations.signed_up_but_REASON instead. The default values are:\n\n#{example}\n"
end

if I18n.t(:"devise.registrations.inactive_signed_up", :default => "").present?
warn "\n[DEVISE] devise.registrations.inactive_signed_up in yml files is deprecated, " \
"please use devise.registrations.signed_up_but_REASON instead. The default values are:\n\n#{example}\n"
end
end
end
end
end
109 changes: 0 additions & 109 deletions lib/devise/schema.rb

This file was deleted.

Loading

0 comments on commit 32f20dd

Please sign in to comment.