jira-ruby 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,22 @@ describe JIRA::HttpClient do
12
12
  JIRA::HttpClient.new(options)
13
13
  end
14
14
 
15
+ let(:basic_cookie_client_with_context_path) do
16
+ options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(
17
+ :use_cookies => true,
18
+ :context_path => '/context'
19
+ )
20
+ JIRA::HttpClient.new(options)
21
+ end
22
+
23
+ let(:basic_cookie_client_with_additional_cookies) do
24
+ options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(
25
+ :use_cookies => true,
26
+ :additional_cookies => ['sessionToken=abc123', 'internal=true']
27
+ )
28
+ JIRA::HttpClient.new(options)
29
+ end
30
+
15
31
  let(:response) do
16
32
  response = double("response")
17
33
  allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
@@ -28,6 +44,26 @@ describe JIRA::HttpClient do
28
44
  expect(basic_client.basic_auth_http_conn.class).to eq(Net::HTTP)
29
45
  end
30
46
 
47
+ it "makes a correct HTTP request for make_cookie_auth_request" do
48
+ request = double()
49
+ basic_auth_http_conn = double()
50
+
51
+ headers = {"Content-Type" => "application/json"}
52
+ expected_path = '/context/rest/auth/1/session'
53
+ expected_body = '{"username":"","password":""}'
54
+
55
+ allow(basic_cookie_client_with_context_path).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn)
56
+ expect(basic_auth_http_conn).to receive(:request).with(request).and_return(response)
57
+
58
+ allow(request).to receive(:basic_auth)
59
+ allow(response).to receive(:get_fields).with('set-cookie')
60
+
61
+ expect(request).to receive(:body=).with(expected_body)
62
+ expect(Net::HTTP.const_get(:post.to_s.capitalize)).to receive(:new).with(expected_path, headers).and_return(request)
63
+
64
+ basic_cookie_client_with_context_path.make_cookie_auth_request
65
+ end
66
+
31
67
  it "responds to the http methods" do
32
68
  body = ''
33
69
  headers = double()
@@ -67,6 +103,27 @@ describe JIRA::HttpClient do
67
103
  end
68
104
  end
69
105
 
106
+ it "sets additional cookies when they are provided" do
107
+ client = basic_cookie_client_with_additional_cookies
108
+ body = ''
109
+ headers = double()
110
+ basic_auth_http_conn = double()
111
+ request = double()
112
+ allow(client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn)
113
+ expect(request).to receive(:basic_auth).with(client.options[:username], client.options[:password]).exactly(5).times.and_return(request)
114
+ expect(request).to receive(:add_field).with("Cookie", "sessionToken=abc123; internal=true").exactly(5).times
115
+ expect(cookie_response).to receive(:get_fields).with('set-cookie').exactly(5).times
116
+ expect(basic_auth_http_conn).to receive(:request).exactly(5).times.with(request).and_return(cookie_response)
117
+ [:delete, :get, :head].each do |method|
118
+ expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
119
+ expect(client.make_request(method, '/path', nil, headers)).to eq(cookie_response)
120
+ end
121
+ [:post, :put].each do |method|
122
+ expect(Net::HTTP.const_get(method.to_s.capitalize)).to receive(:new).with('/path', headers).and_return(request)
123
+ expect(request).to receive(:body=).with(body).and_return(request)
124
+ expect(client.make_request(method, '/path', body, headers)).to eq(cookie_response)
125
+ end
126
+ end
70
127
 
71
128
  it "performs a basic http client request" do
