diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/lib/api/helpers/merge_requests_helpers_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/lib/api/helpers/merge_requests_helpers_spec.rb')
-rw-r--r-- | spec/lib/api/helpers/merge_requests_helpers_spec.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/lib/api/helpers/merge_requests_helpers_spec.rb b/spec/lib/api/helpers/merge_requests_helpers_spec.rb new file mode 100644 index 00000000000..1d68b7985f1 --- /dev/null +++ b/spec/lib/api/helpers/merge_requests_helpers_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe API::Helpers::MergeRequestsHelpers do + describe '#handle_merge_request_errors!' do + let(:helper) do + Class.new do + include API::Helpers::MergeRequestsHelpers + end.new + end + + let(:merge_request) { double } + + context 'when merge request is valid' do + it 'returns nil' do + allow(merge_request).to receive(:valid?).and_return(true) + + expect(merge_request).not_to receive(:errors) + + helper.handle_merge_request_errors!(merge_request) + end + end + + context 'when merge request is invalid' do + before do + allow(merge_request).to receive(:valid?).and_return(false) + allow(helper).to receive_messages([ + :unprocessable_entity!, :conflict!, :render_validation_error! + ]) + end + + API::Helpers::MergeRequestsHelpers::UNPROCESSABLE_ERROR_KEYS.each do |error_key| + it "responds to a #{error_key} error with unprocessable_entity" do + error = double + allow(merge_request).to receive(:errors).and_return({ error_key => error }) + + expect(helper).to receive(:unprocessable_entity!).with(error) + + helper.handle_merge_request_errors!(merge_request) + end + end + + it 'responds to a validate_branches error with conflict' do + error = double + allow(merge_request).to receive(:errors).and_return({ validate_branches: error }) + + expect(helper).to receive(:conflict!).with(error) + + helper.handle_merge_request_errors!(merge_request) + end + + it 'responds with bad request' do + error = double + allow(merge_request).to receive(:errors).and_return({ other_error: error }) + + expect(helper).to receive(:render_validation_error!).with(merge_request) + + helper.handle_merge_request_errors!(merge_request) + end + end + end +end |