Skip to content

Commit 140b89f

Browse files
KirtashW17danielmorrison
authored andcommitted
Changes the way old audits are combined. Now we keep the first value of each attribute and the last one, instead of the last 2.
1 parent 0e019bb commit 140b89f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/audited/auditor.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,15 @@ def own_and_associated_audits
188188
# Combine multiple audits into one.
189189
def combine_audits(audits_to_combine)
190190
combine_target = audits_to_combine.last
191-
combine_target.audited_changes = audits_to_combine.pluck(:audited_changes).reduce(&:merge)
191+
combine_target.audited_changes = audits_to_combine.pluck(:audited_changes).reduce do |h1, h2|
192+
h1.merge(h2) do |_key, this, other|
193+
if this.is_a?(Array) && other.is_a?(Array)
194+
[this.first, other.last]
195+
else
196+
other
197+
end
198+
end
199+
end
192200
combine_target.comment = "#{combine_target.comment}\nThis audit is the result of multiple audits being combined."
193201

194202
transaction do

spec/audited/auditor_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ class CallbacksSpecified < ::ActiveRecord::Base
706706
audits = user.audits
707707

708708
expect(audits.count).to eq(3)
709-
expect(audits[0].audited_changes).to include({"name" => ["Foobar", "Awesome"], "username" => ["brandon", "keepers"]})
709+
expect(audits[0].audited_changes).to include({"name" => ["Brandon", "Awesome"], "username" => ["brandon", "keepers"]})
710710
expect(audits[1].audited_changes).to eq({"activated" => [nil, true]})
711711
expect(audits[2].audited_changes).to eq({"favourite_device" => [nil, "Android Phone"]})
712712
end

0 commit comments

Comments
 (0)