Commit 5bf2e672 authored by Alex Kalderimis's avatar Alex Kalderimis

Add specs verifying use of build data in hooks

parent 7e275e62
......@@ -1047,7 +1047,7 @@ module Ci
end
def build_data
@build_data ||= Gitlab::DataBuilder::Build.build(self)
strong_memoize(:build_data) { Gitlab::DataBuilder::Build.build(self) }
end
def successful_deployment_status
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Ci::Build do
include AfterNextHelpers
let_it_be(:user) { create(:user) }
let_it_be(:group, reload: true) { create(:group) }
let_it_be(:project, reload: true) { create(:project, :repository, group: group) }
......@@ -4679,25 +4681,30 @@ RSpec.describe Ci::Build do
end
describe '#execute_hooks' do
before do
build.clear_memoization(:build_data)
end
context 'with project hooks' do
let(:build_data) { double(:BuildData, dup: double(:DupedData)) }
before do
create(:project_hook, project: project, job_events: true)
end
it 'execute hooks' do
expect_any_instance_of(ProjectHook).to receive(:async_execute)
it 'calls project.execute_hooks(build_data, :job_hooks)' do
expect(::Gitlab::DataBuilder::Build)
.to receive(:build).with(build).and_return(build_data)
expect(build.project)
.to receive(:execute_hooks).with(build_data.dup, :job_hooks)
build.execute_hooks
end
end
context 'without relevant project hooks' do
before do
create(:project_hook, project: project, job_events: false)
end
it 'does not execute a hook' do
expect_any_instance_of(ProjectHook).not_to receive(:async_execute)
context 'without project hooks' do
it 'does not call project.execute_hooks' do
expect(build.project).not_to receive(:execute_hooks)
build.execute_hooks
end
......@@ -4708,7 +4715,7 @@ RSpec.describe Ci::Build do
create(:service, active: true, job_events: true, project: project)
end
it 'execute services' do
it 'executes services' do
expect_any_instance_of(Service).to receive(:async_execute)
build.execute_hooks
......@@ -4720,7 +4727,7 @@ RSpec.describe Ci::Build do
create(:service, active: true, job_events: false, project: project)
end
it 'execute services' do
it 'does not execute services' do
expect_any_instance_of(Service).not_to receive(:async_execute)
build.execute_hooks
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment