diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-10-18 12:02:50 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-10-18 12:02:50 +0200 |
commit | 0aa232704c5df68f0ed111e355a07cfaf241e8a9 (patch) | |
tree | e8e91070b0cde623325f6af596d9482ba0681cc6 /spec/models/environment_spec.rb | |
parent | 66ff67b063f2c8d06f40625595c4208c33ffd1f1 (diff) | |
download | gitlab-ce-0aa232704c5df68f0ed111e355a07cfaf241e8a9.tar.gz |
Add `stop!` to `environment`
Diffstat (limited to 'spec/models/environment_spec.rb')
-rw-r--r-- | spec/models/environment_spec.rb | 37 |
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 |