Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gem "normalizr" cause CouldNotSetAttributeError on downcased email attribute #1107

Closed
aya-soft opened this issue Jun 7, 2018 · 3 comments
Closed

Comments

@aya-soft
Copy link

aya-soft commented Jun 7, 2018

Hi, guys!

Given: https://github.com/dimko/normalizr

class User
  normalize :email, with: :strip_downcase
end

Spec:
it { is_expected.to validate_uniqueness_of(:email).with_message('an account with this email address already exists').case_insensitive }
Error:

  1) User Validations Email validations should require unique value for email
     Failure/Error: it { is_expected.to validate_uniqueness_of(:email).with_message('an account with this email address already exists').case_insensitive }
     
     Shoulda::Matchers::ActiveModel::AllowValueMatcher::CouldNotSetAttributeError:
       The allow_value matcher attempted to set :email on User to "A", but
       when the attribute was read back, it had stored "a" instead.

Guys, what is the right way to test attributes which values can be changed on the fly?
With this line commented all works fine (allow_value_matcher.rb):
# ensure_that_attribute_was_set!(value)

@mcmire
Copy link
Collaborator

mcmire commented Jun 7, 2018

@aya-soft Try tacking .ignoring_case_insensitivity onto the end of the matcher instead of .case_insensitive. See: http://matchers.shoulda.io/docs/v3.1.1/Shoulda/Matchers/ActiveRecord.html#validate_uniqueness_of-instance_method (you might have to scroll down a bit).

@aya-soft
Copy link
Author

Works with .ignoring_case_sensitivity, thank you! Please correct the typo.

@mcmire
Copy link
Collaborator

mcmire commented Jun 12, 2018

@aya-soft Oops, that's what I meant :)

@mcmire mcmire closed this as completed Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants