Permalink
Browse files

Renamed authenticable to authenticatable and added deprecation warnings.

  • Loading branch information...
1 parent 8c1bab4 commit b28d7e8b1ca4653c5a51e9e2bb6aeba98089ca4b @josevalim josevalim committed Oct 30, 2009
View
1 CHANGELOG.rdoc
@@ -4,6 +4,7 @@
* deprecations
* Renamed confirm_in to confirm_within
* [#14] Do not send confirmation messages when user changes his e-mail
+ * [#13] Renamed authenticable to authenticatable and added deprecation warnings
== 0.2.3
View
18 README.rdoc
@@ -9,7 +9,7 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
Right now it's composed of five mainly modules:
-* Authenticable: responsible for encrypting password and validating authenticity of a user while signing in.
+* Authenticatable: responsible for encrypting password and validating authenticity of a user while signing in.
* Confirmable: responsible for verifying whether an account is already confirmed to sign in, and to send emails with confirmation instructions.
* Recoverable: takes care of reseting the user password and send reset instructions.
* Rememberable: manages generating and clearing token for remember the user from a saved cookie.
@@ -51,7 +51,7 @@ Devise must be setted up within the model (or models) you want to use, and devis
We're assuming here you want a User model. First of all you have to setup a migration with the following fields:
create_table :users do
- t.authenticable
+ t.authenticatable
t.confirmable
t.recoverable
t.rememberable
@@ -70,17 +70,17 @@ Now let's setup a User model adding the devise line to have your authentication
devise
end
-This line adds devise authenticable automatically for you inside your User class. Devise don't rely on _attr_accessible_ or _attr_protected_ inside its modules, so be sure to setup what attributes are accessible or protected in your model.
+This line adds devise authenticatable automatically for you inside your User class. Devise don't rely on _attr_accessible_ or _attr_protected_ inside its modules, so be sure to setup what attributes are accessible or protected in your model.
You could also include the other devise modules as below:
- # Same as using only devise, authenticable is activated by default
- devise :authenticable
+ # Same as using only devise, authenticatable is activated by default
+ devise :authenticatable
- # Include authenticable + confirmable
+ # Include authenticatable + confirmable
devise :confirmable
- # Include authenticable + recoverable + rememberable
+ # Include authenticatable + recoverable + rememberable
devise :recoverable, :rememberable
# Include all of them
@@ -123,7 +123,7 @@ The next step after setting up your model is to configure your routes for devise
This is going to look inside you User model and create the needed routes:
- # Session routes for Authenticable (default)
+ # Session routes for Authenticatable (default)
new_user_session GET /users/sign_in {:controller=>"sessions", :action=>"new"}
user_session POST /users/sign_in {:controller=>"sessions", :action=>"create"}
destroy_user_session GET /users/sign_out {:controller=>"sessions", :action=>"destroy"}
@@ -191,7 +191,7 @@ Devise let's you setup as many roles as you want, so let's say you already have
# Create a migration with the required fields
create_table :admins do |t|
- t.authenticable
+ t.authenticatable
end
# Inside your Admin model
View
4 lib/devise.rb
@@ -1,9 +1,9 @@
module Devise
- ALL = [:authenticable, :confirmable, :recoverable, :rememberable, :validatable].freeze
+ ALL = [:authenticatable, :confirmable, :recoverable, :rememberable, :validatable].freeze
# Maps controller names to devise modules
CONTROLLERS = {
- :sessions => :authenticable,
+ :sessions => :authenticatable,
:passwords => :recoverable,
:confirmations => :confirmable
}.freeze
View
21 lib/devise/active_record.rb
@@ -32,22 +32,22 @@ module ActiveRecord
#
# Examples:
#
- # # include only authenticable module (default)
+ # # include only authenticatable module (default)
# devise
#
- # # include authenticable + confirmable modules
+ # # include authenticatable + confirmable modules
# devise :confirmable
#
- # # include authenticable + recoverable modules
+ # # include authenticatable + recoverable modules
# devise :recoverable
#
- # # include authenticable + rememberable modules
+ # # include authenticatable + rememberable modules
# devise :rememberable
#
- # # include authenticable + validatable modules
+ # # include authenticatable + validatable modules
# devise :validatable
#
- # # include authenticable + confirmable + recoverable + rememberable + validatable
+ # # include authenticatable + confirmable + recoverable + rememberable + validatable
# devise :confirmable, :recoverable, :rememberable, :validatable
#
# # shortcut to include all modules (same as above)
@@ -59,9 +59,16 @@ module ActiveRecord
def devise(*modules)
options = modules.extract_options!
+ # TODO Remove me in a next release
+ if modules.include?(:authenticable)
+ modules.delete(:authenticable)
+ modules.unshift(:authenticatable)
+ ActiveSupport::Deprecation.warn "devise :authenticate is deprecated, use authenticatable instead"
+ end
+
modules = Devise::ALL if modules.include?(:all)
modules -= Array(options.delete(:except))
- modules |= [:authenticable]
+ modules = [:authenticatable] | modules
modules.each do |m|
devise_modules << m.to_sym
View
4 lib/devise/controllers/filters.rb
@@ -54,8 +54,8 @@ def sign_out(scope, *args)
# Example:
#
# Maps:
- # User => :authenticable
- # Admin => :authenticable
+ # User => :authenticatable
+ # Admin => :authenticatable
#
# Generated methods:
# authenticate_user! # Signs user in or redirect
View
2 lib/devise/mapping.rb
@@ -18,7 +18,7 @@ module Devise
# mapping.to #=> User
# # is the class to be loaded from routes, given in the route as :class_name.
#
- # mapping.for #=> [:authenticable]
+ # mapping.for #=> [:authenticatable]
# # is the modules included in the class
#
class Mapping #:nodoc:
View
11 lib/devise/migrations.rb
@@ -2,7 +2,7 @@ module Devise
# Helpers to migration:
#
# create_table :accounts do |t|
- # t.authenticable
+ # t.authenticatable
# t.confirmable
# t.recoverable
# t.rememberable
@@ -19,13 +19,20 @@ module Migrations
# Creates email, encrypted_password and password_salt.
#
- def authenticable(options={})
+ def authenticatable(options={})
null = options[:null] || false
string :email, :limit => 100, :null => null
string :encrypted_password, :limit => 40, :null => null
string :password_salt, :limit => 20, :null => null
end
+ # TODO Remove me in a next release.
+ #
+ def authenticable(*args)
+ ActiveSupport::Deprecation.warn "authenticable in migrations is deprecated, use authenticatable instead"
+ authenticatable(*args)
+ end
+
# Creates confirmation_token, confirmed_at and confirmation_sent_at.
#
def confirmable
View
8 lib/devise/models/authenticable.rb → lib/devise/models/authenticatable.rb
@@ -1,5 +1,5 @@
require 'digest/sha1'
-require 'devise/strategies/authenticable'
+require 'devise/strategies/authenticatable'
module Devise
module Models
@@ -24,7 +24,7 @@ module Models
# User.authenticate('email@test.com', 'password123') # returns authenticated user or nil
# User.find(1).valid_password?('password123') # returns true/false
#
- module Authenticable
+ module Authenticatable
def self.included(base)
base.class_eval do
extend ClassMethods
@@ -75,8 +75,8 @@ module ClassMethods
# authenticated user if it's valid or nil.
# Attributes are :email and :password
def authenticate(attributes={})
- authenticable = find_by_email(attributes[:email])
- authenticable if authenticable.try(:valid_password?, attributes[:password])
+ authenticatable = find_by_email(attributes[:email])
+ authenticatable if authenticatable.try(:valid_password?, attributes[:password])
end
# Attempt to find a user by it's email. If not user is found, returns a
View
6 lib/devise/routes.rb
@@ -19,15 +19,15 @@ class Mapper #:doc:
# generate all needed routes for devise, based on what modules you have
# defined in your model.
# Examples: Let's say you have an User model configured to use
- # authenticable, confirmable and recoverable modules. After creating this
+ # authenticatable, confirmable and recoverable modules. After creating this
# inside your routes:
#
# map.devise_for :users
#
# this method is going to look inside your User model and create the
# needed routes:
#
- # # Session routes for Authenticable (default)
+ # # Session routes for Authenticatable (default)
# new_user_session GET /users/sign_in {:controller=>"sessions", :action=>"new"}
# user_session POST /users/sign_in {:controller=>"sessions", :action=>"create"}
# destroy_user_session GET /users/sign_out {:controller=>"sessions", :action=>"destroy"}
@@ -69,7 +69,7 @@ def devise_for(*resources)
mapping = Devise::Mapping.new(resource, options)
Devise.mappings[mapping.name] = mapping
- if mapping.authenticable?
+ if mapping.authenticatable?
with_options(:controller => 'sessions', :path_prefix => mapping.as) do |session|
session.send(:"new_#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'new', :conditions => { :method => :get })
session.send(:"#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => { :method => :post })
View
4 lib/devise/strategies/authenticable.rb → lib/devise/strategies/authenticatable.rb
@@ -2,7 +2,7 @@ module Devise
module Strategies
# Default strategy for signing in a user, based on his email and password.
# Redirects to sign_in page if it's not authenticated
- class Authenticable < Devise::Strategies::Base
+ class Authenticatable < Devise::Strategies::Base
# Authenticate a user based on email and password params, returning to warden
# success and the authenticated user if everything is okay. Otherwise redirect
@@ -43,4 +43,4 @@ def store_location
end
end
-Warden::Strategies.add(:authenticable, Devise::Strategies::Authenticable)
+Warden::Strategies.add(:authenticatable, Devise::Strategies::Authenticatable)
View
2 lib/devise/strategies/rememberable.rb
@@ -3,7 +3,7 @@ module Strategies
# Remember the user through the remember token. This strategy is responsible
# to verify whether there is a cookie with the remember token, and to
# recreate the user from this cookie if it exists. Must be called *before*
- # authenticable.
+ # authenticatable.
class Rememberable < Devise::Strategies::Base
# A valid strategy for rememberable needs a remember token in the cookies.
View
2 lib/devise/warden.rb
@@ -55,7 +55,7 @@ def cookies
# Adds Warden Manager to Rails middleware stack, configuring default devise
# strategy and also the controller who will manage not authenticated users.
Rails.configuration.middleware.use Warden::Manager do |manager|
- manager.default_strategies :rememberable, :authenticable
+ manager.default_strategies :rememberable, :authenticatable
manager.failure_app = Devise::Failure
manager.silence_missing_strategies!
end
View
16 test/active_record_test.rb
@@ -54,38 +54,38 @@ def assert_not_include_modules(klass, *modules)
end
end
- test 'include by default authenticable only' do
- assert_include_modules Authenticable, :authenticable
+ test 'include by default authenticatable only' do
+ assert_include_modules Authenticable, :authenticatable
assert_not_include_modules Authenticable, :confirmable, :recoverable, :rememberable, :validatable
end
test 'add confirmable module only' do
- assert_include_modules Confirmable, :authenticable, :confirmable
+ assert_include_modules Confirmable, :authenticatable, :confirmable
assert_not_include_modules Confirmable, :recoverable, :rememberable, :validatable
end
test 'add recoverable module only' do
- assert_include_modules Recoverable, :authenticable, :recoverable
+ assert_include_modules Recoverable, :authenticatable, :recoverable
assert_not_include_modules Recoverable, :confirmable, :rememberable, :validatable
end
test 'add rememberable module only' do
- assert_include_modules Rememberable, :authenticable, :rememberable
+ assert_include_modules Rememberable, :authenticatable, :rememberable
assert_not_include_modules Rememberable, :confirmable, :recoverable, :validatable
end
test 'add validatable module only' do
- assert_include_modules Validatable, :authenticable, :validatable
+ assert_include_modules Validatable, :authenticatable, :validatable
assert_not_include_modules Validatable, :confirmable, :recoverable, :rememberable
end
test 'add all modules' do
assert_include_modules Devisable,
- :authenticable, :confirmable, :recoverable, :rememberable, :validatable
+ :authenticatable, :confirmable, :recoverable, :rememberable, :validatable
end
test 'configure modules with except option' do
- assert_include_modules Exceptable, :authenticable, :confirmable
+ assert_include_modules Exceptable, :authenticatable, :confirmable
assert_not_include_modules Exceptable, :recoverable, :rememberable, :validatable
end
View
0 test/integration/authenticable_test.rb → test/integration/authenticatable_test.rb
File renamed without changes.
View
4 test/mapping_test.rb
@@ -57,13 +57,13 @@ class MapTest < ActiveSupport::TestCase
test 'magic predicates' do
mapping = Devise.mappings[:user]
- assert mapping.authenticable?
+ assert mapping.authenticatable?
assert mapping.confirmable?
assert mapping.recoverable?
assert mapping.rememberable?
mapping = Devise.mappings[:admin]
- assert mapping.authenticable?
+ assert mapping.authenticatable?
assert_not mapping.confirmable?
assert_not mapping.recoverable?
assert_not mapping.rememberable?
View
2 test/models/authenticable_test.rb → test/models/authenticatable_test.rb
@@ -1,7 +1,7 @@
require 'test/test_helper'
require 'digest/sha1'
-class AuthenticableTest < ActiveSupport::TestCase
+class AuthenticatableTest < ActiveSupport::TestCase
def encrypt_password(user, pepper=nil, stretches=1)
user.class_eval { define_method(:stretches) { stretches } } if stretches
View
2 test/test_helper.rb
@@ -17,7 +17,7 @@
ActiveRecord::Schema.define(:version => 1) do
[:users, :admins].each do |table|
create_table table do |t|
- t.authenticable :null => table == :admins
+ t.authenticatable :null => table == :admins
if table == :users
t.confirmable

0 comments on commit b28d7e8

Please sign in to comment.