docbrown/spec/policies/user_policy_spec.rb
Jacob Herrington a5b2d109d5
Rename banned and comment_banned roles (#12270)
* Rename banned and comment_banned roles

* Add data update script to rename roles containing 'ban'

* Add named error for Suspended users

* Update unidiomatic method names

* Rename misc banned to suspended

* Apply suggestions from code review

Co-authored-by: Michael Kohl <me@citizen428.net>

* Add unit tests for suspended methods

This commit also adds TODO comments for removing banned and
comment_banned from the codebase after data update scripts have
successfully run on all of our Forems.

Co-authored-by: Michael Kohl <me@citizen428.net>
2021-04-06 10:12:14 -05:00

53 lines
1.3 KiB
Ruby

require "rails_helper"
RSpec.describe UserPolicy, type: :policy do
subject { described_class.new(user, other_user) }
let(:other_user) { create(:user) }
context "when user is not signed-in" do
let(:user) { nil }
it { within_block_is_expected.to raise_error(Pundit::NotAuthorizedError) }
end
context "when user is signed-in" do
let(:user) { other_user }
permitted_actions = %i[
edit update onboarding_update join_org dashboard_show remove_identity destroy
]
it { is_expected.to permit_actions(permitted_actions) }
context "with suspended status" do
before { user.add_role(:suspended) }
it { is_expected.to forbid_actions(%i[join_org moderation_routes]) }
end
end
context "when user is trusted" do
let(:user) { build(:user, :trusted) }
it { is_expected.to permit_actions(%i[moderation_routes]) }
end
context "when user is not trusted" do
let(:user) { build_stubbed(:user) }
it { is_expected.to forbid_actions(%i[moderation_routes]) }
end
context "when the user is an admin" do
let(:user) { build(:user, :admin) }
it { is_expected.to permit_actions(%i[moderation_routes]) }
end
context "when the user is a super admin" do
let(:user) { build(:user, :super_admin) }
it { is_expected.to permit_actions(%i[moderation_routes]) }
end
end