72
129
  body = nil
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Agile do
4
+ let(:client) { double(options: {rest_base_path: '/jira/rest/api/2', context_path: '/jira'}) }
5
+ let(:response) { double }
6
+
7
+ describe '#all' do
8
+ it 'should query url without parameters' do
9
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board').and_return(response)
10
+ expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
11
+
12
+ JIRA::Resource::Agile.all(client)
13
+ end
14
+ end
15
+
16
+ describe '#get_backlog_issues' do
17
+ it 'should query the url without parameters' do
18
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/backlog?maxResults=100').and_return(response)
19
+ expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
20
+
21
+ JIRA::Resource::Agile.get_backlog_issues(client, 1)
22
+ end
23
+ end
24
+
25
+ describe '#get_sprints' do
26
+ it 'should query correct url without parameters' do
27
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=100').and_return(response)
28
+ expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
29
+
30
+ JIRA::Resource::Agile.get_sprints(client, 1)
31
+ end
32
+
33
+ it 'should query correct url with parameters' do
34
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?startAt=50&maxResults=100').and_return(response)
35
+ expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
36
+
37
+ JIRA::Resource::Agile.get_sprints(client, 1, startAt: 50)
38
+ end
39
+ end
40
+
41
+ describe '#get_sprint_issues' do
42
+ it 'should query correct url without parameters' do
43
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/1/issue?maxResults=100').and_return(response)
44
+ expect(response).to receive(:body).and_return(get_mock_response('sprint/1_issues.json'))
45
+
46
+ JIRA::Resource::Agile.get_sprint_issues(client, 1)
47
+ end
48
+
49
+ it 'should query correct url with parameters' do
50
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/1/issue?startAt=50&maxResults=100').and_return(response)
51
+ expect(response).to receive(:body).and_return(get_mock_response('sprint/1_issues.json'))
52
+
53
+ JIRA::Resource::Agile.get_sprint_issues(client, 1, startAt: 50)
54
+ end
55
+ end
56
+
57
+ describe '#get_projects_full' do
58
+ it 'should query correct url without parameters' do
59
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project/full').and_return(response)
60
+ expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
61
+
62
+ JIRA::Resource::Agile.get_projects_full(client, 1)
63
+ end
64
+ end
65
+
66
+ describe '#get_projects' do
67
+ it 'should query correct url without parameters' do
68
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project?maxResults=100').and_return(response)
69
+ expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
70
+
71
+ JIRA::Resource::Agile.get_projects(client, 1)
72
+ end
73
+
74
+ it 'should query correct url with parameters' do
75
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/project?startAt=50&maxResults=100').and_return(response)
76
+ expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
77
+
78
+ JIRA::Resource::Agile.get_projects(client, 1, startAt: 50)
79
+ end
80
+ end
81
+ end
@@ -2,13 +2,26 @@ require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Attachment do
4
4
 
5
- let(:client) { double() }
5
+ let(:client) {
6
+ double(
7
+ 'client',
8
+ :options => {
9
+ :rest_base_path => '/jira/rest/api/2'
10
+ },
11
+ :request_client => double(
12
+ :options => {
13
+ :username => 'username',
14
+ :password => 'password'
15
+ }
16
+ )
17
+ )
18
+ }
6
19
 
7
20
  describe "relationships" do
8
21
  subject {
9
- JIRA::Resource::Attachment.new(client, :attrs => {
10
- 'author' => {'foo' => 'bar'}
11
- })
22
+ JIRA::Resource::Attachment.new(client,
23
+ :issue => JIRA::Resource::Issue.new(client),
24
+ :attrs => { 'author' => {'foo' => 'bar'} })
12
25
  }
13
26
 
14
27
  it "has the correct relationships" do
@@ -17,4 +30,47 @@ describe JIRA::Resource::Attachment do
17
30
  end
18
31
  end
19
32
 
