diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-10-01 17:22:41 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-10-01 17:22:41 +0000 |
commit | 2176477de86ec3580461807075c42da982c5f988 (patch) | |
tree | 31372cb3e151afcdea602021cf2f5d64bc213899 /spec | |
parent | 34d24c1ff5a081eb34de455bf8edf0c8c7ac15c4 (diff) | |
parent | 57a4ee88aeb4f1f67e54544229ebb86540dac49f (diff) | |
download | gitlab-ce-2176477de86ec3580461807075c42da982c5f988.tar.gz |
Merge branch 'variables_in_events' into 'master'
Add variables on pipeline webhook
See merge request gitlab-org/gitlab-ce!18171
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/data_builder/pipeline_spec.rb | 47 | ||||
-rw-r--r-- | spec/models/ci/pipeline_variable_spec.rb | 9 |
2 files changed, 41 insertions, 15 deletions
diff --git a/spec/lib/gitlab/data_builder/pipeline_spec.rb b/spec/lib/gitlab/data_builder/pipeline_spec.rb index 9ca960502c8..98f1696badb 100644 --- a/spec/lib/gitlab/data_builder/pipeline_spec.rb +++ b/spec/lib/gitlab/data_builder/pipeline_spec.rb @@ -6,10 +6,10 @@ describe Gitlab::DataBuilder::Pipeline do let(:pipeline) do create(:ci_pipeline, - project: project, - status: 'success', - sha: project.commit.sha, - ref: project.default_branch) + project: project, + status: 'success', + sha: project.commit.sha, + ref: project.default_branch) end let!(:build) { create(:ci_build, pipeline: pipeline) } @@ -20,18 +20,35 @@ describe Gitlab::DataBuilder::Pipeline do let(:build_data) { data[:builds].first } let(:project_data) { data[:project] } - it { expect(attributes).to be_a(Hash) } - it { expect(attributes[:ref]).to eq(pipeline.ref) } - it { expect(attributes[:sha]).to eq(pipeline.sha) } - it { expect(attributes[:tag]).to eq(pipeline.tag) } - it { expect(attributes[:id]).to eq(pipeline.id) } - it { expect(attributes[:status]).to eq(pipeline.status) } - it { expect(attributes[:detailed_status]).to eq('passed') } + it 'has correct attributes' do + expect(attributes).to be_a(Hash) + expect(attributes[:ref]).to eq(pipeline.ref) + expect(attributes[:sha]).to eq(pipeline.sha) + expect(attributes[:tag]).to eq(pipeline.tag) + expect(attributes[:id]).to eq(pipeline.id) + expect(attributes[:status]).to eq(pipeline.status) + expect(attributes[:detailed_status]).to eq('passed') + expect(build_data).to be_a(Hash) + expect(build_data[:id]).to eq(build.id) + expect(build_data[:status]).to eq(build.status) + expect(project_data).to eq(project.hook_attrs(backward: false)) + end - it { expect(build_data).to be_a(Hash) } - it { expect(build_data[:id]).to eq(build.id) } - it { expect(build_data[:status]).to eq(build.status) } + context 'pipeline without variables' do + it 'has empty variables hash' do + expect(attributes[:variables]).to be_a(Array) + expect(attributes[:variables]).to be_empty() + end + end - it { expect(project_data).to eq(project.hook_attrs(backward: false)) } + context 'pipeline with variables' do + let(:build) { create(:ci_build, pipeline: pipeline) } + let(:data) { described_class.build(pipeline) } + let(:attributes) { data[:object_attributes] } + let!(:pipeline_variable) { create(:ci_pipeline_variable, pipeline: pipeline, key: 'TRIGGER_KEY_1', value: 'TRIGGER_VALUE_1') } + + it { expect(attributes[:variables]).to be_a(Array) } + it { expect(attributes[:variables]).to contain_exactly({ key: 'TRIGGER_KEY_1', value: 'TRIGGER_VALUE_1' }) } + end end end diff --git a/spec/models/ci/pipeline_variable_spec.rb b/spec/models/ci/pipeline_variable_spec.rb index 889c243c8d8..03d09cb31d6 100644 --- a/spec/models/ci/pipeline_variable_spec.rb +++ b/spec/models/ci/pipeline_variable_spec.rb @@ -5,4 +5,13 @@ describe Ci::PipelineVariable do it { is_expected.to include_module(HasVariable) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_id) } + + describe '#hook_attrs' do + let(:variable) { create(:ci_pipeline_variable, key: 'foo', value: 'bar') } + + subject { variable.hook_attrs } + + it { is_expected.to be_a(Hash) } + it { is_expected.to eq({ key: 'foo', value: 'bar' }) } + end end |