diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-14 12:06:30 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-14 12:06:30 +0000 |
commit | d8c06be498acbfc2024c01b6b6b02d120dc499f2 (patch) | |
tree | 9e2e0852c45332d6222898676a2f6f096e600084 /spec/models | |
parent | 2fa7d2ddf6a7004f89616e43b8279229af831e25 (diff) | |
download | gitlab-ce-d8c06be498acbfc2024c01b6b6b02d120dc499f2.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/merge_request_diff_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 46 |
2 files changed, 49 insertions, 5 deletions
diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index b86663fd7d9..0f7f68e0b38 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -378,6 +378,14 @@ describe MergeRequestDiff do expect(diff_with_commits.commit_shas).not_to be_empty expect(diff_with_commits.commit_shas).to all(match(/\h{40}/)) end + + context 'with limit attribute' do + it 'returns limited number of shas' do + expect(diff_with_commits.commit_shas(limit: 2).size).to eq(2) + expect(diff_with_commits.commit_shas(limit: 100).size).to eq(29) + expect(diff_with_commits.commit_shas.size).to eq(29) + end + end end describe '#compare_with' do diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index f775dfb87a2..b19f7a80d63 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -1261,13 +1261,49 @@ describe MergeRequest do end describe '#commit_shas' do - before do - allow(subject.merge_request_diff).to receive(:commit_shas) - .and_return(['sha1']) + context 'persisted merge request' do + context 'with a limit' do + it 'returns a limited number of commit shas' do + expect(subject.commit_shas(limit: 2)).to eq(%w[ + b83d6e391c22777fca1ed3012fce84f633d7fed0 498214de67004b1da3d820901307bed2a68a8ef6 + ]) + end + end + + context 'without a limit' do + it 'returns all commit shas of the merge request diff' do + expect(subject.commit_shas.size).to eq(29) + end + end end - it 'delegates to merge request diff' do - expect(subject.commit_shas).to eq ['sha1'] + context 'new merge request' do + subject { build(:merge_request) } + + context 'compare commits' do + before do + subject.compare_commits = [ + double(sha: 'sha1'), double(sha: 'sha2') + ] + end + + context 'without a limit' do + it 'returns all shas of compare commits' do + expect(subject.commit_shas).to eq(%w[sha2 sha1]) + end + end + + context 'with a limit' do + it 'returns a limited number of shas' do + expect(subject.commit_shas(limit: 1)).to eq(['sha2']) + end + end + end + + it 'returns diff_head_sha as an array' do + expect(subject.commit_shas).to eq([subject.diff_head_sha]) + expect(subject.commit_shas(limit: 2)).to eq([subject.diff_head_sha]) + end end end |