Commit 8661a35e authored by Olivier Gonzalez's avatar Olivier Gonzalez

Add pipeline.default_branch? mehod

Helps to know if the pipeline ref matches  the project's default branch
parent dfb9ac3a
......@@ -627,6 +627,10 @@ module Ci
end
end
def default_branch?
ref == project.default_branch
end
private
def ci_yaml_from_repo
......
......@@ -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
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