Skip to content

Commit

Permalink
Re-fix 'except' not being honored when used with 'comment_required'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdill2 committed Mar 19, 2018
1 parent c727373 commit 02c6e5c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/audited/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,22 @@ def write_audit(attrs)
end

def presence_of_audit_comment
if comment_required_state?
errors.add(:audit_comment, "Comment can't be blank!") unless audit_comment.present?
unless commenting_requirements_met?
errors.add(:audit_comment, "Comment can't be blank!")
end
end

def comment_required_state?
auditing_enabled &&
((audited_options[:on].include?(:create) && self.new_record?) ||
(audited_options[:on].include?(:update) && self.persisted? && self.changed?))
def commenting_requirements_met?
if !auditing_enabled ||
audit_comment.present? ||
(audited_options[:on].exclude?(:create) && self.new_record?) ||
(audited_options[:on].exclude?(:update) && self.persisted?) ||
(audited_changes.empty? && self.persisted?)
then
false
else
true
end
end

def combine_audits_if_needed
Expand Down

0 comments on commit 02c6e5c

Please sign in to comment.