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

Detect correct digestible attributes #1204

Conversation

alpaca-tc
Copy link

RailsShim.digestible_attributes_in should return only digestible attributes when AR class has _confirmation writer method.

Example:

class UserSession < ApplicationRecord
  has_one :xxx_confirmation
end

record = UserSession.new
RailsShim.digestible_attributes_in(record) #=> [:xxx]  ooops :(
# spec
it { is_expected.to validate_uniqueness_of(:bar) }

# result
Failure/Error: fit { is_expected.to validate_uniqueness_of(:bar) }

NoMethodError:
 undefined method `xxx=' for #<UserSession:0x00007feb23b822a0>

This bug introduced in #1193.

@alpaca-tc alpaca-tc force-pushed the detect_correct_digestible_attributes branch from 73c59f7 to a1a160b Compare April 28, 2019 07:28
@alpaca-tc alpaca-tc force-pushed the detect_correct_digestible_attributes branch from a1a160b to f18b896 Compare April 28, 2019 11:28
@mcmire
Copy link
Collaborator

mcmire commented May 21, 2019

Hey @alpaca-tc, just want to let you know that I saw this earlier, but we need tests for this in order to merge it. If you want to take a crack at it that's fine but I'll add those when I merge this in.

@mcmire mcmire added this to the v4.1.0 milestone May 29, 2019
@mcmire
Copy link
Collaborator

mcmire commented Jun 1, 2019

Hey there — so I looked more closely into this. There are two places where RailsShim.digestible_attributes_in is used. One is in validate_presence_of, but I did a quick check at what it was doing and there doesn't seem to be any issues there. The second, as you point out, is validate_uniqueness_of. I looked further into its use of RailsShim.digestible_attributes_in, and did some digging around in the Git history to figure out why it was added. It turns out that has_secure_password makes some sanity checks on the password attribute, and back in the day, it used to use before_create, which broke the uniqueness matcher. However, since then it's been changed to use validations. So, instead of changing RailsShim.digestible_attributes_in, I think we can just remove it completely from validate_uniqueness_of. I've done this in 9f0def1. Do you want to try this commit and see if it unbreaks your test?

@alpaca-tc
Copy link
Author

9f0def1 works perfectly🙏🙏🙏Thank you for the fixing bug 😭

@alpaca-tc alpaca-tc closed this Jun 1, 2019
@alpaca-tc alpaca-tc deleted the detect_correct_digestible_attributes branch June 1, 2019 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants