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

Fix change of vritual attribute can not be tracked. #353

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bealking
Copy link

@bealking bealking commented Jun 3, 2017

Some gems like "acts-as-taggable-on" may add some vritual attribute/method that inherits activerecord dirty feature. Please see the follow links:

https://github.com/mbleigh/acts-as-taggable-on/blob/64ed839a8a6021c719fbff9c6bdf74a4fcd65f18/lib/acts_as_taggable_on/taggable/core.rb#L193
https://github.com/mbleigh/acts-as-taggable-on/blob/8e64c3d4a81cfbb8af621228eae36a65c1f94501/lib/acts_as_taggable_on/taggable/dirty.rb#L14

audited_changes uses rails "[]" method to fetch the new value of changed attribute which leads those gems that didn't extend this method to return nil (please see the test example added).

so I change the method to public_send to solve this problem.

Copy link
Collaborator

@domcleal domcleal left a comment

Choose a reason for hiding this comment

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

Could you check the test failures please? The expectation in the new test is failing as updated_at is also in the audited_changes hash.

Also there's a small typo in the commit message, "vritual"/"virtual".

@@ -180,6 +180,12 @@ def non_column_attr=(val)
expect(@user.audits.last.audited_changes).to eq({ 'name' => ['Brandon', 'Changed'] })
end

it "should store the change of the custom attribute which extended dirty feature" do
@user = Models::ActiveRecord::UserDelegateCompany.create(name: 'Brandon', username: 'brandon', password: 'password')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use two spaces, not tabs please.

end

# mock activerecord dirty feature
def company_list_changed?
Copy link
Collaborator

Choose a reason for hiding this comment

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

tabs/spaces

@@ -64,6 +110,7 @@ class Company < ::ActiveRecord::Base
class Company::STICompany < Company
end


Copy link
Collaborator

Choose a reason for hiding this comment

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

Unnecessary?

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.

None yet

2 participants