jira-ruby 1.1.3 → 2.3.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.
Files changed (108) 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 +38 -6
  9. data/http-basic-example.rb +14 -13
  10. data/jira-ruby.gemspec +13 -13
  11. data/lib/jira/base.rb +58 -53
  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 +14 -22
  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 +8 -8
  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 +39 -34
  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 +86 -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 -54
  107. data/README.rdoc +0 -329
  108. /data/spec/mock_responses/{attachment → issue/10002/attachments}/10000.json +0 -0
@@ -1,153 +1,157 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Issue do
4
-
5
4
  class JIRAResourceDelegation < SimpleDelegator # :nodoc:
6
5
  end
7
6
 
8
7
  let(:client) do
9
- client = double(options: {rest_base_path: '/jira/rest/api/2'} )
8
+ client = double(options: { rest_base_path: '/jira/rest/api/2' })
10
9
  allow(client).to receive(:Field).and_return(JIRA::Resource::FieldFactory.new(client))
11
10
  allow(client).to receive(:cache).and_return(OpenStruct.new)
12
11
  client
13
12
  end
14
13
 
15
- describe "#respond_to?" do
16
- describe "when decorated by SimpleDelegator" do
14
+ describe '#respond_to?' do
15
+ describe 'when decorated by SimpleDelegator' do
17
16
  before(:each) do
18
- response = double()
17
+ response = double
19
18
  allow(response).to receive(:body).and_return('{"key":"foo","id":"101"}')
20
19
  allow(JIRA::Resource::Issue).to receive(:collection_path).and_return('/jira/rest/api/2/issue')
21
- allow(client).to receive(:get).with('/jira/rest/api/2/issue/101').
22
- and_return(response)
20
+ allow(client).to receive(:get).with('/jira/rest/api/2/issue/101')
21
+ .and_return(response)
23
22
 
24
- issue = JIRA::Resource::Issue.find(client,101)
25
- @decorated = JIRAResourceDelegation.new( issue )
23
+ issue = JIRA::Resource::Issue.find(client, 101)
24
+ @decorated = JIRAResourceDelegation.new(issue)
26
25
  end
27
- it "responds to key" do
26
+ it 'responds to key' do
28
27
  expect(@decorated.respond_to?(:key)).to eq(true)
29
28
  end
30
- it "does not raise an error" do
31
- expect {
29
+ it 'does not raise an error' do
30
+ expect do
32
31
  @issue.respond_to?(:project)
33
- }.not_to raise_error
32
+ end.not_to raise_error
34
33
  end
35
34
  end
36
35
  end
37
36
 
38
- it "should find all issues" do
39
- response = double()
40
- issue = double()
37
+ it 'should find all issues' do
38
+ response = double
39
+ empty_response = double
40
+ issue = double
41
41
 
42
42
  allow(response).to receive(:body).and_return('{"issues":[{"id":"1","summary":"Bugs Everywhere"}]}')
43
- expect(client).to receive(:get).with('/jira/rest/api/2/search?expand=transitions.fields').
44
- and_return(response)
43
+ expect(client).to receive(:get).with('/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=0')
44
+ .and_return(response)
45
+ allow(empty_response).to receive(:body).and_return('{"issues":[]}')
46
+ expect(client).to receive(:get).with('/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=1')
47
+ .and_return(empty_response)
48
+
45
49
  expect(client).to receive(:Issue).and_return(issue)
46
- expect(issue).to receive(:build).with({"id"=>"1","summary"=>"Bugs Everywhere"})
50
+ expect(issue).to receive(:build).with({ 'id' => '1', 'summary' => 'Bugs Everywhere' })
47
51
 
48
52
  issues = JIRA::Resource::Issue.all(client)
49
53
  end
50
54
 
51
- it "should find an issue by key or id" do
52
- response = double()
55
+ it 'should find an issue by key or id' do
56
+ response = double
53
57
 
54
58
  allow(response).to receive(:body).and_return('{"key":"foo","id":"101"}')
55
59
  allow(JIRA::Resource::Issue).to receive(:collection_path).and_return('/jira/rest/api/2/issue')
56
- expect(client).to receive(:get).with('/jira/rest/api/2/issue/foo').
57
- and_return(response)
58
- expect(client).to receive(:get).with('/jira/rest/api/2/issue/101').
59
- and_return(response)
60
+ expect(client).to receive(:get).with('/jira/rest/api/2/issue/foo')
61
+ .and_return(response)
62
+ expect(client).to receive(:get).with('/jira/rest/api/2/issue/101')
63
+ .and_return(response)
60
64
 
