lib/action_policy/testing.rb in action_policy-0.6.3 vs lib/action_policy/testing.rb in action_policy-0.6.4
- old
+ new
@@ -11,17 +11,26 @@
def initialize(policy, rule)
@policy = policy
@rule = rule
end
- def matches?(policy_class, actual_rule, target)
+ def matches?(policy_class, actual_rule, target, context)
policy_class == policy.class &&
(target.is_a?(Class) ? target == policy.record : target === policy.record) &&
- rule == actual_rule
+ rule == actual_rule && context_matches?(context, policy.authorization_context)
end
def inspect
- "#{policy.record.inspect} was authorized with #{policy.class}##{rule}"
+ "#{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:
attr_reader :policy, :target, :type, :name, :scope_options