jira-ruby 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Gemfile +7 -1
- data/Guardfile +1 -1
- data/Rakefile +4 -5
- data/http-basic-example.rb +13 -12
- data/jira-ruby.gemspec +9 -10
- data/lib/jira-ruby.rb +5 -2
- data/lib/jira/base.rb +49 -48
- data/lib/jira/base_factory.rb +1 -4
- data/lib/jira/client.rb +29 -20
- data/lib/jira/has_many_proxy.rb +0 -1
- data/lib/jira/http_client.rb +9 -10
- data/lib/jira/http_error.rb +3 -5
- data/lib/jira/oauth_client.rb +19 -20
- data/lib/jira/request_client.rb +3 -4
- data/lib/jira/resource/agile.rb +10 -8
- data/lib/jira/resource/applinks.rb +5 -8
- data/lib/jira/resource/attachment.rb +1 -2
- data/lib/jira/resource/board.rb +84 -0
- data/lib/jira/resource/comment.rb +0 -2
- data/lib/jira/resource/component.rb +1 -3
- data/lib/jira/resource/createmeta.rb +12 -14
- data/lib/jira/resource/field.rb +22 -22
- data/lib/jira/resource/filter.rb +2 -2
- data/lib/jira/resource/issue.rb +41 -39
- data/lib/jira/resource/issuelink.rb +3 -5
- data/lib/jira/resource/issuelinktype.rb +0 -1
- data/lib/jira/resource/issuetype.rb +1 -3
- data/lib/jira/resource/priority.rb +1 -3
- data/lib/jira/resource/project.rb +5 -7
- data/lib/jira/resource/rapidview.rb +28 -7
- data/lib/jira/resource/remotelink.rb +1 -4
- data/lib/jira/resource/resolution.rb +2 -4
- data/lib/jira/resource/serverinfo.rb +1 -2
- data/lib/jira/resource/sprint.rb +82 -18
- data/lib/jira/resource/sprint_report.rb +8 -0
- data/lib/jira/resource/status.rb +1 -3
- data/lib/jira/resource/transition.rb +2 -6
- data/lib/jira/resource/user.rb +12 -2
- data/lib/jira/resource/version.rb +1 -3
- data/lib/jira/resource/watcher.rb +1 -5
- data/lib/jira/resource/webhook.rb +3 -6
- data/lib/jira/resource/worklog.rb +3 -5
- data/lib/jira/version.rb +1 -1
- data/lib/tasks/generate.rake +4 -4
- data/spec/integration/attachment_spec.rb +15 -16
- data/spec/integration/comment_spec.rb +31 -34
- data/spec/integration/component_spec.rb +21 -24
- data/spec/integration/field_spec.rb +15 -18
- data/spec/integration/issue_spec.rb +44 -48
- data/spec/integration/issuelinktype_spec.rb +8 -11
- data/spec/integration/issuetype_spec.rb +5 -7
- data/spec/integration/priority_spec.rb +5 -8
- data/spec/integration/project_spec.rb +13 -20
- data/spec/integration/rapidview_spec.rb +17 -10
- data/spec/integration/resolution_spec.rb +7 -10
- data/spec/integration/status_spec.rb +5 -8
- data/spec/integration/transition_spec.rb +17 -20
- data/spec/integration/user_spec.rb +24 -8
- data/spec/integration/version_spec.rb +21 -25
- data/spec/integration/watcher_spec.rb +28 -34
- data/spec/integration/webhook.rb +8 -17
- data/spec/integration/worklog_spec.rb +30 -34
- data/spec/jira/base_factory_spec.rb +11 -12
- data/spec/jira/base_spec.rb +204 -228
- data/spec/jira/client_spec.rb +26 -28
- data/spec/jira/has_many_proxy_spec.rb +11 -12
- data/spec/jira/http_client_spec.rb +51 -52
- data/spec/jira/http_error_spec.rb +7 -9
- data/spec/jira/oauth_client_spec.rb +44 -46
- data/spec/jira/request_client_spec.rb +5 -5
- data/spec/jira/resource/agile_spec.rb +5 -7
- data/spec/jira/resource/attachment_spec.rb +25 -26
- data/spec/jira/resource/board_spec.rb +175 -0
- data/spec/jira/resource/createmeta_spec.rb +29 -32
- data/spec/jira/resource/field_spec.rb +42 -48
- data/spec/jira/resource/filter_spec.rb +40 -40
- data/spec/jira/resource/issue_spec.rb +87 -89
- data/spec/jira/resource/issuelink_spec.rb +1 -1
- data/spec/jira/resource/project_factory_spec.rb +2 -4
- data/spec/jira/resource/project_spec.rb +33 -33
- data/spec/jira/resource/sprint_spec.rb +78 -0
- data/spec/jira/resource/user_factory_spec.rb +6 -8
- data/spec/jira/resource/worklog_spec.rb +9 -11
- data/spec/spec_helper.rb +8 -9
- data/spec/support/clients_helper.rb +4 -4
- data/spec/support/shared_examples/integration.rb +60 -77
- metadata +59 -53
data/spec/jira/client_spec.rb
CHANGED
@@ -16,7 +16,7 @@ RSpec.shared_examples 'Client Common Tests' do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'merges headers' do
|
19
|
-
expect(subject.send(:merge_default_headers, {})).to eq(
|
19
|
+
expect(subject.send(:merge_default_headers, {})).to eq('Accept' => 'application/json')
|
20
20
|
end
|
21
21
|
|
22
22
|
describe 'http methods' do
|
@@ -30,17 +30,17 @@ RSpec.shared_examples 'Client Common Tests' do
|
|
30
30
|
# response for merging headers for http methods with body
|
31
31
|
expect(subject).to receive(:merge_default_headers).exactly(2).times.with(content_type_header)
|
32
32
|
|
33
|
-
[
|
34
|
-
[
|
33
|
+
%i[delete get head].each { |method| subject.send(method, '/path', {}) }
|
34
|
+
%i[post put].each { |method| subject.send(method, '/path', '', content_type_header) }
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'calls the generic request method' do
|
38
|
-
[
|
38
|
+
%i[delete get head].each do |method|
|
39
39
|
expect(subject).to receive(:request).with(method, '/path', nil, headers).and_return(successful_response)
|
40
40
|
subject.send(method, '/path', {})
|
41
41
|
end
|
42
42
|
|
43
|
-
[
|
43
|
+
%i[post put].each do |method|
|
44
44
|
expect(subject).to receive(:request).with(method, '/path', '', merged_headers)
|
45
45
|
subject.send(method, '/path', '', {})
|
46
46
|
end
|
@@ -63,11 +63,11 @@ end
|
|
63
63
|
|
64
64
|
RSpec.shared_examples 'HttpClient tests' do
|
65
65
|
it 'makes a valid request' do
|
66
|
-
[
|
66
|
+
%i[delete get head].each do |method|
|
67
67
|
expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(successful_response)
|
68
68
|
subject.send(method, '/path', headers)
|
69
69
|
end
|
70
|
-
[
|
70
|
+
%i[post put].each do |method|
|
71
71
|
expect(subject.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(successful_response)
|
72
72
|
subject.send(method, '/path', '', headers)
|
73
73
|
end
|
@@ -92,11 +92,11 @@ RSpec.shared_examples 'OAuth Common Tests' do
|
|
92
92
|
|
93
93
|
describe 'that call a oauth client' do
|
94
94
|
specify 'which makes a request' do
|
95
|
-
[
|
95
|
+
%i[delete get head].each do |method|
|
96
96
|
expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(successful_response)
|
97
97
|
subject.send(method, '/path', {})
|
98
98
|
end
|
99
|
-
[
|
99
|
+
%i[post put].each do |method|
|
100
100
|
expect(subject.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(successful_response)
|
101
101
|
subject.send(method, '/path', '', {})
|
102
102
|
end
|
@@ -108,16 +108,16 @@ describe JIRA::Client do
|
|
108
108
|
let(:request) { subject.request_client.class }
|
109
109
|
let(:successful_response) do
|
110
110
|
response = double('response')
|
111
|
-
allow(response).to receive(:
|
111
|
+
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
112
112
|
response
|
113
113
|
end
|
114
|
-
let(:content_type_header) { {'Content-Type' => 'application/json'} }
|
115
|
-
let(:headers) { {'Accept' => 'application/json'} }
|
114
|
+
let(:content_type_header) { { 'Content-Type' => 'application/json' } }
|
115
|
+
let(:headers) { { 'Accept' => 'application/json' } }
|
116
116
|
let(:merged_headers) { headers.merge(content_type_header) }
|
117
117
|
|
118
118
|
context 'behaviour that applies to all client classes irrespective of authentication method' do
|
119
119
|
it 'allows the overriding of some options' do
|
120
|
-
client = JIRA::Client.new(
|
120
|
+
client = JIRA::Client.new(consumer_key: 'foo', consumer_secret: 'bar', site: 'http://foo.com/')
|
121
121
|
expect(client.options[:site]).to eq('http://foo.com/')
|
122
122
|
expect(JIRA::Client::DEFAULT_OPTIONS[:site]).not_to eq('http://foo.com/')
|
123
123
|
end
|
@@ -128,10 +128,10 @@ describe JIRA::Client do
|
|
128
128
|
|
129
129
|
before(:each) do
|
130
130
|
stub_request(:get, 'https://foo:bar@localhost:2990/jira/rest/api/2/project')
|
131
|
-
.to_return(status: 200, body: '[]', headers: {}
|
131
|
+
.to_return(status: 200, body: '[]', headers: {})
|
132
132
|
|
133
|
-
stub_request(:get, 'https://foo:badpassword@localhost:2990/jira/rest/api/2/project')
|
134
|
-
to_return(status: 401, headers: {}
|
133
|
+
stub_request(:get, 'https://foo:badpassword@localhost:2990/jira/rest/api/2/project')
|
134
|
+
.to_return(status: 401, headers: {})
|
135
135
|
end
|
136
136
|
|
137
137
|
include_examples 'Client Common Tests'
|
@@ -147,7 +147,7 @@ describe JIRA::Client do
|
|
147
147
|
it 'fails with wrong user name and password' do
|
148
148
|
bad_login = JIRA::Client.new(username: 'foo', password: 'badpassword', auth_type: :basic)
|
149
149
|
expect(bad_login.authenticated?).to be_falsey
|
150
|
-
expect{bad_login.Project.all}.to raise_error JIRA::HTTPError
|
150
|
+
expect { bad_login.Project.all }.to raise_error JIRA::HTTPError
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'only returns a true for #authenticated? once we have requested some data' do
|
@@ -155,7 +155,6 @@ describe JIRA::Client do
|
|
155
155
|
expect(subject.Project.all).to be_empty
|
156
156
|
expect(subject.authenticated?).to be_truthy
|
157
157
|
end
|
158
|
-
|
159
158
|
end
|
160
159
|
|
161
160
|
context 'with cookie authentication' do
|
@@ -164,27 +163,27 @@ describe JIRA::Client do
|
|
164
163
|
let(:session_cookie) { '6E3487971234567896704A9EB4AE501F' }
|
165
164
|
let(:session_body) do
|
166
165
|
{
|
167
|
-
'session': {'name' =>
|
168
|
-
'loginInfo': {'failedLoginCount' => 1, 'loginCount' => 2,
|
169
|
-
|
170
|
-
|
166
|
+
'session': { 'name' => 'JSESSIONID', 'value' => session_cookie },
|
167
|
+
'loginInfo': { 'failedLoginCount' => 1, 'loginCount' => 2,
|
168
|
+
'lastFailedLoginTime' => (DateTime.now - 2).iso8601,
|
169
|
+
'previousLoginTime' => (DateTime.now - 5).iso8601 }
|
171
170
|
}
|
172
171
|
end
|
173
172
|
|
174
173
|
before(:each) do
|
175
174
|
# General case of API call with no authentication, or wrong authentication
|
176
|
-
stub_request(:post, 'https://localhost:2990/jira/rest/auth/1/session')
|
177
|
-
to_return(status: 401, headers: {}
|
175
|
+
stub_request(:post, 'https://localhost:2990/jira/rest/auth/1/session')
|
176
|
+
.to_return(status: 401, headers: {})
|
178
177
|
|
179
178
|
# Now special case of API with correct authentication. This gets checked first by RSpec.
|
180
179
|
stub_request(:post, 'https://localhost:2990/jira/rest/auth/1/session')
|
181
180
|
.with(body: '{"username":"foo","password":"bar"}')
|
182
181
|
.to_return(status: 200, body: session_body.to_json,
|
183
|
-
headers: { 'Set-Cookie': "JSESSIONID=#{session_cookie}; Path=/; HttpOnly"})
|
182
|
+
headers: { 'Set-Cookie': "JSESSIONID=#{session_cookie}; Path=/; HttpOnly" })
|
184
183
|
|
185
184
|
stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project')
|
186
|
-
.with(headers: { cookie: "JSESSIONID=#{session_cookie}" }
|
187
|
-
.to_return(status: 200, body: '[]', headers: {}
|
185
|
+
.with(headers: { cookie: "JSESSIONID=#{session_cookie}" })
|
186
|
+
.to_return(status: 200, body: '[]', headers: {})
|
188
187
|
end
|
189
188
|
|
190
189
|
include_examples 'Client Common Tests'
|
@@ -220,4 +219,3 @@ describe JIRA::Client do
|
|
220
219
|
include_examples 'OAuth Common Tests'
|
221
220
|
end
|
222
221
|
end
|
223
|
-
|
@@ -1,46 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe JIRA::HasManyProxy do
|
4
|
-
|
5
|
-
class Foo ; end
|
4
|
+
class Foo; end
|
6
5
|
|
7
6
|
subject { JIRA::HasManyProxy.new(parent, Foo, collection) }
|
8
7
|
|
9
|
-
let(:parent) { double(
|
10
|
-
let(:collection) { double(
|
8
|
+
let(:parent) { double('parent') }
|
9
|
+
let(:collection) { double('collection') }
|
11
10
|
|
12
|
-
it
|
11
|
+
it 'has a target class' do
|
13
12
|
expect(subject.target_class).to eq(Foo)
|
14
13
|
end
|
15
14
|
|
16
|
-
it
|
15
|
+
it 'has a parent' do
|
17
16
|
expect(subject.parent).to eq(parent)
|
18
17
|
end
|
19
18
|
|
20
|
-
it
|
19
|
+
it 'has a collection' do
|
21
20
|
expect(subject.collection).to eq(collection)
|
22
21
|
end
|
23
22
|
|
24
|
-
it
|
23
|
+
it 'can build a new instance' do
|
25
24
|
client = double('client')
|
26
25
|
foo = double('foo')
|
27
26
|
allow(parent).to receive(:client).and_return(client)
|
28
27
|
allow(parent).to receive(:to_sym).and_return(:parent)
|
29
|
-
expect(Foo).to receive(:new).with(client, :
|
28
|
+
expect(Foo).to receive(:new).with(client, attrs: { 'foo' => 'bar' }, parent: parent).and_return(foo)
|
30
29
|
expect(collection).to receive(:<<).with(foo)
|
31
30
|
expect(subject.build('foo' => 'bar')).to eq(foo)
|
32
31
|
end
|
33
32
|
|
34
|
-
it
|
33
|
+
it 'can get all the instances' do
|
35
34
|
foo = double('foo')
|
36
35
|
client = double('client')
|
37
36
|
allow(parent).to receive(:client).and_return(client)
|
38
37
|
allow(parent).to receive(:to_sym).and_return(:parent)
|
39
|
-
expect(Foo).to receive(:all).with(client, :
|
38
|
+
expect(Foo).to receive(:all).with(client, parent: parent).and_return(foo)
|
40
39
|
expect(subject.all).to eq(foo)
|
41
40
|
end
|
42
41
|
|
43
|
-
it
|
42
|
+
it 'delegates missing methods to the collection' do
|
44
43
|
expect(collection).to receive(:missing_method)
|
45
44
|
subject.missing_method
|
46
45
|
end
|
@@ -1,63 +1,62 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe JIRA::HttpClient do
|
4
|
-
|
5
4
|
let(:basic_client) do
|
6
5
|
options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS)
|
7
6
|
JIRA::HttpClient.new(options)
|
8
7
|
end
|
9
8
|
|
10
9
|
let(:basic_cookie_client) do
|
11
|
-
options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(:
|
10
|
+
options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(use_cookies: true)
|
12
11
|
JIRA::HttpClient.new(options)
|
13
12
|
end
|
14
13
|
|
15
14
|
let(:basic_cookie_client_with_context_path) do
|
16
15
|
options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(
|
17
|
-
:
|
18
|
-
:
|
16
|
+
use_cookies: true,
|
17
|
+
context_path: '/context'
|
19
18
|
)
|
20
19
|
JIRA::HttpClient.new(options)
|
21
20
|
end
|
22
21
|
|
23
22
|
let(:basic_cookie_client_with_additional_cookies) do
|
24
23
|
options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(
|
25
|
-
:
|
26
|
-
:
|
24
|
+
use_cookies: true,
|
25
|
+
additional_cookies: ['sessionToken=abc123', 'internal=true']
|
27
26
|
)
|
28
27
|
JIRA::HttpClient.new(options)
|
29
28
|
end
|
30
29
|
|
31
30
|
let(:basic_client_cert_client) do
|
32
31
|
options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
32
|
+
use_client_cert: true,
|
33
|
+
cert: 'public certificate contents',
|
34
|
+
key: 'private key contents'
|
36
35
|
)
|
37
36
|
JIRA::HttpClient.new(options)
|
38
37
|
end
|
39
38
|
|
40
39
|
let(:response) do
|
41
|
-
response = double(
|
40
|
+
response = double('response')
|
42
41
|
allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
|
43
42
|
response
|
44
43
|
end
|
45
44
|
|
46
45
|
let(:cookie_response) do
|
47
|
-
response = double(
|
46
|
+
response = double('response')
|
48
47
|
allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
|
49
48
|
response
|
50
49
|
end
|
51
50
|
|
52
|
-
it
|
51
|
+
it 'creates an instance of Net:HTTP for a basic auth client' do
|
53
52
|
expect(basic_client.basic_auth_http_conn.class).to eq(Net::HTTP)
|
54
53
|
end
|
55
54
|
|
56
|
-
it
|
57
|
-
request = double
|
58
|
-
basic_auth_http_conn = double
|
55
|
+
it 'makes a correct HTTP request for make_cookie_auth_request' do
|
56
|
+
request = double
|
57
|
+
basic_auth_http_conn = double
|
59
58
|
|
60
|
-
headers = {
|
59
|
+
headers = { 'Content-Type' => 'application/json' }
|
61
60
|
expected_path = '/context/rest/auth/1/session'
|
62
61
|
expected_body = '{"username":"","password":""}'
|
63
62
|
|
@@ -73,72 +72,72 @@ describe JIRA::HttpClient do
|
|
73
72
|
basic_cookie_client_with_context_path.make_cookie_auth_request
|
74
73
|
end
|
75
74
|
|
76
|
-
it
|
75
|
+
it 'responds to the http methods' do
|
77
76
|
body = ''
|
78
|
-
headers = double
|
79
|
-
basic_auth_http_conn = double
|
80
|
-
request = double
|
77
|
+
headers = double
|
78
|
+
basic_auth_http_conn = double
|
79
|
+
request = double
|
81
80
|
allow(basic_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn)
|
82
81
|
expect(request).to receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).exactly(5).times.and_return(request)
|
83
82
|
expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(response)
|
84
|
-
[
|
83
|
+
%i[delete get head].each do |method|
|
85
84
|
expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
|
86
85
|
expect(basic_client.make_request(method, '/path', nil, headers)).to eq(response)
|
87
86
|
end
|
88
|
-
[
|
87
|
+
%i[post put].each do |method|
|
89
88
|
expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
|
90
89
|
expect(request).to receive(:body=).with(body).and_return(request)
|
91
90
|
expect(basic_client.make_request(method, '/path', body, headers)).to eq(response)
|
92
91
|
end
|
93
92
|
end
|
94
93
|
|
95
|
-
it
|
94
|
+
it 'gets and sets cookies' do
|
96
95
|
body = ''
|
97
|
-
headers = double
|
98
|
-
basic_auth_http_conn = double
|
99
|
-
request = double
|
96
|
+
headers = double
|
97
|
+
basic_auth_http_conn = double
|
98
|
+
request = double
|
100
99
|
allow(basic_cookie_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn)
|
101
100
|
expect(request).to receive(:basic_auth).with(basic_cookie_client.options[:username], basic_cookie_client.options[:password]).exactly(5).times.and_return(request)
|
102
101
|
expect(cookie_response).to receive(:get_fields).with('set-cookie').exactly(5).times
|
103
102
|
expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(cookie_response)
|
104
|
-
[
|
103
|
+
%i[delete get head].each do |method|
|
105
104
|
expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
|
106
105
|
expect(basic_cookie_client.make_request(method, '/path', nil, headers)).to eq(cookie_response)
|
107
106
|
end
|
108
|
-
[
|
107
|
+
%i[post put].each do |method|
|
109
108
|
expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
|
110
109
|
expect(request).to receive(:body=).with(body).and_return(request)
|
111
110
|
expect(basic_cookie_client.make_request(method, '/path', body, headers)).to eq(cookie_response)
|
112
111
|
end
|
113
112
|
end
|
114
113
|
|
115
|
-
it
|
114
|
+
it 'sets additional cookies when they are provided' do
|
116
115
|
client = basic_cookie_client_with_additional_cookies
|
117
116
|
body = ''
|
118
|
-
headers = double
|
119
|
-
basic_auth_http_conn = double
|
120
|
-
request = double
|
117
|
+
headers = double
|
118
|
+
basic_auth_http_conn = double
|
119
|
+
request = double
|
121
120
|
allow(client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn)
|
122
121
|
expect(request).to receive(:basic_auth).with(client.options[:username], client.options[:password]).exactly(5).times.and_return(request)
|
123
|
-
expect(request).to receive(:add_field).with(
|
122
|
+
expect(request).to receive(:add_field).with('Cookie', 'sessionToken=abc123; internal=true').exactly(5).times
|
124
123
|
expect(cookie_response).to receive(:get_fields).with('set-cookie').exactly(5).times
|
125
124
|
expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(cookie_response)
|
126
|
-
[
|
125
|
+
%i[delete get head].each do |method|
|
127
126
|
expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
|
128
127
|
expect(client.make_request(method, '/path', nil, headers)).to eq(cookie_response)
|
129
128
|
end
|
130
|
-
[
|
129
|
+
%i[post put].each do |method|
|
131
130
|
expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
|
132
131
|
expect(request).to receive(:body=).with(body).and_return(request)
|
133
132
|
expect(client.make_request(method, '/path', body, headers)).to eq(cookie_response)
|
134
133
|
end
|
135
134
|
end
|
136
135
|
|
137
|
-
it
|
136
|
+
it 'performs a basic http client request' do
|
138
137
|
body = nil
|
139
|
-
headers = double
|
140
|
-
basic_auth_http_conn = double
|
141
|
-
http_request = double
|
138
|
+
headers = double
|
139
|
+
basic_auth_http_conn = double
|
140
|
+
http_request = double
|
142
141
|
expect(Net::HTTP::Get).to receive(:new).with('/foo', headers).and_return(http_request)
|
143
142
|
|
144
143
|
expect(basic_auth_http_conn).to receive(:request).with(http_request).and_return(response)
|
@@ -147,11 +146,11 @@ describe JIRA::HttpClient do
|
|
147
146
|
basic_client.make_request(:get, '/foo', body, headers)
|
148
147
|
end
|
149
148
|
|
150
|
-
it
|
149
|
+
it 'performs a basic http client request with a full domain' do
|
151
150
|
body = nil
|
152
|
-
headers = double
|
153
|
-
basic_auth_http_conn = double
|
154
|
-
http_request = double
|
151
|
+
headers = double
|
152
|
+
basic_auth_http_conn = double
|
153
|
+
http_request = double
|
155
154
|
expect(Net::HTTP::Get).to receive(:new).with('/foo', headers).and_return(http_request)
|
156
155
|
|
157
156
|
expect(basic_auth_http_conn).to receive(:request).with(http_request).and_return(response)
|
@@ -160,16 +159,16 @@ describe JIRA::HttpClient do
|
|
160
159
|
basic_client.make_request(:get, 'http://mydomain.com/foo', body, headers)
|
161
160
|
end
|
162
161
|
|
163
|
-
it
|
162
|
+
it 'returns a URI' do
|
164
163
|
uri = URI.parse(basic_client.options[:site])
|
165
164
|
expect(basic_client.uri).to eq(uri)
|
166
165
|
end
|
167
166
|
|
168
|
-
it
|
169
|
-
http_conn = double
|
170
|
-
uri = double
|
171
|
-
host = double
|
172
|
-
port = double
|
167
|
+
it 'sets up a http connection with options' do
|
168
|
+
http_conn = double
|
169
|
+
uri = double
|
170
|
+
host = double
|
171
|
+
port = double
|
173
172
|
expect(uri).to receive(:host).and_return(host)
|
174
173
|
expect(uri).to receive(:port).and_return(port)
|
175
174
|
expect(Net::HTTP).to receive(:new).with(host, port).and_return(http_conn)
|
@@ -195,9 +194,9 @@ describe JIRA::HttpClient do
|
|
195
194
|
expect(basic_client_cert_client.http_conn(uri)).to eq(http_conn)
|
196
195
|
end
|
197
196
|
|
198
|
-
it
|
199
|
-
http_conn = double
|
200
|
-
uri = double
|
197
|
+
it 'returns a http connection' do
|
198
|
+
http_conn = double
|
199
|
+
uri = double
|
201
200
|
expect(basic_client).to receive(:uri).and_return(uri)
|
202
201
|
expect(basic_client).to receive(:http_conn).and_return(http_conn)
|
203
202
|
expect(basic_client.basic_auth_http_conn).to eq(http_conn)
|
@@ -1,26 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe JIRA::HTTPError do
|
4
|
-
|
5
|
-
|
6
|
-
response = double("response")
|
4
|
+
let(:response) do
|
5
|
+
response = double('response')
|
7
6
|
allow(response).to receive(:code).and_return(401)
|
8
|
-
allow(response).to receive(:message).and_return(
|
7
|
+
allow(response).to receive(:message).and_return('A MESSAGE WOO')
|
9
8
|
response
|
10
|
-
|
9
|
+
end
|
11
10
|
|
12
11
|
subject { described_class.new(response) }
|
13
12
|
|
14
|
-
it
|
13
|
+
it 'takes the response object as an argument' do
|
15
14
|
expect(subject.response).to eq(response)
|
16
15
|
end
|
17
16
|
|
18
|
-
it
|
17
|
+
it 'has a code method' do
|
19
18
|
expect(subject.code).to eq(response.code)
|
20
19
|
end
|
21
20
|
|
22
|
-
it
|
21
|
+
it 'returns code and class from message' do
|
23
22
|
expect(subject.message).to eq(response.message)
|
24
23
|
end
|
25
|
-
|
26
24
|
end
|