docbrown/spec/policies/organization_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

55 lines
1.6 KiB
Ruby

require "rails_helper"
RSpec.describe OrganizationPolicy, type: :policy do
subject(:organization_policy) { described_class.new(user, organization) }
let(:organization) { build_stubbed(:organization) }
context "when user is not signed-in" do
let(:user) { nil }
it { within_block_is_expected.to raise_error(Pundit::NotAuthorizedError) }
end
context "when a non-org user" do
let(:user) { build_stubbed(:user) }
it { is_expected.to forbid_action(:update) }
it { is_expected.to permit_action(:create) }
end
context "when user is suspended" do
let(:user) { build(:user, :suspended) }
it { is_expected.to forbid_actions(%i[create update]) }
end
context "when user is an org admin of an org" do
subject(:organization_policy) { described_class.new(user, org) }
let(:user) { create(:user) }
let(:org) { create(:organization) }
before do
create(:organization_membership, user: user, organization: org, type_of_user: "admin")
end
it "allows the user to update their own org" do
expect(organization_policy).to permit_action(:update)
end
end
context "when user is an org admin of another org" do
subject(:organization_policy) { described_class.new(user, new_org) }
let(:user) { create(:user) }
let(:org) { create(:organization) }
let(:new_org) { build_stubbed(:organization) }
before { create(:organization_membership, user: user, organization: org, type_of_user: "admin") }
it "does not allow the user to update another org" do
expect(organization_policy).to forbid_action(:update)
end
end
end