docbrown/spec/policies/organization_policy_spec.rb
rhymes 6553f08d94 Rubocop cleanups (#1415)
* Update rubocop-todo.yml with new violations

* Fix Layout/EmptyLine* rules

* Fix Layout/Indentation* rules

* Fix remaining Layout/* rules

* Fix Lint/DuplicateMethods by removing unused accessor

* Fix Lint/IneffectiveAccessModifier

* Fix Lint/MissingCopEnableDirective

* Re-run rubocop auto gen config

* Fix Layout/RescueEnsureAlignment

* Fix Naming/* rules

* Fix some RSpec/* rules

* Fix typos

* Fix RSpec/LetBeforeExamples

* Series should only be an attr_writer, not an attr_accessor

* Fix RSpec/InstanceVariable

* Fix RSpec/InstanceVariable

* Fix RSpec/RepeatedDescription and RSpec/RepeatedExample

* Fix Style/ClassAndModuleChildren

* Fix Style/ConditionalAssignment

* Fix some Style/* rules

* Trigger Travis CI build because failing tests are not failing locally

* Revert "Fix Style/ClassAndModuleChildren"

This reverts commit 1686801d8a1516ba1894f79e24401a20dea65f99.
2019-01-02 11:20:02 -05:00

47 lines
1.2 KiB
Ruby

require "rails_helper"
RSpec.describe OrganizationPolicy do
subject(:organization_policy) { described_class.new(user, organization) }
let(:organization) { build(: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(:user) }
it { is_expected.to forbid_action(:update) }
it { is_expected.to permit_action(:create) }
end
context "when user is banned" do
let(:user) { build(:user, :banned) }
it { is_expected.to forbid_actions(%i[create update]) }
end
context "when user is an org admin of an org" do
let(:user) { build(:user) }
before { user.update(organization: organization, org_admin: true) }
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
let(:user) { build(:user) }
let(:new_org) { build(:organization) }
before { user.update(organization: new_org, org_admin: true) }
it "does not allow the user to update another org" do
expect(organization_policy).to forbid_action(:update)
end
end
end