-
Notifications
You must be signed in to change notification settings - Fork 899
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
Skip creating version for timestamp when ignoring attribute with a Hash #1256
Conversation
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 |
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.
This test fails. This should succeed right?
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.
Hi @jaredbeck, so when using ignored
with a Hash, it still creates a version for the timestamp.
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.
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 }) |
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.
Updated name to Picard
so the line doesn't exceed the maximum for Rubocop.
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.
That's fine. You can also break long lines like this:
expect { gadget.update_attribute(:brand, "Picard") }.not_to(change { gadget.versions.size }) | |
expect { | |
gadget.update_attribute(:brand, "Stanley") | |
}.not_to(change { gadget.versions.size }) |
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.
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] |
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.
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] |
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.
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 |
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.
Extracts this calculation to be used by changed_and_not_ignored
as well as ignored_attr_has_changed?
Hi @jaredbeck, hope you're well. Please let me know if I should go into more detail on this change. |
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.
LGTM. Nice work! Please also add an entry to the changelog under "Unreleased -> Fixed"
8dec5c6
to
24982ae
Compare
…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
24982ae
to
f7a94d0
Compare
updated_at
.Thank you for your contribution!
Check the following boxes:
master
(if not - rebase it).code introduces user-observable changes.
and description in grammatically correct, complete sentences.