1
0
Fork 0
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:
Jonas Nicklas and Kim Burgestrand 2015-03-27 09:31:10 +01:00
parent 56a8bdee5a
commit 2eed1d9136
2 changed files with 4 additions and 4 deletions

View file

@ -21,12 +21,12 @@ module Pundit
end end
def scope! 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}`" scope or raise NotDefinedError, "unable to find scope `#{find}::Scope` for `#{object.inspect}`"
end end
def policy! 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}`" policy or raise NotDefinedError, "unable to find policy `#{find}` for `#{object.inspect}`"
end end

View file

@ -64,7 +64,7 @@ describe Pundit do
end end
it "throws an exception if the given policy scope is nil" do 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
end end
@ -188,7 +188,7 @@ describe Pundit do
end end
it "throws an exception if the given policy is nil" do 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
end end