jira-ruby 0.1.10 → 0.1.11
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.
- checksums.yaml +4 -4
- data/jira-ruby.gemspec +6 -6
- data/lib/jira/version.rb +1 -1
- data/spec/integration/issue_spec.rb +1 -1
- data/spec/integration/project_spec.rb +5 -5
- data/spec/integration/transition_spec.rb +1 -1
- data/spec/jira/base_factory_spec.rb +9 -9
- data/spec/jira/base_spec.rb +164 -167
- data/spec/jira/client_spec.rb +45 -45
- data/spec/jira/has_many_proxy_spec.rb +13 -11
- data/spec/jira/http_client_spec.rb +34 -34
- data/spec/jira/http_error_spec.rb +8 -7
- data/spec/jira/oauth_client_spec.rb +25 -25
- data/spec/jira/request_client_spec.rb +2 -2
- data/spec/jira/resource/attachment_spec.rb +2 -2
- data/spec/jira/resource/filter_spec.rb +7 -7
- data/spec/jira/resource/issue_spec.rb +39 -39
- data/spec/jira/resource/project_factory_spec.rb +2 -2
- data/spec/jira/resource/project_spec.rb +12 -12
- data/spec/jira/resource/worklog_spec.rb +4 -4
- data/spec/support/matchers/have_attributes.rb +2 -2
- data/spec/support/matchers/have_many.rb +3 -3
- data/spec/support/matchers/have_one.rb +1 -1
- data/spec/support/shared_examples/integration.rb +20 -22
- metadata +26 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd0485d4d1924b9830318cc9875ff1d5284f605a
|
4
|
+
data.tar.gz: b211fbe17e3ffa4033a93ab043abeeb93db0d5df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d26f6b648a24d94301771c970c224acce705508354f58eee97884ddd92fcac60a1779c332a248a8b4ad9bd03af6ebb4ae10e4a37416f44f49ddab534416566fa
|
7
|
+
data.tar.gz: 16293a18535b195e2df37a86b25195de1e39cd68ab350e3f872753e3537fd8090548058aa6d3ec52dcfdf8ac5c36326fcc6a3036e79edd49545c303d06c66f9b
|
data/jira-ruby.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_development_dependency "railties"
|
22
|
-
s.add_runtime_dependency "oauth"
|
23
|
-
s.add_runtime_dependency "activesupport"
|
24
|
-
s.add_development_dependency "webmock"
|
25
|
-
s.add_development_dependency "rspec"
|
26
|
-
s.add_development_dependency "rake"
|
21
|
+
s.add_development_dependency "railties", '~> 4.1.4'
|
22
|
+
s.add_runtime_dependency "oauth", '~> 0.4.7'
|
23
|
+
s.add_runtime_dependency "activesupport", '~> 4.1.4'
|
24
|
+
s.add_development_dependency "webmock", '~> 1.18.0'
|
25
|
+
s.add_development_dependency "rspec", '~> 3.0.0'
|
26
|
+
s.add_development_dependency "rake", '~> 10.3.2'
|
27
27
|
end
|
28
28
|
|
data/lib/jira/version.rb
CHANGED
@@ -69,7 +69,7 @@ describe JIRA::Resource::Issue do
|
|
69
69
|
it "fails to save when fields and update are missing" do
|
70
70
|
subject = client.Issue.build('id' => '10002')
|
71
71
|
subject.fetch
|
72
|
-
subject.save('missing' => 'fields and update').
|
72
|
+
expect(subject.save('missing' => 'fields and update')).to be_falsey
|
73
73
|
end
|
74
74
|
|
75
75
|
end
|
@@ -30,10 +30,10 @@ describe JIRA::Resource::Project do
|
|
30
30
|
to_return(:status => 200, :body => get_mock_response('project/SAMPLEPROJECT.issues.json'))
|
31
31
|
subject = client.Project.build('key' => key)
|
32
32
|
issues = subject.issues
|
33
|
-
issues.length.
|
33
|
+
expect(issues.length).to eq(11)
|
34
34
|
issues.each do |issue|
|
35
|
-
issue.class.
|
36
|
-
issue.expanded
|
35
|
+
expect(issue.class).to eq(JIRA::Resource::Issue)
|
36
|
+
expect(issue.expanded?).to be_falsey
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
@@ -46,9 +46,9 @@ describe JIRA::Resource::Project do
|
|
46
46
|
to_return(:status => 200, :body => get_mock_response('project/SAMPLEPROJECT.json'))
|
47
47
|
|
48
48
|
subject = client.Project.find(key)
|
49
|
-
subject.components.length.
|
49
|
+
expect(subject.components.length).to eq(2)
|
50
50
|
subject.components.each do |component|
|
51
|
-
component.class.
|
51
|
+
expect(component.class).to eq(JIRA::Resource::Component)
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
@@ -43,7 +43,7 @@ describe JIRA::Resource::Transition do
|
|
43
43
|
.with(:body => attributes_for_post.to_json)
|
44
44
|
.to_return(:status => 200, :body => get_mock_from_path(:post))
|
45
45
|
subject = build_receiver.build
|
46
|
-
subject.save(attributes_for_post).
|
46
|
+
expect(subject.save(attributes_for_post)).to be_truthy
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -9,38 +9,38 @@ describe JIRA::BaseFactory do
|
|
9
9
|
subject { JIRA::Resource::FooFactory.new(client) }
|
10
10
|
|
11
11
|
it "initializes correctly" do
|
12
|
-
subject.class.
|
13
|
-
subject.client.
|
14
|
-
subject.target_class.
|
12
|
+
expect(subject.class).to eq(JIRA::Resource::FooFactory)
|
13
|
+
expect(subject.client).to eq(client)
|
14
|
+
expect(subject.target_class).to eq(JIRA::Resource::Foo)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "proxies all to the target class" do
|
18
|
-
JIRA::Resource::Foo.
|
18
|
+
expect(JIRA::Resource::Foo).to receive(:all).with(client)
|
19
19
|
subject.all
|
20
20
|
end
|
21
21
|
|
22
22
|
it "proxies find to the target class" do
|
23
|
-
JIRA::Resource::Foo.
|
23
|
+
expect(JIRA::Resource::Foo).to receive(:find).with(client, 'FOO')
|
24
24
|
subject.find('FOO')
|
25
25
|
end
|
26
26
|
|
27
27
|
it "returns the target class" do
|
28
|
-
subject.target_class.
|
28
|
+
expect(subject.target_class).to eq(JIRA::Resource::Foo)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "proxies build to the target class" do
|
32
32
|
attrs = double()
|
33
|
-
JIRA::Resource::Foo.
|
33
|
+
expect(JIRA::Resource::Foo).to receive(:build).with(client, attrs)
|
34
34
|
subject.build(attrs)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "proxies collection path to the target class" do
|
38
|
-
JIRA::Resource::Foo.
|
38
|
+
expect(JIRA::Resource::Foo).to receive(:collection_path).with(client)
|
39
39
|
subject.collection_path
|
40
40
|
end
|
41
41
|
|
42
42
|
it "proxies singular path to the target class" do
|
43
|
-
JIRA::Resource::Foo.
|
43
|
+
expect(JIRA::Resource::Foo).to receive(:singular_path).with(client, 'FOO')
|
44
44
|
subject.singular_path('FOO')
|
45
45
|
end
|
46
46
|
end
|
data/spec/jira/base_spec.rb
CHANGED
@@ -37,97 +37,98 @@ describe JIRA::Base do
|
|
37
37
|
subject { JIRA::Resource::Deadbeef.new(client, :attrs => attrs) }
|
38
38
|
|
39
39
|
it "assigns the client and attrs" do
|
40
|
-
subject.client.
|
41
|
-
subject.attrs.
|
40
|
+
expect(subject.client).to eq(client)
|
41
|
+
expect(subject.attrs).to eq(attrs)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "returns all the deadbeefs" do
|
45
45
|
response = double()
|
46
|
-
response.
|
47
|
-
client.
|
48
|
-
JIRA::Resource::Deadbeef.
|
46
|
+
expect(response).to receive(:body).and_return('[{"self":"http://deadbeef/","id":"98765"}]')
|
47
|
+
expect(client).to receive(:get).with('/jira/rest/api/2/deadbeef').and_return(response)
|
48
|
+
expect(JIRA::Resource::Deadbeef).to receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
|
49
49
|
deadbeefs = JIRA::Resource::Deadbeef.all(client)
|
50
|
-
deadbeefs.length.
|
50
|
+
expect(deadbeefs.length).to eq(1)
|
51
51
|
first = deadbeefs.first
|
52
|
-
first.class.
|
53
|
-
first.attrs['self'].
|
54
|
-
first.attrs['id'].
|
55
|
-
first.expanded
|
52
|
+
expect(first.class).to eq(JIRA::Resource::Deadbeef)
|
53
|
+
expect(first.attrs['self']).to eq('http://deadbeef/')
|
54
|
+
expect(first.attrs['id']).to eq('98765')
|
55
|
+
expect(first.expanded?).to be_falsey
|
56
56
|
end
|
57
57
|
|
58
58
|
it "finds a deadbeef by id" do
|
59
|
-
response =
|
60
|
-
|
61
|
-
|
62
|
-
JIRA::Resource::Deadbeef.should_receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
|
59
|
+
response = instance_double("Response", body: '{"self":"http://deadbeef/","id":"98765"}')
|
60
|
+
expect(client).to receive(:get).with('/jira/rest/api/2/deadbeef/98765').and_return(response)
|
61
|
+
expect(JIRA::Resource::Deadbeef).to receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
|
63
62
|
deadbeef = JIRA::Resource::Deadbeef.find(client, '98765')
|
64
|
-
deadbeef.client.
|
65
|
-
deadbeef.attrs['self'].
|
66
|
-
deadbeef.attrs['id'].
|
67
|
-
deadbeef.expanded
|
63
|
+
expect(deadbeef.client).to eq(client)
|
64
|
+
expect(deadbeef.attrs['self']).to eq('http://deadbeef/')
|
65
|
+
expect(deadbeef.attrs['id']).to eq('98765')
|
66
|
+
expect(deadbeef.expanded?).to be_truthy
|
68
67
|
end
|
69
68
|
|
70
69
|
it "finds a deadbeef containing changelog by id" do
|
71
|
-
response =
|
72
|
-
|
73
|
-
|
70
|
+
response = instance_double(
|
71
|
+
"Response",
|
72
|
+
body: '{"self":"http://deadbeef/","id":"98765","changelog":{"histories":[]}}'
|
73
|
+
)
|
74
|
+
expect(client).to receive(:get).with('/jira/rest/api/2/deadbeef/98765?expand=changelog').and_return(response)
|
74
75
|
|
75
|
-
JIRA::Resource::Deadbeef.
|
76
|
+
expect(JIRA::Resource::Deadbeef).to receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
|
76
77
|
|
77
78
|
deadbeef = JIRA::Resource::Deadbeef.find(client, '98765', {expand:'changelog'})
|
78
|
-
deadbeef.client.
|
79
|
-
deadbeef.attrs['self'].
|
80
|
-
deadbeef.attrs['id'].
|
81
|
-
deadbeef.expanded
|
82
|
-
deadbeef.attrs['changelog']['histories'].
|
79
|
+
expect(deadbeef.client).to eq(client)
|
80
|
+
expect(deadbeef.attrs['self']).to eq('http://deadbeef/')
|
81
|
+
expect(deadbeef.attrs['id']).to eq('98765')
|
82
|
+
expect(deadbeef.expanded?).to be_truthy
|
83
|
+
expect(deadbeef.attrs['changelog']['histories']).to eq([])
|
83
84
|
end
|
84
85
|
|
85
86
|
it "builds a deadbeef" do
|
86
87
|
deadbeef = JIRA::Resource::Deadbeef.build(client, 'id' => "98765" )
|
87
|
-
deadbeef.expanded
|
88
|
+
expect(deadbeef.expanded?).to be_falsey
|
88
89
|
|
89
|
-
deadbeef.client.
|
90
|
-
deadbeef.attrs['id'].
|
90
|
+
expect(deadbeef.client).to eq(client)
|
91
|
+
expect(deadbeef.attrs['id']).to eq('98765')
|
91
92
|
end
|
92
93
|
|
93
94
|
it "returns the endpoint name" do
|
94
|
-
subject.class.endpoint_name.
|
95
|
+
expect(subject.class.endpoint_name).to eq('deadbeef')
|
95
96
|
end
|
96
97
|
|
97
98
|
it "returns the path_component" do
|
98
99
|
attrs['id'] = '123'
|
99
|
-
subject.path_component.
|
100
|
+
expect(subject.path_component).to eq('/deadbeef/123')
|
100
101
|
end
|
101
102
|
|
102
103
|
it "returns the path component for unsaved instances" do
|
103
|
-
subject.path_component.
|
104
|
+
expect(subject.path_component).to eq('/deadbeef')
|
104
105
|
end
|
105
106
|
|
106
107
|
it "converts to a symbol" do
|
107
|
-
subject.to_sym.
|
108
|
+
expect(subject.to_sym).to eq(:deadbeef)
|
108
109
|
end
|
109
110
|
|
110
111
|
describe "collection_path" do
|
111
112
|
|
112
113
|
before(:each) do
|
113
|
-
client.
|
114
|
+
expect(client).to receive(:options).and_return(:rest_base_path => '/deadbeef/bar')
|
114
115
|
end
|
115
116
|
|
116
117
|
it "returns the collection_path" do
|
117
|
-
subject.collection_path.
|
118
|
+
expect(subject.collection_path).to eq('/deadbeef/bar/deadbeef')
|
118
119
|
end
|
119
120
|
|
120
121
|
it "returns the collection_path with a prefix" do
|
121
|
-
subject.collection_path('/baz/').
|
122
|
+
expect(subject.collection_path('/baz/')).to eq('/deadbeef/bar/baz/deadbeef')
|
122
123
|
end
|
123
124
|
|
124
125
|
it "has a class method that returns the collection_path" do
|
125
|
-
subject.class.collection_path(client).
|
126
|
+
expect(subject.class.collection_path(client)).to eq('/deadbeef/bar/deadbeef')
|
126
127
|
end
|
127
128
|
end
|
128
129
|
|
129
130
|
it "parses json" do
|
130
|
-
described_class.parse_json('{"foo":"bar"}').
|
131
|
+
expect(described_class.parse_json('{"foo":"bar"}')).to eq({"foo" => "bar"})
|
131
132
|
end
|
132
133
|
|
133
134
|
describe "dynamic instance methods" do
|
@@ -136,17 +137,17 @@ describe JIRA::Base do
|
|
136
137
|
subject { JIRA::Resource::Deadbeef.new(client, :attrs => attrs) }
|
137
138
|
|
138
139
|
it "responds to each of the top level attribute names" do
|
139
|
-
subject.
|
140
|
-
subject.
|
141
|
-
subject.
|
140
|
+
expect(subject).to respond_to(:foo)
|
141
|
+
expect(subject).to respond_to('flum')
|
142
|
+
expect(subject).to respond_to(:object_id)
|
142
143
|
|
143
|
-
subject.foo.
|
144
|
-
subject.flum.
|
144
|
+
expect(subject.foo).to eq('bar')
|
145
|
+
expect(subject.flum).to eq('goo')
|
145
146
|
|
146
147
|
# Should not override existing method names, but should still allow
|
147
148
|
# access to their values via the attrs[] hash
|
148
|
-
subject.object_id.
|
149
|
-
subject.attrs['object_id'].
|
149
|
+
expect(subject.object_id).not_to eq('dummy')
|
150
|
+
expect(subject.attrs['object_id']).to eq('dummy')
|
150
151
|
end
|
151
152
|
end
|
152
153
|
|
@@ -157,23 +158,22 @@ describe JIRA::Base do
|
|
157
158
|
describe "not cached" do
|
158
159
|
|
159
160
|
before(:each) do
|
160
|
-
response =
|
161
|
-
|
162
|
-
|
163
|
-
JIRA::Resource::Deadbeef.should_receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
|
161
|
+
response = instance_double("Response", body: '{"self":"http://deadbeef/","id":"98765"}')
|
162
|
+
expect(client).to receive(:get).with('/jira/rest/api/2/deadbeef/98765').and_return(response)
|
163
|
+
expect(JIRA::Resource::Deadbeef).to receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
|
164
164
|
end
|
165
165
|
|
166
166
|
it "sets expanded to true after fetch" do
|
167
|
-
subject.expanded
|
167
|
+
expect(subject.expanded?).to be_falsey
|
168
168
|
subject.fetch
|
169
|
-
subject.expanded
|
169
|
+
expect(subject.expanded?).to be_truthy
|
170
170
|
end
|
171
171
|
|
172
172
|
it "performs a fetch" do
|
173
|
-
subject.expanded
|
173
|
+
expect(subject.expanded?).to be_falsey
|
174
174
|
subject.fetch
|
175
|
-
subject.self.
|
176
|
-
subject.id.
|
175
|
+
expect(subject.self).to eq("http://deadbeef/")
|
176
|
+
expect(subject.id).to eq("98765")
|
177
177
|
end
|
178
178
|
|
179
179
|
it "performs a fetch if already fetched and force flag is true" do
|
@@ -186,24 +186,26 @@ describe JIRA::Base do
|
|
186
186
|
describe "cached" do
|
187
187
|
it "doesn't perform a fetch if already fetched" do
|
188
188
|
subject.expanded = true
|
189
|
-
client.
|
189
|
+
expect(client).not_to receive(:get)
|
190
190
|
subject.fetch
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
194
|
context "with expand parameter 'changelog'" do
|
195
195
|
it "fetchs changelogs '" do
|
196
|
-
response =
|
197
|
-
|
198
|
-
|
196
|
+
response = instance_double(
|
197
|
+
"Response",
|
198
|
+
body: '{"self":"http://deadbeef/","id":"98765","changelog":{"histories":[]}}'
|
199
|
+
)
|
200
|
+
expect(client).to receive(:get).with('/jira/rest/api/2/deadbeef/98765?expand=changelog').and_return(response)
|
199
201
|
|
200
|
-
JIRA::Resource::Deadbeef.
|
202
|
+
expect(JIRA::Resource::Deadbeef).to receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
|
201
203
|
|
202
204
|
subject.fetch(false, {expand:'changelog'})
|
203
205
|
|
204
|
-
subject.self.
|
205
|
-
subject.id.
|
206
|
-
subject.changelog['histories'].
|
206
|
+
expect(subject.self).to eq("http://deadbeef/")
|
207
|
+
expect(subject.id).to eq("98765")
|
208
|
+
expect(subject.changelog['histories']).to eq([])
|
207
209
|
end
|
208
210
|
end
|
209
211
|
end
|
@@ -215,39 +217,39 @@ describe JIRA::Base do
|
|
215
217
|
subject { JIRA::Resource::Deadbeef.new(client) }
|
216
218
|
|
217
219
|
before(:each) do
|
218
|
-
subject.
|
220
|
+
expect(subject).to receive(:url).and_return('/foo/bar')
|
219
221
|
end
|
220
222
|
|
221
223
|
it "POSTs a new record" do
|
222
|
-
response
|
223
|
-
subject.
|
224
|
-
client.
|
225
|
-
subject.save("foo" => "bar").
|
226
|
-
subject.id.
|
227
|
-
subject.expanded.
|
224
|
+
response = instance_double("Response", body: '{"id":"123"}')
|
225
|
+
allow(subject).to receive(:new_record?) { true }
|
226
|
+
expect(client).to receive(:post).with('/foo/bar','{"foo":"bar"}').and_return(response)
|
227
|
+
expect(subject.save("foo" => "bar")).to be_truthy
|
228
|
+
expect(subject.id).to eq("123")
|
229
|
+
expect(subject.expanded).to be_falsey
|
228
230
|
end
|
229
231
|
|
230
232
|
it "PUTs an existing record" do
|
231
|
-
response
|
232
|
-
subject.
|
233
|
-
client.
|
234
|
-
subject.save("foo" => "bar").
|
235
|
-
subject.expanded.
|
233
|
+
response = instance_double("Response", body: nil)
|
234
|
+
allow(subject).to receive(:new_record?) { false }
|
235
|
+
expect(client).to receive(:put).with('/foo/bar','{"foo":"bar"}').and_return(response)
|
236
|
+
expect(subject.save("foo" => "bar")).to be_truthy
|
237
|
+
expect(subject.expanded).to be_falsey
|
236
238
|
end
|
237
239
|
|
238
240
|
it "merges attrs on save" do
|
239
|
-
response
|
240
|
-
client.
|
241
|
+
response = instance_double("Response", body: nil)
|
242
|
+
expect(client).to receive(:post).with('/foo/bar','{"foo":{"fum":"dum"}}').and_return(response)
|
241
243
|
subject.attrs = {"foo" => {"bar" => "baz"}}
|
242
244
|
subject.save({"foo" => {"fum" => "dum"}})
|
243
|
-
subject.foo.
|
245
|
+
expect(subject.foo).to eq({"bar" => "baz", "fum" => "dum"})
|
244
246
|
end
|
245
247
|
|
246
248
|
it "returns false when an invalid field is set" do # The JIRA REST API apparently ignores fields that you aren't allowed to set manually
|
247
|
-
response
|
248
|
-
subject.
|
249
|
-
client.
|
250
|
-
subject.save("invalid_field" => "foobar").
|
249
|
+
response = instance_double("Response", body: '{"errorMessages":["blah"]}', status: 400)
|
250
|
+
allow(subject).to receive(:new_record?) { false }
|
251
|
+
expect(client).to receive(:put).with('/foo/bar','{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response))
|
252
|
+
expect(subject.save("invalid_field" => "foobar")).to be_falsey
|
251
253
|
end
|
252
254
|
|
253
255
|
end
|
@@ -258,33 +260,31 @@ describe JIRA::Base do
|
|
258
260
|
subject { JIRA::Resource::Deadbeef.new(client) }
|
259
261
|
|
260
262
|
before(:each) do
|
261
|
-
subject.
|
263
|
+
expect(subject).to receive(:url).and_return('/foo/bar')
|
262
264
|
end
|
263
265
|
|
264
266
|
it "POSTs a new record" do
|
265
|
-
response
|
266
|
-
subject.
|
267
|
-
client.
|
268
|
-
subject.save!("foo" => "bar").
|
269
|
-
subject.id.
|
270
|
-
subject.expanded.
|
267
|
+
response = instance_double("Response", body: '{"id":"123"}')
|
268
|
+
allow(subject).to receive(:new_record?) { true }
|
269
|
+
expect(client).to receive(:post).with('/foo/bar','{"foo":"bar"}').and_return(response)
|
270
|
+
expect(subject.save!("foo" => "bar")).to be_truthy
|
271
|
+
expect(subject.id).to eq("123")
|
272
|
+
expect(subject.expanded).to be_falsey
|
271
273
|
end
|
272
274
|
|
273
275
|
it "PUTs an existing record" do
|
274
|
-
response
|
275
|
-
subject.
|
276
|
-
client.
|
277
|
-
subject.save!("foo" => "bar").
|
278
|
-
subject.expanded.
|
276
|
+
response = instance_double("Response", body: nil)
|
277
|
+
allow(subject).to receive(:new_record?) { false }
|
278
|
+
expect(client).to receive(:put).with('/foo/bar','{"foo":"bar"}').and_return(response)
|
279
|
+
expect(subject.save!("foo" => "bar")).to be_truthy
|
280
|
+
expect(subject.expanded).to be_falsey
|
279
281
|
end
|
280
282
|
|
281
283
|
it "throws an exception when an invalid field is set" do
|
282
|
-
response
|
283
|
-
subject.
|
284
|
-
client.
|
285
|
-
lambda
|
286
|
-
subject.save!("invalid_field" => "foobar")
|
287
|
-
end.should raise_error(JIRA::HTTPError)
|
284
|
+
response = instance_double("Response", body: '{"errorMessages":["blah"]}', status: 400)
|
285
|
+
allow(subject).to receive(:new_record?) { false }
|
286
|
+
expect(client).to receive(:put).with('/foo/bar','{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response))
|
287
|
+
expect(lambda{ subject.save!("invalid_field" => "foobar") }).to raise_error(JIRA::HTTPError)
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
@@ -292,27 +292,27 @@ describe JIRA::Base do
|
|
292
292
|
it "merges hashes correctly when clobber is true (default)" do
|
293
293
|
subject.attrs = {"foo" => {"bar" => "baz"}}
|
294
294
|
subject.set_attrs({"foo" => {"fum" => "dum"}})
|
295
|
-
subject.foo.
|
295
|
+
expect(subject.foo).to eq({"fum" => "dum"})
|
296
296
|
end
|
297
297
|
|
298
298
|
it "merges hashes correctly when clobber is false" do
|
299
299
|
subject.attrs = {"foo" => {"bar" => "baz"}}
|
300
300
|
subject.set_attrs({"foo" => {"fum" => "dum"}}, false)
|
301
|
-
subject.foo.
|
301
|
+
expect(subject.foo).to eq({"bar" => "baz", "fum" => "dum"})
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
305
305
|
describe "delete" do
|
306
306
|
|
307
307
|
before(:each) do
|
308
|
-
client.
|
309
|
-
subject.
|
308
|
+
expect(client).to receive(:delete).with('/foo/bar')
|
309
|
+
allow(subject).to receive(:url) { '/foo/bar' }
|
310
310
|
end
|
311
311
|
|
312
312
|
it "flags itself as deleted" do
|
313
|
-
subject.deleted
|
313
|
+
expect(subject.deleted?).to be_falsey
|
314
314
|
subject.delete
|
315
|
-
subject.deleted
|
315
|
+
expect(subject.deleted?).to be_truthy
|
316
316
|
end
|
317
317
|
|
318
318
|
it "sends a DELETE request" do
|
@@ -325,12 +325,12 @@ describe JIRA::Base do
|
|
325
325
|
|
326
326
|
it "returns true for new_record? when new object" do
|
327
327
|
subject.attrs['id'] = nil
|
328
|
-
subject.new_record
|
328
|
+
expect(subject.new_record?).to be_truthy
|
329
329
|
end
|
330
330
|
|
331
331
|
it "returns false for new_record? when id is set" do
|
332
332
|
subject.attrs['id'] = '123'
|
333
|
-
subject.new_record
|
333
|
+
expect(subject.new_record?).to be_falsey
|
334
334
|
end
|
335
335
|
|
336
336
|
end
|
@@ -339,11 +339,11 @@ describe JIRA::Base do
|
|
339
339
|
|
340
340
|
it "returns true when the response contains errors" do
|
341
341
|
attrs["errors"] = {"invalid" => "Field invalid"}
|
342
|
-
subject.has_errors
|
342
|
+
expect(subject.has_errors?).to be_truthy
|
343
343
|
end
|
344
344
|
|
345
345
|
it "returns false when the response does not contain any errors" do
|
346
|
-
subject.has_errors
|
346
|
+
expect(subject.has_errors?).to be_falsey
|
347
347
|
end
|
348
348
|
|
349
349
|
end
|
@@ -351,37 +351,37 @@ describe JIRA::Base do
|
|
351
351
|
describe 'url' do
|
352
352
|
|
353
353
|
before(:each) do
|
354
|
-
client.
|
354
|
+
allow(client).to receive(:options) { {:rest_base_path => '/foo/bar'} }
|
355
355
|
end
|
356
356
|
|
357
357
|
it "returns self as the URL if set" do
|
358
358
|
pending("Identified bug on real jira instance")
|
359
359
|
attrs['self'] = 'http://foo/bar'
|
360
|
-
subject.url.
|
360
|
+
expect(subject.url).to eq("http://foo/bar")
|
361
361
|
end
|
362
362
|
|
363
363
|
it "generates the URL from id if self not set" do
|
364
364
|
attrs['self'] = nil
|
365
365
|
attrs['id'] = '98765'
|
366
|
-
subject.url.
|
366
|
+
expect(subject.url).to eq("/foo/bar/deadbeef/98765")
|
367
367
|
end
|
368
368
|
|
369
369
|
it "generates the URL from collection_path if self and id not set" do
|
370
370
|
attrs['self'] = nil
|
371
371
|
attrs['id'] = nil
|
372
|
-
subject.url.
|
372
|
+
expect(subject.url).to eq("/foo/bar/deadbeef")
|
373
373
|
end
|
374
374
|
|
375
375
|
it "has a class method for the collection path" do
|
376
|
-
JIRA::Resource::Deadbeef.collection_path(client).
|
376
|
+
expect(JIRA::Resource::Deadbeef.collection_path(client)).to eq("/foo/bar/deadbeef")
|
377
377
|
#Should accept an optional prefix (flum in this case)
|
378
|
-
JIRA::Resource::Deadbeef.collection_path(client, '/flum/').
|
378
|
+
expect(JIRA::Resource::Deadbeef.collection_path(client, '/flum/')).to eq("/foo/bar/flum/deadbeef")
|
379
379
|
end
|
380
380
|
|
381
381
|
it "has a class method for the singular path" do
|
382
|
-
JIRA::Resource::Deadbeef.singular_path(client, 'abc123').
|
382
|
+
expect(JIRA::Resource::Deadbeef.singular_path(client, 'abc123')).to eq("/foo/bar/deadbeef/abc123")
|
383
383
|
#Should accept an optional prefix (flum in this case)
|
384
|
-
JIRA::Resource::Deadbeef.singular_path(client, 'abc123', '/flum/').
|
384
|
+
expect(JIRA::Resource::Deadbeef.singular_path(client, 'abc123', '/flum/')).to eq("/foo/bar/flum/deadbeef/abc123")
|
385
385
|
end
|
386
386
|
end
|
387
387
|
|
@@ -389,22 +389,22 @@ describe JIRA::Base do
|
|
389
389
|
subject.attrs['foo'] = 'bar'
|
390
390
|
subject.attrs['dead'] = 'beef'
|
391
391
|
|
392
|
-
subject.to_s.
|
392
|
+
expect(subject.to_s).to match(/#<JIRA::Resource::Deadbeef:\d+ @attrs=#{Regexp.quote(attrs.inspect)}>/)
|
393
393
|
end
|
394
394
|
|
395
395
|
it "returns the key attribute" do
|
396
|
-
subject.class.key_attribute.
|
396
|
+
expect(subject.class.key_attribute).to eq(:id)
|
397
397
|
end
|
398
398
|
|
399
399
|
it "returns the key value" do
|
400
400
|
subject.attrs['id'] = '123'
|
401
|
-
subject.key_value.
|
401
|
+
expect(subject.key_value).to eq('123')
|
402
402
|
end
|
403
403
|
|
404
404
|
it "converts to json" do
|
405
405
|
subject.attrs = {"foo" => "bar","dead" => "beef"}
|
406
406
|
|
407
|
-
subject.to_json.
|
407
|
+
expect(subject.to_json).to eq(subject.attrs.to_json)
|
408
408
|
end
|
409
409
|
|
410
410
|
describe "extract attrs from response" do
|
@@ -412,42 +412,39 @@ describe JIRA::Base do
|
|
412
412
|
subject { JIRA::Resource::Deadbeef.new(client, :attrs => {}) }
|
413
413
|
|
414
414
|
it "sets the attrs from a response" do
|
415
|
-
response =
|
416
|
-
response.stub(:body).and_return('{"foo":"bar"}')
|
415
|
+
response = instance_double("Response", body: '{"foo":"bar"}')
|
417
416
|
|
418
|
-
subject.set_attrs_from_response(response).
|
419
|
-
subject.foo.
|
417
|
+
expect(subject.set_attrs_from_response(response)).to eq({'foo' => 'bar'})
|
418
|
+
expect(subject.foo).to eq("bar")
|
420
419
|
end
|
421
420
|
|
422
421
|
it "doesn't clobber existing attrs not in response" do
|
423
|
-
response =
|
424
|
-
response.stub(:body).and_return('{"foo":"bar"}')
|
422
|
+
response = instance_double("Response", body: '{"foo":"bar"}')
|
425
423
|
|
426
424
|
subject.attrs = {'flum' => 'flar'}
|
427
|
-
subject.set_attrs_from_response(response).
|
428
|
-
subject.foo.
|
429
|
-
subject.flum.
|
425
|
+
expect(subject.set_attrs_from_response(response)).to eq({'foo' => 'bar'})
|
426
|
+
expect(subject.foo).to eq("bar")
|
427
|
+
expect(subject.flum).to eq("flar")
|
430
428
|
end
|
431
429
|
|
432
430
|
it "handles nil response body" do
|
433
|
-
response =
|
434
|
-
response.stub(:body).and_return(nil)
|
431
|
+
response = instance_double("Response", body: nil)
|
435
432
|
|
436
433
|
subject.attrs = {'flum' => 'flar'}
|
437
|
-
subject.set_attrs_from_response(response).
|
438
|
-
subject.flum.
|
434
|
+
expect(subject.set_attrs_from_response(response)).to be_nil
|
435
|
+
expect(subject.flum).to eq('flar')
|
439
436
|
end
|
440
437
|
end
|
441
438
|
|
442
439
|
describe "nesting" do
|
443
440
|
|
444
441
|
it "defaults collection_attributes_are_nested to false" do
|
445
|
-
JIRA::Resource::Deadbeef.collection_attributes_are_nested.
|
442
|
+
expect(JIRA::Resource::Deadbeef.collection_attributes_are_nested).to be_falsey
|
446
443
|
end
|
447
444
|
|
448
445
|
it "allows collection_attributes_are_nested to be set" do
|
449
446
|
JIRA::Resource::Deadbeef.nested_collections true
|
450
|
-
JIRA::Resource::Deadbeef.collection_attributes_are_nested.
|
447
|
+
expect(JIRA::Resource::Deadbeef.collection_attributes_are_nested).to be_truthy
|
451
448
|
end
|
452
449
|
|
453
450
|
end
|
@@ -457,23 +454,23 @@ describe JIRA::Base do
|
|
457
454
|
subject { JIRA::Resource::HasManyExample.new(client, :attrs => {'deadbeefs' => [{'id' => '123'}]}) }
|
458
455
|
|
459
456
|
it "returns a collection of instances for has_many relationships" do
|
460
|
-
subject.deadbeefs.class.
|
461
|
-
subject.deadbeefs.length.
|
457
|
+
expect(subject.deadbeefs.class).to eq(JIRA::HasManyProxy)
|
458
|
+
expect(subject.deadbeefs.length).to eq(1)
|
462
459
|
subject.deadbeefs.each do |deadbeef|
|
463
|
-
deadbeef.class.
|
460
|
+
expect(deadbeef.class).to eq(JIRA::Resource::Deadbeef)
|
464
461
|
end
|
465
462
|
end
|
466
463
|
|
467
464
|
it "returns an empty collection for empty has_many relationships" do
|
468
465
|
subject = JIRA::Resource::HasManyExample.new(client)
|
469
|
-
subject.deadbeefs.length.
|
466
|
+
expect(subject.deadbeefs.length).to eq(0)
|
470
467
|
end
|
471
468
|
|
472
469
|
it "allows the has_many attributes to be nested inside another attribute" do
|
473
470
|
subject = JIRA::Resource::HasManyExample.new(client, :attrs => {'nested' => {'brunchmuffins' => [{'id' => '123'},{'id' => '456'}]}})
|
474
|
-
subject.brunchmuffins.length.
|
471
|
+
expect(subject.brunchmuffins.length).to eq(2)
|
475
472
|
subject.brunchmuffins.each do |brunchmuffin|
|
476
|
-
brunchmuffin.class.
|
473
|
+
expect(brunchmuffin.class).to eq(JIRA::Resource::Deadbeef)
|
477
474
|
end
|
478
475
|
end
|
479
476
|
|
@@ -481,9 +478,9 @@ describe JIRA::Base do
|
|
481
478
|
subject = JIRA::Resource::HasManyExample.new(client, :attrs => {'nested' => {
|
482
479
|
'breakfastscone' => { 'breakfastscones' => [{'id' => '123'},{'id' => '456'}] }
|
483
480
|
}})
|
484
|
-
subject.breakfastscones.length.
|
481
|
+
expect(subject.breakfastscones.length).to eq(2)
|
485
482
|
subject.breakfastscones.each do |breakfastscone|
|
486
|
-
breakfastscone.class.
|
483
|
+
expect(breakfastscone.class).to eq(JIRA::Resource::Deadbeef)
|
487
484
|
end
|
488
485
|
end
|
489
486
|
|
@@ -491,20 +488,20 @@ describe JIRA::Base do
|
|
491
488
|
subject = JIRA::Resource::HasManyExample.new(client, :attrs => {
|
492
489
|
'nested' => {}
|
493
490
|
})
|
494
|
-
subject.breakfastscones.length.
|
491
|
+
expect(subject.breakfastscones.length).to eq(0)
|
495
492
|
end
|
496
493
|
|
497
494
|
it "allows the attribute key to be specified" do
|
498
495
|
subject = JIRA::Resource::HasManyExample.new(client, :attrs => {'irregularlyNamedThings' => [{'id' => '123'},{'id' => '456'}]})
|
499
|
-
subject.irregularly_named_things.length.
|
496
|
+
expect(subject.irregularly_named_things.length).to eq(2)
|
500
497
|
subject.irregularly_named_things.each do |thing|
|
501
|
-
thing.class.
|
498
|
+
expect(thing.class).to eq(JIRA::Resource::Deadbeef)
|
502
499
|
end
|
503
500
|
end
|
504
501
|
|
505
502
|
it "can build child instances" do
|
506
503
|
deadbeef = subject.deadbeefs.build
|
507
|
-
deadbeef.class.
|
504
|
+
expect(deadbeef.class).to eq(JIRA::Resource::Deadbeef)
|
508
505
|
end
|
509
506
|
|
510
507
|
end
|
@@ -514,39 +511,39 @@ describe JIRA::Base do
|
|
514
511
|
subject { JIRA::Resource::HasOneExample.new(client, :attrs => {'deadbeef' => {'id' => '123'}}) }
|
515
512
|
|
516
513
|
it "returns an instance for a has one relationship" do
|
517
|
-
subject.deadbeef.class.
|
518
|
-
subject.deadbeef.id.
|
514
|
+
expect(subject.deadbeef.class).to eq(JIRA::Resource::Deadbeef)
|
515
|
+
expect(subject.deadbeef.id).to eq('123')
|
519
516
|
end
|
520
517
|
|
521
518
|
it "returns nil when resource attribute is nonexistent" do
|
522
519
|
subject = JIRA::Resource::HasOneExample.new(client)
|
523
|
-
subject.deadbeef.
|
520
|
+
expect(subject.deadbeef).to be_nil
|
524
521
|
end
|
525
522
|
|
526
523
|
it "returns an instance with a different class name to the attribute name" do
|
527
524
|
subject = JIRA::Resource::HasOneExample.new(client, :attrs => {'muffin' => {'id' => '123'}})
|
528
|
-
subject.muffin.class.
|
529
|
-
subject.muffin.id.
|
525
|
+
expect(subject.muffin.class).to eq(JIRA::Resource::Deadbeef)
|
526
|
+
expect(subject.muffin.id).to eq('123')
|
530
527
|
end
|
531
528
|
|
532
529
|
it "allows the has_one attributes to be nested inside another attribute" do
|
533
530
|
subject = JIRA::Resource::HasOneExample.new(client, :attrs => {'nested' => {'brunchmuffin' => {'id' => '123'}}})
|
534
|
-
subject.brunchmuffin.class.
|
535
|
-
subject.brunchmuffin.id.
|
531
|
+
expect(subject.brunchmuffin.class).to eq(JIRA::Resource::Deadbeef)
|
532
|
+
expect(subject.brunchmuffin.id).to eq('123')
|
536
533
|
end
|
537
534
|
|
538
535
|
it "allows it to be deeply nested" do
|
539
536
|
subject = JIRA::Resource::HasOneExample.new(client, :attrs => {'nested' => {
|
540
537
|
'breakfastscone' => { 'breakfastscone' => {'id' => '123'} }
|
541
538
|
}})
|
542
|
-
subject.breakfastscone.class.
|
543
|
-
subject.breakfastscone.id.
|
539
|
+
expect(subject.breakfastscone.class).to eq(JIRA::Resource::Deadbeef)
|
540
|
+
expect(subject.breakfastscone.id).to eq('123')
|
544
541
|
end
|
545
542
|
|
546
543
|
it "allows the attribute key to be specified" do
|
547
544
|
subject = JIRA::Resource::HasOneExample.new(client, :attrs => {'irregularlyNamedThing' => {'id' => '123'}})
|
548
|
-
subject.irregularly_named_thing.class.
|
549
|
-
subject.irregularly_named_thing.id.
|
545
|
+
expect(subject.irregularly_named_thing.class).to eq(JIRA::Resource::Deadbeef)
|
546
|
+
expect(subject.irregularly_named_thing.id).to eq('123')
|
550
547
|
end
|
551
548
|
|
552
549
|
end
|
@@ -562,24 +559,24 @@ describe JIRA::Base do
|
|
562
559
|
subject { JIRA::Resource::BelongsToExample.new(client, :attrs => {'id' => '123'}, :deadbeef => deadbeef) }
|
563
560
|
|
564
561
|
it "sets up an accessor for the belongs to relationship" do
|
565
|
-
subject.deadbeef.
|
562
|
+
expect(subject.deadbeef).to eq(deadbeef)
|
566
563
|
end
|
567
564
|
|
568
565
|
it "raises an exception when initialized without a belongs_to instance" do
|
569
|
-
lambda
|
566
|
+
expect(lambda {
|
570
567
|
JIRA::Resource::BelongsToExample.new(client, :attrs => {'id' => '123'})
|
571
|
-
|
568
|
+
}).to raise_exception(ArgumentError,"Required option :deadbeef missing")
|
572
569
|
end
|
573
570
|
|
574
571
|
it "returns the right url" do
|
575
|
-
client.
|
576
|
-
subject.url.
|
572
|
+
allow(client).to receive(:options) { { :rest_base_path => "/foo" } }
|
573
|
+
expect(subject.url).to eq("/foo/deadbeef/999/belongstoexample/123")
|
577
574
|
end
|
578
575
|
|
579
576
|
it "can be initialized with an instance or a key value" do
|
580
|
-
client.
|
577
|
+
allow(client).to receive(:options) { { :rest_base_path => "/foo" } }
|
581
578
|
subject = JIRA::Resource::BelongsToExample.new(client, :attrs => {'id' => '123'}, :deadbeef_id => '987')
|
582
|
-
subject.url.
|
579
|
+
expect(subject.url).to eq("/foo/deadbeef/987/belongstoexample/123")
|
583
580
|
end
|
584
581
|
|
585
582
|
end
|