spec/pundit_spec.rb in pundit-2.3.1 vs spec/pundit_spec.rb in pundit-2.4.0

- old
+ new

@@ -55,29 +55,54 @@ it "works with anonymous class policies" do expect(Pundit.authorize(user, article_tag, :show?)).to be_truthy expect { Pundit.authorize(user, article_tag, :destroy?) }.to raise_error(Pundit::NotAuthorizedError) end - it "raises an error with a query and action" do + it "raises an error with the policy, query and record" do # rubocop:disable Style/MultilineBlockChain expect do Pundit.authorize(user, post, :destroy?) - end.to raise_error(Pundit::NotAuthorizedError, "not allowed to destroy? this Post") do |error| + end.to raise_error(Pundit::NotAuthorizedError, "not allowed to PostPolicy#destroy? this Post") do |error| expect(error.query).to eq :destroy? expect(error.record).to eq post - expect(error.policy).to eq Pundit.policy(user, post) + expect(error.policy).to have_attributes( + user: user, + record: post + ) + expect(error.policy).to be_a(PostPolicy) end # rubocop:enable Style/MultilineBlockChain end - it "raises an error with a the record, query and action when the record is namespaced" do + it "raises an error with the policy, query and record when the record is namespaced" do # rubocop:disable Style/MultilineBlockChain expect do Pundit.authorize(user, [:project, :admin, comment], :destroy?) - end.to raise_error(Pundit::NotAuthorizedError, "not allowed to destroy? this Comment") do |error| + end.to raise_error(Pundit::NotAuthorizedError, + "not allowed to Project::Admin::CommentPolicy#destroy? this Comment") do |error| expect(error.query).to eq :destroy? expect(error.record).to eq comment - expect(error.policy).to eq Pundit.policy(user, [:project, :admin, comment]) + expect(error.policy).to have_attributes( + user: user, + record: comment + ) + expect(error.policy).to be_a(Project::Admin::CommentPolicy) + end + # rubocop:enable Style/MultilineBlockChain + end + + it "raises an error with the policy, query and the class name when a Class is given" do + # rubocop:disable Style/MultilineBlockChain + expect do + Pundit.authorize(user, Post, :destroy?) + end.to raise_error(Pundit::NotAuthorizedError, "not allowed to PostPolicy#destroy? Post") do |error| + expect(error.query).to eq :destroy? + expect(error.record).to eq Post + expect(error.policy).to have_attributes( + user: user, + record: Post + ) + expect(error.policy).to be_a(PostPolicy) end # rubocop:enable Style/MultilineBlockChain end it "raises an error with a invalid policy constructor" do