diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/finders/merge_requests/oldest_per_commit_finder_spec.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/finders/merge_requests/oldest_per_commit_finder_spec.rb')
-rw-r--r-- | spec/finders/merge_requests/oldest_per_commit_finder_spec.rb | 46 |
1 files changed, 46 insertions, 0 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 new file mode 100644 index 00000000000..4e9d021fa5d --- /dev/null +++ b/spec/finders/merge_requests/oldest_per_commit_finder_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe MergeRequests::OldestPerCommitFinder do + describe '#execute' do + it 'returns a Hash mapping commit SHAs to their oldest merge requests' do + project = create(:project) + mr1 = create(:merge_request, :merged, target_project: project) + mr2 = create(:merge_request, :merged, target_project: project) + 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) + create( + :merge_request_diff_commit, + merge_request_diff: mr2_diff, + sha: sha2, + relative_order: 1 + ) + + commits = [double(:commit, id: sha1), double(:commit, id: sha2)] + + expect(described_class.new(project).execute(commits)).to eq( + sha1 => mr1, + sha2 => mr2 + ) + end + + it 'skips merge requests that are not merged' do + mr = create(:merge_request) + mr_diff = create(:merge_request_diff, merge_request: mr) + sha = Digest::SHA1.hexdigest('foo') + + create(:merge_request_diff_commit, merge_request_diff: mr_diff, sha: sha) + + commits = [double(:commit, id: sha)] + + expect(described_class.new(mr.target_project).execute(commits)) + .to be_empty + end + end +end |