extract method to adhere to "tell, don't ask"

This commit is contained in:
Alexis Reigel 2018-02-26 16:20:29 +01:00
parent e13026a378
commit 9447e5c27d
No known key found for this signature in database
GPG key ID: 55ADA7C7B683B329
3 changed files with 33 additions and 1 deletions

View file

@ -217,6 +217,12 @@ module Ci
end
end
def invalidate_build_cache!(build)
if can_pick?(build)
tick_runner_queue
end
end
private
def cleanup_runner_queue

View file

@ -16,7 +16,7 @@ module Ci
def tick_for(build, runners)
runners.each do |runner|
runner.tick_runner_queue if runner.can_pick?(build)
runner.invalidate_build_cache!(build)
end
end
end

View file

@ -858,4 +858,30 @@ describe Ci::Runner do
end
end
end
describe '#invalidate_build_cache!' do
context 'runner can pick the build' do
it 'calls #tick_runner_queue' do
ci_build = build :ci_build
runner = build :ci_runner
allow(runner).to receive(:can_pick?).with(ci_build).and_return(true)
expect(runner).to receive(:tick_runner_queue)
runner.invalidate_build_cache!(ci_build)
end
end
context 'runner cannot pick the build' do
it 'does not call #tick_runner_queue' do
ci_build = build :ci_build
runner = build :ci_runner
allow(runner).to receive(:can_pick?).with(ci_build).and_return(false)
expect(runner).not_to receive(:tick_runner_queue)
runner.invalidate_build_cache!(ci_build)
end
end
end
end