diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2018-07-10 11:11:04 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-07-10 11:11:04 +0300 |
commit | d79cef3a9a5577765d975326fbf4bc1b8c5634de (patch) | |
tree | fad8dce6f89102fda75f511dee80b7fae7675994 /spec | |
parent | ca1deb9e5ec1429a65d73b3352d1207301f9fc6f (diff) |
Support manually stopping any environment from the UI
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/projects/environments/environment_spec.rb | 13 | ||||
-rw-r--r-- | spec/features/projects/environments/environments_spec.rb | 12 | ||||
-rw-r--r-- | spec/javascripts/environments/environment_rollback_spec.js | 4 | ||||
-rw-r--r-- | spec/javascripts/environments/environment_stop_spec.js | 12 | ||||
-rw-r--r-- | spec/policies/environment_policy_spec.rb | 106 | ||||
-rw-r--r-- | spec/serializers/environment_entity_spec.rb | 3 | ||||
-rw-r--r-- | spec/serializers/environment_serializer_spec.rb | 10 |
7 files changed, 103 insertions, 57 deletions
diff --git a/spec/features/projects/environments/environment_spec.rb b/spec/features/projects/environments/environment_spec.rb index 0c34309c1f4..624f7139605 100644 --- a/spec/features/projects/environments/environment_spec.rb +++ b/spec/features/projects/environments/environment_spec.rb @@ -166,7 +166,8 @@ describe 'Environment' do end it 'allows to stop environment' do - click_link('Stop') + click_button('Stop') + click_button('Stop environment') # confirm modal expect(page).to have_content('close_app') end @@ -174,7 +175,7 @@ describe 'Environment' do context 'when user has no ability to stop environment' do it 'does not allow to stop environment' do - expect(page).to have_no_link('Stop') + expect(page).not_to have_button('Stop') end end @@ -182,7 +183,7 @@ describe 'Environment' do let(:role) { :reporter } it 'does not show stop button' do - expect(page).not_to have_link('Stop') + expect(page).not_to have_button('Stop') end end end @@ -192,7 +193,7 @@ describe 'Environment' do let(:environment) { create(:environment, project: project, state: :stopped) } it 'does not show stop button' do - expect(page).not_to have_link('Stop') + expect(page).not_to have_button('Stop') end end end @@ -230,7 +231,7 @@ describe 'Environment' do it 'user visits environment page' do visit_environment(environment) - expect(page).to have_link('Stop') + expect(page).to have_button('Stop') end it 'user deletes the branch with running environment' do @@ -242,7 +243,7 @@ describe 'Environment' do visit_environment(environment) - expect(page).to have_no_link('Stop') + expect(page).not_to have_button('Stop') end ## diff --git a/spec/features/projects/environments/environments_spec.rb b/spec/features/projects/environments/environments_spec.rb index 9900c13095e..c2ed753c409 100644 --- a/spec/features/projects/environments/environments_spec.rb +++ b/spec/features/projects/environments/environments_spec.rb @@ -10,6 +10,10 @@ describe 'Environments page', :js do sign_in(user) end + def stop_button_selector + %q{button[data-original-title="Stop environment"]} + end + describe 'page tabs' do it 'shows "Available" and "Stopped" tab with links' do visit_environments(project) @@ -120,7 +124,7 @@ describe 'Environments page', :js do end it 'does not show stip button when environment is not stoppable' do - expect(page).not_to have_selector('.stop-env-link') + expect(page).not_to have_selector(stop_button_selector) end end @@ -178,7 +182,7 @@ describe 'Environments page', :js do end it 'shows a stop button' do - expect(page).not_to have_selector('.stop-env-link') + expect(page).not_to have_selector(stop_button_selector) end it 'does not show external link button' do @@ -211,14 +215,14 @@ describe 'Environments page', :js do end it 'shows a stop button' do - expect(page).to have_selector('.stop-env-link') + expect(page).to have_selector(stop_button_selector) end context 'when user is a reporter' do let(:role) { :reporter } it 'does not show stop button' do - expect(page).not_to have_selector('.stop-env-link') + expect(page).not_to have_selector(stop_button_selector) end end end diff --git a/spec/javascripts/environments/environment_rollback_spec.js b/spec/javascripts/environments/environment_rollback_spec.js index eb8e49d81fe..79f33c5bc8a 100644 --- a/spec/javascripts/environments/environment_rollback_spec.js +++ b/spec/javascripts/environments/environment_rollback_spec.js @@ -18,7 +18,7 @@ describe('Rollback Component', () => { }, }).$mount(); - expect(component.$el.querySelector('span').textContent).toContain('Re-deploy'); + expect(component.$el).toHaveSpriteIcon('repeat'); }); it('Should render Rollback label when isLastDeployment is false', () => { @@ -30,6 +30,6 @@ describe('Rollback Component', () => { }, }).$mount(); - expect(component.$el.querySelector('span').textContent).toContain('Rollback'); + expect(component.$el).toHaveSpriteIcon('redo'); }); }); diff --git a/spec/javascripts/environments/environment_stop_spec.js b/spec/javascripts/environments/environment_stop_spec.js index 3f95faf466a..4d9caa57566 100644 --- a/spec/javascripts/environments/environment_stop_spec.js +++ b/spec/javascripts/environments/environment_stop_spec.js @@ -4,7 +4,6 @@ import stopComp from '~/environments/components/environment_stop.vue'; describe('Stop Component', () => { let StopComponent; let component; - const stopURL = '/stop'; beforeEach(() => { StopComponent = Vue.extend(stopComp); @@ -12,20 +11,13 @@ describe('Stop Component', () => { component = new StopComponent({ propsData: { - stopUrl: stopURL, + environment: {}, }, }).$mount(); }); - describe('computed', () => { - it('title', () => { - expect(component.title).toEqual('Stop'); - }); - }); - it('should render a button to stop the environment', () => { expect(component.$el.tagName).toEqual('BUTTON'); - expect(component.$el.getAttribute('data-original-title')).toEqual('Stop'); - expect(component.$el.getAttribute('aria-label')).toEqual('Stop'); + expect(component.$el.getAttribute('data-original-title')).toEqual('Stop environment'); }); }); diff --git a/spec/policies/environment_policy_spec.rb b/spec/policies/environment_policy_spec.rb index de4cb5b30c5..3728218accc 100644 --- a/spec/policies/environment_policy_spec.rb +++ b/spec/policies/environment_policy_spec.rb @@ -1,57 +1,101 @@ require 'spec_helper' describe EnvironmentPolicy do - let(:user) { create(:user) } - let(:project) { create(:project, :repository) } + using RSpec::Parameterized::TableSyntax - let(:environment) do - create(:environment, :with_review_app, project: project) - end + let(:user) { create(:user) } let(:policy) do described_class.new(user, environment) end describe '#rules' do - context 'when user does not have access to the project' do - let(:project) { create(:project, :private, :repository) } + shared_examples 'project permissions' do + context 'with stop action' do + let(:environment) do + create(:environment, :with_review_app, project: project) + end - it 'does not include ability to stop environment' do - expect(policy).to be_disallowed :stop_environment - end - end + where(:access_level, :allowed?) do + nil | false + :guest | false + :reporter | false + :developer | true + :master | true + end - context 'when anonymous user has access to the project' do - let(:project) { create(:project, :public, :repository) } + with_them do + before do + project.add_user(user, access_level) unless access_level.nil? + end - it 'does not include ability to stop environment' do - expect(policy).to be_disallowed :stop_environment - end - end + it { expect(policy.allowed?(:stop_environment)).to be allowed? } + end - context 'when team member has access to the project' do - let(:project) { create(:project, :public, :repository) } + context 'when an admin user' do + let(:user) { create(:user, :admin) } - before do - project.add_developer(user) - end + it { expect(policy).to be_allowed :stop_environment } + end + + context 'with protected branch' do + with_them do + before do + project.add_user(user, access_level) unless access_level.nil? + create(:protected_branch, :no_one_can_push, + name: 'master', project: project) + end - context 'when team member has ability to stop environment' do - it 'does includes ability to stop environment' do - expect(policy).to be_allowed :stop_environment + it { expect(policy).to be_disallowed :stop_environment } + end + + context 'when an admin user' do + let(:user) { create(:user, :admin) } + + it { expect(policy).to be_allowed :stop_environment } + end 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) + context 'without stop action' do + let(:environment) do + create(:environment, project: project) + end + + where(:access_level, :allowed?) do + nil | false + :guest | false + :reporter | false + :developer | false + :master | true end - it 'does not include ability to stop environment' do - expect(policy).to be_disallowed :stop_environment + with_them do + before do + project.add_user(user, access_level) unless access_level.nil? + end + + it { expect(policy.allowed?(:stop_environment)).to be allowed? } + end + + context 'when an admin user' do + let(:user) { create(:user, :admin) } + + it { expect(policy).to be_allowed :stop_environment } end end end + + context 'when project is public' do + let(:project) { create(:project, :public, :repository) } + + include_examples 'project permissions' + end + + context 'when project is private' do + let(:project) { create(:project, :private, :repository) } + + include_examples 'project permissions' + end end end diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb index 8f32c5639a1..b7324a26ed2 100644 --- a/spec/serializers/environment_entity_spec.rb +++ b/spec/serializers/environment_entity_spec.rb @@ -1,8 +1,9 @@ require 'spec_helper' describe EnvironmentEntity do + let(:request) { double('request') } let(:entity) do - described_class.new(environment, request: double) + described_class.new(environment, request: spy('request')) end let(:environment) { create(:environment) } diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb index ca9b520fb38..0f0ab5ac796 100644 --- a/spec/serializers/environment_serializer_spec.rb +++ b/spec/serializers/environment_serializer_spec.rb @@ -54,7 +54,9 @@ describe EnvironmentSerializer do context 'when representing environments within folders' do let(:serializer) do - described_class.new(project: project).within_folders + described_class + .new(current_user: user, project: project) + .within_folders end let(:resource) { Environment.all } @@ -123,7 +125,8 @@ describe EnvironmentSerializer do let(:pagination) { { page: 1, per_page: 2 } } let(:serializer) do - described_class.new(project: project) + described_class + .new(current_user: user, project: project) .with_pagination(request, response) end @@ -169,7 +172,8 @@ describe EnvironmentSerializer do context 'when grouping environments within folders' do let(:serializer) do - described_class.new(project: project) + described_class + .new(current_user: user, project: project) .with_pagination(request, response) .within_folders end |