mirror of
https://github.com/varvet/pundit.git
synced 2022-11-09 12:30:11 -05:00
Use #inspect
over #to_s
, closes #200
This commit is contained in:
parent
2eed1d9136
commit
66ba305eb8
3 changed files with 4 additions and 2 deletions
|
@ -15,7 +15,7 @@ module Pundit
|
||||||
@record = options[:record]
|
@record = options[:record]
|
||||||
@policy = options[:policy]
|
@policy = options[:policy]
|
||||||
|
|
||||||
message = options.fetch(:message) { "not allowed to #{query} this #{record}" }
|
message = options.fetch(:message) { "not allowed to #{query} this #{record.inspect}" }
|
||||||
|
|
||||||
super(message)
|
super(message)
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,7 @@ describe Pundit do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an error with a query and action" do
|
it "raises an error with a query and action" do
|
||||||
expect { Pundit.authorize(user, post, :destroy?) }.to raise_error(Pundit::NotAuthorizedError) do |error|
|
expect { Pundit.authorize(user, post, :destroy?) }.to raise_error(Pundit::NotAuthorizedError, "not allowed to destroy? this #<Post>") do |error|
|
||||||
expect(error.query).to eq :destroy?
|
expect(error.query).to eq :destroy?
|
||||||
expect(error.record).to eq post
|
expect(error.record).to eq post
|
||||||
expect(error.policy).to eq Pundit.policy(user, post)
|
expect(error.policy).to eq Pundit.policy(user, post)
|
||||||
|
|
|
@ -42,6 +42,8 @@ class Post < Struct.new(:user)
|
||||||
def self.published
|
def self.published
|
||||||
:published
|
:published
|
||||||
end
|
end
|
||||||
|
def to_s; "Post"; end
|
||||||
|
def inspect; "#<Post>"; end
|
||||||
end
|
end
|
||||||
|
|
||||||
class CommentPolicy < Struct.new(:user, :comment); end
|
class CommentPolicy < Struct.new(:user, :comment); end
|
||||||
|
|
Loading…
Add table
Reference in a new issue