From afe867921cab046a34bc463840c6e9f5d51f1f70 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 9 Aug 2019 15:41:07 -0700 Subject: Rename branches_exist? -> includes_branches? --- app/workers/post_receive.rb | 2 +- lib/gitlab/git_post_receive.rb | 8 +++----- spec/lib/gitlab/git_post_receive_spec.rb | 8 ++++---- spec/workers/post_receive_spec.rb | 11 ++++++++--- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb index 0865c2f0e0e..d8dfbc0faf7 100644 --- a/app/workers/post_receive.rb +++ b/app/workers/post_receive.rb @@ -43,7 +43,7 @@ class PostReceive return false unless user # Expire the branches cache so we have updated data for this push - post_received.project.repository.expire_branches_cache if post_received.branches_exist? + post_received.project.repository.expire_branches_cache if post_received.includes_branches? post_received.enum_for(:changes_refs).with_index do |(oldrev, newrev, ref), index| service_klass = diff --git a/lib/gitlab/git_post_receive.rb b/lib/gitlab/git_post_receive.rb index 307ec8b2cfb..6c7f23a673c 100644 --- a/lib/gitlab/git_post_receive.rb +++ b/lib/gitlab/git_post_receive.rb @@ -27,12 +27,10 @@ module Gitlab end end - def branches_exist? - changes_refs do |_oldrev, _newrev, ref| - return true if Gitlab::Git.branch_ref?(ref) # rubocop:disable Cop/AvoidReturnFromBlocks + def includes_branches? + enum_for(:changes_refs).any? do |_oldrev, _newrev, ref| + Gitlab::Git.branch_ref?(ref) end - - false end private diff --git a/spec/lib/gitlab/git_post_receive_spec.rb b/spec/lib/gitlab/git_post_receive_spec.rb index f4a10d8d984..1911e954df9 100644 --- a/spec/lib/gitlab/git_post_receive_spec.rb +++ b/spec/lib/gitlab/git_post_receive_spec.rb @@ -7,7 +7,7 @@ describe ::Gitlab::GitPostReceive do subject { described_class.new(project, "project-#{project.id}", changes.dup, {}) } - describe '#branches_exist?' do + describe '#includes_branches?' do context 'with no branches' do let(:changes) do <<~EOF @@ -18,7 +18,7 @@ describe ::Gitlab::GitPostReceive do end it 'returns false' do - expect(subject.branches_exist?).to be_falsey + expect(subject.includes_branches?).to be_falsey end end @@ -32,7 +32,7 @@ describe ::Gitlab::GitPostReceive do end it 'returns true' do - expect(subject.branches_exist?).to be_truthy + expect(subject.includes_branches?).to be_truthy end end @@ -45,7 +45,7 @@ describe ::Gitlab::GitPostReceive do end it 'returns false' do - expect(subject.branches_exist?).to be_falsey + expect(subject.includes_branches?).to be_falsey end end end diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb index 01ccae194fb..081d95d4d79 100644 --- a/spec/workers/post_receive_spec.rb +++ b/spec/workers/post_receive_spec.rb @@ -61,16 +61,21 @@ describe PostReceive do end context "branches" do - let(:changes) { '123456 789012 refs/heads/tést' } + let(:changes) do + <<~EOF + '123456 789012 refs/heads/tést1' + '123456 789012 refs/heads/tést2' + EOF + end it 'expires the branches cache' do - expect(project.repository).to receive(:expire_branches_cache) + expect(project.repository).to receive(:expire_branches_cache).once described_class.new.perform(gl_repository, key_id, base64_changes) end it 'calls Git::BranchPushService' do - expect_next_instance_of(Git::BranchPushService) do |service| + expect_any_instance_of(Git::BranchPushService) do |service| expect(service).to receive(:execute).and_return(true) end -- cgit v1.2.1