From 2f20c58484aea6b6aacd2b7da926165b2a8d73ca Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Mon, 7 Jul 2014 20:50:22 -0500 Subject: [PATCH] Raise more description exception for verify_policy_scoped * The AuthorizationNotPerformedError is very descriptive of the situation when authorization is forgotten. In the case of no scoping, it can be a head scratcher. * This new error type is implemented as a subclass of the current error type to prevent regressions in existing code. While this is not ideal, it is the simplest solution I could come up with for compatibility. --- lib/pundit.rb | 3 ++- spec/pundit_spec.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/pundit.rb b/lib/pundit.rb index a147417..be41f9d 100644 --- a/lib/pundit.rb +++ b/lib/pundit.rb @@ -11,6 +11,7 @@ module Pundit attr_accessor :query, :record, :policy end class AuthorizationNotPerformedError < StandardError; end + class PolicyScopingNotPerformedError < AuthorizationNotPerformedError; end class NotDefinedError < StandardError; end extend ActiveSupport::Concern @@ -58,7 +59,7 @@ module Pundit end def verify_policy_scoped - raise AuthorizationNotPerformedError unless @_policy_scoped + raise PolicyScopingNotPerformedError unless @_policy_scoped end def authorize(record, query=nil) diff --git a/spec/pundit_spec.rb b/spec/pundit_spec.rb index 1acd97b..232c047 100644 --- a/spec/pundit_spec.rb +++ b/spec/pundit_spec.rb @@ -148,7 +148,7 @@ describe Pundit do end it "raises an exception when policy_scope is not used" do - expect { controller.verify_policy_scoped }.to raise_error(Pundit::AuthorizationNotPerformedError) + expect { controller.verify_policy_scoped }.to raise_error(Pundit::PolicyScopingNotPerformedError) end end