Commit ab8ef17f authored by Grzegorz Bizon's avatar Grzegorz Bizon Committed by Annabel Dunstone Gray

Extend merge request tests for all commits method

parent d5b1d0ea
......@@ -798,7 +798,8 @@ class MergeRequest < ActiveRecord::Base
if persisted?
merge_request_diffs.flat_map(&:commits_sha).uniq
else
compare_commits.reverse.map(&:id)
cached_commits = compare_commits.to_a.reverse.map(&:id)
cached_commits.any? ? cached_commits : [diff_head_sha]
end
end
......
......@@ -640,6 +640,7 @@ describe MergeRequest, models: true do
end
describe '#all_commits_sha' do
context 'when merge request is persisted' do
let(:all_commits_sha) do
subject.merge_request_diffs.flat_map(&:commits).map(&:sha).uniq
end
......@@ -669,6 +670,29 @@ describe MergeRequest, models: true do
end
end
context 'when merge request is not persisted' do
context 'when compare commits are set in the service' do
let(:commit) { spy('commit') }
subject do
build(:merge_request, compare_commits: [commit, commit])
end
it 'returns commits from compare commits temporary data' do
expect(subject.all_commits_sha).to eq [commit, commit]
end
end
context 'when compare commits are not set in the service' do
subject { build(:merge_request) }
it 'returns array with diff head sha element only' do
expect(subject.all_commits_sha).to eq [subject.diff_head_sha]
end
end
end
end
describe '#participants' do
let(:project) { create(:project, :public) }
......
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