From 55de6e15d3b29c89a137e3e8824f02ddc4b7c1e7 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 20 Sep 2016 20:07:56 +0800 Subject: [PATCH] Test against MergeRequest#all_commits_sha, feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6414#note_15750344 So that we could just use it in testing for MergeRequest#all_pipelines --- spec/models/merge_request_spec.rb | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index fb599e1207d..5baed2946e5 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -496,20 +496,18 @@ describe MergeRequest, models: true do describe '#all_pipelines' do shared_examples 'returning pipelines with proper ordering' do - let!(:pipelines) do - subject.merge_request_diffs.flat_map do |diff| - diff.commits.map do |commit| - create(:ci_empty_pipeline, - project: subject.source_project, - sha: commit.id, - ref: subject.source_branch) - end + let!(:all_pipelines) do + subject.all_commits_sha.map do |sha| + create(:ci_empty_pipeline, + project: subject.source_project, + sha: sha, + ref: subject.source_branch) end end it 'returns all pipelines' do expect(subject.all_pipelines).not_to be_empty - expect(subject.all_pipelines).to eq(pipelines.reverse) + expect(subject.all_pipelines).to eq(all_pipelines.reverse) end end @@ -526,6 +524,21 @@ describe MergeRequest, models: true do end end + describe '#all_commits_sha' do + let(:all_commits_sha) do + subject.merge_request_diffs.flat_map(&:commits).map(&:sha).uniq + end + + before do + subject.update(target_branch: 'markdown') + end + + it 'returns all SHA from all merge_request_diffs' do + expect(subject.merge_request_diffs.size).to eq(2) + expect(subject.all_commits_sha).to eq(all_commits_sha) + end + end + describe '#participants' do let(:project) { create(:project, :public) }