diff options
author | Rémy Coutable <remy@rymai.me> | 2017-02-07 16:44:54 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-02-07 16:44:54 +0000 |
commit | f7d900aa42f01bf24f35162aa042a0725a6b8bdc (patch) | |
tree | 9fe0400b3d941cc2b908c42d6543b06f5bc78211 /spec | |
parent | a658654c695b81b2b8a28af01b273e6e3db08184 (diff) | |
parent | 0886b0fe98c640579fa1e4e88a28c9a62b866f2a (diff) | |
download | gitlab-ce-f7d900aa42f01bf24f35162aa042a0725a6b8bdc.tar.gz |
Merge branch '24147-delete-env-button' into 'master'
Makes stop button visible in environment page
Closes #24147
See merge request !7379
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/environment_spec.rb | 48 | ||||
-rw-r--r-- | spec/features/environments_spec.rb | 16 | ||||
-rw-r--r-- | spec/javascripts/environments/environment_item_spec.js.es6 | 2 | ||||
-rw-r--r-- | spec/javascripts/environments/mock_data.js.es6 | 10 | ||||
-rw-r--r-- | spec/models/deployment_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/environment_spec.rb | 34 | ||||
-rw-r--r-- | spec/services/ci/stop_environments_service_spec.rb | 4 |
7 files changed, 84 insertions, 34 deletions
diff --git a/spec/features/environment_spec.rb b/spec/features/environment_spec.rb index 511c95b758f..2f49e89b4e4 100644 --- a/spec/features/environment_spec.rb +++ b/spec/features/environment_spec.rb @@ -64,10 +64,6 @@ feature 'Environment', :feature do expect(page).to have_link('Re-deploy') end - scenario 'does not show stop button' do - expect(page).not_to have_link('Stop') - end - scenario 'does not show terminal button' do expect(page).not_to have_terminal_button end @@ -116,27 +112,43 @@ feature 'Environment', :feature do end end - context 'with stop action' do - given(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'close_app') } - given(:deployment) { create(:deployment, environment: environment, deployable: build, on_stop: 'close_app') } + context 'when environment is available' do + context 'with stop action' do + given(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'close_app') } + given(:deployment) { create(:deployment, environment: environment, deployable: build, on_stop: 'close_app') } - scenario 'does show stop button' do - expect(page).to have_link('Stop') - end + scenario 'does show stop button' do + expect(page).to have_link('Stop') + end - scenario 'does allow to stop environment' do - click_link('Stop') + scenario 'does allow to stop environment' do + click_link('Stop') - expect(page).to have_content('close_app') - end + expect(page).to have_content('close_app') + end - context 'for reporter' do - let(:role) { :reporter } + context 'for reporter' do + let(:role) { :reporter } - scenario 'does not show stop button' do - expect(page).not_to have_link('Stop') + scenario 'does not show stop button' do + expect(page).not_to have_link('Stop') + end end end + + context 'without stop action' do + scenario 'does allow to stop environment' do + click_link('Stop') + end + end + end + + context 'when environment is stopped' do + given(:environment) { create(:environment, project: project, state: :stopped) } + + scenario 'does not show stop button' do + expect(page).not_to have_link('Stop') + end end end end diff --git a/spec/features/environments_spec.rb b/spec/features/environments_spec.rb index c033b693213..78be7d36f47 100644 --- a/spec/features/environments_spec.rb +++ b/spec/features/environments_spec.rb @@ -52,6 +52,22 @@ feature 'Environments page', :feature, :js do scenario 'does show no deployments' do expect(page).to have_content('No deployments yet') end + + context 'for available environment' do + given(:environment) { create(:environment, project: project, state: :available) } + + scenario 'does not shows stop button' do + expect(page).not_to have_selector('.stop-env-link') + end + end + + context 'for stopped environment' do + given(:environment) { create(:environment, project: project, state: :stopped) } + + scenario 'does not shows stop button' do + expect(page).not_to have_selector('.stop-env-link') + end + end end context 'with deployments' do diff --git a/spec/javascripts/environments/environment_item_spec.js.es6 b/spec/javascripts/environments/environment_item_spec.js.es6 index 9858f346c83..d87cc0996c9 100644 --- a/spec/javascripts/environments/environment_item_spec.js.es6 +++ b/spec/javascripts/environments/environment_item_spec.js.es6 @@ -119,7 +119,7 @@ describe('Environment item', () => { }, ], }, - 'stoppable?': true, + 'stop_action?': true, environment_path: 'root/ci-folders/environments/31', created_at: '2016-11-07T11:11:16.525Z', updated_at: '2016-11-10T15:55:58.778Z', diff --git a/spec/javascripts/environments/mock_data.js.es6 b/spec/javascripts/environments/mock_data.js.es6 index 58f6fb96afb..80e1cbc6f4d 100644 --- a/spec/javascripts/environments/mock_data.js.es6 +++ b/spec/javascripts/environments/mock_data.js.es6 @@ -50,7 +50,7 @@ const environmentsList = [ }, manual_actions: [], }, - 'stoppable?': true, + 'stop_action?': true, environment_path: '/root/ci-folders/environments/31', created_at: '2016-11-07T11:11:16.525Z', updated_at: '2016-11-07T11:11:16.525Z', @@ -105,7 +105,7 @@ const environmentsList = [ }, manual_actions: [], }, - 'stoppable?': false, + 'stop_action?': false, environment_path: '/root/ci-folders/environments/31', created_at: '2016-11-07T11:11:16.525Z', updated_at: '2016-11-07T11:11:16.525Z', @@ -116,7 +116,7 @@ const environmentsList = [ state: 'available', environment_type: 'review', last_deployment: null, - 'stoppable?': true, + 'stop_action?': true, environment_path: '/root/ci-folders/environments/31', created_at: '2016-11-07T11:11:16.525Z', updated_at: '2016-11-07T11:11:16.525Z', @@ -127,7 +127,7 @@ const environmentsList = [ state: 'available', environment_type: 'review', last_deployment: null, - 'stoppable?': true, + 'stop_action?': true, environment_path: '/root/ci-folders/environments/31', created_at: '2016-11-07T11:11:16.525Z', updated_at: '2016-11-07T11:11:16.525Z', @@ -143,7 +143,7 @@ const environment = { external_url: 'http://production.', environment_type: null, last_deployment: {}, - 'stoppable?': false, + 'stop_action?': false, environment_path: '/root/review-app/environments/4', stop_path: '/root/review-app/environments/4/stop', created_at: '2016-12-16T11:51:04.690Z', diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index fc4435a2f64..080ff2f3f43 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -77,8 +77,8 @@ describe Deployment, models: true do end end - describe '#stoppable?' do - subject { deployment.stoppable? } + describe '#stop_action?' do + subject { deployment.stop_action? } context 'when no other actions' do let(:deployment) { build(:deployment) } diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index eba392044bf..8b57d8600fe 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -112,8 +112,8 @@ describe Environment, models: true do end end - describe '#stoppable?' do - subject { environment.stoppable? } + describe '#stop_action?' do + subject { environment.stop_action? } context 'when no other actions' do it { is_expected.to be_falsey } @@ -142,17 +142,39 @@ describe Environment, models: true do end end - describe '#stop!' do + describe '#stop_with_action!' do let(:user) { create(:user) } - subject { environment.stop!(user) } + subject { environment.stop_with_action!(user) } before do - expect(environment).to receive(:stoppable?).and_call_original + expect(environment).to receive(:available?).and_call_original end context 'when no other actions' do - it { is_expected.to be_nil } + context 'environment is available' do + before do + environment.update(state: :available) + end + + it do + subject + + expect(environment).to be_stopped + end + end + + context 'environment is already stopped' do + before do + environment.update(state: :stopped) + end + + it do + subject + + expect(environment).to be_stopped + end + end end context 'when matching action is defined' do diff --git a/spec/services/ci/stop_environments_service_spec.rb b/spec/services/ci/stop_environments_service_spec.rb index 6f7d1a5d28d..560f83d94f7 100644 --- a/spec/services/ci/stop_environments_service_spec.rb +++ b/spec/services/ci/stop_environments_service_spec.rb @@ -42,10 +42,10 @@ describe Ci::StopEnvironmentsService, services: true do end end - context 'when environment is not stoppable' do + context 'when environment is not stopped' do before do allow_any_instance_of(Environment) - .to receive(:stoppable?).and_return(false) + .to receive(:state).and_return(:stopped) end it 'does not stop environment' do |