summaryrefslogtreecommitdiff
path: root/spec/policies/environment_policy_spec.rb
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-05-06 21:36:03 +0100
committerFilipa Lacerda <filipa@gitlab.com>2017-05-06 21:36:03 +0100
commitcc27180ecd7236e78b3b495d05e87fefc17220cb (patch)
tree9b747b02feee39e94c26c9738e9e4313ad2b9cbe /spec/policies/environment_policy_spec.rb
parent13b31d25ec9c5f8d17f95ca8ad756a88b5e3dbd9 (diff)
parent6ad3814e1b31bfacfae7a2aabb4e4607b12ca66f (diff)
downloadgitlab-ce-cc27180ecd7236e78b3b495d05e87fefc17220cb.tar.gz
Merge branch 'master' into 25226-realtime-pipelines-fe
* master: (40 commits) Use GitLab Pages v0.4.2 Do not reprocess actions when user retries pipeline Add specs for extended status for manual actions Refine inheritance model of extended CI/CD statuses Introduce generic manual action extended status class Check ability to update build on the API resource Require build to be present in the controller Authorize build update on per object basis Use update build policy instead of new play policy Improve environment policy class Rephrase documentation for protected actions feature Improve code style related to protected actions Add changelog entry for external env URL btn fix Hide environment external URL button if not defined Fix builds controller spec related to protected actions Fix environment policy class name in specs Add Changelog entry for protected manual actions Document protected manual actions feature Improve specs for jobs API regarding manual actions Fix Rubocop offense in environments policy class ...
Diffstat (limited to 'spec/policies/environment_policy_spec.rb')
-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..0e15beaa5e8
--- /dev/null
+++ b/spec/policies/environment_policy_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+
+describe 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