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

Ensure configuration options are allowed exactly after each module is included.

This commit is contained in:
José Valim 2011-03-30 14:33:56 +02:00
parent d3a374777b
commit e4902143f8
3 changed files with 28 additions and 4 deletions

View file

@ -1,6 +1,12 @@
* enhancements
* All controllers can now handle different mime types than html using Responders (by github.com/sikachu)
* bug fix
* Fix a bug where configuration options were being included too late
* backward incompatible changes
* authentication_keys are no longer considered when creating the e-mail validations, the previous behavior was buggy. You must double check if you were relying on such behavior.
== 1.2.1
* enhancements

View file

@ -17,6 +17,9 @@ module Devise
# inside the given class.
#
def self.config(mod, *accessors) #:nodoc:
(class << mod; self; end).send :attr_accessor, :available_configs
mod.available_configs = accessors
accessors.each do |accessor|
mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{accessor}
@ -46,13 +49,29 @@ module Devise
#
def devise(*modules)
include Devise::Models::Authenticatable
options = modules.extract_options!
options = modules.extract_options!.dup
self.devise_modules += modules.map(&:to_sym).uniq.sort_by { |s|
Devise::ALL.index(s) || -1 # follow Devise::ALL order
}
devise_modules_hook! do
devise_modules.each { |m| include Devise::Models.const_get(m.to_s.classify) }
devise_modules.each do |m|
mod = Devise::Models.const_get(m.to_s.classify)
include mod
if mod.const_defined?("ClassMethods")
class_mod = mod.const_get("ClassMethods")
if class_mod.respond_to?(:available_configs)
available_configs = class_mod.available_configs
available_configs.each do |config|
next unless options.key?(config)
send(:"#{config}=", options.delete(config))
end
end
end
end
options.each { |key, value| send(:"#{key}=", value) }
end
end

View file

@ -23,8 +23,7 @@ module Devise
base.class_eval do
validates_presence_of :email, :if => :email_required?
validates_uniqueness_of :email, :scope => authentication_keys[1..-1],
:case_sensitive => (case_insensitive_keys != false), :allow_blank => true
validates_uniqueness_of :email, :case_sensitive => (case_insensitive_keys != false), :allow_blank => true
validates_format_of :email, :with => email_regexp, :allow_blank => true
with_options :if => :password_required? do |v|