61
- issue_from_id = JIRA::Resource::Issue.find(client,101)
62
- issue_from_key = JIRA::Resource::Issue.find(client,'foo')
65
+ issue_from_id = JIRA::Resource::Issue.find(client, 101)
66
+ issue_from_key = JIRA::Resource::Issue.find(client, 'foo')
63
67
 
64
68
  expect(issue_from_id.attrs).to eq(issue_from_key.attrs)
65
69
  end
66
70
 
67
- it "should search an issue with a jql query string" do
68
- response = double()
69
- issue = double()
71
+ it 'should search an issue with a jql query string' do
72
+ response = double
73
+ issue = double
70
74
 
71
75
  allow(response).to receive(:body).and_return('{"issues": {"key":"foo"}}')
72
- expect(client).to receive(:get).with('/jira/rest/api/2/search?jql=foo+bar').
73
- and_return(response)
76
+ expect(client).to receive(:get).with('/jira/rest/api/2/search?jql=foo+bar')
77
+ .and_return(response)
74
78
  expect(client).to receive(:Issue).and_return(issue)
75
- expect(issue).to receive(:build).with(["key", "foo"]).and_return('')
79
+ expect(issue).to receive(:build).with(%w[key foo]).and_return('')
76
80
 
77
- expect(JIRA::Resource::Issue.jql(client,'foo bar')).to eq([''])
81
+ expect(JIRA::Resource::Issue.jql(client, 'foo bar')).to eq([''])
78
82
  end
79
83
 
80
- it "should search an issue with a jql query string and fields" do
81
- response = double()
82
- issue = double()
84
+ it 'should search an issue with a jql query string and fields' do
85
+ response = double
86
+ issue = double
83
87
 
84
88
  allow(response).to receive(:body).and_return('{"issues": {"key":"foo"}}')
85
89
  expect(client).to receive(:get)
86
90
  .with('/jira/rest/api/2/search?jql=foo+bar&fields=foo,bar')
87
91
  .and_return(response)
88
92
  expect(client).to receive(:Issue).and_return(issue)
89
- expect(issue).to receive(:build).with(["key", "foo"]).and_return('')
93
+ expect(issue).to receive(:build).with(%w[key foo]).and_return('')
90
94
 
91
- expect(JIRA::Resource::Issue.jql(client, 'foo bar', fields: ['foo','bar'])).to eq([''])
95
+ expect(JIRA::Resource::Issue.jql(client, 'foo bar', fields: %w[foo bar])).to eq([''])
92
96
  end
93
97
 
94
- it "should search an issue with a jql query string, start at, and maxResults" do
95
- response = double()
96
- issue = double()
98
+ it 'should search an issue with a jql query string, start at, and maxResults' do
99
+ response = double
100
+ issue = double
97
101
 
98
102
  allow(response).to receive(:body).and_return('{"issues": {"key":"foo"}}')
99
103
  expect(client).to receive(:get)
100
104
  .with('/jira/rest/api/2/search?jql=foo+bar&startAt=1&maxResults=3')
101
105
  .and_return(response)
102
106
  expect(client).to receive(:Issue).and_return(issue)
103
- expect(issue).to receive(:build).with(["key", "foo"]).and_return('')
107
+ expect(issue).to receive(:build).with(%w[key foo]).and_return('')
104
108
 
105
- expect(JIRA::Resource::Issue.jql(client,'foo bar', start_at: 1, max_results: 3)).to eq([''])
109
+ expect(JIRA::Resource::Issue.jql(client, 'foo bar', start_at: 1, max_results: 3)).to eq([''])
106
110
  end
107
111
 
108
- it "should search an issue with a jql query string and maxResults equals zero and should return the count of tickets" do
109
- response = double()
110
- issue = double()
112
+ it 'should search an issue with a jql query string and maxResults equals zero and should return the count of tickets' do
113
+ response = double
114
+ issue = double
111
115
 
112
116
  allow(response).to receive(:body).and_return('{"total": 1, "issues": []}')
113
117
  expect(client).to receive(:get)
114
118
  .with('/jira/rest/api/2/search?jql=foo+bar&maxResults=0')
115
119
  .and_return(response)
116
120
 
117
- expect(JIRA::Resource::Issue.jql(client,'foo bar', max_results: 0)).to eq(1)
121
+ expect(JIRA::Resource::Issue.jql(client, 'foo bar', max_results: 0)).to eq(1)
118
122
  end
119
123
 
