Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-10-18 13:02:50 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-10-18 13:02:50 +0300
commit0aa232704c5df68f0ed111e355a07cfaf241e8a9 (patch)
treee8e91070b0cde623325f6af596d9482ba0681cc6 /spec/models
parent66ff67b063f2c8d06f40625595c4208c33ffd1f1 (diff)
Add `stop!` to `environment`
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/environment_spec.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 1c1fef57fc4..e1755f940b3 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -128,4 +128,41 @@ describe Environment, models: true do
end
end
end
+
+ describe '#stop!' do
+ let(:user) { create(:user) }
+
+ subject { environment.stop!(user) }
+
+ before do
+ expect(environment).to receive(:stoppable?).and_call_original
+ end
+
+ context 'when no other actions' do
+ it { is_expected.to be_nil }
+ end
+
+ context 'when matching action is defined' do
+ let(:build) { create(:ci_build) }
+ let!(:deployment) { create(:deployment, environment: environment, deployable: build, on_stop: 'close_app') }
+
+ context 'when action did not yet finish' do
+ let!(:close_action) { create(:ci_build, :manual, pipeline: build.pipeline, name: 'close_app') }
+
+ it 'returns the same action' do
+ is_expected.to eq(close_action)
+ is_expected.to include(user: user)
+ end
+ end
+
+ context 'if action did finish' do
+ let!(:close_action) { create(:ci_build, :manual, :success, pipeline: build.pipeline, name: 'close_app') }
+
+ it 'returns a new action of the same type' do
+ is_expected.to be_persisted
+ is_expected.to include(name: close_action.name, user: user)
+ end
+ end
+ end
+ end
end