summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-10-14 19:13:11 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-10-14 19:13:11 +0800
commitb5f9d4c4bc48b252d3175432a3bb6fb1ca394af9 (patch)
tree45c5305aaf0baf3b36c9692d8e37cba1011935b1 /spec
parent5b9971fa9b967eb5591242155d6f5fce2c292b7d (diff)
downloadgitlab-ce-b5f9d4c4bc48b252d3175432a3bb6fb1ca394af9.tar.gz
Introduce Pipeline#merge_requests_with_active_first,
Feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6019#note_16956802
Diffstat (limited to 'spec')
-rw-r--r--spec/models/ci/pipeline_spec.rb31
-rw-r--r--spec/models/merge_request_spec.rb10
2 files changed, 40 insertions, 1 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 550a890797e..2a0b00dc545 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -523,4 +523,35 @@ describe Ci::Pipeline, models: true do
expect(pipeline.merge_requests).to be_empty
end
end
+
+ describe '#merge_requests_with_active_first' do
+ let(:project) { create(:project) }
+
+ let(:pipeline) do
+ create(:ci_empty_pipeline,
+ status: 'created',
+ project: project,
+ ref: 'master',
+ sha: project.repository.commit('master').sha)
+ end
+
+ let!(:merge_requests) do
+ [create_merge_request(:merged, Time.at(0)),
+ create_merge_request(:merged, Time.at(9)),
+ create_merge_request(:opened, Time.at(0))]
+ end
+
+ it 'returns opened/recent merge requests first, then closed ones' do
+ expect(pipeline.merge_requests_with_active_first).
+ to eq(merge_requests.reverse)
+ end
+
+ def create_merge_request(state, updated_at)
+ create(:merge_request,
+ source_project: project,
+ source_branch: pipeline.ref,
+ state: state,
+ updated_at: updated_at)
+ end
+ end
end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 38b6da50168..8cf53fd1dee 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -58,6 +58,14 @@ describe MergeRequest, models: true do
it { is_expected.to respond_to(:merge_when_build_succeeds) }
end
+ describe '#state_priority' do
+ it 'returns the priority of state' do
+ %w[opened reopened closed merged locked].each.with_index do |state, idx|
+ expect(MergeRequest.new(state: state).state_priority).to eq(idx)
+ end
+ end
+ end
+
describe '.in_projects' do
it 'returns the merge requests for a set of projects' do
expect(described_class.in_projects(Project.all)).to eq([subject])
@@ -334,7 +342,7 @@ describe MergeRequest, models: true do
wip_title = "WIP: #{subject.title}"
expect(subject.wip_title).to eq wip_title
- end
+ end
it "does not add the WIP: prefix multiple times" do
wip_title = "WIP: #{subject.title}"