diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 973e4a59..88452cd7 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -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 diff --git a/lib/devise/models.rb b/lib/devise/models.rb index 9b8782e3..2c142196 100644 --- a/lib/devise/models.rb +++ b/lib/devise/models.rb @@ -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 diff --git a/lib/devise/models/validatable.rb b/lib/devise/models/validatable.rb index 34636381..af251ee4 100644 --- a/lib/devise/models/validatable.rb +++ b/lib/devise/models/validatable.rb @@ -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|