From 9b5512bd9f8080a70fa95b4945951aaa9baaa04b Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Fri, 30 Jul 2021 11:42:47 -0500 Subject: [PATCH] expect to forbid, rather than expect not to permit (#14390) I noticed a warning from rspec when this policy spec ran: Using expect { }.not_to permit_actions could produce confusing results. Please use `.to forbid_actions` instead. To clarify, `.not_to permit_actions` will look at all of the actions and checks if ANY actions fail, not if all actions fail. Therefore, you could result in something like this: it { is_expected.to permit_actions([:new, :create, :edit]) } it { is_expected.not_to permit_actions([:edit, :destroy]) } In this case, edit would be true and destroy would be false, but both tests would pass. I just follow the helpful advice. --- spec/policies/pinned_article_policy_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/policies/pinned_article_policy_spec.rb b/spec/policies/pinned_article_policy_spec.rb index 4700d62bb..1b1351603 100644 --- a/spec/policies/pinned_article_policy_spec.rb +++ b/spec/policies/pinned_article_policy_spec.rb @@ -12,7 +12,7 @@ RSpec.describe PinnedArticlePolicy, type: :policy do context "when user is signed in as a regular user" do let(:user) { build_stubbed(:user) } - it { is_expected.not_to permit_actions(%i[show update destroy]) } + it { is_expected.to forbid_actions(%i[show update destroy]) } end context "when user is signed in as an admin" do