Module: ActionPolicy::Testing::AuthorizeTracker
- Defined in:
- lib/action_policy/testing.rb
Overview
Collects all Authorizer calls
Defined Under Namespace
Class Method Summary collapse
- .calls ⇒ Object
- .scopings ⇒ Object
-
.track(policy, rule) ⇒ Object
Called from Authorizer.
-
.track_scope(target, policy, type:, name:, scope_options:) ⇒ Object
Called from Authorizer.
-
.tracking ⇒ Object
Wrap code under inspection into this method to track authorize! calls.
- .tracking? ⇒ Boolean
Class Method Details
.calls ⇒ Object
98 99 100 |
# File 'lib/action_policy/testing.rb', line 98 def calls Thread.current[:__action_policy_calls] ||= [] end |
.scopings ⇒ Object
102 103 104 |
# File 'lib/action_policy/testing.rb', line 102 def scopings Thread.current[:__action_policy_scopings] ||= [] end |
.track(policy, rule) ⇒ Object
Called from Authorizer
87 88 89 90 |
# File 'lib/action_policy/testing.rb', line 87 def track(policy, rule) return unless tracking? calls << Call.new(policy, rule) end |
.track_scope(target, policy, type:, name:, scope_options:) ⇒ Object
Called from Authorizer
93 94 95 96 |
# File 'lib/action_policy/testing.rb', line 93 def track_scope(target, policy, type:, name:, scope_options:) return unless tracking? scopings << Scoping.new(policy, target, type, name, ) end |
.tracking ⇒ Object
Wrap code under inspection into this method to track authorize! calls
77 78 79 80 81 82 83 84 |
# File 'lib/action_policy/testing.rb', line 77 def tracking calls.clear scopings.clear Thread.current[:__action_policy_tracking] = true yield ensure Thread.current[:__action_policy_tracking] = false end |
.tracking? ⇒ Boolean
106 107 108 |
# File 'lib/action_policy/testing.rb', line 106 def tracking? Thread.current[:__action_policy_tracking] == true end |