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

Don't include the same module several times, closes #765.

This commit is contained in:
José Valim 2011-04-16 13:15:31 +02:00
parent 3d5e692c2c
commit 8f3539c14f
2 changed files with 21 additions and 8 deletions

View file

@ -51,12 +51,12 @@ module Devise
include Devise::Models::Authenticatable
options = modules.extract_options!.dup
self.devise_modules += modules.map(&:to_sym).uniq.sort_by { |s|
selected_modules = modules.map(&:to_sym).uniq.sort_by do |s|
Devise::ALL.index(s) || -1 # follow Devise::ALL order
}
end
devise_modules_hook! do
devise_modules.each do |m|
selected_modules.each do |m|
mod = Devise::Models.const_get(m.to_s.classify)
if mod.const_defined?("ClassMethods")
@ -75,6 +75,7 @@ module Devise
include mod
end
self.devise_modules |= selected_modules
options.each { |key, value| send(:"#{key}=", value) }
end
end

View file

@ -10,6 +10,11 @@ class WithValidation < Admin
devise :database_authenticatable, :validatable, :password_length => 2..6
end
class Several < Admin
devise :validatable
devise :lockable
end
class Inheritable < Admin
end
@ -33,11 +38,18 @@ class ActiveRecordTest < ActiveSupport::TestCase
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable, :encryptable
end
test 'validations options are not applied to late' do
validators = WithValidation.validators_on :password
length = validators.find { |v| v.kind == :length }
assert_equal 2, length.options[:minimum]
assert_equal 6, length.options[:maximum]
if DEVISE_ORM == :active_record
test 'validations options are not applied to late' do
validators = WithValidation.validators_on :password
length = validators.find { |v| v.kind == :length }
assert_equal 2, length.options[:minimum]
assert_equal 6, length.options[:maximum]
end
test 'validations are applied just once' do
validators = Several.validators_on :password
assert_equal 1, validators.select{ |v| v.kind == :length }.length
end
end
test 'chosen modules are inheritable' do