1
0
Fork 0
mirror of https://github.com/varvet/pundit.git synced 2022-11-09 12:30:11 -05:00

NotAuthorizedError can be initialized with a string

This commit is contained in:
Martin Sereinig 2015-05-05 08:07:50 +02:00
parent 582ee78c2b
commit 1723a1b038
2 changed files with 15 additions and 4 deletions

View file

@ -14,11 +14,15 @@ module Pundit
attr_reader :query, :record, :policy attr_reader :query, :record, :policy
def initialize(options = {}) def initialize(options = {})
@query = options[:query] if options.is_a? String
@record = options[:record] message = options
@policy = options[:policy] else
@query = options[:query]
@record = options[:record]
@policy = options[:policy]
message = options.fetch(:message) { "not allowed to #{query} this #{record.inspect}" } message = options.fetch(:message) { "not allowed to #{query} this #{record.inspect}" }
end
super(message) super(message)
end end

View file

@ -344,4 +344,11 @@ describe Pundit do
expect(Controller.new(double, params).permitted_attributes(post)).to eq({ 'votes' => 5 }) expect(Controller.new(double, params).permitted_attributes(post)).to eq({ 'votes' => 5 })
end end
end end
describe "Pundit::NotAuthorizedError" do
it "can be initialized with a string as message" do
error = Pundit::NotAuthorizedError.new("must be logged in")
expect(error.message).to eq "must be logged in"
end
end
end end