-
-
Notifications
You must be signed in to change notification settings - Fork 910
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
Added support for ignoring_interference_by_writer to validate_uniqueness_of #800
Conversation
&add_attribute_upcase_normalization | ||
) | ||
|
||
expect(record).to validate_uniqueness.case_insensitive.ignoring_interference_by_writer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [94/80]
|
||
expect(&running_matcher).to raise_error( | ||
Shoulda::Matchers::ActiveModel:: | ||
AllowValueMatcher::CouldNotSetAttributeError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last parameter of a multiline method call.
|
||
expect(&running_matcher).to raise_error( | ||
Shoulda::Matchers::ActiveModel:: | ||
AllowValueMatcher::CouldNotSetAttributeError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a comma after the last parameter of a multiline method call.
Hound finally stopped barking at me! |
Thanks for doing this -- I appreciate it. The thing is, I don't want to add I just wrote this in #799, but I'm actually considering adding a |
I think the idea of passing in a lambda works, but anything else is likely to fall short. This isn't so much serialization as normalization, and the limits of normalization are only bounded by what the developer can invent. The developer may trim leading and trailing spaces, may eliminate long lengths of white space, may proper case things, etc. I've written code in the past that would accept both Metric and US Customary unitized values and would store them as metric (i.e. 3.3 ft would get stored as 1.0 in a floating point field and be displayed as either 1.0 m or 3.3 ft depending upon the user's preferences). The issue there is that a) you're type casting to some type but b) the transformation may be fairly opaque (think of code that can accept -10.5, 10.5 S, -10 30', 10 30' S, as well as optional degree symbols, decimal minutes, seconds instead decimal minutes, etc.). I'm using https://github.com/mdeering/attribute_normalizer for normalization, and I added custom normalizers for upcase and downcase that use the logic I used in the test suite for Personally, I'm happy with
But it would be easy enough for me to define a lambda in one place with So I can go either way on this one - I agree that |
Sigh... see... I feel like this is one of those cases where doing things the "Rails way" and stuffing all of this behavior into your ActiveRecord model goes a little too far. If it were me, I'd make a facade that was responsible for normalization and wouldn't even have to consider the possibility of typecasting or any of that jazz. I realize that not everyone shares or is going to share my opinion, though. Anyway :) I'm a little split on this, but this seems like a bit of an edge case to me. My feeling is that |
After some more thought on this, I think that adding So here are some remaining tasks for this PR:
I can begin working on this, although if you want to pitch in on the tests that's fine too. |
@tovodeverett I took the liberty of adding |
That is beautiful! It sounds like you totally rethought |
I think I've finally managed to figure out how to write the tests, and so I could finally put together this pull request. This should help resolve the sort of issues seen in #786.