Skip to content

Commit

Permalink
Changes the way old audits are combined. Now we keep the first value …
Browse files Browse the repository at this point in the history
…of each attribute and the last one, instead of the last 2.
  • Loading branch information
KirtashW17 authored and danielmorrison committed Jul 30, 2024
1 parent 0e019bb commit 140b89f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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

0 comments on commit 140b89f

Please sign in to comment.