33
+ describe '#meta' do
34
+ let(:response) {
35
+ double(
36
+ 'response',
37
+ :body => '{"enabled":true,"uploadLimit":10485760}'
38
+ )
39
+ }
40
+
41
+ it 'returns meta information about attachment upload' do
42
+ expect(client).to receive(:get).with('/jira/rest/api/2/attachment/meta').and_return(response)
43
+ JIRA::Resource::Attachment.meta(client)
44
+ end
45
+ end
46
+
47
+ describe '#save!' do
48
+ it 'successfully update the attachment' do
49
+ basic_auth_http_conn = double()
50
+ response = double(
51
+ body: [
52
+ {
53
+ "id": 10001,
54
+ "self": "http://www.example.com/jira/rest/api/2.0/attachments/10000",
55
+ "filename": "picture.jpg",
56
+ "created": "2017-07-19T12:23:06.572+0000",
57
+ "size": 23123,
58
+ "mimeType": "image/jpeg",
59
+ }
60
+ ].to_json
61
+ )
62
+
63
+ allow(client.request_client).to receive(:basic_auth_http_conn).and_return(basic_auth_http_conn)
64
+ allow(basic_auth_http_conn).to receive(:request).and_return(response)
65
+
66
+ issue = JIRA::Resource::Issue.new(client)
67
+ path_to_file = './spec/mock_responses/issue.json'
68
+ attachment = JIRA::Resource::Attachment.new(client, issue: issue)
69
+ attachment.save!('file' => path_to_file)
70
+
71
+ expect(attachment.filename).to eq 'picture.jpg'
72
+ expect(attachment.mimeType).to eq 'image/jpeg'
73
+ expect(attachment.size).to eq 23123
74
+ end
75
+ end
20
76
  end
