Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Case insensitive keys not applied on virtual attributes #2129

latortuga opened this Issue Nov 5, 2012 · 2 comments


None yet
2 participants

latortuga commented Nov 5, 2012

I'm not sure if this is actually a bug or intended behavior but I have a registration form with a virtual email confirmation field and I have added this field to my devise.rb configuration for case_insensitive_keys. When submitting the form, email is downcased but email_confirmation is not because of Devise::Models::Authenticatable#downcase_keys - it uses self[k].try(:downcase!) which will not downcase virtual attributes.

I could see this being outside the scope of devise's concerns because email confirmation is, strictly speaking, not a devise field and thus having a devise setting like case_insensitive_keys affect it might be counter-intuitive. If you would like this behavior changed to apply downcase_keys to virtual attributes I can try to submit a PR for it.

Other details:
Rails 3.2.8
Devise 2.0.4

My setup basically boils down to this:

# config/devise.rb
config.case_insensitive_keys = [:email, :email_confirmation]

# app/models/user.rb
devise :confirmable, :database_authenticatable, :recoverable, :registerable, :rememberable, :trackable, :validatable
attr_accessible :email, :email_confirmation # truncated
validates :email, :confirmation => {:on => :create}

Submitting the registration form with a capital letter in the email address field yields a validation error because the email field is downcased but the email_confirmation field is not.


josevalim commented Nov 5, 2012

I think both case_insensitive_keys and strip_whitespace_keys could be improved to consider virtual attributes. We use self[k] for convenience, but it could be send too.


latortuga commented Nov 7, 2012

I managed to write a failing test for this (after some considerable tribulations) and send seems to do the trick.

As a side-note, I had difficulty reproducing this issue in test due to my test code initially looking like this:

email = "Foo@Bar.com"
User.new(:email => email, :email_confirmation => email)

I can't tell if that's an argument against bang methods or incompetence on my part :)

@latortuga latortuga added a commit to latortuga/devise that referenced this issue Dec 2, 2012

@latortuga latortuga Add failing test for #2129 0c6f2ad

@josevalim josevalim closed this Dec 2, 2012

@oki oki added a commit to oki/devise that referenced this issue Jan 29, 2013

@latortuga @oki latortuga + oki Add failing test for #2129 3dc3615
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment