summaryrefslogtreecommitdiff
path: root/spec/policies
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-05-01 13:38:57 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-05-01 13:38:57 +0200
commit6baaa8a98e10ff93ba3f481052bb68fdafb6e2c1 (patch)
tree6b595de63b26a823d63d0d1d5a7089bf68fe9bd7 /spec/policies
parent52bfc0efa95f991f17618aa049f799f4e44e13ac (diff)
downloadgitlab-ce-6baaa8a98e10ff93ba3f481052bb68fdafb6e2c1.tar.gz
Add new ability check for stopping environment
Diffstat (limited to 'spec/policies')
-rw-r--r--spec/policies/environment_policy_spec.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/policies/environment_policy_spec.rb b/spec/policies/environment_policy_spec.rb
new file mode 100644
index 00000000000..f43caffa946
--- /dev/null
+++ b/spec/policies/environment_policy_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+
+describe Ci::EnvironmentPolicy do
+ 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
+ project.add_master(user)
+ 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