Merge branch '6717_add_security_reports_logic-ce' into 'master'

Add pipeline.default_branch? mehod

See merge request gitlab-org/gitlab-ce!22102
This commit is contained in:
Kamil Trzciński 2018-10-04 09:11:00 +00:00
commit 673971c824
2 changed files with 34 additions and 0 deletions

View File

@ -627,6 +627,10 @@ module Ci
end
end
def default_branch?
ref == project.default_branch
end
private
def ci_yaml_from_repo

View File

@ -1968,4 +1968,34 @@ describe Ci::Pipeline, :mailer do
end
end
end
describe '#default_branch?' do
let(:default_branch) { 'master'}
subject { pipeline.default_branch? }
before do
allow(project).to receive(:default_branch).and_return(default_branch)
end
context 'when pipeline ref is the default branch of the project' do
let(:pipeline) do
build(:ci_empty_pipeline, status: :created, project: project, ref: default_branch)
end
it "returns true" do
expect(subject).to be_truthy
end
end
context 'when pipeline ref is not the default branch of the project' do
let(:pipeline) do
build(:ci_empty_pipeline, status: :created, project: project, ref: 'another_branch')
end
it "returns false" do
expect(subject).to be_falsey
end
end
end
end