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.
Files changed (109) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.travis.yml +5 -3
  4. data/Gemfile +7 -1
  5. data/Guardfile +1 -1
  6. data/README.md +452 -0
  7. data/Rakefile +6 -7
  8. data/example.rb +23 -1
  9. data/http-basic-example.rb +13 -12
  10. data/jira-ruby.gemspec +13 -13
  11. data/lib/jira/base.rb +53 -52
  12. data/lib/jira/base_factory.rb +3 -6
  13. data/lib/jira/client.rb +127 -30
  14. data/lib/jira/has_many_proxy.rb +0 -1
  15. data/lib/jira/http_client.rb +54 -16
  16. data/lib/jira/http_error.rb +3 -5
  17. data/lib/jira/jwt_client.rb +67 -0
  18. data/lib/jira/oauth_client.rb +47 -17
  19. data/lib/jira/request_client.rb +16 -5
  20. data/lib/jira/resource/agile.rb +34 -9
  21. data/lib/jira/resource/applinks.rb +5 -8
  22. data/lib/jira/resource/attachment.rb +41 -3
  23. data/lib/jira/resource/board.rb +91 -0
  24. data/lib/jira/resource/board_configuration.rb +9 -0
  25. data/lib/jira/resource/comment.rb +0 -2
  26. data/lib/jira/resource/component.rb +1 -3
  27. data/lib/jira/resource/createmeta.rb +12 -14
  28. data/lib/jira/resource/field.rb +22 -22
  29. data/lib/jira/resource/filter.rb +2 -2
  30. data/lib/jira/resource/issue.rb +69 -38
  31. data/lib/jira/resource/issue_picker_suggestions.rb +24 -0
  32. data/lib/jira/resource/issue_picker_suggestions_issue.rb +10 -0
  33. data/lib/jira/resource/issuelink.rb +3 -5
  34. data/lib/jira/resource/issuelinktype.rb +0 -1
  35. data/lib/jira/resource/issuetype.rb +1 -3
  36. data/lib/jira/resource/priority.rb +1 -3
  37. data/lib/jira/resource/project.rb +5 -7
  38. data/lib/jira/resource/rapidview.rb +28 -7
  39. data/lib/jira/resource/remotelink.rb +1 -4
  40. data/lib/jira/resource/resolution.rb +2 -4
  41. data/lib/jira/resource/serverinfo.rb +1 -2
  42. data/lib/jira/resource/sprint.rb +86 -17
  43. data/lib/jira/resource/sprint_report.rb +8 -0
  44. data/lib/jira/resource/status.rb +1 -3
  45. data/lib/jira/resource/suggested_issue.rb +9 -0
  46. data/lib/jira/resource/transition.rb +2 -6
  47. data/lib/jira/resource/user.rb +12 -2
  48. data/lib/jira/resource/version.rb +1 -3
  49. data/lib/jira/resource/watcher.rb +35 -0
  50. data/lib/jira/resource/webhook.rb +3 -6
  51. data/lib/jira/resource/worklog.rb +3 -5
  52. data/lib/jira/version.rb +1 -1
  53. data/lib/jira-ruby.rb +12 -2
  54. data/lib/tasks/generate.rake +4 -4
  55. data/spec/integration/attachment_spec.rb +17 -8
  56. data/spec/integration/comment_spec.rb +31 -34
  57. data/spec/integration/component_spec.rb +21 -24
  58. data/spec/integration/field_spec.rb +15 -18
  59. data/spec/integration/issue_spec.rb +45 -46
  60. data/spec/integration/issuelinktype_spec.rb +8 -11
  61. data/spec/integration/issuetype_spec.rb +5 -7
  62. data/spec/integration/priority_spec.rb +5 -8
  63. data/spec/integration/project_spec.rb +13 -20
  64. data/spec/integration/rapidview_spec.rb +17 -10
  65. data/spec/integration/resolution_spec.rb +7 -10
  66. data/spec/integration/status_spec.rb +5 -8
  67. data/spec/integration/transition_spec.rb +17 -20
  68. data/spec/integration/user_spec.rb +24 -8
  69. data/spec/integration/version_spec.rb +21 -25
  70. data/spec/integration/watcher_spec.rb +62 -0
  71. data/spec/integration/webhook.rb +8 -17
  72. data/spec/integration/worklog_spec.rb +30 -34
  73. data/spec/jira/base_factory_spec.rb +11 -12
  74. data/spec/jira/base_spec.rb +216 -229
  75. data/spec/jira/client_spec.rb +227 -159
  76. data/spec/jira/has_many_proxy_spec.rb +11 -12
  77. data/spec/jira/http_client_spec.rb +254 -31
  78. data/spec/jira/http_error_spec.rb +7 -9
  79. data/spec/jira/jwt_uri_builder_spec.rb +59 -0
  80. data/spec/jira/oauth_client_spec.rb +110 -39
  81. data/spec/jira/request_client_spec.rb +36 -9
  82. data/spec/jira/resource/agile_spec.rb +135 -0
  83. data/spec/jira/resource/attachment_spec.rb +127 -9
  84. data/spec/jira/resource/board_spec.rb +224 -0
  85. data/spec/jira/resource/createmeta_spec.rb +29 -32
  86. data/spec/jira/resource/field_spec.rb +42 -48
  87. data/spec/jira/resource/filter_spec.rb +40 -40
  88. data/spec/jira/resource/issue_picker_suggestions_spec.rb +79 -0
  89. data/spec/jira/resource/issue_spec.rb +88 -85
  90. data/spec/jira/resource/issuelink_spec.rb +1 -1
  91. data/spec/jira/resource/jira_picker_suggestions_issue_spec.rb +18 -0
  92. data/spec/jira/resource/project_factory_spec.rb +2 -4
  93. data/spec/jira/resource/project_spec.rb +33 -33
  94. data/spec/jira/resource/sprint_spec.rb +90 -0
  95. data/spec/jira/resource/user_factory_spec.rb +6 -8
  96. data/spec/jira/resource/worklog_spec.rb +9 -11
  97. data/spec/mock_responses/board/1.json +33 -0
  98. data/spec/mock_responses/board/1_issues.json +62 -0
  99. data/spec/mock_responses/empty_issues.json +8 -0
  100. data/spec/mock_responses/issue/10002/watchers.json +13 -0
  101. data/spec/mock_responses/issue.json +1 -1
  102. data/spec/mock_responses/sprint/1_issues.json +125 -0
  103. data/spec/spec_helper.rb +8 -9
  104. data/spec/support/clients_helper.rb +4 -4
  105. data/spec/support/shared_examples/integration.rb +60 -77
  106. metadata +115 -55
  107. data/.ruby-version +0 -1
  108. data/README.rdoc +0 -333
  109. /data/spec/mock_responses/{attachment → issue/10002/attachments}/10000.json +0 -0
