mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Fix a bug with STI. Closes #195.
This commit is contained in:
parent
6bd0c7fc2b
commit
b2a50db1df
3 changed files with 25 additions and 9 deletions
|
@ -19,6 +19,9 @@
|
||||||
* No need to append ?unauthenticated=true in URLs anymore since Flash was moved to a middleware in Rails 3.
|
* No need to append ?unauthenticated=true in URLs anymore since Flash was moved to a middleware in Rails 3.
|
||||||
* :activatable is included by default in your models.
|
* :activatable is included by default in your models.
|
||||||
|
|
||||||
|
* bug fix
|
||||||
|
* fix a bug with STI
|
||||||
|
|
||||||
* deprecations
|
* deprecations
|
||||||
* Rails 3 compatible only.
|
* Rails 3 compatible only.
|
||||||
* Scoped views are no longer "sessions/users/new". Now use "users/sessions/new".
|
* Scoped views are no longer "sessions/users/new". Now use "users/sessions/new".
|
||||||
|
|
|
@ -1,5 +1,17 @@
|
||||||
module Devise
|
module Devise
|
||||||
module Models
|
module Models
|
||||||
|
class << self
|
||||||
|
def hook(base)
|
||||||
|
base.class_eval do
|
||||||
|
class_attribute :devise_modules, :instance_writer => false
|
||||||
|
self.devise_modules ||= []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
alias :included :hook
|
||||||
|
alias :extended :hook
|
||||||
|
end
|
||||||
|
|
||||||
# Creates configuration values for Devise and for the given module.
|
# Creates configuration values for Devise and for the given module.
|
||||||
#
|
#
|
||||||
# Devise::Models.config(Devise::Authenticable, :stretches, 10)
|
# Devise::Models.config(Devise::Authenticable, :stretches, 10)
|
||||||
|
@ -61,20 +73,14 @@ module Devise
|
||||||
ActiveSupport::Deprecation.warn ":http_authenticatable as module is deprecated and is on by default. Revert by setting :http_authenticatable => false.", caller
|
ActiveSupport::Deprecation.warn ":http_authenticatable as module is deprecated and is on by default. Revert by setting :http_authenticatable => false.", caller
|
||||||
end
|
end
|
||||||
|
|
||||||
@devise_modules = Devise::ALL & modules.map(&:to_sym).uniq
|
self.devise_modules += Devise::ALL & modules.map(&:to_sym).uniq
|
||||||
|
|
||||||
devise_modules_hook! do
|
devise_modules_hook! do
|
||||||
@devise_modules.each { |m| include Devise::Models.const_get(m.to_s.classify) }
|
devise_modules.each { |m| include Devise::Models.const_get(m.to_s.classify) }
|
||||||
options.each { |key, value| send(:"#{key}=", value) }
|
options.each { |key, value| send(:"#{key}=", value) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stores all modules included inside the model, so we are able to verify
|
|
||||||
# which routes are needed.
|
|
||||||
def devise_modules
|
|
||||||
@devise_modules ||= []
|
|
||||||
end
|
|
||||||
|
|
||||||
# The hook which is called inside devise. So your ORM can include devise
|
# The hook which is called inside devise. So your ORM can include devise
|
||||||
# compatibility stuff.
|
# compatibility stuff.
|
||||||
def devise_modules_hook!
|
def devise_modules_hook!
|
||||||
|
|
|
@ -6,6 +6,9 @@ class Configurable < User
|
||||||
:remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
|
:remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Inheritable < Admin
|
||||||
|
end
|
||||||
|
|
||||||
class ActiveRecordTest < ActiveSupport::TestCase
|
class ActiveRecordTest < ActiveSupport::TestCase
|
||||||
def include_module?(klass, mod)
|
def include_module?(klass, mod)
|
||||||
klass.devise_modules.include?(mod) &&
|
klass.devise_modules.include?(mod) &&
|
||||||
|
@ -22,10 +25,14 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'add modules cherry pick' do
|
test 'can cherry pick modules' do
|
||||||
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable
|
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'chosen modules are inheritable' do
|
||||||
|
assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable
|
||||||
|
end
|
||||||
|
|
||||||
test 'order of module inclusion' do
|
test 'order of module inclusion' do
|
||||||
correct_module_order = [:database_authenticatable, :recoverable, :registerable, :timeoutable]
|
correct_module_order = [:database_authenticatable, :recoverable, :registerable, :timeoutable]
|
||||||
incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable]
|
incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable]
|
||||||
|
|
Loading…
Reference in a new issue