From 1494abe982583c564969baaba7daa251ef333156 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 10 Nov 2016 13:59:26 +0100 Subject: Allow to stop any environment --- spec/features/environments_spec.rb | 22 ++++++++++++++++++---- spec/models/environment_spec.rb | 34 ++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 10 deletions(-) (limited to 'spec') diff --git a/spec/features/environments_spec.rb b/spec/features/environments_spec.rb index b565586ee14..7c9584f6bf1 100644 --- a/spec/features/environments_spec.rb +++ b/spec/features/environments_spec.rb @@ -149,6 +149,24 @@ feature 'Environments', feature: true do scenario 'does show no deployments' do expect(page).to have_content('You don\'t have any deployments right now.') end + + context 'for available environment' do + given(:environment) { create(:environment, project: project, state: :available) } + + scenario 'does allow to stop environment' do + click_link('Stop') + + expect(page).to have_content(environment.name.titleize) + 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_link('Stop') + end + end end context 'with deployments' do @@ -175,10 +193,6 @@ feature 'Environments', feature: true do expect(page).to have_link('Re-deploy') end - scenario 'does not show stop button' do - expect(page).not_to have_link('Stop') - end - context 'with manual action' do given(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'deploy to production') } diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index a94e6d0165f..b860ba2a26c 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -99,8 +99,8 @@ describe Environment, models: true do end end - describe '#stoppable?' do - subject { environment.stoppable? } + describe '#can_run_stop_action?' do + subject { environment.can_run_stop_action? } context 'when no other actions' do it { is_expected.to be_falsey } @@ -129,17 +129,39 @@ describe Environment, models: true do end end - describe '#stop!' do + describe '#run_stop!' do let(:user) { create(:user) } - subject { environment.stop!(user) } + subject { environment.run_stop!(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 -- cgit v1.2.1 From 5f106512be09b6230080c5cff7eb7a7f896284b9 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Thu, 10 Nov 2016 16:03:43 +0000 Subject: Adds tests Adds changelog entry in the correct place --- spec/features/environments_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec') diff --git a/spec/features/environments_spec.rb b/spec/features/environments_spec.rb index 7c9584f6bf1..eded771201b 100644 --- a/spec/features/environments_spec.rb +++ b/spec/features/environments_spec.rb @@ -239,6 +239,14 @@ feature 'Environments', feature: true do end end end + + context 'whitout stop action'do + scenario 'does allow to stop environment' do + click_link('Stop') + + expect(page).to have_content(environment.name.capitalize) + end + end end end end -- cgit v1.2.1 From 8faabdf7d33b575de11b043cfe6698021d33a973 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Fri, 11 Nov 2016 10:23:44 +0000 Subject: Fix rubocop error --- spec/features/environments_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/features/environments_spec.rb b/spec/features/environments_spec.rb index eded771201b..f75b197f4fe 100644 --- a/spec/features/environments_spec.rb +++ b/spec/features/environments_spec.rb @@ -240,7 +240,7 @@ feature 'Environments', feature: true do end end - context 'whitout stop action'do + context 'whitout stop action' do scenario 'does allow to stop environment' do click_link('Stop') -- cgit v1.2.1 From 1664354c65c103bd3ad55ebe32e84635bef22a6d Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 6 Feb 2017 16:50:03 +0100 Subject: Update changes --- spec/features/environment_spec.rb | 48 ++++++++++++++-------- spec/models/environment_spec.rb | 8 ++-- spec/services/ci/stop_environments_service_spec.rb | 4 +- 3 files changed, 36 insertions(+), 24 deletions(-) (limited to 'spec') 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/models/environment_spec.rb b/spec/models/environment_spec.rb index 1ac5e0413ee..ffce6847ff3 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 '#can_run_stop_action?' do - subject { environment.can_run_stop_action? } + describe '#stoppable?' do + subject { environment.stoppable? } context 'when no other actions' do it { is_expected.to be_falsey } @@ -142,10 +142,10 @@ describe Environment, models: true do end end - describe '#run_stop!' do + describe '#stop_with_action!' do let(:user) { create(:user) } - subject { environment.run_stop!(user) } + subject { environment.stop_with_action!(user) } before do expect(environment).to receive(:available?).and_call_original 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 -- cgit v1.2.1 From bc66944248bf62816f830b5769449c2c3a9dbd04 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 7 Feb 2017 13:30:33 +0100 Subject: Fix stoppable? --- spec/javascripts/environments/environment_item_spec.js.es6 | 2 +- spec/javascripts/environments/mock_data.js.es6 | 10 +++++----- spec/models/deployment_spec.rb | 4 ++-- spec/models/environment_spec.rb | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'spec') 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 ffce6847ff3..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 } -- cgit v1.2.1 From 0886b0fe98c640579fa1e4e88a28c9a62b866f2a Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 7 Feb 2017 16:00:44 +0100 Subject: Fix stop action --- spec/features/environments_spec.rb | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'spec') diff --git a/spec/features/environments_spec.rb b/spec/features/environments_spec.rb index 010186d77fa..78be7d36f47 100644 --- a/spec/features/environments_spec.rb +++ b/spec/features/environments_spec.rb @@ -56,10 +56,8 @@ feature 'Environments page', :feature, :js do context 'for available environment' do given(:environment) { create(:environment, project: project, state: :available) } - scenario 'does allow to stop environment' do - click_link('Stop') - - expect(page).to have_content(environment.name.titleize) + scenario 'does not shows stop button' do + expect(page).not_to have_selector('.stop-env-link') end end @@ -67,7 +65,7 @@ feature 'Environments page', :feature, :js do given(:environment) { create(:environment, project: project, state: :stopped) } scenario 'does not shows stop button' do - expect(page).not_to have_link('Stop') + expect(page).not_to have_selector('.stop-env-link') end end end @@ -186,14 +184,6 @@ feature 'Environments page', :feature, :js do expect(page).not_to have_terminal_button end end - - context 'whitout stop action' do - scenario 'does allow to stop environment' do - click_link('Stop') - - expect(page).to have_content(environment.name.capitalize) - end - end end end end -- cgit v1.2.1