@@ -0,0 +1,33 @@
1
+ {
2
+ "maxResults": 50,
3
+ "startAt": 0,
4
+ "isLast": true,
5
+ "values": [
6
+ {
7
+ "id": 1,
8
+ "self": "https://test.com/jira/rest/agile/1.0/sprint/1",
9
+ "state": "closed",
10
+ "name": "Test Sprint 1",
11
+ "startDate": "2016-05-03T01:45:17.624-04:00",
12
+ "endDate": "2016-05-06T13:30:00.000-04:00",
13
+ "completeDate": "2016-05-08T04:05:31.959-04:00",
14
+ "originBoardId": 1
15
+ },
16
+ {
17
+ "id": 2,
18
+ "self": "https://test.com/jira/rest/agile/1.0/sprint/2",
19
+ "state": "active",
20
+ "name": "Test Sprint 2",
21
+ "startDate": "2016-12-12T04:42:46.184-05:00",
22
+ "endDate": "2017-01-02T13:56:00.000-05:00",
23
+ "originBoardId": 1
24
+ },
25
+ {
26
+ "id": 3,
27
+ "self": "https://test.com/jira/rest/agile/1.0/sprint/2",
28
+ "state": "future",
29
+ "name": "Test Sprint 2",
30
+ "originBoardId": 1
31
+ }
32
+ ]
33
+ }
@@ -0,0 +1,125 @@
1
+ {
2
+ "expand": "schema,names",
3
+ "startAt": 0,
4
+ "maxResults": 50,
5
+ "total": 1,
6
+ "issues": [
7
+ {
8
+ "expand": "",
9
+ "id": "10001",
10
+ "self": "http://www.example.com/jira/rest/agile/1.0/board/92/issue/10001",
11
+ "key": "HSP-1",
12
+ "fields": {
13
+ "flagged": true,
14
+ "sprint": {
15
+ "id": 37,
16
+ "self": "http://www.example.com/jira/rest/agile/1.0/sprint/13",
17
+ "state": "future",
18
+ "name": "sprint 2"
19
+ },
20
+ "closedSprints": [
21
+ {
22
+ "id": 37,
23
+ "self": "http://www.example.com/jira/rest/agile/1.0/sprint/23",
24
+ "state": "closed",
25
+ "name": "sprint 1",
26
+ "startDate": "2015-04-11T15:22:00.000+10:00",
27
+ "endDate": "2015-04-20T01:22:00.000+10:00",
28
+ "completeDate": "2015-04-20T11:04:00.000+10:00"
29
+ }
30
+ ],
31
+ "description": "example bug report",
32
+ "project": {
33
+ "self": "http://www.example.com/jira/rest/api/2/project/EX",
34
+ "id": "10000",
35
+ "key": "EX",
36
+ "name": "Example",
37
+ "avatarUrls": {
38
+ "48x48": "http://www.example.com/jira/secure/projectavatar?size=large&pid=10000",
39
+ "24x24": "http://www.example.com/jira/secure/projectavatar?size=small&pid=10000",
40
+ "16x16": "http://www.example.com/jira/secure/projectavatar?size=xsmall&pid=10000",
41
+ "32x32": "http://www.example.com/jira/secure/projectavatar?size=medium&pid=10000"
42
+ },
43
+ "projectCategory": {
44
+ "self": "http://www.example.com/jira/rest/api/2/projectCategory/10000",
45
+ "id": "10000",
46
+ "name": "FIRST",
47
+ "description": "First Project Category"
48
+ }
49
+ },
50
+ "comment": [
51
+ {
52
+ "self": "http://www.example.com/jira/rest/api/2/issue/10010/comment/10000",
53
+ "id": "10000",
54
+ "author": {
55
+ "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
56
+ "name": "fred",
57
+ "displayName": "Fred F. User",
58
+ "active": false
59
+ },
60
+ "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
61
+ "updateAuthor": {
62
+ "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
63
+ "name": "fred",
64
+ "displayName": "Fred F. User",
65
+ "active": false
66
+ },
67
+ "created": "2016-06-22T11:49:57.797+0200",
68
+ "updated": "2016-06-22T11:49:57.800+0200",
69
+ "visibility": {
70
+ "type": "role",
71
+ "value": "Administrators"
72
+ }
73
+ }
74
+ ],
75
+ "epic": {
76
+ "id": 37,
77
+ "self": "http://www.example.com/jira/rest/agile/1.0/epic/23",
78
+ "name": "epic 1",
79
+ "summary": "epic 1 summary",
80
+ "color": {
81
+ "key": "color_4"
82
+ },
83
+ "done": true
84
+ },
85
+ "worklog": [
86
+ {
87
+ "self": "http://www.example.com/jira/rest/api/2/issue/10010/worklog/10000",
88
+ "author": {
89
+ "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
90
+ "name": "fred",
91
+ "displayName": "Fred F. User",
92
+ "active": false
93
+ },
94
+ "updateAuthor": {
95
+ "self": "http://www.example.com/jira/rest/api/2/user?username=fred",
96
+ "name": "fred",
97
+ "displayName": "Fred F. User",
98
+ "active": false
99
+ },
100
+ "comment": "I did some work here.",
101
+ "updated": "2016-06-22T11:49:57.804+0200",
102
+ "visibility": {
103
+ "type": "group",
104
+ "value": "jira-developers"
105
+ },
106
+ "started": "2016-06-22T11:49:57.804+0200",
107
+ "timeSpent": "3h 20m",
108
+ "timeSpentSeconds": 12000,
109
+ "id": "100028",
110
+ "issueId": "10002"
111
+ }
112
+ ],
113
+ "updated": 1,
114
+ "timetracking": {
115
+ "originalEstimate": "10m",
116
+ "remainingEstimate": "3m",
117
+ "timeSpent": "6m",
118
+ "originalEstimateSeconds": 600,
119
+ "remainingEstimateSeconds": 200,
120
+ "timeSpentSeconds": 400
121
+ }
122
+ }
123
+ }
124
+ ]
125
+ }
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SUMO Heavy Industries
8
+ - test IO
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-12-30 00:00:00.000000000 Z
12
+ date: 2017-07-21 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: oauth
@@ -44,6 +45,20 @@ dependencies:
44
45
  - - ">="
45
46
  - !ruby/object:Gem::Version
46
47
  version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: multipart-post
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: railties
49
64
  requirement: !ruby/object:Gem::Requirement
@@ -190,7 +205,7 @@ files:
190
205
  - Gemfile
191
206
  - Guardfile
192
207
  - LICENSE
193
- - README.rdoc
208
+ - README.md
194
209
  - Rakefile
195
210
  - example.rb
196
211
  - http-basic-example.rb
