github_api 0.8.3 → 0.8.4

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.
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Issues::Labels, '#update' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:label_id) { 1 }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/labels/#{label_id}" }
10
+ let(:inputs) {
11
+ {
12
+ "name" => "API",
13
+ "color" => "FFFFFF",
14
+ }
15
+ }
16
+
17
+ before {
18
+ stub_patch(request_path).with(inputs).
19
+ to_return(:body => body, :status => status,
20
+ :headers => {:content_type => "application/json; charset=utf-8"})
21
+ }
22
+
23
+ after { reset_authentication_for(subject) }
24
+
25
+ context "resouce updated" do
26
+ let(:body) { fixture('issues/label.json') }
27
+ let(:status) { 200 }
28
+
29
+ it "should fail to create resource if 'name' input is missing" do
30
+ expect {
31
+ subject.update user, repo, label_id, inputs.except('name')
32
+ }.to raise_error(Github::Error::RequiredParams)
33
+ end
34
+
35
+ it "should fail to create resource if 'color' input is missing" do
36
+ expect {
37
+ subject.update user, repo, label_id, inputs.except('color')
38
+ }.to raise_error(Github::Error::RequiredParams)
39
+ end
40
+
41
+ it "should update resource successfully" do
42
+ subject.update user, repo, label_id, inputs
43
+ a_patch(request_path).with(inputs).should have_been_made
44
+ end
45
+
46
+ it "should return the resource" do
47
+ label = subject.update user, repo, label_id, inputs
48
+ label.should be_a Hashie::Mash
49
+ end
50
+
51
+ it "should get the label information" do
52
+ label = subject.update user, repo, label_id, inputs
53
+ label.name.should == 'bug'
54
+ end
55
+ end
56
+
57
+ it_should_behave_like 'request failure' do
58
+ let(:requestable) { subject.update user, repo, label_id, inputs }
59
+ end
60
+
61
+ end # update
@@ -10,359 +10,6 @@ describe Github::Issues::Labels do
10
10
 
11
11
  it { described_class::VALID_LABEL_INPUTS.should_not be_nil }
12
12
 