120
- it "should search an issue with a jql query string and string expand" do
121
- response = double()
122
- issue = double()
124
+ it 'should search an issue with a jql query string and string expand' do
125
+ response = double
126
+ issue = double
123
127
 
124
128
  allow(response).to receive(:body).and_return('{"issues": {"key":"foo"}}')
125
129
  expect(client).to receive(:get)
126
130
  .with('/jira/rest/api/2/search?jql=foo+bar&expand=transitions')
127
131
  .and_return(response)
128
132
  expect(client).to receive(:Issue).and_return(issue)
129
- expect(issue).to receive(:build).with(["key", "foo"]).and_return('')
133
+ expect(issue).to receive(:build).with(%w[key foo]).and_return('')
130
134
 
131
- expect(JIRA::Resource::Issue.jql(client,'foo bar', expand: 'transitions')).to eq([''])
135
+ expect(JIRA::Resource::Issue.jql(client, 'foo bar', expand: 'transitions')).to eq([''])
132
136
  end
133
137
 
134
- it "should search an issue with a jql query string and array expand" do
135
- response = double()
136
- issue = double()
138
+ it 'should search an issue with a jql query string and array expand' do
139
+ response = double
140
+ issue = double
137
141
 
138
142
  allow(response).to receive(:body).and_return('{"issues": {"key":"foo"}}')
139
143
  expect(client).to receive(:get)
140
144
  .with('/jira/rest/api/2/search?jql=foo+bar&expand=transitions')
141
145
  .and_return(response)
142
146
  expect(client).to receive(:Issue).and_return(issue)
143
- expect(issue).to receive(:build).with(["key", "foo"]).and_return('')
147
+ expect(issue).to receive(:build).with(%w[key foo]).and_return('')
144
148
 
145
- expect(JIRA::Resource::Issue.jql(client,'foo bar', expand: %w(transitions))).to eq([''])
149
+ expect(JIRA::Resource::Issue.jql(client, 'foo bar', expand: %w[transitions])).to eq([''])
146
150
  end
147
151
 
148
152
  it 'should return meta data available for editing an issue' do
149
- subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'key' =>'TST=123'}})
150
- response = double()
153
+ subject = JIRA::Resource::Issue.new(client, attrs: { 'fields' => { 'key' => 'TST=123' } })
154
+ response = double
151
155
 
152
156
  allow(response).to receive(:body).and_return(
153
157
  '{"fields":{"summary":{"required":true,"name":"Summary","operations":["set"]}}}'
@@ -156,37 +160,36 @@ describe JIRA::Resource::Issue do
156
160
  .with('/jira/rest/api/2/issue/TST=123/editmeta')
157
161
  .and_return(response)
158
162
 
159
- expect(subject.editmeta).to eq({'summary' => {'required' => true, 'name' => 'Summary', 'operations' => ['set']}})
163
+ expect(subject.editmeta).to eq('summary' => { 'required' => true, 'name' => 'Summary', 'operations' => ['set'] })
160
164
  end
161
165
 
162
-
163
- it "provides direct accessors to the fields" do
164
- subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'foo' =>'bar'}})
166
+ it 'provides direct accessors to the fields' do
167
+ subject = JIRA::Resource::Issue.new(client, attrs: { 'fields' => { 'foo' => 'bar' } })
165
168
  expect(subject).to respond_to(:foo)
166
169
  expect(subject.foo).to eq('bar')
167
170
  end
168
171
 
169
- describe "relationships" do
170
- subject {
171
- JIRA::Resource::Issue.new(client, :attrs => {
172
- 'id' => '123',
173
- 'fields' => {
174
- 'reporter' => {'foo' => 'bar'},
175
- 'assignee' => {'foo' => 'bar'},
176
- 'project' => {'foo' => 'bar'},
177
- 'priority' => {'foo' => 'bar'},
178
- 'issuetype' => {'foo' => 'bar'},
179
- 'status' => {'foo' => 'bar'},
180
- 'components' => [{'foo' => 'bar'}, {'baz' => 'flum'}],
181
- 'versions' => [{'foo' => 'bar'}, {'baz' => 'flum'}],
182
- 'comment' => { 'comments' => [{'foo' => 'bar'}, {'baz' => 'flum'}]},
183
- 'attachment' => [{'foo' => 'bar'}, {'baz' => 'flum'}],
184
- 'worklog' => { 'worklogs' => [{'foo' => 'bar'}, {'baz' => 'flum'}]},
185
- }
186
- })
187
- }
188
-
189
- it "has the correct relationships" do
172
+ describe 'relationships' do
173
+ subject do
174
+ JIRA::Resource::Issue.new(client, attrs: {
175
+ 'id' => '123',
176
+ 'fields' => {
177
+ 'reporter' => { 'foo' => 'bar' },
178
+ 'assignee' => { 'foo' => 'bar' },
179
+ 'project' => { 'foo' => 'bar' },
180
+ 'priority' => { 'foo' => 'bar' },
181
+ 'issuetype' => { 'foo' => 'bar' },
182
+ 'status' => { 'foo' => 'bar' },
183
+ 'components' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }],
184
+ 'versions' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }],
185
+ 'comment' => { 'comments' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] },
186
+ 'attachment' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }],
187
+ 'worklog' => { 'worklogs' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] }
188
+ }
189
+ })
190
+ end
191
+
192
+ it 'has the correct relationships' do
190
193
  expect(subject).to have_one(:reporter, JIRA::Resource::User)
