Skip to content

Commit

Permalink
Use on: conditional directly on callback declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdill2 committed Mar 7, 2018
1 parent cc3357a commit 3045bd6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/audited/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def audited(options = {})

if audited_options[:comment_required]
validate :presence_of_audit_comment
before_destroy :require_comment
before_destroy :require_comment if audited_options[:on].include?(:destroy)
end

has_many :audits, -> { order(version: :asc) }, as: :auditable, class_name: Audited.audit_class.name, inverse_of: :auditable
Expand Down Expand Up @@ -238,11 +238,9 @@ def presence_of_audit_comment

def require_comment
if auditing_enabled && audit_comment.blank?
unless audited_options[:on].present? && audited_options[:on].exclude?(:destroy)
errors.add(:audit_comment, "Comment required before destruction")
return false if Rails.version.start_with?('4.')
throw :abort
end
errors.add(:audit_comment, "Comment required before destruction")
return false if Rails.version.start_with?('4.')
throw :abort
end
end

Expand Down

0 comments on commit 3045bd6

Please sign in to comment.