@@ -258,6 +273,7 @@ files:
258
273
  - spec/jira/http_error_spec.rb
259
274
  - spec/jira/oauth_client_spec.rb
260
275
  - spec/jira/request_client_spec.rb
276
+ - spec/jira/resource/agile_spec.rb
261
277
  - spec/jira/resource/attachment_spec.rb
262
278
  - spec/jira/resource/createmeta_spec.rb
263
279
  - spec/jira/resource/field_spec.rb
@@ -268,7 +284,7 @@ files:
268
284
  - spec/jira/resource/project_spec.rb
269
285
  - spec/jira/resource/user_factory_spec.rb
270
286
  - spec/jira/resource/worklog_spec.rb
271
- - spec/mock_responses/attachment/10000.json
287
+ - spec/mock_responses/board/1.json
272
288
  - spec/mock_responses/component.post.json
273
289
  - spec/mock_responses/component/10000.invalid.put.json
274
290
  - spec/mock_responses/component/10000.json
@@ -280,6 +296,7 @@ files:
280
296
  - spec/mock_responses/issue/10002.invalid.put.json
281
297
  - spec/mock_responses/issue/10002.json
282
298
  - spec/mock_responses/issue/10002.put.missing_field_update.json
299
+ - spec/mock_responses/issue/10002/attachment/10000.json
283
300
  - spec/mock_responses/issue/10002/comment.json
284
301
  - spec/mock_responses/issue/10002/comment.post.json
285
302
  - spec/mock_responses/issue/10002/comment/10000.json
@@ -307,6 +324,7 @@ files:
307
324
  - spec/mock_responses/rapidview/SAMPLEPROJECT.json
308
325
  - spec/mock_responses/resolution.json
309
326
  - spec/mock_responses/resolution/1.json
327
+ - spec/mock_responses/sprint/1_issues.json
310
328
  - spec/mock_responses/status.json
311
329
  - spec/mock_responses/status/1.json
312
330
  - spec/mock_responses/user_username=admin.json
@@ -372,6 +390,7 @@ test_files:
372
390
  - spec/jira/http_error_spec.rb
373
391
  - spec/jira/oauth_client_spec.rb
374
392
  - spec/jira/request_client_spec.rb
393
+ - spec/jira/resource/agile_spec.rb
375
394
  - spec/jira/resource/attachment_spec.rb
376
395
  - spec/jira/resource/createmeta_spec.rb
377
396
  - spec/jira/resource/field_spec.rb
@@ -382,7 +401,7 @@ test_files:
382
401
  - spec/jira/resource/project_spec.rb
383
402
  - spec/jira/resource/user_factory_spec.rb
384
403
  - spec/jira/resource/worklog_spec.rb
385
- - spec/mock_responses/attachment/10000.json
404
+ - spec/mock_responses/board/1.json
386
405
  - spec/mock_responses/component.post.json
387
406
  - spec/mock_responses/component/10000.invalid.put.json
388
407
  - spec/mock_responses/component/10000.json
@@ -394,6 +413,7 @@ test_files:
394
413
  - spec/mock_responses/issue/10002.invalid.put.json
395
414
  - spec/mock_responses/issue/10002.json
396
415
  - spec/mock_responses/issue/10002.put.missing_field_update.json
416
+ - spec/mock_responses/issue/10002/attachment/10000.json
397
417
  - spec/mock_responses/issue/10002/comment.json
398
418
  - spec/mock_responses/issue/10002/comment.post.json
399
419
  - spec/mock_responses/issue/10002/comment/10000.json
@@ -421,6 +441,7 @@ test_files:
421
441
  - spec/mock_responses/rapidview/SAMPLEPROJECT.json
422
442
  - spec/mock_responses/resolution.json
423
443
  - spec/mock_responses/resolution/1.json
444
+ - spec/mock_responses/sprint/1_issues.json
424
445
  - spec/mock_responses/status.json
425
446
  - spec/mock_responses/status/1.json
426
447
  - spec/mock_responses/user_username=admin.json