mirror of
https://github.com/varvet/pundit.git
synced 2022-11-09 12:30:11 -05:00
Check for nil?
, not blank?
So we don't accidentally reject empty collections
This commit is contained in:
parent
56a8bdee5a
commit
2eed1d9136
2 changed files with 4 additions and 4 deletions
|
@ -21,12 +21,12 @@ module Pundit
|
|||
end
|
||||
|
||||
def scope!
|
||||
raise NotDefinedError, "unable to find policy scope of blank object `#{object.inspect}`" if object.blank?
|
||||
raise NotDefinedError, "unable to find policy scope of nil" if object.nil?
|
||||
scope or raise NotDefinedError, "unable to find scope `#{find}::Scope` for `#{object.inspect}`"
|
||||
end
|
||||
|
||||
def policy!
|
||||
raise NotDefinedError, "unable to find policy of blank object `#{object.inspect}`" if object.blank?
|
||||
raise NotDefinedError, "unable to find policy of nil" if object.nil?
|
||||
policy or raise NotDefinedError, "unable to find policy `#{find}` for `#{object.inspect}`"
|
||||
end
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ describe Pundit do
|
|||
end
|
||||
|
||||
it "throws an exception if the given policy scope is nil" do
|
||||
expect { Pundit.policy_scope!(user, nil) }.to raise_error(Pundit::NotDefinedError, "unable to find policy scope of blank object `nil`")
|
||||
expect { Pundit.policy_scope!(user, nil) }.to raise_error(Pundit::NotDefinedError, "unable to find policy scope of nil")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -188,7 +188,7 @@ describe Pundit do
|
|||
end
|
||||
|
||||
it "throws an exception if the given policy is nil" do
|
||||
expect { Pundit.policy!(user, nil) }.to raise_error(Pundit::NotDefinedError, "unable to find policy of blank object `nil`")
|
||||
expect { Pundit.policy!(user, nil) }.to raise_error(Pundit::NotDefinedError, "unable to find policy of nil")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue