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.
This commit is contained in:
Daniel Uber 2021-07-30 11:42:47 -05:00 committed by GitHub
parent 7567e77132
commit 9b5512bd9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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