Skip to content

Commit

Permalink
Update to normalize audit ordering when in loaded branch for auditor …
Browse files Browse the repository at this point in the history
…interactions
  • Loading branch information
wkirby committed Jul 2, 2024
1 parent 0e1b3b4 commit 2d42ecd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/audited/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def revision(version)

# Find the oldest revision recorded prior to the date/time provided.
def revision_at(date_or_time)
targeted_audits = audits.loaded? ? audits.filter { |audit| audit.created_at <= date_or_time } : audits.up_until(date_or_time)
targeted_audits = audits.loaded? ? audits.filter { |audit| audit.created_at <= date_or_time }.sort_by(&:version) : audits.up_until(date_or_time)
revision_with Audited.audit_class.reconstruct_attributes(targeted_audits) unless targeted_audits.empty?
end

Expand Down Expand Up @@ -332,7 +332,7 @@ def audits_to(version = nil)
end
end

audits.loaded? ? audits.filter { |audit| audit.version <= version } : audits.to_version(version)
audits.loaded? ? audits.filter { |audit| audit.version <= version }.sort_by(&:version) : audits.to_version(version)
end

def audit_create
Expand Down Expand Up @@ -391,7 +391,7 @@ def comment_required_state?
def combine_audits_if_needed
max_audits = audited_options[:max_audits]
if max_audits && (extra_count = audits.count - max_audits) > 0
audits_to_combine = audits.loaded? ? audits.take(extra_count + 1) : audits.limit(extra_count + 1)
audits_to_combine = audits.loaded? ? audits.sort_by(&:version).take(extra_count + 1) : audits.limit(extra_count + 1)
combine_audits(audits_to_combine)
end
end
Expand Down

0 comments on commit 2d42ecd

Please sign in to comment.