-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add Attribute#changed? with to: and from: options #295
Add Attribute#changed? with to: and from: options #295
Conversation
…inal_value property
I kept https://github.com/wout/avram/tree/attribute-changed-with-explicit-nil/ But this might not be the ideal solution as it treats setting a |
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.
I haven’t been at my computer all day so haven’t done a deep dive but I don’t think we need to match the old behavior exactly. I think if the original value is nil and you set the value to nil again that changed? Should be false. Does that answer the question?
If not lmk and I’ll try to dive in deeper later :D
Thank you so much for this. This is SUPER exciting
With the original behaviour, setting any value would make But it does not feel right to do it that way, just to make specs pass.Unless you disagree, of course. 😄 |
I didn’t notice the other PR! Oops. Yes I agree the old behavior did not make sense. Better to only return true if the value actually changed and change the specs that broke due to the new behavior. |
…bute#changes in favour of plain getters
Ok, so now everything passes, except for one spec, which I temporarily set to pending. That is a situation where a jsonb column has a default value and a record is created with a explicit So for this to pass, we should either:
|
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.
I think you could fix the spec by setting the box to a json value. Then updating it to nil. Lmk if that fixes it! This is lookin hood
…ith a default value.
Here you go. Now all specs run green. :) |
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.
Looks great. Thanks for adding this. This will make things like auditing a lot easier!
Adds:
#changed?
with optionalfrom:
andto:
arguments#changes
#original_value