From 02d2e24a55a4eee42f1baa9ba5f0083ef8793ef9 Mon Sep 17 00:00:00 2001 From: rauan Date: Wed, 16 May 2018 17:20:41 -0300 Subject: [PATCH] allow private methods on audited condition --- lib/audited/auditor.rb | 3 +-- spec/audited/auditor_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/audited/auditor.rb b/lib/audited/auditor.rb index 9ff0b3b93..2eeaa76ea 100644 --- a/lib/audited/auditor.rb +++ b/lib/audited/auditor.rb @@ -285,9 +285,8 @@ def auditing_enabled def run_conditional_check(condition, matching: true) return true if condition.blank? - return condition.call(self) == matching if condition.respond_to?(:call) - return send(condition) == matching if respond_to?(condition.to_sym) + return send(condition) == matching if respond_to?(condition.to_sym, true) true end diff --git a/spec/audited/auditor_spec.rb b/spec/audited/auditor_spec.rb index 10e8fb533..a78729ddf 100644 --- a/spec/audited/auditor_spec.rb +++ b/spec/audited/auditor_spec.rb @@ -22,6 +22,24 @@ context "should be configurable which conditions are audited" do subject { ConditionalCompany.new.send(:auditing_enabled) } + context "when condition method is private" do + subject { ConditionalPrivateCompany.new.send(:auditing_enabled) } + + before do + class ConditionalPrivateCompany < ::ActiveRecord::Base + self.table_name = 'companies' + + audited if: :foo? + + private def foo? + true + end + end + end + + it { is_expected.to be_truthy } + end + context "when passing a method name" do before do class ConditionalCompany < ::ActiveRecord::Base