Skip to content

Commit

Permalink
allow private methods on audited condition
Browse files Browse the repository at this point in the history
  • Loading branch information
rauann authored and tbrisker committed Jun 24, 2018
1 parent 46e560d commit 02d2e24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/audited/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions spec/audited/auditor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 02d2e24

Please sign in to comment.