191
194
  expect(subject.reporter.foo).to eq('bar')
192
195
 
@@ -11,4 +11,4 @@
11
11
  # )
12
12
  # }
13
13
  # end
14
- # end
14
+ # end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::IssuePickerSuggestionsIssue do
4
+ let(:client) { double('client') }
5
+
6
+ describe 'relationships' do
7
+ subject do
8
+ JIRA::Resource::IssuePickerSuggestionsIssue.new(client, attrs: {
9
+ 'issues' => [{ 'id' => '1'}, { 'id' => '2' }]
10
+ })
11
+ end
12
+
13
+ it 'has the correct relationships' do
14
+ expect(subject).to have_many(:issues, JIRA::Resource::SuggestedIssue)
15
+ expect(subject.issues.length).to eq(2)
16
+ end
17
+ end
18
+ end
@@ -1,13 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::ProjectFactory do
4
-
5
- let(:client) { double() }
4
+ let(:client) { double }
6
5
  subject { JIRA::Resource::ProjectFactory.new(client) }
7
6
 
8
- it "initializes correctly" do
7
+ it 'initializes correctly' do
9
8
  expect(subject.class).to eq(JIRA::Resource::ProjectFactory)
10
9
  expect(subject.client).to eq(client)
11
10
  end
12
-
13
11
  end
@@ -1,22 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Project do
4
+ let(:client) do
5
+ double('client', options: {
6
+ rest_base_path: '/jira/rest/api/2'
7
+ })
8
+ end
9
+
10
+ describe 'relationships' do
11
+ subject do
12
+ JIRA::Resource::Project.new(client, attrs: {
13
+ 'lead' => { 'foo' => 'bar' },
14
+ 'issueTypes' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }],
15
+ 'versions' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }]
16
+ })
17
+ end
4
18
 
5
- let(:client) { double("client", :options => {
6
- :rest_base_path => '/jira/rest/api/2'
7
- })
8
- }
9
-
10
- describe "relationships" do
11
- subject {
12
- JIRA::Resource::Project.new(client, :attrs => {
13
- 'lead' => {'foo' => 'bar'},
14
- 'issueTypes' => [{'foo' =>'bar'},{'baz' => 'flum'}],
15
- 'versions' => [{'foo' =>'bar'},{'baz' => 'flum'}],
16
- })
17
- }
18
-
19
- it "has the correct relationships" do
19
+ it 'has the correct relationships' do
20
20
  expect(subject).to have_one(:lead, JIRA::Resource::User)
21
21
  expect(subject.lead.foo).to eq('bar')
22
22
 
@@ -28,42 +28,95 @@ describe JIRA::Resource::Project do
28
28
  end
29
29
  end
30
30
 
31
- describe "issues" do
32
- subject {
33
- JIRA::Resource::Project.new(client, :attrs => {
34
- 'key' => 'test'
35
- })
36
- }
31
+ describe 'issues' do
32
+ subject do
33
+ JIRA::Resource::Project.new(client, attrs: {
34
+ 'key' => 'test'
35
+ })
36
+ end
37
37
 
38
- it "returns issues" do
38
+ it 'returns issues' do
39
39
  response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"}}]}'
40
- response = double("response",
41
- :body => response_body)
42
- issue_factory = double("issue factory")
40
+ response = double('response',
41
+ body: response_body)
42
+ issue_factory = double('issue factory')
43
43
 
44
44
  expect(client).to receive(:get)
45
45
  .with('/jira/rest/api/2/search?jql=project%3D%22test%22')
46
46
  .and_return(response)
