diff options
author | Luke Duncalfe <lduncalfe@eml.cc> | 2019-04-08 08:07:53 +0300 |
---|---|---|
committer | Luke Duncalfe <lduncalfe@eml.cc> | 2019-04-09 01:57:01 +0300 |
commit | e73f537cb5097e85849110bafe184cb89e3bbc22 (patch) | |
tree | c711e4148007708c5dcb9fb45eab68092b8a9503 /spec/requests | |
parent | 68f189ad23d7a384f40caa152d263fdf1465b30a (diff) |
Refactor PushOptionsHandlerService from review
Exceptions are no longer raised, instead all errors encountered are
added to the errors property.
MergeRequests::BuildService is used to generate attributes of a new
merge request.
Code moved from Api::Internal to Api::Helpers::InternalHelpers.
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/internal_spec.rb | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index a5a6e08e73b..26645ff0a44 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -888,8 +888,10 @@ describe API::Internal do } end + let(:branch_name) { 'feature' } + let(:changes) do - "#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/new_branch" + "#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{branch_name}" end let(:push_options) do @@ -924,8 +926,8 @@ describe API::Internal do post api('/internal/post_receive'), params: valid_params expect(json_response['merge_request_urls']).to match [{ - "branch_name" => "new_branch", - "url" => "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=new_branch", + "branch_name" => branch_name, + "url" => "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/new?merge_request%5Bsource_branch%5D=#{branch_name}", "new_merge_request" => true }] end @@ -955,26 +957,22 @@ describe API::Internal do post api('/internal/post_receive'), params: valid_params end + it 'creates a new merge request' do + expect do + post api('/internal/post_receive'), params: valid_params + end.to change { MergeRequest.count }.by(1) + end + it 'links to the newly created merge request' do post api('/internal/post_receive'), params: valid_params expect(json_response['merge_request_urls']).to match [{ - 'branch_name' => 'new_branch', + 'branch_name' => branch_name, 'url' => "http://#{Gitlab.config.gitlab.host}/#{project.namespace.name}/#{project.path}/merge_requests/1", 'new_merge_request' => false }] end - it 'adds errors raised from MergeRequests::PushOptionsHandlerService to warnings' do - expect(MergeRequests::PushOptionsHandlerService).to receive(:new).and_raise( - MergeRequests::PushOptionsHandlerService::Error, 'my warning' - ) - - post api('/internal/post_receive'), params: valid_params - - expect(json_response['warnings']).to eq('Error encountered with push options \'merge_request.create\': my warning') - end - it 'adds errors on the service instance to warnings' do expect_any_instance_of( MergeRequests::PushOptionsHandlerService |