diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
commit | 41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch) | |
tree | 9c8d89a8624828992f06d892cd2f43818ff5dcc8 /spec/lib/gitlab/merge_requests | |
parent | 0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff) |
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'spec/lib/gitlab/merge_requests')
3 files changed, 105 insertions, 5 deletions
diff --git a/spec/lib/gitlab/merge_requests/commit_message_generator_spec.rb b/spec/lib/gitlab/merge_requests/commit_message_generator_spec.rb index 2407b497249..ad528dca81a 100644 --- a/spec/lib/gitlab/merge_requests/commit_message_generator_spec.rb +++ b/spec/lib/gitlab/merge_requests/commit_message_generator_spec.rb @@ -403,6 +403,90 @@ RSpec.describe Gitlab::MergeRequests::CommitMessageGenerator do end end + context 'when project has commit template with all_commits' do + let(message_template_name) { "All commits:\n%{all_commits}" } + + it 'returns all commit messages' do + expect(result_message).to eq <<~MSG.rstrip + All commits: + * Feature added + + Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> + MSG + end + + context 'with 2 commits' do + let(:source_branch) { 'fix' } + + it 'returns both messages' do + expect(result_message).to eq <<~MSG.rstrip + All commits: + * Test file for directories with a leading dot + + * JS fix + + Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> + MSG + end + end + + context 'with over 100 commits' do + let(:source_branch) { 'signed-commits' } + + it 'returns first 100 commits skipping merge commit' do + expected_message = <<~MSG + All commits: + * Multiple signatures commit + + * Add conflicting file + + * Add conflicting file + + MSG + expected_message += (5..100).to_a.reverse + .map { |n| "* Unrelated signed commit #{n} to exceed page size of endpoint\n\n" } + .join.rstrip + expect(result_message).to eq expected_message + end + end + + context 'when branch has no unmerged commits' do + let(:source_branch) { 'v1.1.0' } + + it 'is an empty string' do + expect(result_message).to eq "All commits:\n" + end + end + + context 'when branch has commit with message over 100kb' do + let(:source_branch) { 'add_commit_with_5mb_subject' } + + it 'skips commit body' do + expect(result_message).to eq <<~MSG.rstrip + All commits: + * Commit with 5MB text subject + + -- Skipped commit body exceeding 100KiB in size. + + * Correct test_env.rb path for adding branch + + * Add file with a _flattable_ path + + + (cherry picked from commit ce369011c189f62c815f5971d096b26759bab0d1) + + * Add file larger than 1 mb + + In order to test Max File Size push rule we need a file larger than 1 MB + + * LFS tracks "*.lfs" through .gitattributes + + * Update README.md to include `Usage in testing and development` + MSG + end + end + end + context 'user' do subject { described_class.new(merge_request: merge_request, current_user: nil) } @@ -466,6 +550,7 @@ RSpec.describe Gitlab::MergeRequests::CommitMessageGenerator do approved_by:%{approved_by} merged_by:%{merged_by} co_authored_by:%{co_authored_by} + all_commits:%{all_commits} MSG it 'uses custom template' do @@ -486,6 +571,9 @@ RSpec.describe Gitlab::MergeRequests::CommitMessageGenerator do approved_by: merged_by:#{current_user.name} <#{current_user.commit_email_or_default}> co_authored_by:Co-authored-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> + all_commits:* Feature added + + Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> MSG end end diff --git a/spec/lib/gitlab/merge_requests/mergeability/check_result_spec.rb b/spec/lib/gitlab/merge_requests/mergeability/check_result_spec.rb index 4f437e57600..50cfa6b64ea 100644 --- a/spec/lib/gitlab/merge_requests/mergeability/check_result_spec.rb +++ b/spec/lib/gitlab/merge_requests/mergeability/check_result_spec.rb @@ -70,8 +70,8 @@ RSpec.describe Gitlab::MergeRequests::Mergeability::CheckResult do let(:payload) { { test: 'test' } } let(:hash) do { - status: status, - payload: payload + 'status' => status, + 'payload' => payload } end diff --git a/spec/lib/gitlab/merge_requests/mergeability/results_store_spec.rb b/spec/lib/gitlab/merge_requests/mergeability/results_store_spec.rb index d376dcb5b18..ed11f8ea6bb 100644 --- a/spec/lib/gitlab/merge_requests/mergeability/results_store_spec.rb +++ b/spec/lib/gitlab/merge_requests/mergeability/results_store_spec.rb @@ -10,10 +10,22 @@ RSpec.describe Gitlab::MergeRequests::Mergeability::ResultsStore do let(:merge_request) { double } describe '#read' do - it 'calls #retrieve on the interface' do - expect(interface).to receive(:retrieve_check).with(merge_check: merge_check) + let(:result_hash) { { 'status' => 'success', 'payload' => {} } } - results_store.read(merge_check: merge_check) + it 'calls #retrieve_check on the interface' do + expect(interface).to receive(:retrieve_check).with(merge_check: merge_check).and_return(result_hash) + + cached_result = results_store.read(merge_check: merge_check) + + expect(cached_result.status).to eq(result_hash['status'].to_sym) + expect(cached_result.payload).to eq(result_hash['payload']) + end + + context 'when #retrieve_check returns nil' do + it 'returns nil' do + expect(interface).to receive(:retrieve_check).with(merge_check: merge_check).and_return(nil) + expect(results_store.read(merge_check: merge_check)).to be_nil + end end end |