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

Skip creating version for timestamp when ignoring attribute with a Hash #1256

Merged

Conversation

tlynam
Copy link
Contributor

@tlynam tlynam commented Aug 3, 2020

Thank you for your contribution!

Check the following boxes:

  • Wrote good commit messages.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new
    code introduces user-observable changes.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.

expect(gadget.versions.last.changeset.keys).to eq %w[color updated_at]
end

it "doesn't generate a version when the ignored attribute is true" do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test fails. This should succeed right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @jaredbeck, so when using ignored with a Hash, it still creates a version for the timestamp.

Copy link
Member

Choose a reason for hiding this comment

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

This test fails. This should succeed right?

Yeah, I think so. Nice test. 👍

expect { gadget.update_attribute(:brand, "Stanley") }.not_to(change { gadget.versions.size })
context "ignored via symbol" do
it "doesn't generate a version" do
expect { gadget.update_attribute(:brand, "Picard") }.not_to(change { gadget.versions.size })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated name to Picard so the line doesn't exceed the maximum for Rubocop.

Copy link
Member

Choose a reason for hiding this comment

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

That's fine. You can also break long lines like this:

Suggested change
expect { gadget.update_attribute(:brand, "Picard") }.not_to(change { gadget.versions.size })
expect {
gadget.update_attribute(:brand, "Stanley")
}.not_to(change { gadget.versions.size })

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good!

@@ -148,7 +152,7 @@ def changes_in_latest_version
#
# @api private
def ignored_attr_has_changed?
ignored = @record.paper_trail_options[:ignore] + @record.paper_trail_options[:skip]
Copy link
Contributor Author

@tlynam tlynam Aug 9, 2020

Choose a reason for hiding this comment

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

Here it was only considering ignored attributes defined in the array as symbols and not hashes.

@@ -148,7 +152,7 @@ def changes_in_latest_version
#
# @api private
def ignored_attr_has_changed?
ignored = @record.paper_trail_options[:ignore] + @record.paper_trail_options[:skip]
ignored = calculated_ignored_array + @record.paper_trail_options[:skip]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ignores when attributes are either defined as symbols or hashes.

@@ -107,7 +107,7 @@ def attribute_in_previous_version(attr_name, is_touch)
end

# @api private
def changed_and_not_ignored
def calculated_ignored_array
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracts this calculation to be used by changed_and_not_ignored as well as ignored_attr_has_changed?

@tlynam
Copy link
Contributor Author

tlynam commented Aug 9, 2020

Hi @jaredbeck, hope you're well. Please let me know if I should go into more detail on this change.

Copy link
Member

@jaredbeck jaredbeck left a comment

Choose a reason for hiding this comment

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

LGTM. Nice work! Please also add an entry to the changelog under "Unreleased -> Fixed"

@tlynam tlynam force-pushed the fix-ignore-via-hash-creating-version branch from 8dec5c6 to 24982ae Compare August 16, 2020 20:15
…d via Hash

- It was only ignoring attributes defined as symbols.
- It now ignores when attributes are either defined as symbols or Hashes.
- Consolidates calculation to be shared when determining if changed and not ignored.

Resolves paper-trail-gem#1240
@tlynam tlynam force-pushed the fix-ignore-via-hash-creating-version branch from 24982ae to f7a94d0 Compare August 16, 2020 20:16
@tlynam tlynam marked this pull request as ready for review August 16, 2020 20:33
@tlynam tlynam merged commit 97501f0 into paper-trail-gem:master Aug 16, 2020
@tlynam tlynam deleted the fix-ignore-via-hash-creating-version branch August 16, 2020 20:35
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.

Ignore or Skip attributes dynamically is not working
2 participants