@@ -1,223 +1,291 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe JIRA::Client do
4
- before(:each) do
5
- stub_request(:post, "https://foo:bar@localhost:2990/rest/auth/1/session").
6
- to_return(:status => 200, :body => "", :headers => {})
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
- let(:oauth_client) do
10
- JIRA::Client.new({ :consumer_key => 'foo', :consumer_secret => 'bar' })
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
- let(:basic_client) do
14
- JIRA::Client.new({ :username => 'foo', :password => 'bar', :auth_type => :basic })
18
+ it 'merges headers' do
19
+ expect(subject.send(:merge_default_headers, {})).to eq('Accept' => 'application/json')
15
20
  end
16
21
 
17
- let(:cookie_client) do
18
- JIRA::Client.new({ :username => 'foo', :password => 'bar', :auth_type => :cookie })
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
- let(:clients) { [oauth_client, basic_client, cookie_client] }
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
- let(:response) do
24
- response = double("response")
25
- allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
26
- response
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
- let(:headers) { {'Accept' => 'application/json'} }
30
- let(:content_type_header) { {'Content-Type' => 'application/json'} }
31
- let(:merged_headers) { headers.merge(content_type_header) }
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
- it "creates an instance" do
34
- clients.each {|client| expect(client.class).to eq(JIRA::Client) }
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
- it "allows the overriding of some options" do
38
- client = JIRA::Client.new({:consumer_key => 'foo', :consumer_secret => 'bar', :site => 'http://foo.com/'})
39
- expect(client.options[:site]).to eq('http://foo.com/')
40
- expect(JIRA::Client::DEFAULT_OPTIONS[:site]).not_to eq('http://foo.com/')
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
- it "prepends the context path to the rest base path" do
44
- options = [:rest_base_path]
45
- defaults = JIRA::Client::DEFAULT_OPTIONS
46
- options.each do |key|
47
- clients.each { |client| expect(client.options[key]).to eq(defaults[:context_path] + defaults[key]) }
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
- # To avoid having to validate options after initialisation, e.g. setting
52
- # client.options[:invalid] = 'foo'
53
- it "freezes the options" do
54
- clients.each { |client| expect(client.options).to be_frozen }
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
- it "merges headers" do
58
- clients.each { |client| expect(client.send(:merge_default_headers, {})).to eq({'Accept' => 'application/json'}) }
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
- describe "creates instances of request clients" do
62
- specify "that are of the correct class" do
63
- expect(oauth_client.request_client.class).to eq(JIRA::OauthClient)
64
- expect(basic_client.request_client.class).to eq(JIRA::HttpClient)
65
- expect(cookie_client.request_client.class).to eq(JIRA::HttpClient)
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
- specify "which have a corresponding auth type option" do
69
- expect(oauth_client.options[:auth_type]).to eq(:oauth)
70
- expect(basic_client.options[:auth_type]).to eq(:basic)
71
- expect(cookie_client.options[:auth_type]).to eq(:cookie)
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
- describe "like oauth" do
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
- it "allows setting an access token" do
77
- token = double()
78
- expect(OAuth::AccessToken).to receive(:new).with(oauth_client.consumer, 'foo', 'bar').and_return(token)
79
- access_token = oauth_client.set_access_token('foo', 'bar')
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
- expect(access_token).to eq(token)
82
- expect(oauth_client.access_token).to eq(token)
83
- end
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
- it "allows initializing the access token" do
86
- request_token = OAuth::RequestToken.new(oauth_client.consumer)
87
- allow(oauth_client.consumer).to receive(:get_request_token).and_return(request_token)
88
- mock_access_token = double()
89
- expect(request_token).to receive(:get_access_token).with(:oauth_verifier => 'abc123').and_return(mock_access_token)
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
- specify "that has specific default options" do
95
- options = [:signature_method, :private_key_file]
96
- options.each do |key|
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
- describe "like basic http" do
103
- it "sets the username and password" do
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
- expect(cookie_client.options[:username]).to eq('foo')
108
- expect(cookie_client.options[:password]).to eq('bar')
109
- end
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
- describe "has http methods" do
115
- before do
116
- oauth_client.set_access_token("foo", "bar")
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
- specify "that merge default headers" do
120
- # stubbed response for generic client request method
121
- expect(oauth_client).to receive(:request).exactly(5).times.and_return(response)
122
- expect(basic_client).to receive(:request).exactly(5).times.and_return(response)
123
- expect(cookie_client).to receive(:request).exactly(5).times.and_return(response)
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
- # response for merging headers for http methods with no body
126
- expect(oauth_client).to receive(:merge_default_headers).exactly(3).times.with({})
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
- # response for merging headers for http methods with body
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
- [:post, :put].each do |method|
142
- oauth_client.send(method, '/path', '', content_type_header)
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
- specify "that call the generic request method" do
149
- [:delete, :get, :head].each do |method|
150
- expect(oauth_client).to receive(:request).with(method, '/path', nil, headers).and_return(response)
151
- expect(basic_client).to receive(:request).with(method, '/path', nil, headers).and_return(response)
152
- expect(cookie_client).to receive(:request).with(method, '/path', nil, headers).and_return(response)
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
- [:post, :put].each do |method|
159
- expect(oauth_client).to receive(:request).with(method, '/path', '', merged_headers)
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
- describe "that call a oauth client" do
169
- specify "which makes a request" do
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
- describe "that call a http client" do
182
- it "which makes a request" do
183
- [:delete, :get, :head].each do |method|
184
- expect(basic_client.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(response)
185
- basic_client.send(method, '/path', headers)
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
- expect(cookie_client.request_client).to receive(:make_request).with(method, '/path', nil, headers).and_return(response)
188
- cookie_client.send(method, '/path', headers)
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
- expect(cookie_client.request_client).to receive(:make_request).with(method, '/path', '', merged_headers).and_return(response)
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
- describe "Resource Factories" do
202
- it "gets all projects" do
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
- expect(oauth_client.Project.all).to eq([])
208
- expect(basic_client.Project.all).to eq([])
209
- expect(cookie_client.Project.all).to eq([])
210
- end
280
+ include_examples 'OAuth Common Tests'
281
+ end
211
282
 
212
- it "finds a single project" do
213
- find_result = double()
214
- expect(JIRA::Resource::Project).to receive(:find).with(oauth_client, '123').and_return(find_result)
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
- expect(oauth_client.Project.find('123')).to eq(find_result)
219
- expect(basic_client.Project.find('123')).to eq(find_result)
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("parent") }
10
- let(:collection) { double("collection") }
8
+ let(:parent) { double('parent') }
9
+ let(:collection) { double('collection') }
11
10
 
12
- it "has a target class" do
11
+ it 'has a target class' do
13
12
  expect(subject.target_class).to eq(Foo)
14
13
  end
15
14
 
16
- it "has a parent" do
15
+ it 'has a parent' do
17
16
  expect(subject.parent).to eq(parent)
18
17
  end
19
18
 
20
- it "has a collection" do
19
+ it 'has a collection' do
21
20
  expect(subject.collection).to eq(collection)
22
21
  end
23
22
 
24
- it "can build a new instance" do
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, :attrs => {'foo' => 'bar'}, :parent => parent).and_return(foo)
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 "can get all the instances" do
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, :parent => parent).and_return(foo)
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 "delegates missing methods to the collection" do
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