13
- describe '#list' do
14
- it { github.issues.should respond_to :all }
15
-
16
- context "resource found" do
17
- before do
18
- stub_get("/repos/#{user}/#{repo}/labels").
19
- to_return(:body => fixture('issues/labels.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
20
- end
21
-
22
- it "should fail to get resource without username" do
23
- expect {
24
- github.issues.labels.list nil, repo
25
- }.to raise_error(ArgumentError)
26
- end
27
-
28
- it "should get the resources" do
29
- github.issues.labels.list user, repo
30
- a_get("/repos/#{user}/#{repo}/labels").should have_been_made
31
- end
32
-
33
- it "should return array of resources" do
34
- labels = github.issues.labels.list user, repo
35
- labels.should be_an Array
36
- labels.should have(1).items
37
- end
38
-
39
- it "should be a mash type" do
40
- labels = github.issues.labels.list user, repo
41
- labels.first.should be_a Hashie::Mash
42
- end
43
-
44
- it "should get issue information" do
45
- labels = github.issues.labels.list user, repo
46
- labels.first.name.should == 'bug'
47
- end
48
-
49
- it "should yield to a block" do
50
- github.issues.labels.should_receive(:list).with(user, repo).and_yield('web')
51
- github.issues.labels.list(user, repo) { |param| 'web' }.should == 'web'
52
- end
53
- end
54
-
55
- context "resource not found" do
56
- before do
57
- stub_get("/repos/#{user}/#{repo}/labels").
58
- to_return(:body => "", :status => [404, "Not Found"])
59
- end
60
-
61
- it "should return 404 with a message 'Not Found'" do
62
- expect {
63
- github.issues.labels.list user, repo
64
- }.to raise_error(Github::Error::NotFound)
65
- end
66
- end
67
- end # list
68
-
69
- describe "#find" do
70
- context "resource found" do
71
- before do
72
- stub_get("/repos/#{user}/#{repo}/labels/#{label_id}").
73
- to_return(:body => fixture('issues/label.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
74
- end
75
-
76
- it "should fail to get resource without label id" do
77
- expect {
78
- github.issues.labels.find(user, repo, nil)
79
- }.to raise_error(ArgumentError)
80
- end
81
-
82
- it "should get the resource" do
83
- github.issues.labels.find user, repo, label_id
84
- a_get("/repos/#{user}/#{repo}/labels/#{label_id}").should have_been_made
85
- end
86
-
87
- it "should get label information" do
88
- label = github.issues.labels.find user, repo, label_id
89
- label.name.should == 'bug'
90
- end
91
-
92
- it "should return mash" do
93
- label = github.issues.labels.find user, repo, label_id
94
- label.should be_a Hashie::Mash
95
- end
96
- end
97
-
98
- context "resource not found" do
99
- before do
100
- stub_get("/repos/#{user}/#{repo}/labels/#{label_id}").
101
- to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
102
- end
103
-
104
- it "should fail to retrive resource" do
105
- expect {
106
- github.issues.labels.find user, repo, label_id
107
- }.to raise_error(Github::Error::NotFound)
108
- end
109
- end
110
- end # find
111
-
112
- describe "#create" do
113
- let(:inputs) {
114
- {
115
- "name" => "API",
116
- "color" => "FFFFFF",
117
- }
118
- }
119
-
120
- context "resouce created" do
121
- before do
122
- stub_post("/repos/#{user}/#{repo}/labels").with(inputs).
123
- to_return(:body => fixture('issues/label.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
124
- end
125
-
126
- it "should fail to create resource if 'name' input is missing" do
127
- expect {
128
- github.issues.labels.create user, repo, inputs.except('name')
129
- }.to raise_error(Github::Error::RequiredParams)
130
- end
131
-
132
- it "should fail to create resource if 'color' input is missing" do
133
- expect {
134
- github.issues.labels.create user, repo, inputs.except('color')
135
- }.to raise_error(Github::Error::RequiredParams)
136
- end
137
-
138
- it "should create resource successfully" do
139
- github.issues.labels.create user, repo, inputs
140
- a_post("/repos/#{user}/#{repo}/labels").with(inputs).should have_been_made
141
- end
142
-
143
- it "should return the resource" do
144
- label = github.issues.labels.create user, repo, inputs
145
- label.should be_a Hashie::Mash
146
- end
147
-
148
- it "should get the label information" do
149
- label = github.issues.labels.create user, repo, inputs
150
- label.name.should == 'bug'
151
- end
152
- end
153
-
154
- context "failed to create resource" do
155
- before do
156
- stub_post("/repos/#{user}/#{repo}/labels").with(inputs).
157
- to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
158
- end
159
-
160
- it "should faile to retrieve resource" do
161
- expect {
162
- github.issues.labels.create user, repo, inputs
163
- }.to raise_error(Github::Error::NotFound)
164
- end
165
- end
166
- end # create
167
-
168
- describe "#update" do
169
- let(:inputs) {
170
- {
171
- "name" => "API",
172
- "color" => "FFFFFF",
173
- }
174
- }
175
-
176
- context "resouce updated" do
177
- before do
178
- stub_patch("/repos/#{user}/#{repo}/labels/#{label_id}").with(inputs).
179
- to_return(:body => fixture('issues/label.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
180
- end
181
-
182
- it "should fail to create resource if 'name' input is missing" do
183
- expect {
184
- github.issues.labels.update user, repo, label_id, inputs.except('name')
185
- }.to raise_error(Github::Error::RequiredParams)
186
- end
187
-
188
- it "should fail to create resource if 'color' input is missing" do
189
- expect {
190
- github.issues.labels.update user, repo, label_id, inputs.except('color')
191
- }.to raise_error(Github::Error::RequiredParams)
192
- end
193
-
194
- it "should update resource successfully" do
195
- github.issues.labels.update user, repo, label_id, inputs
196
- a_patch("/repos/#{user}/#{repo}/labels/#{label_id}").with(inputs).should have_been_made
197
- end
198
-
199
- it "should return the resource" do
200
- label = github.issues.labels.update user, repo, label_id, inputs
201
- label.should be_a Hashie::Mash
202
- end
203
-
204
- it "should get the label information" do
205
- label = github.issues.labels.update user, repo, label_id, inputs
206
- label.name.should == 'bug'
207
- end
208
- end
209
-
210
- context "failed to create resource" do
211
- before do
212
- stub_patch("/repos/#{user}/#{repo}/labels/#{label_id}").with(inputs).
213
- to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
214
- end
215
-
216
- it "should faile to retrieve resource" do
217
- expect {
218
- github.issues.labels.update user, repo, label_id, inputs
219
- }.to raise_error(Github::Error::NotFound)
220
- end
221
- end
222
- end # update
223
-
224
- describe "#delete" do
225
- context "resouce removed" do
226
- before do
227
- stub_delete("/repos/#{user}/#{repo}/labels/#{label_id}").
228
- to_return(:body => fixture('issues/label.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
229
- end
230
-
231
- it "should remove resource successfully" do
232
- github.issues.labels.delete user, repo, label_id
233
- a_delete("/repos/#{user}/#{repo}/labels/#{label_id}").should have_been_made
234
- end
235
-
236
- it "should return the resource" do
237
- label = github.issues.labels.delete user, repo, label_id
238
- label.should be_a Hashie::Mash
239
- end
240
-
241
- it "should get the label information" do
242
- label = github.issues.labels.delete user, repo, label_id
243
- label.name.should == 'bug'
244
- end
245
- end
246
-
247
- context "failed to remove resource" do
248
- before do
249
- stub_delete("/repos/#{user}/#{repo}/labels/#{label_id}").
250
- to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
251
- end
252
-
253
- it "should faile to retrieve resource" do
254
- expect {
255
- github.issues.labels.delete user, repo, label_id
256
- }.to raise_error(Github::Error::NotFound)
257
- end
258
- end
259
- end # delete
260
-
261
- describe '#issue' do
262
- let(:issue_id) { 1 }
263
-
264
- context "resource found" do
265
- before do
266
- stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
267
- to_return(:body => fixture('issues/labels.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
268
- end
269
-
270
- it "should fail to get resource without issue_id" do
271
- expect {
272
- github.issues.labels.issue user, repo, nil
273
- }.to raise_error(ArgumentError)
274
- end
275
-
276
- it "should get the resources" do
277
- github.issues.labels.issue user, repo, issue_id
278
- a_get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
279
- should have_been_made
280
- end
281
-
282
- it "should return array of resources" do
283
- labels = github.issues.labels.issue user, repo, issue_id
284
- labels.should be_an Array
285
- labels.should have(1).items
286
- end
287
-
288
- it "should be a mash type" do
289
- labels = github.issues.labels.issue user, repo, issue_id
290
- labels.first.should be_a Hashie::Mash
291
- end
292
-
293
- it "should get issue information" do
294
- labels = github.issues.labels.issue user, repo, issue_id
295
- labels.first.name.should == 'bug'
296
- end
297
-
298
- it "should yield to a block" do
299
- github.issues.labels.should_receive(:issue).
300
- with(user, repo, issue_id).and_yield('web')
301
- github.issues.labels.issue(user, repo, issue_id) { |param| 'web' }.should == 'web'
302
- end
303
- end
304
-
305
- context "resource not found" do
306
- before do
307
- stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
308
- to_return(:body => "", :status => [404, "Not Found"])
309
- end
310
-
311
- it "should return 404 with a message 'Not Found'" do
312
- expect {
313
- github.issues.labels.issue user, repo, issue_id
314
- }.to raise_error(Github::Error::NotFound)
315
- end
316
- end
317
- end # issue
318
-
319
- describe "#add" do
320
- let(:issue_id) { 1 }
321
- let(:labels) { "Label 1" }
322
-
323
- context "labels added" do
324
- before do
325
- stub_post("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
326
- to_return(:body => fixture('issues/labels.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
327
- end
328
-
329
- it "should fail to add labels if issue-id is missing" do
330
- expect {
331
- github.issues.labels.add user, repo, nil, labels
332
- }.to raise_error(ArgumentError)
333
- end
334
-
335
- it "should create resource successfully" do
336
- github.issues.labels.add user, repo, issue_id, labels
337
- a_post("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").should have_been_made
338
- end
339
-
340
- it "should return the resource" do
341
- labels = github.issues.labels.add user, repo, issue_id, labels
342
- labels.first.should be_a Hashie::Mash
343
- end
344
-
345
- it "should get the label information" do
346
- labels = github.issues.labels.add user, repo, issue_id, labels
347
- labels.first.name.should == 'bug'
348
- end
349
- end
350
-
351
- context "failed to add labels" do
352
- before do
353
- stub_post("/repos/#{user}/#{repo}/issues/#{issue_id}/labels").
354
- to_return(:body => fixture('issues/label.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
355
-
356
- end
357
-
358
- it "should fail to retrieve resource" do
359
- expect {
360
- github.issues.labels.add user, repo, issue_id, labels
361
- }.to raise_error(Github::Error::NotFound)
362
- end
363
- end
364
- end # add
365
-
366
13
  describe "#remove" do
367
14
  let(:issue_id) { 1 }
368
15
  let(:label_id) { 1 }
@@ -468,61 +115,4 @@ describe Github::Issues::Labels do
468
115
  end
469
116
  end # replace
470
117
 
471
- describe '#milestone' do
472
- let(:milestone_id) { 1 }
473
-
474
- context "resource found" do
475
- before do
476
- stub_get("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels").
477
- to_return(:body => fixture('issues/labels.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
478
- end
479
-
480
- it "should throw exception if milestone-id not present" do
481
- expect {
482
- github.issues.labels.milestone user, repo, nil
483
- }.to raise_error(ArgumentError)
484
- end
485
-
486
- it "should get the resources" do
487
- github.issues.labels.milestone user, repo, milestone_id
488
- a_get("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels").should have_been_made
489
- end
490
-
491
- it "should return array of resources" do
492
- labels = github.issues.labels.milestone user, repo, milestone_id
493
- labels.should be_an Array
494
- labels.should have(1).items
495
- end
496
-
497
- it "should be a mash type" do
498
- labels = github.issues.labels.milestone user, repo, milestone_id
499
- labels.first.should be_a Hashie::Mash
500
- end
501
-
502
- it "should get issue information" do
503
- labels = github.issues.labels.milestone user, repo, milestone_id
504
- labels.first.name.should == 'bug'
505
- end
506
-
507
- it "should yield to a block" do
508
- github.issues.labels.should_receive(:milestone).
509
- with(user, repo, milestone_id).and_yield('web')
510
- github.issues.labels.milestone(user, repo, milestone_id) { |param| 'web' }.should == 'web'
511
- end
512
- end
513
-
514
- context "resource not found" do
515
- before do
516
- stub_get("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels").
517
- to_return(:body => "", :status => [404, "Not Found"])
518
- end
519
-
520
- it "should return 404 with a message 'Not Found'" do
521
- expect {
522
- github.issues.labels.milestone user, repo, milestone_id
523
- }.to raise_error(Github::Error::NotFound)
524
- end
525
- end
526
- end # milestone
527
-
528
118
  end # Github::Issues::Labels