47
47
  expect(client).to receive(:Issue).and_return(issue_factory)
48
48
  expect(issue_factory).to receive(:build)
49
- .with(JSON.parse(response_body)["issues"][0])
49
+ .with(JSON.parse(response_body)['issues'][0])
50
50
  subject.issues
51
51
  end
52
52
 
53
- context "with changelog" do
54
- it "returns issues" do
53
+ context 'with changelog' do
54
+ it 'returns issues' do
55
55
  response_body = '{"expand":"schema,names","startAt":0,"maxResults":1,"total":1,"issues":[{"expand":"editmeta,renderedFields,transitions,changelog,operations","id":"53062","self":"/rest/api/2/issue/53062","key":"test key","fields":{"summary":"test summary"},"changelog":{}}]}'
56
- response = double("response",
57
- :body => response_body)
58
- issue_factory = double("issue factory")
56
+ response = double('response',
57
+ body: response_body)
58
+ issue_factory = double('issue factory')
59
59
 
60
60
  expect(client).to receive(:get)
61
61
  .with('/jira/rest/api/2/search?jql=project%3D%22test%22&expand=changelog&startAt=1&maxResults=100')
62
62
  .and_return(response)
63
63
  expect(client).to receive(:Issue).and_return(issue_factory)
64
64
  expect(issue_factory).to receive(:build)
65
- .with(JSON.parse(response_body)["issues"][0])
66
- subject.issues({expand:'changelog', startAt:1, maxResults:100})
65
+ .with(JSON.parse(response_body)['issues'][0])
66
+ subject.issues(expand: 'changelog', startAt: 1, maxResults: 100)
67
+ end
68
+ end
69
+ end
70
+
71
+ describe 'users' do
72
+ let(:project) { JIRA::Resource::Project.new(client, attrs: { 'key' => project_key }) }
73
+ let(:project_key) { SecureRandom.hex }
74
+ let(:response) { double('response', body: '[{}]') }
75
+
76
+ context 'pagination' do
77
+ before(:each) do
78
+ user_factory = double('user factory')
79
+ expect(client).to receive(:User).and_return(user_factory)
80
+ expect(user_factory).to receive(:build).with(any_args)
81
+ end
82
+
83
+ it 'doesn\'t use pagination parameters by default' do
84
+ expect(client).to receive(:get)
85
+ .with("/jira/rest/api/2/user/assignable/search?project=#{project_key}")
86
+ .and_return(response)
87
+
88
+ project.users
89
+ end
90
+
91
+ it 'accepts start_at option' do
92
+ start_at = rand(1000)
93
+
94
+ expect(client).to receive(:get)
95
+ .with("/jira/rest/api/2/user/assignable/search?project=#{project_key}&startAt=#{start_at}")
96
+ .and_return(response)
97
+
98
+ project.users(start_at: start_at)
99
+ end
100
+
101
+ it 'accepts max_results option' do
102
+ max_results = rand(1000)
103
+
104
+ expect(client).to receive(:get)
105
+ .with("/jira/rest/api/2/user/assignable/search?project=#{project_key}&maxResults=#{max_results}")
106
+ .and_return(response)
107
+
108
+ project.users(max_results: max_results)
109
+ end
110
+
111
+ it 'accepts start_at and max_results options' do
112
+ start_at = rand(1000)
113
+ max_results = rand(1000)
114
+
115
+ expect(client).to receive(:get)
116
+ .with("/jira/rest/api/2/user/assignable/search?project=#{project_key}&startAt=#{start_at}&maxResults=#{max_results}")
117
+ .and_return(response)
118
+
119
+ project.users(start_at: start_at, max_results: max_results)
67
120
  end
68
121
  end
69
122
  end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::Resource::Sprint do
