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

Add support for Rails 5.1+ AR Dirty changes #379

Closed
wants to merge 2 commits into from
Closed

Add support for Rails 5.1+ AR Dirty changes #379

wants to merge 2 commits into from

Conversation

jjuliano
Copy link
Contributor

@jjuliano jjuliano commented Mar 6, 2018

from saved_changes? to has_changes_to_save?, column_was to column_in_database and changed to changed_attribute_names_to_save. Check version string for each changes for backward compatibility.

…`has_changes_to_save?`, `column_was` to `column_in_database` and `changed` to `changed_attribute_names_to_save`. Check version string for each changes for backward compatibility.
@coveralls
Copy link

coveralls commented Mar 6, 2018

Coverage Status

Coverage decreased (-0.3%) to 97.808% when pulling 81d02b2 on jjuliano:master into 7764bf5 on stefankroes:master.

@@ -86,7 +86,7 @@ def has_ancestry options = {}
after_destroy :touch_ancestors_callback

if ActiveRecord::VERSION::STRING >= '5.1.0'
after_save :touch_ancestors_callback, if: :saved_changes?
after_save :touch_ancestors_callback, if: :has_changes_to_save?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saved_changes? and has_changes_to_save? have different semantics. saved_changes? is true if there were any changes when an instance was saved last time. has_changes_to_save? (which is an alias to changed?) is true if there are unsaved changes.

With this change touch_ancestors_callback is never called, two more tests fail. Tested with AR 5.2.0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khustochka thanks for the insight. It sounds like save_changes? is the one we till want to use

@kbrock
Copy link
Collaborator

kbrock commented Apr 17, 2018

thank you for diving into this. I'm trying to make some cleanup to make this easier to get fixed

@kbrock
Copy link
Collaborator

kbrock commented Apr 18, 2018

This is great stuff.

  • I added appraisals for 5.2
  • I changed the changed check to just use_was
  • I got the tests passing (though I'm unsure if they are false positives)
  • I used your fix for dangerous errors

Could you rebase and then help me understand the various methods that you all suggest instead of usingancestry_was?

Thanks for this PR. It is helping me get up to date with 5.2.

ASIDE: I'm looking at replacing child_ancestry with path_ids_was, ancestry withancestry_ids and ancestry_was with ancestry_ids_was everywhere. Keep that in mind as we are going through this code.

@kbrock
Copy link
Collaborator

kbrock commented May 2, 2018

I do have a branch that uses ids instead of the ancestry strings. but I've separated that.

I did need to revisit this. I've put together #387 instead. Hope that will meet our needs

@kbrock kbrock closed this May 2, 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

Successfully merging this pull request may close these issues.

4 participants