summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-08-10 18:40:10 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-08-10 18:40:10 +0800
commit3eae0641ef0708f9b223abbe0070e332ea0b20ac (patch)
tree89e0983b50ae3584b58e99dec065857bdef4a270 /spec
parent6234b32785061330e62c5681509cec5bd98e5302 (diff)
downloadgitlab-ce-3eae0641ef0708f9b223abbe0070e332ea0b20ac.tar.gz
Introduce Pipeline#latest and Pipeline.latest_for:
So that we could easily access it for the view
Diffstat (limited to 'spec')
-rw-r--r--spec/models/ci/pipeline_spec.rb48
1 files changed, 46 insertions, 2 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index ccee591cf7a..556a6e1b59a 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
describe Ci::Pipeline, models: true do
- let(:project) { FactoryGirl.create :empty_project }
- let(:pipeline) { FactoryGirl.create :ci_pipeline, project: project }
+ let(:project) { create(:empty_project) }
+ let(:pipeline) { create(:ci_pipeline, project: project) }
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:user) }
@@ -481,6 +481,50 @@ describe Ci::Pipeline, models: true do
end
end
+ context 'with non-empty project' do
+ let(:project) { create(:project) }
+ let(:pipeline) { create_pipeline }
+
+ describe '#latest?' do
+ context 'with latest sha' do
+ it 'returns true' do
+ expect(pipeline).to be_latest
+ end
+ end
+
+ context 'with not latest sha' do
+ before do
+ pipeline.update(
+ sha: project.commit("#{project.default_branch}~1").sha)
+ end
+
+ it 'returns false' do
+ expect(pipeline).not_to be_latest
+ end
+ end
+ end
+
+ describe '#latest' do
+ let(:previous_pipeline) { create_pipeline }
+
+ before do
+ previous_pipeline
+ pipeline
+ end
+
+ it 'gives the latest pipeline' do
+ expect(previous_pipeline.latest).to eq(pipeline)
+ end
+ end
+
+ def create_pipeline
+ create(:ci_pipeline,
+ project: project,
+ ref: project.default_branch,
+ sha: project.commit.sha)
+ end
+ end
+
describe '#manual_actions' do
subject { pipeline.manual_actions }