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

Faster uniqueness queries, closes #917

This commit is contained in:
José Valim 2011-03-15 12:52:53 +01:00
parent cb778d033f
commit 74166e224b
5 changed files with 7 additions and 6 deletions

View file

@ -1,5 +1,6 @@
* bug fix
* Properly ignore path prefix on omniauthable
* Faster uniqueness queries
== 1.2.rc2

View file

@ -70,9 +70,9 @@ module Devise
@@request_keys = []
# Keys that should be case-insensitive.
# Empty by default for backwards compatibility.
# False by default for backwards compatibility.
mattr_accessor :case_insensitive_keys
@@case_insensitive_keys = []
@@case_insensitive_keys = false
# If http authentication is enabled by default.
mattr_accessor :http_authenticatable

View file

@ -101,7 +101,7 @@ module Devise
#
def find_for_authentication(conditions)
filter_auth_params(conditions)
case_insensitive_keys.each { |k| conditions[k].try(:downcase!) }
(case_insensitive_keys || []).each { |k| conditions[k].try(:downcase!) }
to_adapter.find_first(conditions)
end
@ -112,7 +112,7 @@ module Devise
# Find an initialize a group of attributes based on a list of required attributes.
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
case_insensitive_keys.each { |k| attributes[k].try(:downcase!) }
(case_insensitive_keys || []).each { |k| attributes[k].try(:downcase!) }
attributes = attributes.slice(*required_attributes)
attributes.delete_if { |key, value| value.blank? }

View file

@ -78,7 +78,7 @@ module Devise
# Downcase case-insensitive keys
def downcase_keys
self.class.case_insensitive_keys.each { |k| self[k].try(:downcase!) }
(self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
end
# Digests the password using bcrypt.

View file

@ -24,7 +24,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.exclude?(:email), :allow_blank => true
: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|