github_api 0.8.6 → 0.8.7

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.
@@ -1,402 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Github::PullRequests do
4
- let(:github) { Github.new }
5
- let(:user) { 'peter-murach' }
6
- let(:repo) { 'github' }
7
- let(:pull_request_id) { 1 }
8
-
9
- after { reset_authentication_for github }
10
-
11
- describe "#list" do
12
- it { should respond_to :all }
13
-
14
- context 'resource found' do
15
- let(:inputs) { { 'state'=> 'closed', 'unrelated' => true } }
16
-
17
- before do
18
- stub_get("/repos/#{user}/#{repo}/pulls").
19
- with(:query => inputs.except('unrelated')).
20
- to_return(:body => fixture('pull_requests/pull_requests.json'),
21
- :status => 200,
22
- :headers => {:content_type => "application/json; charset=utf-8"})
23
- end
24
-
25
- it "throws error if pull_request id not provided" do
26
- expect { github.pull_requests.list nil}.to raise_error(ArgumentError)
27
- end
28
-
29
- it "should get the resources" do
30
- github.pull_requests.list user, repo, inputs
31
- a_get("/repos/#{user}/#{repo}/pulls").with(:query => inputs).should have_been_made
32
- end
33
-
34
- it "should return array of resources" do
35
- pull_requests = github.pull_requests.list user, repo, inputs
36
- pull_requests.should be_an Array
37
- pull_requests.should have(1).items
38
- end
39
-
40
- it "should be a mash type" do
41
- pull_requests = github.pull_requests.list user, repo, inputs
42
- pull_requests.first.should be_a Hashie::Mash
43
- end
44
-
45
- it "should get pull request information" do
46
- pull_requests = github.pull_requests.list user, repo, inputs
47
- pull_requests.first.title.should == 'new-feature'
48
- end
49
-
50
- it "should yield to a block" do
51
- github.pull_requests.should_receive(:list).with(user, repo).
52
- and_yield('web')
53
- github.pull_requests.list(user, repo) { |param| 'web' }
54
- end
55
- end
56
-
57
- context 'resource not found' do
58
- before do
59
- stub_get("/repos/#{user}/#{repo}/pulls").
60
- to_return(:body => "[]", :status => [404, "Not Found"])
61
- end
62
-
63
- it "should return 404 with a message 'Not Found'" do
64
- expect {
65
- github.pull_requests.list user, repo
66
- }.to raise_error(Github::Error::NotFound)
67
- end
68
- end
69
- end # list
70
-
71
- describe "#get" do
72
- it { github.pull_requests.should respond_to :find }
73
-
74
- context 'resource found' do
75
- before do
76
- stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").
77
- to_return(:body => fixture('pull_requests/pull_request.json'),
78
- :status => 200,
79
- :headers => {:content_type => "application/json; charset=utf-8"})
80
- end
81
-
82
- it "should fail to get resource without pull_request id" do
83
- expect { github.pull_requests.get nil }.to raise_error(ArgumentError)
84
- end
85
-
86
- it "should get the resource" do
87
- github.pull_requests.get user, repo, pull_request_id
88
- a_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").
89
- should have_been_made
90
- end
91
-
92
- it "should get pull_request information" do
93
- pull_request = github.pull_requests.get user, repo, pull_request_id
94
- pull_request.number.should eq pull_request_id
95
- pull_request.head.user.login.should == 'octocat'
96
- end
97
-
98
- it "should return mash" do
99
- pull_request = github.pull_requests.get user, repo, pull_request_id
100
- pull_request.should be_a Hashie::Mash
101
- end
102
- end
103
-
104
- context 'resource not found' do
105
- before do
106
- stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").
107
- to_return(:body => fixture('pull_requests/pull_request.json'),
108
- :status => 404,
109
- :headers => {:content_type => "application/json; charset=utf-8"})
110
- end
111
-
112
- it "should fail to retrive resource" do
113
- expect {
114
- github.pull_requests.get user, repo, pull_request_id
115
- }.to raise_error(Github::Error::NotFound)
116
- end
117
- end
118
- end # get
119
-
120
- describe "#create" do
121
- let(:inputs) {
122
- {
123
- "title" => "Amazing new feature",
124
- "body" => "Please pull this in!",
125
- "head" => "octocat:new-feature",
126
- "base" => "master",
127
- "state" => "open",
128
- 'unrelated' => 'giberrish'
129
- }
130
- }
131
-
132
- context "resouce created" do
133
- before do
134
- stub_post("/repos/#{user}/#{repo}/pulls").
135
- with(inputs.except('unrelated')).
136
- to_return(:body => fixture('pull_requests/pull_request.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
137
- end
138
-
139
- it "should create resource successfully" do
140
- github.pull_requests.create user, repo, inputs
141
- a_post("/repos/#{user}/#{repo}/pulls").with(inputs).should have_been_made
142
- end
143
-
144
- it "should return the resource" do
145
- pull_request = github.pull_requests.create user, repo, inputs
146
- pull_request.should be_a Hashie::Mash
147
- end
148
-
149
- it "should get the request information" do
150
- pull_request = github.pull_requests.create user, repo, inputs
151
- pull_request.title.should eql "new-feature"
152
- end
153
- end
154
-
155
- context "failed to create resource" do
156
- before do
157
- stub_post("/repos/#{user}/#{repo}/pulls").with(inputs).
158
- to_return(:body => fixture('pull_requests/pull_request.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
159
-
160
- end
161
-
162
- it "should faile to retrieve resource" do
163
- expect {
164
- github.pull_requests.create user, repo, inputs
165
- }.to raise_error(Github::Error::NotFound)
166
- end
167
- end
168
- end # create
169
-
170
- describe "#update" do
171
- let(:inputs) {
172
- {
173
- "title" => "new title",
174
- "body" => "updated body",
175
- "state" => "open",
176
- "unrelated" => true
177
- }
178
- }
179
-
180
- context "resouce updateed" do
181
- before do
182
- stub_patch("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").
183
- with(inputs.except('unrelated')).
184
- to_return(:body => fixture('pull_requests/pull_request.json'),
185
- :status => 201,
186
- :headers => {:content_type => "application/json; charset=utf-8"})
187
- end
188
-
189
- it "should create resource successfully" do
190
- github.pull_requests.update user, repo, pull_request_id, inputs
191
- a_patch("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").with(inputs).
192
- should have_been_made
193
- end
194
-
195
- it "should return the resource" do
196
- pull_request = github.pull_requests.update user, repo, pull_request_id, inputs
197
- pull_request.should be_a Hashie::Mash
198
- end
199
-
200
- it "should get the pull_request information" do
201
- pull_request = github.pull_requests.update user, repo, pull_request_id, inputs
202
- pull_request.title.should == 'new-feature'
203
- end
204
- end
205
-
206
- context "failed to create resource" do
207
- before do
208
- stub_patch("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").
209
- with(inputs).
210
- to_return(:body => fixture('pull_requests/pull_request.json'),
211
- :status => 404,
212
- :headers => {:content_type => "application/json; charset=utf-8"})
213
- end
214
-
215
- it "should faile to retrieve resource" do
216
- expect {
217
- github.pull_requests.update user, repo, pull_request_id, inputs
218
- }.to raise_error(Github::Error::NotFound)
219
- end
220
- end
221
- end # update
222
-
223
- describe "#commits" do
224
- context 'resource found' do
225
- before do
226
- stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/commits").
227
- to_return(:body => fixture('pull_requests/commits.json'),
228
- :status => 200,
229
- :headers => {:content_type => "application/json; charset=utf-8"})
230
- end
231
-
232
- it "throws error if pull_request_id not provided" do
233
- expect {
234
- github.pull_requests.commits user, repo, nil
235
- }.to raise_error(ArgumentError)
236
- end
237
-
238
- it "should get the resources" do
239
- github.pull_requests.commits user, repo, pull_request_id
240
- a_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/commits").
241
- should have_been_made
242
- end
243
-
244
- it "should return array of resources" do
245
- pull_requests = github.pull_requests.commits user, repo, pull_request_id
246
- pull_requests.should be_an Array
247
- pull_requests.should have(1).items
248
- end
249
-
250
- it "should be a mash type" do
251
- pull_requests = github.pull_requests.commits user, repo, pull_request_id
252
- pull_requests.first.should be_a Hashie::Mash
253
- end
254
-
255
- it "should get pull request information" do
256
- pull_requests = github.pull_requests.commits user, repo, pull_request_id
257
- pull_requests.first.committer.name.should == 'Scott Chacon'
258
- end
259
-
260
- it "should yield to a block" do
261
- github.pull_requests.should_receive(:commits).
262
- with(user, repo, pull_request_id).and_yield('web')
263
- github.pull_requests.commits(user, repo, pull_request_id) {|param| 'web' }
264
- end
265
- end
266
-
267
- context 'resource not found' do
268
- before do
269
- stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/commits").
270
- to_return(:body => "", :status => [404, "Not Found"])
271
- end
272
-
273
- it "should return 404 with a message 'Not Found'" do
274
- expect {
275
- github.pull_requests.commits user, repo, pull_request_id
276
- }.to raise_error(Github::Error::NotFound)
277
- end
278
- end
279
- end # commits
280
-
281
- describe "#files" do
282
- it { github.pull_requests.should respond_to :files }
283
-
284
- context 'resource found' do
285
- before do
286
- stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/files").
287
- to_return(:body => fixture('pull_requests/files.json'),
288
- :status => 200,
289
- :headers => {:content_type => "application/json; charset=utf-8"})
290
- end
291
-
292
- it "should get the resources" do
293
- github.pull_requests.files user, repo, pull_request_id
294
- a_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/files").
295
- should have_been_made
296
- end
297
-
298
- it "should return array of resources" do
299
- pull_requests = github.pull_requests.files user, repo, pull_request_id
300
- pull_requests.should be_an Array
301
- pull_requests.should have(1).items
302
- end
303
-
304
- it "should be a mash type" do
305
- pull_requests = github.pull_requests.files user, repo, pull_request_id
306
- pull_requests.first.should be_a Hashie::Mash
307
- end
308
-
309
- it "should get pull request information" do
310
- pull_requests = github.pull_requests.files user, repo, pull_request_id
311
- pull_requests.first.filename.should == 'file1.txt'
312
- end
313
-
314
- it "should yield to a block" do
315
- github.pull_requests.should_receive(:files).with(user, repo, pull_request_id).
316
- and_yield('web')
317
- github.pull_requests.files(user, repo, pull_request_id) { |param| 'web' }
318
- end
319
- end
320
-
321
- context 'resource not found' do
322
- before do
323
- stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/files").
324
- to_return(:body => "", :status => [404, "Not Found"])
325
- end
326
-
327
- it "should return 404 with a message 'Not Found'" do
328
- expect {
329
- github.pull_requests.files user, repo, pull_request_id
330
- }.to raise_error(Github::Error::NotFound)
331
- end
332
- end
333
- end # files
334
-
335
- describe "#merged?" do
336
- context "checks whetehr pull request has been merged" do
337
- before do
338
- github.oauth_token = nil
339
- github.user = nil
340
- stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
341
- to_return(:body => "[]", :status => 404, :headers => {:user_agent => github.user_agent})
342
- end
343
-
344
- it "should fail validation " do
345
- expect {
346
- github.pull_requests.merged?(nil, nil, pull_request_id)
347
- }.to raise_error(ArgumentError)
348
- end
349
-
350
- it "should return false if resource not found" do
351
- merged = github.pull_requests.merged? user, repo, pull_request_id
352
- merged.should be_false
353
- end
354
-
355
- it "should return true if resoure found" do
356
- stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
357
- to_return(:body => "[]", :status => 200,
358
- :headers => {:user_agent => github.user_agent})
359
- merged = github.pull_requests.merged? user, repo, pull_request_id
360
- merged.should be_true
361
- end
362
- end
363
- end # merged?
364
-
365
- describe "#merge" do
366
- context 'successful' do
367
- before do
368
- stub_put("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
369
- to_return(:body => fixture('pull_requests/merge_success.json'),
370
- :status => 200,
371
- :headers => {:user_agent => github.user_agent})
372
- end
373
-
374
- it 'performs request' do
375
- github.pull_requests.merge user, repo, pull_request_id
376
- a_put("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
377
- should have_been_made
378
- end
379
-
380
- it 'response contains merge success flag' do
381
- response = github.pull_requests.merge(user, repo, pull_request_id)
382
- response.merged.should be_true
383
- end
384
- end
385
-
386
- context 'cannot be performed' do
387
- before do
388
- stub_put("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
389
- to_return(:body => fixture('pull_requests/merge_failure.json'),
390
- :status => 200,
391
- :headers => {:user_agent => github.user_agent})
392
-
393
- end
394
-
395
- it 'response contains merge failure flag' do
396
- response = github.pull_requests.merge(user, repo, pull_request_id)
397
- response.merged.should be_false
398
- end
399
- end
400
- end # merge
401
-
402
- end # Github::PullRequests