summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-07-17 01:48:51 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-07-18 14:46:20 +0200
commite00da96c88314df79600e7848ae6fe7e4a29af2e (patch)
tree48d3da01b161442812fb83939f4cbeafdf9be7e3 /spec/models
parent3248c9fb56e5d5cb8980cb37effec1ee2f4f664a (diff)
downloadgitlab-ce-e00da96c88314df79600e7848ae6fe7e4a29af2e.tar.gz
Improve manual actions code and add model, service and feature tests
Manual actions are accessible from: - Pipelines - Builds - Environments - Deployments
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/build_spec.rb51
-rw-r--r--spec/models/ci/pipeline_spec.rb24
-rw-r--r--spec/models/deployment_spec.rb1
3 files changed, 76 insertions, 0 deletions
diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb
index 481416319dd..4846c87a100 100644
--- a/spec/models/build_spec.rb
+++ b/spec/models/build_spec.rb
@@ -670,4 +670,55 @@ describe Ci::Build, models: true do
end
end
end
+
+ describe '#manual?' do
+ before do
+ build.update(when: value)
+ end
+
+ subject { build.manual? }
+
+ context 'when is set to manual' do
+ let(:value) { 'manual' }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'when set to something else' do
+ let(:value) { 'something else' }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe '#other_actions' do
+ let(:build) { create(:ci_build, :manual, pipeline: pipeline) }
+ let!(:other_build) { create(:ci_build, :manual, pipeline: pipeline, name: 'other action') }
+
+ subject { build.other_actions }
+
+ it 'returns other actions' do
+ is_expected.to contain_exactly(other_build)
+ end
+ end
+
+ describe '#play' do
+ let(:build) { create(:ci_build, :manual, pipeline: pipeline) }
+
+ subject { build.play }
+
+ it 'enques a build' do
+ is_expected.to be_pending
+ is_expected.to eq(build)
+ end
+
+ context 'for success build' do
+ before { build.queue }
+
+ it 'creates a new build' do
+ is_expected.to be_pending
+ is_expected.not_to eq(build)
+ end
+ end
+ end
end
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 10db79bd15f..887f36db519 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -416,4 +416,28 @@ describe Ci::Pipeline, models: true do
end
end
end
+
+ describe '#manual_actions' do
+ subject { pipeline.manual_actions }
+
+ it 'when none defined' do
+ is_expected.to be_empty
+ end
+
+ context 'when action defined' do
+ let!(:manual) { create(:ci_build, :manual, pipeline: pipeline, name: 'deploy') }
+
+ it 'returns one action' do
+ is_expected.to contain_exactly(manual)
+ end
+
+ context 'there are multiple of the same name' do
+ let!(:manual2) { create(:ci_build, :manual, pipeline: pipeline, name: 'deploy') }
+
+ it 'returns latest one' do
+ is_expected.to contain_exactly(manual2)
+ end
+ end
+ end
+ end
end
diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb
index b273018707f..7df3df4bb9e 100644
--- a/spec/models/deployment_spec.rb
+++ b/spec/models/deployment_spec.rb
@@ -11,6 +11,7 @@ describe Deployment, models: true do
it { is_expected.to delegate_method(:name).to(:environment).with_prefix }
it { is_expected.to delegate_method(:commit).to(:project) }
it { is_expected.to delegate_method(:commit_title).to(:commit).as(:try) }
+ it { is_expected.to delegate_method(:manual_actions).to(:deployable).as(:try) }
it { is_expected.to validate_presence_of(:ref) }
it { is_expected.to validate_presence_of(:sha) }