jira-ruby 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,43 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe JIRA::OauthClient do
|
4
|
-
|
5
4
|
let(:oauth_client) do
|
6
|
-
options = { :
|
5
|
+
options = { consumer_key: 'foo', consumer_secret: 'bar' }
|
7
6
|
options = JIRA::Client::DEFAULT_OPTIONS.merge(options)
|
8
7
|
JIRA::OauthClient.new(options)
|
9
8
|
end
|
10
9
|
|
11
10
|
let(:response) do
|
12
|
-
response = double(
|
13
|
-
allow(response).to receive(:
|
11
|
+
response = double('response')
|
12
|
+
allow(response).to receive(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
14
13
|
response
|
15
14
|
end
|
16
15
|
|
17
|
-
describe
|
18
|
-
it
|
19
|
-
options = [
|
16
|
+
describe 'authenticating with oauth' do
|
17
|
+
it 'prepends the context path to all authorization and rest paths' do
|
18
|
+
options = %i[request_token_path authorize_path access_token_path]
|
20
19
|
defaults = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::OauthClient::DEFAULT_OPTIONS)
|
21
20
|
options.each do |key|
|
22
21
|
expect(oauth_client.options[key]).to eq(defaults[:context_path] + defaults[key])
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
it
|
25
|
+
it 'creates a Oauth::Consumer on initialize' do
|
27
26
|
expect(oauth_client.consumer.class).to eq(OAuth::Consumer)
|
28
27
|
expect(oauth_client.consumer.key).to eq(oauth_client.key)
|
29
28
|
expect(oauth_client.consumer.secret).to eq(oauth_client.secret)
|
30
29
|
end
|
31
30
|
|
32
|
-
it
|
31
|
+
it 'returns an OAuth request_token' do
|
33
32
|
# Cannot just check for method delegation as http connection will be attempted
|
34
33
|
request_token = OAuth::RequestToken.new(oauth_client.consumer)
|
35
34
|
allow(oauth_client).to receive(:get_request_token).and_return(request_token)
|
36
35
|
expect(oauth_client.get_request_token).to eq(request_token)
|
37
36
|
end
|
38
37
|
|
39
|
-
it
|
40
|
-
token = double
|
38
|
+
it 'allows setting the request token' do
|
39
|
+
token = double
|
41
40
|
expect(OAuth::RequestToken).to receive(:new).with(oauth_client.consumer, 'foo', 'bar').and_return(token)
|
42
41
|
|
43
42
|
request_token = oauth_client.set_request_token('foo', 'bar')
|
@@ -46,34 +45,33 @@ describe JIRA::OauthClient do
|
|
46
45
|
expect(oauth_client.request_token).to eq(token)
|
47
46
|
end
|
48
47
|
|
49
|
-
it
|
48
|
+
it 'allows setting the consumer key' do
|
50
49
|
expect(oauth_client.key).to eq('foo')
|
51
50
|
end
|
52
51
|
|
53
|
-
it
|
52
|
+
it 'allows setting the consumer secret' do
|
54
53
|
expect(oauth_client.secret).to eq('bar')
|
55
54
|
end
|
56
55
|
|
57
|
-
describe
|
58
|
-
|
59
|
-
it "initializes" do
|
56
|
+
describe 'the access token' do
|
57
|
+
it 'initializes' do
|
60
58
|
request_token = OAuth::RequestToken.new(oauth_client.consumer)
|
61
59
|
allow(oauth_client).to receive(:get_request_token).and_return(request_token)
|
62
|
-
mock_access_token = double
|
63
|
-
expect(request_token).to receive(:get_access_token).with(:
|
64
|
-
oauth_client.init_access_token(:
|
60
|
+
mock_access_token = double
|
61
|
+
expect(request_token).to receive(:get_access_token).with(oauth_verifier: 'abc123').and_return(mock_access_token)
|
62
|
+
oauth_client.init_access_token(oauth_verifier: 'abc123')
|
65
63
|
expect(oauth_client.access_token).to eq(mock_access_token)
|
66
64
|
end
|
67
65
|
|
68
|
-
it
|
69
|
-
expect
|
66
|
+
it 'raises an exception when accessing without initialisation' do
|
67
|
+
expect do
|
70
68
|
oauth_client.access_token
|
71
|
-
|
72
|
-
|
69
|
+
end.to raise_exception(JIRA::OauthClient::UninitializedAccessTokenError,
|
70
|
+
'init_access_token must be called before using the client')
|
73
71
|
end
|
74
72
|
|
75
|
-
it
|
76
|
-
token = double
|
73
|
+
it 'allows setting the access token' do
|
74
|
+
token = double
|
77
75
|
expect(OAuth::AccessToken).to receive(:new).with(oauth_client.consumer, 'foo', 'bar').and_return(token)
|
78
76
|
|
79
77
|
access_token = oauth_client.set_access_token('foo', 'bar')
|
@@ -83,61 +81,61 @@ describe JIRA::OauthClient do
|
|
83
81
|
end
|
84
82
|
end
|
85
83
|
|
86
|
-
describe
|
87
|
-
it
|
88
|
-
headers = double
|
89
|
-
mock_access_token = double
|
84
|
+
describe 'http' do
|
85
|
+
it 'responds to the http methods' do
|
86
|
+
headers = double
|
87
|
+
mock_access_token = double
|
90
88
|
allow(oauth_client).to receive(:access_token).and_return(mock_access_token)
|
91
|
-
[
|
89
|
+
%i[delete get head].each do |method|
|
92
90
|
expect(mock_access_token).to receive(method).with('/path', headers).and_return(response)
|
93
91
|
oauth_client.make_request(method, '/path', '', headers)
|
94
92
|
end
|
95
|
-
[
|
93
|
+
%i[post put].each do |method|
|
96
94
|
expect(mock_access_token).to receive(method).with('/path', '', headers).and_return(response)
|
97
95
|
oauth_client.make_request(method, '/path', '', headers)
|
98
96
|
end
|
99
97
|
end
|
100
98
|
|
101
|
-
it
|
99
|
+
it 'performs a request' do
|
102
100
|
body = nil
|
103
|
-
headers = double
|
104
|
-
access_token = double
|
101
|
+
headers = double
|
102
|
+
access_token = double
|
105
103
|
expect(access_token).to receive(:send).with(:get, '/foo', headers).and_return(response)
|
106
104
|
allow(oauth_client).to receive(:access_token).and_return(access_token)
|
107
105
|
oauth_client.request(:get, '/foo', body, headers)
|
108
106
|
end
|
109
107
|
end
|
110
108
|
|
111
|
-
describe
|
109
|
+
describe 'auth type is oauth_2legged' do
|
112
110
|
let(:oauth__2legged_client) do
|
113
|
-
options = { :
|
111
|
+
options = { consumer_key: 'foo', consumer_secret: 'bar', auth_type: :oauth_2legged }
|
114
112
|
options = JIRA::Client::DEFAULT_OPTIONS.merge(options)
|
115
113
|
JIRA::OauthClient.new(options)
|
116
114
|
end
|
117
115
|
|
118
|
-
it
|
119
|
-
headers = double
|
120
|
-
mock_access_token = double
|
116
|
+
it 'responds to the http methods adding oauth_token parameter' do
|
117
|
+
headers = double
|
118
|
+
mock_access_token = double
|
121
119
|
allow(oauth__2legged_client).to receive(:access_token).and_return(mock_access_token)
|
122
|
-
[
|
120
|
+
%i[delete get head].each do |method|
|
123
121
|
expect(mock_access_token).to receive(method).with('/path?oauth_token=', headers).and_return(response)
|
124
122
|
oauth__2legged_client.make_request(method, '/path', '', headers)
|
125
123
|
end
|
126
|
-
[
|
124
|
+
%i[post put].each do |method|
|
127
125
|
expect(mock_access_token).to receive(method).with('/path?oauth_token=', '', headers).and_return(response)
|
128
126
|
oauth__2legged_client.make_request(method, '/path', '', headers)
|
129
127
|
end
|
130
128
|
end
|
131
129
|
|
132
|
-
it
|
133
|
-
headers = double
|
134
|
-
mock_access_token = double
|
130
|
+
it 'responds to the http methods adding oauth_token parameter to any existing parameters' do
|
131
|
+
headers = double
|
132
|
+
mock_access_token = double
|
135
133
|
allow(oauth__2legged_client).to receive(:access_token).and_return(mock_access_token)
|
136
|
-
[
|
134
|
+
%i[delete get head].each do |method|
|
137
135
|
expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', headers).and_return(response)
|
138
136
|
oauth__2legged_client.make_request(method, '/path?any_param=toto', '', headers)
|
139
137
|
end
|
140
|
-
[
|
138
|
+
%i[post put].each do |method|
|
141
139
|
expect(mock_access_token).to receive(method).with('/path?any_param=toto&oauth_token=', '', headers).and_return(response)
|
142
140
|
oauth__2legged_client.make_request(method, '/path?any_param=toto', '', headers)
|
143
141
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe JIRA::RequestClient do
|
4
|
-
|
5
|
-
|
6
|
-
response = double()
|
4
|
+
it 'raises an exception for non success responses' do
|
5
|
+
response = double
|
7
6
|
allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(false)
|
8
7
|
rc = JIRA::RequestClient.new
|
9
8
|
expect(rc).to receive(:make_request).with(:get, '/foo', '', {}).and_return(response)
|
10
|
-
|
9
|
+
|
10
|
+
expect do
|
11
11
|
rc.request(:get, '/foo', '', {})
|
12
|
-
|
12
|
+
end.to raise_exception(JIRA::HTTPError)
|
13
13
|
end
|
14
14
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe JIRA::Resource::Agile do
|
4
4
|
let(:client) do
|
5
|
-
client = double(options: {rest_base_path: '/jira/rest/api/2', context_path: '/jira'})
|
5
|
+
client = double(options: { rest_base_path: '/jira/rest/api/2', context_path: '/jira' })
|
6
6
|
allow(client).to receive(:Issue).and_return(JIRA::Resource::IssueFactory.new(client))
|
7
7
|
client
|
8
8
|
end
|
@@ -42,7 +42,6 @@ describe JIRA::Resource::Agile do
|
|
42
42
|
expect(issue.class).to eq(JIRA::Resource::Issue)
|
43
43
|
expect(issue.expanded?).to be_falsey
|
44
44
|
end
|
45
|
-
|
46
45
|
end
|
47
46
|
|
48
47
|
it 'should query correct url with parameters' do
|
@@ -60,7 +59,6 @@ describe JIRA::Resource::Agile do
|
|
60
59
|
expect(issue.class).to eq(JIRA::Resource::Issue)
|
61
60
|
expect(issue.expanded?).to be_falsey
|
62
61
|
end
|
63
|
-
|
64
62
|
end
|
65
63
|
end
|
66
64
|
|
@@ -78,18 +76,18 @@ describe JIRA::Resource::Agile do
|
|
78
76
|
|
79
77
|
JIRA::Resource::Agile.get_sprints(client, 1, startAt: 50)
|
80
78
|
end
|
81
|
-
|
79
|
+
|
82
80
|
it 'should work with pagination starting at 0' do
|
83
81
|
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=1&startAt=0').and_return(response)
|
84
82
|
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
85
|
-
|
83
|
+
|
86
84
|
JIRA::Resource::Agile.get_sprints(client, 1, maxResults: 1, startAt: 0)
|
87
85
|
end
|
88
|
-
|
86
|
+
|
89
87
|
it 'should work with pagination not starting at 0' do
|
90
88
|
expect(client).to receive(:get).with('/jira/rest/agile/1.0/board/1/sprint?maxResults=1&startAt=1').and_return(response)
|
91
89
|
expect(response).to receive(:body).and_return(get_mock_response('board/1.json'))
|
92
|
-
|
90
|
+
|
93
91
|
JIRA::Resource::Agile.get_sprints(client, 1, maxResults: 1, startAt: 1)
|
94
92
|
end
|
95
93
|
end
|
@@ -1,42 +1,41 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe JIRA::Resource::Attachment do
|
4
|
-
|
5
|
-
let(:client) {
|
4
|
+
let(:client) do
|
6
5
|
double(
|
7
6
|
'client',
|
8
|
-
:
|
9
|
-
:
|
7
|
+
options: {
|
8
|
+
rest_base_path: '/jira/rest/api/2'
|
10
9
|
},
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
10
|
+
request_client: double(
|
11
|
+
options: {
|
12
|
+
username: 'username',
|
13
|
+
password: 'password'
|
15
14
|
}
|
16
15
|
)
|
17
16
|
)
|
18
|
-
|
17
|
+
end
|
19
18
|
|
20
|
-
describe
|
21
|
-
subject
|
19
|
+
describe 'relationships' do
|
20
|
+
subject do
|
22
21
|
JIRA::Resource::Attachment.new(client,
|
23
|
-
:
|
24
|
-
:
|
25
|
-
|
22
|
+
issue: JIRA::Resource::Issue.new(client),
|
23
|
+
attrs: { 'author' => { 'foo' => 'bar' } })
|
24
|
+
end
|
26
25
|
|
27
|
-
it
|
26
|
+
it 'has the correct relationships' do
|
28
27
|
expect(subject).to have_one(:author, JIRA::Resource::User)
|
29
28
|
expect(subject.author.foo).to eq('bar')
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
32
|
describe '#meta' do
|
34
|
-
let(:response)
|
33
|
+
let(:response) do
|
35
34
|
double(
|
36
35
|
'response',
|
37
|
-
:
|
36
|
+
body: '{"enabled":true,"uploadLimit":10485760}'
|
38
37
|
)
|
39
|
-
|
38
|
+
end
|
40
39
|
|
41
40
|
it 'returns meta information about attachment upload' do
|
42
41
|
expect(client).to receive(:get).with('/jira/rest/api/2/attachment/meta').and_return(response)
|
@@ -52,16 +51,16 @@ describe JIRA::Resource::Attachment do
|
|
52
51
|
|
53
52
|
describe '#save!' do
|
54
53
|
it 'successfully update the attachment' do
|
55
|
-
basic_auth_http_conn = double
|
54
|
+
basic_auth_http_conn = double
|
56
55
|
response = double(
|
57
56
|
body: [
|
58
57
|
{
|
59
|
-
"id":
|
60
|
-
"self":
|
61
|
-
"filename":
|
62
|
-
"created":
|
63
|
-
"size":
|
64
|
-
"mimeType":
|
58
|
+
"id": 10_001,
|
59
|
+
"self": 'http://www.example.com/jira/rest/api/2.0/attachments/10000',
|
60
|
+
"filename": 'picture.jpg',
|
61
|
+
"created": '2017-07-19T12:23:06.572+0000',
|
62
|
+
"size": 23_123,
|
63
|
+
"mimeType": 'image/jpeg'
|
65
64
|
}
|
66
65
|
].to_json
|
67
66
|
)
|
@@ -76,7 +75,7 @@ describe JIRA::Resource::Attachment do
|
|
76
75
|
|
77
76
|
expect(attachment.filename).to eq 'picture.jpg'
|
78
77
|
expect(attachment.mimeType).to eq 'image/jpeg'
|
79
|
-
expect(attachment.size).to eq
|
78
|
+
expect(attachment.size).to eq 23_123
|
80
79
|
end
|
81
80
|
end
|
82
81
|
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support/core_ext/hash'
|
3
|
+
|
4
|
+
describe JIRA::Resource::Board do
|
5
|
+
class JIRAResourceDelegation < SimpleDelegator # :nodoc:
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:client) do
|
9
|
+
double(options: {
|
10
|
+
rest_base_path: '/jira/rest/api/2',
|
11
|
+
context_path: ''
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:board) do
|
16
|
+
response = double
|
17
|
+
api_json_board = "{
|
18
|
+
\"id\": 84,
|
19
|
+
\"self\": \"http://www.example.com/jira/rest/agile/1.0/board/84\",
|
20
|
+
\"name\": \"scrum board\",
|
21
|
+
\"type\": \"scrum\"
|
22
|
+
}"
|
23
|
+
allow(response).to receive(:body).and_return(api_json_board)
|
24
|
+
expect(client).to receive(:get).with('/rest/agile/1.0/board/84')
|
25
|
+
.and_return(response)
|
26
|
+
|
27
|
+
expect(client).to receive(:Board).and_return(JIRA::Resource::BoardFactory.new(client))
|
28
|
+
JIRA::Resource::Board.find(client, '84')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should find all boards' do
|
32
|
+
response = double
|
33
|
+
api_json = <<eos
|
34
|
+
{
|
35
|
+
"maxResults": 50,
|
36
|
+
"startAt": 0,
|
37
|
+
"isLast": true,
|
38
|
+
"values": [
|
39
|
+
{
|
40
|
+
"id": 84,
|
41
|
+
"name": "scrum board",
|
42
|
+
"type": "scrum"
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"id": 92,
|
46
|
+
"name": "kanban board",
|
47
|
+
"type": "kanban"
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
51
|
+
eos
|
52
|
+
allow(response).to receive(:body).and_return(api_json)
|
53
|
+
expect(client).to receive(:get).with('/rest/agile/1.0/board')
|
54
|
+
.and_return(response)
|
55
|
+
expect(client).to receive(:Board).twice.and_return(JIRA::Resource::BoardFactory.new(client))
|
56
|
+
boards = JIRA::Resource::Board.all(client)
|
57
|
+
expect(boards.count).to eq(2)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should find one board by id' do
|
61
|
+
expect(board).to be_a(JIRA::Resource::Board)
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#issues' do
|
65
|
+
it 'should find all issues' do
|
66
|
+
issues_response = double
|
67
|
+
|
68
|
+
api_json_issues = <<eos
|
69
|
+
{
|
70
|
+
"expand": "names,schema",
|
71
|
+
"startAt": 0,
|
72
|
+
"maxResults": 50,
|
73
|
+
"total": 1,
|
74
|
+
"issues": [
|
75
|
+
{
|
76
|
+
"id": "10001",
|
77
|
+
"fields": {
|
78
|
+
"sprint": {
|
79
|
+
"id": 37,
|
80
|
+
"state": "future",
|
81
|
+
"name": "sprint 2"
|
82
|
+
},
|
83
|
+
"description": "example bug report"
|
84
|
+
}
|
85
|
+
}
|
86
|
+
]
|
87
|
+
}
|
88
|
+
eos
|
89
|
+
|
90
|
+
allow(issues_response).to receive(:body).and_return(api_json_issues)
|
91
|
+
allow(board).to receive(:id).and_return(84)
|
92
|
+
expect(client).to receive(:get).with('/rest/agile/1.0/board/84/issue?')
|
93
|
+
.and_return(issues_response)
|
94
|
+
expect(client).to receive(:Issue).and_return(JIRA::Resource::IssueFactory.new(client))
|
95
|
+
|
96
|
+
expect(board.issues.size).to be(1)
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'pagination' do
|
100
|
+
subject { described_class.new(client) }
|
101
|
+
let(:client) { JIRA::Client.new }
|
102
|
+
|
103
|
+
before do
|
104
|
+
allow(subject).to receive(:id).and_return('123')
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when there are multiple pages of results' do
|
108
|
+
let(:result_1) do
|
109
|
+
OpenStruct.new(body: {
|
110
|
+
'startAt' => 0,
|
111
|
+
'maxResults' => 1,
|
112
|
+
'total' => 2,
|
113
|
+
'issues' => []
|
114
|
+
}.to_json)
|
115
|
+
end
|
116
|
+
let(:result_2) do
|
117
|
+
OpenStruct.new(body: {
|
118
|
+
'startAt' => 1,
|
119
|
+
'maxResults' => 1,
|
120
|
+
'total' => 2,
|
121
|
+
'issues' => []
|
122
|
+
}.to_json)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'makes multiple requests and increments the startAt param' do
|
126
|
+
expect(client).to receive(:get).and_return(result_1)
|
127
|
+
expect(client).to receive(:get).and_return(result_2)
|
128
|
+
subject.issues
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when there is only one page of results' do
|
133
|
+
let(:result_1) do
|
134
|
+
OpenStruct.new(body: {
|
135
|
+
'startAt' => 0,
|
136
|
+
'maxResults' => 2,
|
137
|
+
'total' => 2,
|
138
|
+
'issues' => []
|
139
|
+
}.to_json)
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'only requires one request' do
|
143
|
+
expect(client).to receive(:get).once.and_return(result_1)
|
144
|
+
subject.issues
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should get all sprints for a board' do
|
151
|
+
response = double
|
152
|
+
|
153
|
+
api_json = <<-eos
|
154
|
+
{
|
155
|
+
"values": [
|
156
|
+
{
|
157
|
+
"id": 37,
|
158
|
+
"state": "closed",
|
159
|
+
"name": "sprint 1"
|
160
|
+
},
|
161
|
+
{
|
162
|
+
"id": 72,
|
163
|
+
"state": "future",
|
164
|
+
"name": "sprint 2"
|
165
|
+
}
|
166
|
+
]
|
167
|
+
}
|
168
|
+
eos
|
169
|
+
allow(response).to receive(:body).and_return(api_json)
|
170
|
+
allow(board).to receive(:id).and_return(84)
|
171
|
+
expect(client).to receive(:get).with('/rest/agile/1.0/board/84/sprint?').and_return(response)
|
172
|
+
expect(client).to receive(:Sprint).twice.and_return(JIRA::Resource::SprintFactory.new(client))
|
173
|
+
expect(board.sprints.size).to be(2)
|
174
|
+
end
|
175
|
+
end
|