summaryrefslogtreecommitdiff
path: root/spec/models/ci/pipeline_spec.rb
diff options
context:
space:
mode:
authorOlivier Gonzalez <ogonzalez@gitlab.com>2018-10-04 02:23:29 -0400
committerOlivier Gonzalez <ogonzalez@gitlab.com>2018-10-04 02:23:29 -0400
commit8661a35e5f20943ff749093f7f8aeb2758d2a993 (patch)
tree37af5d456a1d4d8ecc39055dc7b8f09a2c0193da /spec/models/ci/pipeline_spec.rb
parentdfb9ac3a5f97a4c556bacea78174836fe7d39145 (diff)
downloadgitlab-ce-8661a35e5f20943ff749093f7f8aeb2758d2a993.tar.gz
Add pipeline.default_branch? mehod
Helps to know if the pipeline ref matches the project's default branch
Diffstat (limited to 'spec/models/ci/pipeline_spec.rb')
-rw-r--r--spec/models/ci/pipeline_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 4755702c0e9..ec0bf580115 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -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