Module: ActionPolicy::Testing::AuthorizeTracker

Defined in:
lib/action_policy/testing.rb

Overview

Collects all Authorizer calls

Defined Under Namespace

Classes: Call

Class Method Summary collapse

Class Method Details

.callsObject



44
45
46
# File 'lib/action_policy/testing.rb', line 44

def calls
  Thread.current[:__action_policy_calls] ||= []
end

.track(policy, rule) ⇒ Object

Called from Authorizer



39
40
41
42
# File 'lib/action_policy/testing.rb', line 39

def track(policy, rule)
  return unless tracking?
  calls << Call.new(policy, rule)
end

.trackingObject

Wrap code under inspection into this method to track authorize! calls



30
31
32
33
34
35
36
# File 'lib/action_policy/testing.rb', line 30

def tracking
  calls.clear
  Thread.current[:__action_policy_tracking] = true
  yield
ensure
  Thread.current[:__action_policy_tracking] = false
end

.tracking?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/action_policy/testing.rb', line 48

def tracking?
  Thread.current[:__action_policy_tracking] == true
end