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

normalized_when_valid: true seems broken if there are two phone attributes #195

Closed
dlikhten opened this issue Jun 25, 2019 · 4 comments
Closed

Comments

@dlikhten
Copy link
Contributor

definition:

validates_plausible_phone :phone, if: :phone?, message: :bad_format
validates_plausible_phone :fax, if: :fax?, message: :bad_format
phony_normalize :phone, normalize_when_valid: true
phony_normalize :fax, normalize_when_valid: true

spec

  it "an invalid phone doesn't get reformatted" do
    practice = Thing.new(phone: '212-555-55')
    expect(practice.phone).to eq('212-555-55')
    expect(practice).to_not be_valid
    expect(practice.phone).to eq('212-555-55')
  end

This will fail. HOWEVER the same test on fax will work. It seems that the phone is set to the value of fax because fax is defined second. This is only the case when noramlize_when_valid is set.

@joost
Copy link
Owner

joost commented Jun 25, 2019 via email

dlikhten added a commit to dlikhten/phony_rails that referenced this issue Jun 26, 2019
…e var

Previously was cached in `@original` and would collide if more than 1
definition existed for a class.
joost pushed a commit that referenced this issue Jun 26, 2019
…tribute-caching

Fixing #195 - Original value should be cached in correct instance var
@dlikhten
Copy link
Contributor Author

dlikhten commented Jun 26, 2019

Yaaaaaas! Alright! Thanks! Also bonus points if you make a .13 release! 😸

@joost
Copy link
Owner

joost commented Jul 3, 2019

Done

@joost joost closed this as completed Jul 3, 2019
@dlikhten
Copy link
Contributor Author

dlikhten commented Jul 4, 2019

Thank you!!! :)

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