summaryrefslogtreecommitdiff
path: root/spec/models/ci/pipeline_spec.rb
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-08-17 13:40:18 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-08-17 13:40:18 +0800
commitf673f1e3bdbab25af50da386b29b3661d2536e95 (patch)
treed0cea7f73321ac340c4baa3e0d5d5f6f25d387e5 /spec/models/ci/pipeline_spec.rb
parent1c88ed7a515141b7468b238a679e2ff5cf86e3f9 (diff)
parent1b338d59f641ce629cbecb839b64c9fd65561276 (diff)
downloadgitlab-ce-f673f1e3bdbab25af50da386b29b3661d2536e95.tar.gz
Merge remote-tracking branch 'upstream/master' into artifacts-from-ref-and-build-name
* upstream/master: (109 commits) Update CHANGELOG for 8.10.6, 8.9.7, and 8.8.8 Updated Akismet documentation Add hover state to todos (!5361) Load issues and merge requests templates from repository Backport EE assertions in protected branch related specs. Revert "Merge branch '19957-write-tests-for-adding-comments-for-different-line-types-in-diff' into 'master'" Fix a missed `before_action` for `AutocompleteController`. Backport `AutocompleteController#load_project` from EE!581. Fix API::BranchesSpec. Fix failing tests relating to backporting ee!581. Revert unrelevant changes Fix the protected branches factory. Improve EE compatibility with protected branch access levels. Move the "update" portion of the protected branch view into a partial. Don't select an access level if already selected. Backport changes from gitlab-org/gitlab-ee!581 to CE. Further refactor and syntax fixes. Upgrade httpclient gem from 2.7.0.1 to 2.8.2. Make rubocop happy Make rubocop happy ...
Diffstat (limited to 'spec/models/ci/pipeline_spec.rb')
-rw-r--r--spec/models/ci/pipeline_spec.rb87
1 files changed, 86 insertions, 1 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 25c3f78c3e1..9c8352a0d7e 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe Ci::Pipeline, models: true do
let(:project) { FactoryGirl.create :empty_project }
- let(:pipeline) { FactoryGirl.create :ci_empty_pipeline, project: project }
+ let(:pipeline) { FactoryGirl.create :ci_empty_pipeline, status: 'created', project: project }
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:user) }
@@ -18,6 +18,8 @@ describe Ci::Pipeline, models: true do
it { is_expected.to respond_to :git_author_email }
it { is_expected.to respond_to :short_sha }
+ it { is_expected.to delegate_method(:stages).to(:statuses) }
+
describe '#valid_commit_sha' do
context 'commit.sha can not start with 00000000' do
before do
@@ -340,4 +342,87 @@ describe Ci::Pipeline, models: true do
it { is_expected.to eq('running') }
end
end
+
+ describe '#execute_hooks' do
+ let!(:build_a) { create_build('a') }
+ let!(:build_b) { create_build('b') }
+
+ let!(:hook) do
+ create(:project_hook, project: project, pipeline_events: enabled)
+ end
+
+ before do
+ ProjectWebHookWorker.drain
+ end
+
+ context 'with pipeline hooks enabled' do
+ let(:enabled) { true }
+
+ before do
+ WebMock.stub_request(:post, hook.url)
+ end
+
+ context 'with multiple builds' do
+ context 'when build is queued' do
+ before do
+ build_a.enqueue
+ build_b.enqueue
+ end
+
+ it 'receive a pending event once' do
+ expect(WebMock).to have_requested_pipeline_hook('pending').once
+ end
+ end
+
+ context 'when build is run' do
+ before do
+ build_a.enqueue
+ build_a.run
+ build_b.enqueue
+ build_b.run
+ end
+
+ it 'receive a running event once' do
+ expect(WebMock).to have_requested_pipeline_hook('running').once
+ end
+ end
+
+ context 'when all builds succeed' do
+ before do
+ build_a.success
+ build_b.success
+ end
+
+ it 'receive a success event once' do
+ expect(WebMock).to have_requested_pipeline_hook('success').once
+ end
+ end
+
+ def have_requested_pipeline_hook(status)
+ have_requested(:post, hook.url).with do |req|
+ json_body = JSON.parse(req.body)
+ json_body['object_attributes']['status'] == status &&
+ json_body['builds'].length == 2
+ end
+ end
+ end
+ end
+
+ context 'with pipeline hooks disabled' do
+ let(:enabled) { false }
+
+ before do
+ build_a.enqueue
+ build_b.enqueue
+ end
+
+ it 'did not execute pipeline_hook after touched' do
+ expect(WebMock).not_to have_requested(:post, hook.url)
+ end
+ end
+
+ def create_build(name)
+ create(:ci_build, :created, pipeline: pipeline, name: name)
+ end
+ end
end