lib/action_policy/testing.rb in action_policy-0.6.8 vs lib/action_policy/testing.rb in action_policy-0.6.9

- old
+ new

@@ -3,11 +3,23 @@ module ActionPolicy # Testing utils module Testing # Collects all Authorizer calls module AuthorizeTracker + module Context + private + + def context_matches?(context, actual) + return true unless context + + context === actual || actual >= context + end + end + class Call # :nodoc: + include Context + attr_reader :policy, :rule def initialize(policy, rule) @policy = policy @rule = rule @@ -21,35 +33,30 @@ def inspect "#{policy.record.inspect} was authorized with #{policy.class}##{rule} " \ "and context #{policy.authorization_context.inspect}" end - - private - - def context_matches?(context, actual) - return true unless context - - context === actual || actual >= context - end end class Scoping # :nodoc: + include Context + attr_reader :policy, :target, :type, :name, :scope_options def initialize(policy, target, type, name, scope_options) @policy = policy @target = target @type = type @name = name @scope_options = scope_options end - def matches?(policy_class, actual_type, actual_name, actual_scope_options) + def matches?(policy_class, actual_type, actual_name, actual_scope_options, actual_context) policy_class == policy.class && type == actual_type && name == actual_name && - actual_scope_options === scope_options + actual_scope_options === scope_options && + context_matches?(actual_context, policy.authorization_context) end def inspect "#{policy.class} :#{name} for :#{type} #{scope_options_message}" end