jira-ruby 1.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.travis.yml +5 -3
- data/Gemfile +7 -1
- data/Guardfile +1 -1
- data/README.md +452 -0
- data/Rakefile +6 -7
- data/example.rb +23 -1
- data/http-basic-example.rb +13 -12
- data/jira-ruby.gemspec +13 -13
- data/lib/jira/base.rb +53 -52
- data/lib/jira/base_factory.rb +3 -6
- data/lib/jira/client.rb +127 -30
- data/lib/jira/has_many_proxy.rb +0 -1
- data/lib/jira/http_client.rb +54 -16
- data/lib/jira/http_error.rb +3 -5
- data/lib/jira/jwt_client.rb +67 -0
- data/lib/jira/oauth_client.rb +47 -17
- data/lib/jira/request_client.rb +16 -5
- data/lib/jira/resource/agile.rb +34 -9
- data/lib/jira/resource/applinks.rb +5 -8
- data/lib/jira/resource/attachment.rb +41 -3
- data/lib/jira/resource/board.rb +91 -0
- data/lib/jira/resource/board_configuration.rb +9 -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 +69 -38
- data/lib/jira/resource/issue_picker_suggestions.rb +24 -0
- data/lib/jira/resource/issue_picker_suggestions_issue.rb +10 -0
- 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 +86 -17
- data/lib/jira/resource/sprint_report.rb +8 -0
- data/lib/jira/resource/status.rb +1 -3
- data/lib/jira/resource/suggested_issue.rb +9 -0
- 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 +35 -0
- 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/jira-ruby.rb +12 -2
- data/lib/tasks/generate.rake +4 -4
- data/spec/integration/attachment_spec.rb +17 -8
- 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 +45 -46
- 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 +62 -0
- 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 +216 -229
- data/spec/jira/client_spec.rb +227 -159
- data/spec/jira/has_many_proxy_spec.rb +11 -12
- data/spec/jira/http_client_spec.rb +254 -31
- data/spec/jira/http_error_spec.rb +7 -9
- data/spec/jira/jwt_uri_builder_spec.rb +59 -0
- data/spec/jira/oauth_client_spec.rb +110 -39
- data/spec/jira/request_client_spec.rb +36 -9
- data/spec/jira/resource/agile_spec.rb +135 -0
- data/spec/jira/resource/attachment_spec.rb +127 -9
- data/spec/jira/resource/board_spec.rb +224 -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_picker_suggestions_spec.rb +79 -0
- data/spec/jira/resource/issue_spec.rb +88 -85
- data/spec/jira/resource/issuelink_spec.rb +1 -1
- data/spec/jira/resource/jira_picker_suggestions_issue_spec.rb +18 -0
- 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 +90 -0
- data/spec/jira/resource/user_factory_spec.rb +6 -8
- data/spec/jira/resource/worklog_spec.rb +9 -11
- data/spec/mock_responses/board/1.json +33 -0
- data/spec/mock_responses/board/1_issues.json +62 -0
- data/spec/mock_responses/empty_issues.json +8 -0
- data/spec/mock_responses/issue/10002/watchers.json +13 -0
- data/spec/mock_responses/issue.json +1 -1
- data/spec/mock_responses/sprint/1_issues.json +125 -0
- 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 +115 -55
- data/.ruby-version +0 -1
- data/README.rdoc +0 -333
- /data/spec/mock_responses/{attachment → issue/10002/attachments}/10000.json +0 -0
data/spec/jira/client_spec.rb
CHANGED
@@ -1,223 +1,291 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
# We have three forms of authentication with two clases to represent the client for those different authentications.
|
4
|
+
# Some behaviours are shared across all three types of authentication. these are captured here.
|
5
|
+
RSpec.shared_examples 'Client Common Tests' do
|
6
|
+
it { is_expected.to be_a JIRA::Client }
|
7
|
+
|
8
|
+
it 'freezes the options once initialised' do
|
9
|
+
expect(subject.options).to be_frozen
|
7
10
|
end
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
it 'prepends context path to rest base_path' do
|
13
|
+
options = [:rest_base_path]
|
14
|
+
defaults = JIRA::Client::DEFAULT_OPTIONS
|
15
|
+
options.each { |key| expect(subject.options[key]).to eq(defaults[:context_path] + defaults[key]) }
|
11
16
|
end
|
12
17
|
|
13
|
-
|
14
|
-
|
18
|
+
it 'merges headers' do
|
19
|
+
expect(subject.send(:merge_default_headers, {})).to eq('Accept' => 'application/json')
|
15
20
|
end
|
16
21
|
|
17
|
-
|
18
|
-
|
22
|
+
describe 'http methods' do
|
23
|
+
it 'merges default headers' do
|
24
|
+
# stubbed response for generic client request method
|
25
|
+
expect(subject).to receive(:request).exactly(5).times.and_return(successful_response)
|
26
|
+
|
27
|
+
# response for merging headers for http methods with no body
|
28
|
+
expect(subject).to receive(:merge_default_headers).exactly(3).times.with({})
|
29
|
+
|
30
|
+
# response for merging headers for http methods with body
|
31
|
+
expect(subject).to receive(:merge_default_headers).exactly(2).times.with(content_type_header)
|
32
|
+
|
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
|
+
end
|
36
|
+
|
37
|
+
it 'calls the generic request method' do
|
38
|
+
%i[delete get head].each do |method|
|
39
|
+
expect(subject).to receive(:request).with(method, '/path', nil, headers).and_return(successful_response)
|
40
|
+
subject.send(method, '/path', {})
|
41
|
+
end
|
42
|
+
|
43
|
+
%i[post put].each do |method|
|
44
|
+
expect(subject).to receive(:request).with(method, '/path', '', merged_headers)
|
45
|
+
subject.send(method, '/path', '', {})
|
46
|
+
end
|
47
|
+
end
|
19
48
|
end
|
20
49
|
|
21
|
-
|
50
|
+
describe 'Resource Factories' do
|
51
|
+
it 'gets all projects' do
|
52
|
+
expect(JIRA::Resource::Project).to receive(:all).with(subject).and_return([])
|
53
|
+
expect(subject.Project.all).to eq([])
|
54
|
+
end
|
22
55
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
56
|
+
it 'finds a single project' do
|
57
|
+
find_result = double
|
58
|
+
expect(JIRA::Resource::Project).to receive(:find).with(subject, '123').and_return(find_result)
|
59
|
+
expect(subject.Project.find('123')).to eq(find_result)
|
60
|
+
end
|
27
61
|
end
|
28
62
|
|
29
|
-
|
30
|
-
|
31
|
-
|
63
|
+
describe 'SSL client options' do
|
64
|
+
context 'without certificate and key' do
|
65
|
+
let(:options) { { use_client_cert: true } }
|
66
|
+
subject { JIRA::Client.new(options) }
|
32
67
|
|
33
|
-
|
34
|
-
|
68
|
+
it 'raises an ArgumentError' do
|
69
|
+
expect { subject }.to raise_exception(ArgumentError, 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true')
|
70
|
+
options[:ssl_client_cert] = '<cert></cert>'
|
71
|
+
expect { subject }.to raise_exception(ArgumentError, 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true')
|
72
|
+
end
|
73
|
+
end
|
35
74
|
end
|
75
|
+
end
|
36
76
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
77
|
+
RSpec.shared_examples 'HttpClient tests' do
|
78
|
+
it 'makes a valid request' do
|
79
|
+
%i[delete get head].each do |method|
|
80
|
+
expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(successful_response)
|
81
|
+
subject.send(method, '/path', headers)
|
82
|
+
end
|
83
|
+
%i[post put].each do |method|
|
84
|
+
expect(subject.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(successful_response)
|
85
|
+
subject.send(method, '/path', '', headers)
|
86
|
+
end
|
41
87
|
end
|
88
|
+
end
|
42
89
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
90
|
+
RSpec.shared_examples 'OAuth Common Tests' do
|
91
|
+
include_examples 'Client Common Tests'
|
92
|
+
|
93
|
+
specify { expect(subject.request_client).to be_a JIRA::OauthClient }
|
94
|
+
|
95
|
+
it 'allows setting an access token' do
|
96
|
+
token = double
|
97
|
+
expect(OAuth::AccessToken).to receive(:new).with(subject.consumer, '', '').and_return(token)
|
98
|
+
|
99
|
+
expect(subject.authenticated?).to be_falsey
|
100
|
+
access_token = subject.set_access_token('', '')
|
101
|
+
expect(access_token).to eq(token)
|
102
|
+
expect(subject.access_token).to eq(token)
|
103
|
+
expect(subject.authenticated?).to be_truthy
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'that call a oauth client' do
|
107
|
+
specify 'which makes a request' do
|
108
|
+
%i[delete get head].each do |method|
|
109
|
+
expect(subject.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(successful_response)
|
110
|
+
subject.send(method, '/path', {})
|
111
|
+
end
|
112
|
+
%i[post put].each do |method|
|
113
|
+
expect(subject.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(successful_response)
|
114
|
+
subject.send(method, '/path', '', {})
|
115
|
+
end
|
48
116
|
end
|
49
117
|
end
|
118
|
+
end
|
50
119
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
120
|
+
describe JIRA::Client do
|
121
|
+
let(:request) { subject.request_client.class }
|
122
|
+
let(:successful_response) do
|
123
|
+
response = double('response')
|
124
|
+
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
125
|
+
response
|
55
126
|
end
|
127
|
+
let(:content_type_header) { { 'Content-Type' => 'application/json' } }
|
128
|
+
let(:headers) { { 'Accept' => 'application/json' } }
|
129
|
+
let(:merged_headers) { headers.merge(content_type_header) }
|
56
130
|
|
57
|
-
|
58
|
-
|
131
|
+
context 'behaviour that applies to all client classes irrespective of authentication method' do
|
132
|
+
it 'allows the overriding of some options' do
|
133
|
+
client = JIRA::Client.new(consumer_key: 'foo', consumer_secret: 'bar', site: 'http://foo.com/')
|
134
|
+
expect(client.options[:site]).to eq('http://foo.com/')
|
135
|
+
expect(JIRA::Client::DEFAULT_OPTIONS[:site]).not_to eq('http://foo.com/')
|
136
|
+
end
|
59
137
|
end
|
60
138
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
139
|
+
context 'with basic http authentication' do
|
140
|
+
subject { JIRA::Client.new(username: 'foo', password: 'bar', auth_type: :basic) }
|
141
|
+
|
142
|
+
before(:each) do
|
143
|
+
stub_request(:get, 'https://foo:bar@localhost:2990/jira/rest/api/2/project')
|
144
|
+
.to_return(status: 200, body: '[]', headers: {})
|
145
|
+
|
146
|
+
stub_request(:get, 'https://foo:badpassword@localhost:2990/jira/rest/api/2/project')
|
147
|
+
.to_return(status: 401, headers: {})
|
148
|
+
end
|
149
|
+
|
150
|
+
include_examples 'Client Common Tests'
|
151
|
+
include_examples 'HttpClient tests'
|
152
|
+
|
153
|
+
specify { expect(subject.request_client).to be_a JIRA::HttpClient }
|
154
|
+
|
155
|
+
it 'sets the username and password' do
|
156
|
+
expect(subject.options[:username]).to eq('foo')
|
157
|
+
expect(subject.options[:password]).to eq('bar')
|
66
158
|
end
|
67
159
|
|
68
|
-
|
69
|
-
|
70
|
-
expect(
|
71
|
-
expect
|
160
|
+
it 'fails with wrong user name and password' do
|
161
|
+
bad_login = JIRA::Client.new(username: 'foo', password: 'badpassword', auth_type: :basic)
|
162
|
+
expect(bad_login.authenticated?).to be_falsey
|
163
|
+
expect { bad_login.Project.all }.to raise_error JIRA::HTTPError
|
72
164
|
end
|
73
165
|
|
74
|
-
|
166
|
+
it 'only returns a true for #authenticated? once we have requested some data' do
|
167
|
+
expect(subject.authenticated?).to be_falsey
|
168
|
+
expect(subject.Project.all).to be_empty
|
169
|
+
expect(subject.authenticated?).to be_truthy
|
170
|
+
end
|
171
|
+
end
|
75
172
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
173
|
+
context 'with cookie authentication' do
|
174
|
+
subject { JIRA::Client.new(username: 'foo', password: 'bar', auth_type: :cookie) }
|
175
|
+
|
176
|
+
let(:session_cookie) { '6E3487971234567896704A9EB4AE501F' }
|
177
|
+
let(:session_body) do
|
178
|
+
{
|
179
|
+
'session': { 'name' => 'JSESSIONID', 'value' => session_cookie },
|
180
|
+
'loginInfo': { 'failedLoginCount' => 1, 'loginCount' => 2,
|
181
|
+
'lastFailedLoginTime' => (DateTime.now - 2).iso8601,
|
182
|
+
'previousLoginTime' => (DateTime.now - 5).iso8601 }
|
183
|
+
}
|
184
|
+
end
|
80
185
|
|
81
|
-
|
82
|
-
|
83
|
-
|
186
|
+
before(:each) do
|
187
|
+
# General case of API call with no authentication, or wrong authentication
|
188
|
+
stub_request(:post, 'https://localhost:2990/jira/rest/auth/1/session')
|
189
|
+
.to_return(status: 401, headers: {})
|
84
190
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
oauth_client.init_access_token(:oauth_verifier => 'abc123')
|
91
|
-
expect(oauth_client.access_token).to eq(mock_access_token)
|
92
|
-
end
|
191
|
+
# Now special case of API with correct authentication. This gets checked first by RSpec.
|
192
|
+
stub_request(:post, 'https://localhost:2990/jira/rest/auth/1/session')
|
193
|
+
.with(body: '{"username":"foo","password":"bar"}')
|
194
|
+
.to_return(status: 200, body: session_body.to_json,
|
195
|
+
headers: { 'Set-Cookie': "JSESSIONID=#{session_cookie}; Path=/; HttpOnly" })
|
93
196
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
expect(oauth_client.options[key]).to eq(JIRA::Client::DEFAULT_OPTIONS[key])
|
98
|
-
end
|
99
|
-
end
|
197
|
+
stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project')
|
198
|
+
.with(headers: { cookie: "JSESSIONID=#{session_cookie}" })
|
199
|
+
.to_return(status: 200, body: '[]', headers: {})
|
100
200
|
end
|
101
201
|
|
102
|
-
|
103
|
-
|
104
|
-
expect(basic_client.options[:username]).to eq('foo')
|
105
|
-
expect(basic_client.options[:password]).to eq('bar')
|
202
|
+
include_examples 'Client Common Tests'
|
203
|
+
include_examples 'HttpClient tests'
|
106
204
|
|
107
|
-
|
108
|
-
|
109
|
-
|
205
|
+
specify { expect(subject.request_client).to be_a JIRA::HttpClient }
|
206
|
+
|
207
|
+
it 'authenticates with a correct username and password' do
|
208
|
+
expect(subject).to be_authenticated
|
209
|
+
expect(subject.Project.all).to be_empty
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'does not authenticate with an incorrect username and password' do
|
213
|
+
bad_client = JIRA::Client.new(username: 'foo', password: 'bad_password', auth_type: :cookie)
|
214
|
+
expect(bad_client).not_to be_authenticated
|
110
215
|
end
|
111
216
|
|
217
|
+
it 'destroys the username and password once authenticated' do
|
218
|
+
expect(subject.options[:username]).to be_nil
|
219
|
+
expect(subject.options[:password]).to be_nil
|
220
|
+
end
|
112
221
|
end
|
113
222
|
|
114
|
-
|
115
|
-
|
116
|
-
|
223
|
+
context 'with jwt authentication' do
|
224
|
+
subject do
|
225
|
+
JIRA::Client.new(
|
226
|
+
issuer: 'foo',
|
227
|
+
base_url: 'https://host.tld',
|
228
|
+
shared_secret: 'shared_secret_key',
|
229
|
+
auth_type: :jwt
|
230
|
+
)
|
117
231
|
end
|
118
232
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
233
|
+
before(:each) do
|
234
|
+
stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project')
|
235
|
+
.with(query: hash_including(:jwt))
|
236
|
+
.to_return(status: 200, body: '[]', headers: {})
|
237
|
+
end
|
124
238
|
|
125
|
-
|
126
|
-
|
127
|
-
expect(basic_client).to receive(:merge_default_headers).exactly(3).times.with({})
|
128
|
-
expect(cookie_client).to receive(:merge_default_headers).exactly(3).times.with({})
|
239
|
+
include_examples 'Client Common Tests'
|
240
|
+
include_examples 'HttpClient tests'
|
129
241
|
|
130
|
-
|
131
|
-
expect(oauth_client).to receive(:merge_default_headers).exactly(2).times.with(content_type_header)
|
132
|
-
expect(basic_client).to receive(:merge_default_headers).exactly(2).times.with(content_type_header)
|
133
|
-
expect(cookie_client).to receive(:merge_default_headers).exactly(2).times.with(content_type_header)
|
134
|
-
|
135
|
-
[:delete, :get, :head].each do |method|
|
136
|
-
oauth_client.send(method, '/path', {})
|
137
|
-
basic_client.send(method, '/path', {})
|
138
|
-
cookie_client.send(method, '/path', {})
|
139
|
-
end
|
242
|
+
specify { expect(subject.request_client).to be_a JIRA::JwtClient }
|
140
243
|
|
141
|
-
|
142
|
-
|
143
|
-
basic_client.send(method, '/path', '', content_type_header)
|
144
|
-
cookie_client.send(method, '/path', '', content_type_header)
|
145
|
-
end
|
244
|
+
it 'sets the username and password' do
|
245
|
+
expect(subject.options[:shared_secret]).to eq('shared_secret_key')
|
146
246
|
end
|
147
247
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
oauth_client.send(method, '/path', {})
|
154
|
-
basic_client.send(method, '/path', {})
|
155
|
-
cookie_client.send(method, '/path', {})
|
248
|
+
context 'with a incorrect jwt key' do
|
249
|
+
before do
|
250
|
+
stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project')
|
251
|
+
.with(query: hash_including(:jwt))
|
252
|
+
.to_return(status: 401, body: '[]', headers: {})
|
156
253
|
end
|
157
254
|
|
158
|
-
|
159
|
-
expect(
|
160
|
-
expect(basic_client).to receive(:request).with(method, '/path', '', merged_headers)
|
161
|
-
expect(cookie_client).to receive(:request).with(method, '/path', '', merged_headers)
|
162
|
-
oauth_client.send(method, '/path', '', {})
|
163
|
-
basic_client.send(method, '/path', '', {})
|
164
|
-
cookie_client.send(method, '/path', '', {})
|
255
|
+
it 'is not authenticated' do
|
256
|
+
expect(subject.authenticated?).to be_falsey
|
165
257
|
end
|
166
|
-
end
|
167
258
|
|
168
|
-
|
169
|
-
|
170
|
-
[:delete, :get, :head].each do |method|
|
171
|
-
expect(oauth_client.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(response)
|
172
|
-
oauth_client.send(method, '/path', {})
|
173
|
-
end
|
174
|
-
[:post, :put].each do |method|
|
175
|
-
expect(oauth_client.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(response)
|
176
|
-
oauth_client.send(method, '/path', '', {})
|
177
|
-
end
|
259
|
+
it 'raises a JIRA::HTTPError when trying to fetch projects' do
|
260
|
+
expect { subject.Project.all }.to raise_error JIRA::HTTPError
|
178
261
|
end
|
179
262
|
end
|
180
263
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
264
|
+
it 'only returns a true for #authenticated? once we have requested some data' do
|
265
|
+
expect(subject.authenticated?).to be_falsey
|
266
|
+
expect(subject.Project.all).to be_empty
|
267
|
+
expect(subject.authenticated?).to be_truthy
|
268
|
+
end
|
269
|
+
end
|
186
270
|
|
187
|
-
|
188
|
-
|
189
|
-
end
|
190
|
-
[:post, :put].each do |method|
|
191
|
-
expect(basic_client.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(response)
|
192
|
-
basic_client.send(method, '/path', '', headers)
|
271
|
+
context 'oauth authentication' do
|
272
|
+
subject { JIRA::Client.new(consumer_key: 'foo', consumer_secret: 'bar') }
|
193
273
|
|
194
|
-
|
195
|
-
cookie_client.send(method, '/path', '', headers)
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
274
|
+
include_examples 'OAuth Common Tests'
|
199
275
|
end
|
200
276
|
|
201
|
-
|
202
|
-
|
203
|
-
expect(JIRA::Resource::Project).to receive(:all).with(oauth_client).and_return([])
|
204
|
-
expect(JIRA::Resource::Project).to receive(:all).with(basic_client).and_return([])
|
205
|
-
expect(JIRA::Resource::Project).to receive(:all).with(cookie_client).and_return([])
|
277
|
+
context 'with oauth_2legged' do
|
278
|
+
subject { JIRA::Client.new(consumer_key: 'foo', consumer_secret: 'bar', auth_type: :oauth_2legged) }
|
206
279
|
|
207
|
-
|
208
|
-
|
209
|
-
expect(cookie_client.Project.all).to eq([])
|
210
|
-
end
|
280
|
+
include_examples 'OAuth Common Tests'
|
281
|
+
end
|
211
282
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
expect(JIRA::Resource::Project).to receive(:find).with(basic_client, '123').and_return(find_result)
|
216
|
-
expect(JIRA::Resource::Project).to receive(:find).with(cookie_client, '123').and_return(find_result)
|
283
|
+
context 'with unknown options' do
|
284
|
+
let(:options) { { 'username' => 'foo', 'password' => 'bar', auth_type: :basic } }
|
285
|
+
subject { JIRA::Client.new(options) }
|
217
286
|
|
218
|
-
|
219
|
-
expect
|
220
|
-
expect(cookie_client.Project.find('123')).to eq(find_result)
|
287
|
+
it 'raises an ArgumentError' do
|
288
|
+
expect { subject }.to raise_exception(ArgumentError, 'Unknown option(s) given: ["username", "password"]')
|
221
289
|
end
|
222
290
|
end
|
223
291
|
end
|
@@ -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
|