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

Changes the way old audits are combined. Keep first and last value, discard middle ones. #712

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/audited/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,15 @@ def own_and_associated_audits
# Combine multiple audits into one.
def combine_audits(audits_to_combine)
combine_target = audits_to_combine.last
combine_target.audited_changes = audits_to_combine.pluck(:audited_changes).reduce(&:merge)
combine_target.audited_changes = audits_to_combine.pluck(:audited_changes).reduce do |h1, h2|
h1.merge(h2) do |_key, this, other|
if this.is_a?(Array) && other.is_a?(Array)
[this.first, other.last]
else
other
end
end
end
combine_target.comment = "#{combine_target.comment}\nThis audit is the result of multiple audits being combined."

transaction do
Expand Down
2 changes: 1 addition & 1 deletion spec/audited/auditor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ class CallbacksSpecified < ::ActiveRecord::Base
audits = user.audits

expect(audits.count).to eq(3)
expect(audits[0].audited_changes).to include({"name" => ["Foobar", "Awesome"], "username" => ["brandon", "keepers"]})
expect(audits[0].audited_changes).to include({"name" => ["Brandon", "Awesome"], "username" => ["brandon", "keepers"]})
expect(audits[1].audited_changes).to eq({"activated" => [nil, true]})
expect(audits[2].audited_changes).to eq({"favourite_device" => [nil, "Android Phone"]})
end
Expand Down
Loading