summaryrefslogtreecommitdiff
path: root/spec/models/ci/build_spec.rb
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-09-04 17:17:36 +0900
committerShinya Maeda <shinya@gitlab.com>2017-09-04 21:55:26 +0900
commitfa6b9acaf9759c58353f8407ff20a7d02b8edf92 (patch)
tree501f164216de208239c73889a39ef94e82019099 /spec/models/ci/build_spec.rb
parent3ae2038176b27673b06a040873fdbe19c94d67d3 (diff)
downloadgitlab-ce-fa6b9acaf9759c58353f8407ff20a7d02b8edf92.tar.gz
trigger_variables should consider trigger_request existstance always
Diffstat (limited to 'spec/models/ci/build_spec.rb')
-rw-r--r--spec/models/ci/build_spec.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 08d22f166e4..137c460cce8 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -1690,6 +1690,44 @@ describe Ci::Build do
end
end
+ describe '#trigger_variables' do
+ let(:build) { create(:ci_build, pipeline: pipeline, trigger_request: trigger_request) }
+ let(:trigger) { create(:ci_trigger, project: project) }
+ let(:trigger_request) { create(:ci_trigger_request, pipeline: pipeline, trigger: trigger) }
+
+ subject { build.trigger_variables }
+
+ it { is_expected.to eq(true) }
+
+ context 'when variable is stored in ci_pipeline_variables' do
+ let!(:pipeline_variable) { create(:ci_pipeline_variable, pipeline: pipeline) }
+
+ context 'when pipeline is triggered by trigger API' do
+ it 'returns variables' do
+ is_expected.to eq([pipeline_variable.to_runner_variable])
+ end
+ end
+
+ context 'when pipeline is not triggered by trigger API' do
+ let(:build) { create(:ci_build, pipeline: pipeline) }
+
+ it 'does not return variables' do
+ is_expected.to eq([])
+ end
+ end
+ end
+
+ context 'when variable is stored in ci_trigger_requests.variables' do
+ before do
+ trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' } )
+ end
+
+ it 'returns variables' do
+ is_expected.to eq(trigger_request.user_variables)
+ end
+ end
+ end
+
describe 'state transition: any => [:pending]' do
let(:build) { create(:ci_build, :created) }