1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Final tidy up on removing schema helpers.

This commit is contained in:
José Valim 2011-12-05 12:17:02 +01:00
parent a0294cbae8
commit 7693173ecd
5 changed files with 62 additions and 48 deletions

View file

@ -26,6 +26,12 @@ module Devise
# Tell how to apply schema methods.
def apply_devise_schema(name, type, options={})
@__devise_warning_raised ||= begin
ActiveSupport::Deprecation.warn "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: " \
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style"
true
end
column name, type.to_s.downcase.to_sym, options
end
end

View file

@ -52,7 +52,8 @@ module Devise
if Devise.apply_schema && defined?(Mongoid)
puts "\n[DEVISE] Devise.apply_schema is true. This means Devise was " \
"automatically configuring your DB. This no longer happens. You should " \
"set this options to false and manually set the fields used by Devise."
"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"
end
# TODO: Deprecate the true value of this option as well

View file

@ -6,8 +6,8 @@ class Admin
include SharedAdmin
## Database authenticatable
field :email, :type => String, :null => false, :default => ""
field :encrypted_password, :type => String, :null => false, :default => ""
field :email, :type => String, :null => true
field :encrypted_password, :type => String, :null => true
## Recoverable
field :reset_password_token, :type => String

View file

@ -4,22 +4,62 @@ class CreateTables < ActiveRecord::Migration
t.string :username
t.string :facebook_token
t.database_authenticatable :null => false
t.confirmable
t.recoverable
t.rememberable
t.trackable
t.lockable
t.token_authenticatable
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Encryptable
# t.string :password_salt
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
t.string :unlock_token # Only if unlock strategy is :email or :both
t.datetime :locked_at
# Token authenticatable
t.string :authentication_token
t.timestamps
end
create_table :admins do |t|
t.database_authenticatable :null => true
t.encryptable
t.rememberable :use_salt => false
t.recoverable
t.lockable :lock_strategy => :none, :unlock_strateagy => :time
## Database authenticatable
t.string :email, :null => true
t.string :encrypted_password, :null => true
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Encryptable
t.string :password_salt
## Lockable
t.datetime :locked_at
t.timestamps
end
end

View file

@ -1,33 +0,0 @@
if DEVISE_ORM == :mongoid
require 'test_helper'
class User2
include Mongoid::Document
devise :database_authenticatable
end
class User3
include Mongoid::Document
devise :database_authenticatable, :authentication_keys => [:username, :email]
end
class User4
include Mongoid::Document
devise :database_authenticatable, :authentication_keys => [:username]
end
class SchemaTest < ActiveSupport::TestCase
test 'should create an email field if there are no custom authentication keys' do
assert_not_equal User2.fields['email'], nil
end
test 'should create an email field if there are custom authentication keys and they include email' do
assert_not_equal User3.fields['email'], nil
end
test 'should not create an email field if there are custom authentication keys they don\'t include email' do
assert_equal User4.fields['email'], nil
end
end
end