Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bitbucket_server/connection.rb7
-rw-r--r--spec/lib/bitbucket_server/connection_spec.rb16
2 files changed, 16 insertions, 7 deletions
diff --git a/lib/bitbucket_server/connection.rb b/lib/bitbucket_server/connection.rb
index 8a3775bd152..2d438ae8ca1 100644
--- a/lib/bitbucket_server/connection.rb
+++ b/lib/bitbucket_server/connection.rb
@@ -20,6 +20,7 @@ module BitbucketServer
def get(path, extra_query = {})
response = Gitlab::HTTP.get(build_url(path),
basic_auth: auth,
+ headers: accept_headers,
query: extra_query)
check_errors!(response)
@@ -74,8 +75,12 @@ module BitbucketServer
@auth ||= { username: username, password: token }
end
+ def accept_headers
+ @accept_headers ||= { 'Accept' => 'application/json' }
+ end
+
def post_headers
- @post_headers ||= { 'Content-Type' => 'application/json' }
+ @post_headers ||= accept_headers.merge({ 'Content-Type' => 'application/json' })
end
def build_url(path)
diff --git a/spec/lib/bitbucket_server/connection_spec.rb b/spec/lib/bitbucket_server/connection_spec.rb
index 4a421d062a3..33a037218a0 100644
--- a/spec/lib/bitbucket_server/connection_spec.rb
+++ b/spec/lib/bitbucket_server/connection_spec.rb
@@ -10,46 +10,50 @@ describe BitbucketServer::Connection do
describe '#get' do
it 'returns JSON body' do
- WebMock.stub_request(:get, url).to_return(body: payload.to_json, status: 200, headers: headers)
+ WebMock.stub_request(:get, url).with(headers: { 'Accept' => 'application/json' }).to_return(body: payload.to_json, status: 200, headers: headers)
expect(subject.get(url, { something: 1 })).to eq(payload)
end
it 'throws an exception if the response is not 200' do
- WebMock.stub_request(:get, url).to_return(body: payload.to_json, status: 500, headers: headers)
+ WebMock.stub_request(:get, url).with(headers: { 'Accept' => 'application/json' }).to_return(body: payload.to_json, status: 500, headers: headers)
expect { subject.get(url) }.to raise_error(described_class::ConnectionError)
end
end
describe '#post' do
+ let(:headers) { { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } }
+
it 'returns JSON body' do
- WebMock.stub_request(:post, url).to_return(body: payload.to_json, status: 200, headers: headers)
+ WebMock.stub_request(:post, url).with(headers: headers).to_return(body: payload.to_json, status: 200, headers: headers)
expect(subject.post(url, payload)).to eq(payload)
end
it 'throws an exception if the response is not 200' do
- WebMock.stub_request(:post, url).to_return(body: payload.to_json, status: 500, headers: headers)
+ WebMock.stub_request(:post, url).with(headers: headers).to_return(body: payload.to_json, status: 500, headers: headers)
expect { subject.post(url, payload) }.to raise_error(described_class::ConnectionError)
end
end
describe '#delete' do
+ let(:headers) { { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } }
+
context 'branch API' do
let(:branch_path) { '/projects/foo/repos/bar/branches' }
let(:branch_url) { 'https://test:7990/rest/branch-utils/1.0/projects/foo/repos/bar/branches' }
let(:path) { }
it 'returns JSON body' do
- WebMock.stub_request(:delete, branch_url).to_return(body: payload.to_json, status: 200, headers: headers)
+ WebMock.stub_request(:delete, branch_url).with(headers: headers).to_return(body: payload.to_json, status: 200, headers: headers)
expect(subject.delete(:branches, branch_path, payload)).to eq(payload)
end
it 'throws an exception if the response is not 200' do
- WebMock.stub_request(:delete, branch_url).to_return(body: payload.to_json, status: 500, headers: headers)
+ WebMock.stub_request(:delete, branch_url).with(headers: headers).to_return(body: payload.to_json, status: 500, headers: headers)
expect { subject.delete(:branches, branch_path, payload) }.to raise_error(described_class::ConnectionError)
end