Skip to content
Browse files

Fix a bug with STI. Closes #195.

  • Loading branch information...
1 parent 6bd0c7f commit b2a50db1df91da7d0f0cac56f62a02b38d8b44c6 @josevalim josevalim committed
Showing with 25 additions and 9 deletions.
  1. +3 −0 CHANGELOG.rdoc
  2. +14 −8 lib/devise/models.rb
  3. +8 −1 test/models_test.rb
View
3 CHANGELOG.rdoc
@@ -19,6 +19,9 @@
* 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.
+* bug fix
+ * fix a bug with STI
+
* deprecations
* Rails 3 compatible only.
* Scoped views are no longer "sessions/users/new". Now use "users/sessions/new".
View
22 lib/devise/models.rb
@@ -1,5 +1,17 @@
module Devise
module Models
+ class << self
+ def hook(base)
+ base.class_eval do

Mongoid's object doesn't has method class_eval
I think that raises issue #206

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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.
#
# Devise::Models.config(Devise::Authenticable, :stretches, 10)
@@ -61,20 +73,14 @@ def devise(*modules)
ActiveSupport::Deprecation.warn ":http_authenticatable as module is deprecated and is on by default. Revert by setting :http_authenticatable => false.", caller
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.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) }
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
# compatibility stuff.
def devise_modules_hook!
View
9 test/models_test.rb
@@ -6,6 +6,9 @@ class Configurable < User
:remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
end
+class Inheritable < Admin
+end
+
class ActiveRecordTest < ActiveSupport::TestCase
def include_module?(klass, mod)
klass.devise_modules.include?(mod) &&
@@ -22,10 +25,14 @@ def assert_include_modules(klass, *modules)
end
end
- test 'add modules cherry pick' do
+ test 'can cherry pick modules' do
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable
end
+ test 'chosen modules are inheritable' do
+ assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable
+ end
+
test 'order of module inclusion' do
correct_module_order = [:database_authenticatable, :recoverable, :registerable, :timeoutable]
incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable]

0 comments on commit b2a50db

Please sign in to comment.
Something went wrong with that request. Please try again.