diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/finders/merge_requests | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/finders/merge_requests')
-rw-r--r-- | spec/finders/merge_requests/oldest_per_commit_finder_spec.rb | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/spec/finders/merge_requests/oldest_per_commit_finder_spec.rb b/spec/finders/merge_requests/oldest_per_commit_finder_spec.rb index 4e9d021fa5d..4724a8eb5c7 100644 --- a/spec/finders/merge_requests/oldest_per_commit_finder_spec.rb +++ b/spec/finders/merge_requests/oldest_per_commit_finder_spec.rb @@ -6,12 +6,20 @@ RSpec.describe MergeRequests::OldestPerCommitFinder do describe '#execute' do it 'returns a Hash mapping commit SHAs to their oldest merge requests' do project = create(:project) + sha1 = Digest::SHA1.hexdigest('foo') + sha2 = Digest::SHA1.hexdigest('bar') + sha3 = Digest::SHA1.hexdigest('baz') mr1 = create(:merge_request, :merged, target_project: project) mr2 = create(:merge_request, :merged, target_project: project) + mr3 = create( + :merge_request, + :merged, + target_project: project, + merge_commit_sha: sha3 + ) + mr1_diff = create(:merge_request_diff, merge_request: mr1) mr2_diff = create(:merge_request_diff, merge_request: mr2) - sha1 = Digest::SHA1.hexdigest('foo') - sha2 = Digest::SHA1.hexdigest('bar') create(:merge_request_diff_commit, merge_request_diff: mr1_diff, sha: sha1) create(:merge_request_diff_commit, merge_request_diff: mr2_diff, sha: sha1) @@ -22,11 +30,16 @@ RSpec.describe MergeRequests::OldestPerCommitFinder do relative_order: 1 ) - commits = [double(:commit, id: sha1), double(:commit, id: sha2)] + commits = [ + double(:commit, id: sha1), + double(:commit, id: sha2), + double(:commit, id: sha3) + ] expect(described_class.new(project).execute(commits)).to eq( sha1 => mr1, - sha2 => mr2 + sha2 => mr2, + sha3 => mr3 ) end @@ -42,5 +55,45 @@ RSpec.describe MergeRequests::OldestPerCommitFinder do expect(described_class.new(mr.target_project).execute(commits)) .to be_empty end + + it 'includes the merge request for a merge commit' do + project = create(:project) + sha = Digest::SHA1.hexdigest('foo') + mr = create( + :merge_request, + :merged, + target_project: project, + merge_commit_sha: sha + ) + + commits = [double(:commit, id: sha)] + + # This expectation is set so we're certain that the merge commit SHAs (if + # a matching merge request is found) aren't also used for finding MRs + # according to diffs. + expect(MergeRequestDiffCommit) + .not_to receive(:oldest_merge_request_id_per_commit) + + expect(described_class.new(project).execute(commits)).to eq(sha => mr) + end + + it 'includes the oldest merge request when a merge commit is present in a newer merge request' do + project = create(:project) + sha = Digest::SHA1.hexdigest('foo') + mr1 = create( + :merge_request, + :merged, + target_project: project, merge_commit_sha: sha + ) + + mr2 = create(:merge_request, :merged, target_project: project) + mr_diff = create(:merge_request_diff, merge_request: mr2) + + create(:merge_request_diff_commit, merge_request_diff: mr_diff, sha: sha) + + commits = [double(:commit, id: sha)] + + expect(described_class.new(project).execute(commits)).to eq(sha => mr1) + end end end |