4
+ let(:client) do
5
+ client = double(options: { site: 'https://foo.bar.com', context_path: '/jira' })
6
+ allow(client).to receive(:Sprint).and_return(JIRA::Resource::SprintFactory.new(client))
7
+ client
8
+ end
9
+ let(:sprint) { described_class.new(client) }
10
+ let(:agile_sprint_path) { "#{sprint.client.options[:context_path]}/rest/agile/1.0/sprint/#{sprint.id}" }
11
+
12
+ describe '::find' do
13
+ let(:response) { double('Response', body: '{"some_detail":"some detail"}') }
14
+
15
+ it 'fetches the sprint from JIRA' do
16
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/111').and_return(response)
17
+ expect(JIRA::Resource::Sprint.find(client, '111')).to be_a(JIRA::Resource::Sprint)
18
+ end
19
+ end
20
+
21
+ describe 'peristence' do
22
+ describe '#save' do
23
+ let(:instance_attrs) { { start_date: '2016-06-01' } }
24
+
25
+ before do
26
+ sprint.attrs = instance_attrs
27
+ end
28
+
29
+ context 'when attributes are specified' do
30
+ let(:given_attrs) { { start_date: '2016-06-10' } }
31
+
32
+ it 'calls save on the super class with the given attributes & agile url' do
33
+ expect_any_instance_of(JIRA::Base).to receive(:save).with(given_attrs, agile_sprint_path)
34
+
35
+ sprint.save(given_attrs)
36
+ end
37
+ end
38
+
39
+ context 'when attributes are not specified' do
40
+ it 'calls save on the super class with the instance attributes & agile url' do
41
+ expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_path)
42
+
43
+ sprint.save
44
+ end
45
+ end
46
+
47
+ context 'when providing the path argument' do
48
+ it 'ignores it' do
49
+ expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_path)
50
+
51
+ sprint.save({}, 'mavenlink.com')
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '#save!' do
57
+ let(:instance_attrs) { { start_date: '2016-06-01' } }
58
+
59
+ before do
60
+ sprint.attrs = instance_attrs
61
+ end
62
+
63
+ context 'when attributes are specified' do
64
+ let(:given_attrs) { { start_date: '2016-06-10' } }
65
+
66
+ it 'calls save! on the super class with the given attributes & agile url' do
67
+ expect_any_instance_of(JIRA::Base).to receive(:save!).with(given_attrs, agile_sprint_path)
68
+
69
+ sprint.save!(given_attrs)
70
+ end
71
+ end
72
+
73
+ context 'when attributes are not specified' do
74
+ it 'calls save! on the super class with the instance attributes & agile url' do
75
+ expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_path)
76
+
77
+ sprint.save!
78
+ end
79
+ end
80
+
81
+ context 'when providing the path argument' do
82
+ it 'ignores it' do
83
+ expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_path)
84
+
85
+ sprint.save!({}, 'mavenlink.com')
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -1,19 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::UserFactory do
4
-
5
- let(:client) {
4
+ let(:client) do
6
5
  instance_double('Client', options: { rest_base_path: '/jira/rest/api/2' })
7
- }
6
+ end
8
7
 
9
8
  subject { JIRA::Resource::UserFactory.new(client) }
10
9
 
11
- describe "#myself" do
12
- let(:response) {
10
+ describe '#myself' do
11
+ let(:response) do
13
12
  instance_double(
14
13
  'Response', body: get_mock_response('user_username=admin.json')
15
14
  )
16
- }
15
+ end
17
16
 
18
17
  let(:user) { subject.myself }
19
18
 
@@ -23,11 +22,10 @@ describe JIRA::Resource::UserFactory do
23
22
  ).and_return(response)
24
23
  end
25
24
 
26
- it "returns a JIRA::Resource::User with correct attrs" do
25
+ it 'returns a JIRA::Resource::User with correct attrs' do
27
26
  expect(user).to be_a(JIRA::Resource::User)
28
27
  expect(user.name).to eq('admin')
29
28
  expect(user.emailAddress).to eq('admin@example.com')
30
29
  end
31
30
  end
32
-
33
31
  end
@@ -1,18 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Worklog do
4
+ let(:client) { double }
4
5
 
5
- let(:client) { double() }
6
-
7
- describe "relationships" do
8
- subject {
9
- JIRA::Resource::Worklog.new(client, :issue_id => '99999', :attrs => {
10
- 'author' => {'foo' => 'bar'},
11
- 'updateAuthor' => {'foo' => 'bar'}
12
- })
13
- }
6
+ describe 'relationships' do
7
+ subject do
8
+ JIRA::Resource::Worklog.new(client, issue_id: '99999', attrs: {
9
+ 'author' => { 'foo' => 'bar' },
10
+ 'updateAuthor' => { 'foo' => 'bar' }
11
+ })
12
+ end
14
13
 
15
- it "has the correct relationships" do
14
+ it 'has the correct relationships' do
16
15
  expect(subject).to have_one(:author, JIRA::Resource::User)
17
16
  expect(subject.author.foo).to eq('bar')
18
17
 
@@ -20,5 +19,4 @@ describe JIRA::Resource::Worklog do
20
19
  expect(subject.update_author.foo).to eq('bar')
21
20
  end
22
21
  end
23
-
24
22
  end