BigW Consortium Gitlab

environment_policy_spec.rb 1.53 KB
Newer Older
1 2
require 'spec_helper'

3
describe EnvironmentPolicy do
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  let(:user) { create(:user) }
  let(:project) { create(:project) }

  let(:environment) do
    create(:environment, :with_review_app, project: project)
  end

  let(:policies) do
    described_class.abilities(user, environment).to_set
  end

  describe '#rules' do
    context 'when user does not have access to the project' do
      let(:project) { create(:project, :private) }

      it 'does not include ability to stop environment' do
        expect(policies).not_to include :stop_environment
      end
    end

    context 'when anonymous user has access to the project' do
      let(:project) { create(:project, :public) }

      it 'does not include ability to stop environment' do
        expect(policies).not_to include :stop_environment
      end
    end

    context 'when team member has access to the project' do
      let(:project) { create(:project, :public) }

      before do
36
        project.add_developer(user)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
      end

      context 'when team member has ability to stop environment' do
        it 'does includes ability to stop environment' do
          expect(policies).to include :stop_environment
        end
      end

      context 'when team member has no ability to stop environment' do
        before do
          create(:protected_branch, :no_one_can_push,
                 name: 'master', project: project)
        end

        it 'does not include ability to stop environment' do
          expect(policies).not_to include :stop_environment
        end
      end
    end
  end
end