github_api 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/features/error_codes.feature +1 -1
- data/lib/github_api/error.rb +25 -32
- data/lib/github_api/error/bad_request.rb +12 -0
- data/lib/github_api/error/forbidden.rb +12 -0
- data/lib/github_api/error/internal_server_error.rb +12 -0
- data/lib/github_api/error/not_found.rb +12 -0
- data/lib/github_api/error/service_error.rb +19 -0
- data/lib/github_api/error/service_unavailable.rb +12 -0
- data/lib/github_api/error/unauthorized.rb +12 -0
- data/lib/github_api/error/unprocessable_entity.rb +12 -0
- data/lib/github_api/gists.rb +1 -1
- data/lib/github_api/orgs/members.rb +2 -2
- data/lib/github_api/orgs/teams.rb +2 -2
- data/lib/github_api/pull_requests.rb +14 -7
- data/lib/github_api/pull_requests/comments.rb +19 -14
- data/lib/github_api/repos/collaborators.rb +1 -1
- data/lib/github_api/repos/watching.rb +1 -1
- data/lib/github_api/response/raise_error.rb +8 -13
- data/lib/github_api/users/followers.rb +1 -1
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/pull_requests/comment.json +17 -0
- data/spec/fixtures/pull_requests/comments.json +19 -0
- data/spec/fixtures/pull_requests/commits.json +27 -0
- data/spec/fixtures/pull_requests/files.json +13 -0
- data/spec/fixtures/pull_requests/merge_failure.json +5 -0
- data/spec/fixtures/pull_requests/merge_success.json +5 -0
- data/spec/fixtures/pull_requests/pull_request.json +123 -0
- data/spec/fixtures/pull_requests/pull_requests.json +31 -0
- data/spec/github/authorizations_spec.rb +5 -5
- data/spec/github/events_spec.rb +8 -8
- data/spec/github/gists/comments_spec.rb +5 -5
- data/spec/github/gists_spec.rb +7 -7
- data/spec/github/git_data/blobs_spec.rb +2 -2
- data/spec/github/git_data/commits_spec.rb +2 -2
- data/spec/github/git_data/references_spec.rb +4 -4
- data/spec/github/git_data/tags_spec.rb +2 -2
- data/spec/github/git_data/trees_spec.rb +2 -2
- data/spec/github/git_data_spec.rb +0 -1
- data/spec/github/issues/comments_spec.rb +5 -5
- data/spec/github/issues/events_spec.rb +2 -2
- data/spec/github/issues/labels_spec.rb +10 -10
- data/spec/github/issues/milestones_spec.rb +5 -5
- data/spec/github/issues_spec.rb +5 -5
- data/spec/github/orgs/members_spec.rb +5 -5
- data/spec/github/orgs/teams_spec.rb +11 -11
- data/spec/github/orgs_spec.rb +3 -3
- data/spec/github/pull_requests/comments_spec.rb +265 -0
- data/spec/github/pull_requests_spec.rb +414 -0
- data/spec/github/repos/collaborators_spec.rb +3 -3
- data/spec/github/repos/commits_spec.rb +8 -8
- data/spec/github/repos/downloads_spec.rb +5 -5
- data/spec/github/repos/forks_spec.rb +2 -2
- data/spec/github/repos/hooks_spec.rb +6 -6
- data/spec/github/repos/keys_spec.rb +5 -5
- data/spec/github/repos/pub_sub_hubbub_spec.rb +2 -2
- data/spec/github/repos/watching_spec.rb +6 -6
- data/spec/github/repos_spec.rb +11 -11
- data/spec/github/users/emails_spec.rb +5 -0
- data/spec/github/users/followers_spec.rb +5 -0
- data/spec/github/users/keys_spec.rb +5 -0
- data/spec/github/users_spec.rb +2 -2
- metadata +23 -2
@@ -52,7 +52,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
52
52
|
it "should return 404 with a message 'Not Found'" do
|
53
53
|
expect {
|
54
54
|
github.orgs.teams org
|
55
|
-
}.to raise_error(Github::
|
55
|
+
}.to raise_error(Github::Error::NotFound)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end # teams
|
@@ -94,7 +94,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
94
94
|
it "should fail to retrive resource" do
|
95
95
|
expect {
|
96
96
|
github.orgs.team team
|
97
|
-
}.to raise_error(Github::
|
97
|
+
}.to raise_error(Github::Error::NotFound)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end # team
|
@@ -145,7 +145,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
145
145
|
it "should faile to retrieve resource" do
|
146
146
|
expect {
|
147
147
|
github.orgs.create_team org, inputs
|
148
|
-
}.to raise_error(Github::
|
148
|
+
}.to raise_error(Github::Error::NotFound)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end # create_team
|
@@ -196,7 +196,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
196
196
|
it "should faile to retrieve resource" do
|
197
197
|
expect {
|
198
198
|
github.orgs.edit_team team, inputs
|
199
|
-
}.to raise_error(Github::
|
199
|
+
}.to raise_error(Github::Error::NotFound)
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end # edit_team
|
@@ -228,7 +228,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
228
228
|
end
|
229
229
|
|
230
230
|
it "should fail to find resource" do
|
231
|
-
expect { github.orgs.delete_team team }.to raise_error(Github::
|
231
|
+
expect { github.orgs.delete_team team }.to raise_error(Github::Error::NotFound)
|
232
232
|
end
|
233
233
|
end
|
234
234
|
end # delete_team
|
@@ -280,7 +280,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
280
280
|
it "should return 404 with a message 'Not Found'" do
|
281
281
|
expect {
|
282
282
|
github.orgs.team_members team
|
283
|
-
}.to raise_error(Github::
|
283
|
+
}.to raise_error(Github::Error::NotFound)
|
284
284
|
end
|
285
285
|
end
|
286
286
|
end # team_members
|
@@ -351,7 +351,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
351
351
|
it "should fail to add resource" do
|
352
352
|
expect {
|
353
353
|
github.orgs.add_team_member team, member
|
354
|
-
}.to raise_error(Github::
|
354
|
+
}.to raise_error(Github::Error::NotFound)
|
355
355
|
end
|
356
356
|
end
|
357
357
|
end # add_team_member
|
@@ -390,7 +390,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
390
390
|
it "should fail to remove resource" do
|
391
391
|
expect {
|
392
392
|
github.orgs.remove_team_member team, member
|
393
|
-
}.to raise_error(Github::
|
393
|
+
}.to raise_error(Github::Error::NotFound)
|
394
394
|
end
|
395
395
|
end
|
396
396
|
end # remove_team_member
|
@@ -442,7 +442,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
442
442
|
it "should return 404 with a message 'Not Found'" do
|
443
443
|
expect {
|
444
444
|
github.orgs.team_repos team
|
445
|
-
}.to raise_error(Github::
|
445
|
+
}.to raise_error(Github::Error::NotFound)
|
446
446
|
end
|
447
447
|
end
|
448
448
|
end # team_repos
|
@@ -512,7 +512,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
512
512
|
it "should fail to add resource" do
|
513
513
|
expect {
|
514
514
|
github.orgs.add_team_repo team, user, repo
|
515
|
-
}.to raise_error(Github::
|
515
|
+
}.to raise_error(Github::Error::NotFound)
|
516
516
|
end
|
517
517
|
end
|
518
518
|
end # add_team_repo
|
@@ -551,7 +551,7 @@ describe Github::Orgs::Teams, :type => :base do
|
|
551
551
|
it "should fail to remove resource" do
|
552
552
|
expect {
|
553
553
|
github.orgs.remove_team_repo team, user, repo
|
554
|
-
}.to raise_error(Github::
|
554
|
+
}.to raise_error(Github::Error::NotFound)
|
555
555
|
end
|
556
556
|
end
|
557
557
|
end # remove_team_repo
|
data/spec/github/orgs_spec.rb
CHANGED
@@ -63,7 +63,7 @@ describe Github::Orgs, :type => :base do
|
|
63
63
|
it "should return 404 with a message 'Not Found'" do
|
64
64
|
expect {
|
65
65
|
github.orgs.orgs user
|
66
|
-
}.to raise_error(Github::
|
66
|
+
}.to raise_error(Github::Error::NotFound)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end # orgs
|
@@ -105,7 +105,7 @@ describe Github::Orgs, :type => :base do
|
|
105
105
|
it "should fail to retrive resource" do
|
106
106
|
expect {
|
107
107
|
github.orgs.org org
|
108
|
-
}.to raise_error(Github::
|
108
|
+
}.to raise_error(Github::Error::NotFound)
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end # org
|
@@ -148,7 +148,7 @@ describe Github::Orgs, :type => :base do
|
|
148
148
|
it "should fail to find resource" do
|
149
149
|
expect {
|
150
150
|
github.orgs.edit_org org
|
151
|
-
}.to raise_error(Github::
|
151
|
+
}.to raise_error(Github::Error::NotFound)
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end # edit_org
|
@@ -0,0 +1,265 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Github::PullRequests::Comments, :type => :base do
|
4
|
+
|
5
|
+
let(:pull_request_id) { 1 }
|
6
|
+
let(:comment_id) { 1 }
|
7
|
+
|
8
|
+
describe "#comments" do
|
9
|
+
context 'check aliases' do
|
10
|
+
it { github.pull_requests.should respond_to :comments }
|
11
|
+
it { github.pull_requests.should respond_to :request_comments }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'resource found' do
|
15
|
+
|
16
|
+
before do
|
17
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
|
18
|
+
to_return(:body => fixture('pull_requests/comments.json'),
|
19
|
+
:status => 200,
|
20
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
21
|
+
end
|
22
|
+
|
23
|
+
it "throws error if comment id not provided" do
|
24
|
+
expect {
|
25
|
+
github.pull_requests.comments user, repo, nil
|
26
|
+
}.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should get the resources" do
|
30
|
+
github.pull_requests.comments user, repo, pull_request_id
|
31
|
+
a_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
|
32
|
+
should have_been_made
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return array of resources" do
|
36
|
+
comments = github.pull_requests.comments user, repo, pull_request_id
|
37
|
+
comments.should be_an Array
|
38
|
+
comments.should have(1).items
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be a mash type" do
|
42
|
+
comments = github.pull_requests.comments user, repo, pull_request_id
|
43
|
+
comments.first.should be_a Hashie::Mash
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should get pull request comment information" do
|
47
|
+
comments = github.pull_requests.comments user, repo, pull_request_id
|
48
|
+
comments.first.id.should == pull_request_id
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should yield to a block" do
|
52
|
+
github.pull_requests.should_receive(:comments).
|
53
|
+
with(user, repo, pull_request_id).and_yield('web')
|
54
|
+
github.pull_requests.comments(user, repo, pull_request_id) {|param| 'web' }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'resource not found' do
|
59
|
+
before do
|
60
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
|
61
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return 404 with a message 'Not Found'" do
|
65
|
+
expect {
|
66
|
+
github.pull_requests.comments user, repo, pull_request_id
|
67
|
+
}.to raise_error(Github::Error::NotFound)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end # comments
|
71
|
+
|
72
|
+
describe "#comment" do
|
73
|
+
context 'check aliases' do
|
74
|
+
it { github.pull_requests.should respond_to :comment }
|
75
|
+
it { github.pull_requests.should respond_to :get_comment }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'resource found' do
|
79
|
+
before do
|
80
|
+
stub_get("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}").
|
81
|
+
to_return(:body => fixture('pull_requests/comment.json'),
|
82
|
+
:status => 200,
|
83
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should fail to get resource without comment id" do
|
87
|
+
expect {
|
88
|
+
github.pull_requests.comment user, repo, nil
|
89
|
+
}.to raise_error(ArgumentError)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should get the resource" do
|
93
|
+
github.pull_requests.comment user, repo, pull_request_id
|
94
|
+
a_get("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}").
|
95
|
+
should have_been_made
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should get comment information" do
|
99
|
+
comment = github.pull_requests.comment user, repo, comment_id
|
100
|
+
comment.id.should eq comment_id
|
101
|
+
comment.user.login.should == 'octocat'
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should return mash" do
|
105
|
+
comment = github.pull_requests.comment user, repo, comment_id
|
106
|
+
comment.should be_a Hashie::Mash
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'resource not found' do
|
111
|
+
before do
|
112
|
+
stub_get("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}").
|
113
|
+
to_return(:body => fixture('pull_requests/comment.json'),
|
114
|
+
:status => 404,
|
115
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should fail to retrive resource" do
|
119
|
+
expect {
|
120
|
+
github.pull_requests.comment user, repo, comment_id
|
121
|
+
}.to raise_error(Github::Error::NotFound)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end # comment
|
125
|
+
|
126
|
+
describe "create_request" do
|
127
|
+
let(:inputs) {
|
128
|
+
{
|
129
|
+
"body" => "Nice change",
|
130
|
+
"commit_id" => "6dcb09b5b57875f334f61aebed695e2e4193db5e",
|
131
|
+
"path" => "file1.txt",
|
132
|
+
"position" => 4,
|
133
|
+
"in_reply_to" => 4,
|
134
|
+
'unrelated' => 'giberrish'
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
context "resouce created" do
|
139
|
+
before do
|
140
|
+
stub_post("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
|
141
|
+
with(:body => JSON.generate(inputs.except('unrelated'))).
|
142
|
+
to_return(:body => fixture('pull_requests/comment.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'raises error when pull_request_id is missing' do
|
146
|
+
expect {
|
147
|
+
github.pull_requests user, repo, nil
|
148
|
+
}.to raise_error(ArgumentError)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should create resource successfully" do
|
152
|
+
github.pull_requests.create_comment user, repo, pull_request_id, inputs
|
153
|
+
a_post("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
|
154
|
+
with(inputs).should have_been_made
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should return the resource" do
|
158
|
+
pull_request = github.pull_requests.create_comment user, repo, pull_request_id, inputs
|
159
|
+
pull_request.should be_a Hashie::Mash
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should get the request information" do
|
163
|
+
pull_request = github.pull_requests.create_comment user, repo, pull_request_id, inputs
|
164
|
+
pull_request.id.should == pull_request_id
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "fails to create resource" do
|
169
|
+
before do
|
170
|
+
stub_post("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/comments").
|
171
|
+
with(inputs.except('unrelated')).
|
172
|
+
to_return(:body => fixture('pull_requests/comment.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should faile to retrieve resource" do
|
177
|
+
expect {
|
178
|
+
github.pull_requests.create_comment user, repo, pull_request_id, inputs
|
179
|
+
}.to raise_error(Github::Error::NotFound)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end # create_comment
|
183
|
+
|
184
|
+
describe "#edit_comment" do
|
185
|
+
let(:inputs) {
|
186
|
+
{
|
187
|
+
"body" => "Nice change",
|
188
|
+
'unrelated' => 'giberrish'
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
context "resouce edited" do
|
193
|
+
before do
|
194
|
+
stub_patch("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}").
|
195
|
+
with(:body => JSON.generate(inputs.except('unrelated'))).
|
196
|
+
to_return(:body => fixture('pull_requests/comment.json'),
|
197
|
+
:status => 200,
|
198
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should edit resource successfully" do
|
202
|
+
github.pull_requests.edit_comment user, repo, comment_id, inputs
|
203
|
+
a_patch("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}").
|
204
|
+
with(inputs).should have_been_made
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should return the resource" do
|
208
|
+
comment = github.pull_requests.edit_comment user, repo, comment_id, inputs
|
209
|
+
comment.should be_a Hashie::Mash
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should get the comment information" do
|
213
|
+
comment = github.pull_requests.edit_comment user, repo, comment_id, inputs
|
214
|
+
comment.user.login.should == 'octocat'
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context "failed to edit resource" do
|
219
|
+
before do
|
220
|
+
stub_patch("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}").with(inputs).
|
221
|
+
to_return(:body => fixture('pull_requests/comment.json'),
|
222
|
+
:status => 404,
|
223
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should fail to retrieve resource" do
|
227
|
+
expect {
|
228
|
+
github.pull_requests.edit_comment user, repo, comment_id, inputs
|
229
|
+
}.to raise_error(Github::Error::NotFound)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end # edit_comment
|
233
|
+
|
234
|
+
context "#delete_comment" do
|
235
|
+
before do
|
236
|
+
stub_delete("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}").
|
237
|
+
to_return(:body => fixture('pull_requests/comment.json'),
|
238
|
+
:status => 204,
|
239
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should raise error if comment_id not present' do
|
243
|
+
expect {
|
244
|
+
github.pull_requests.delete_comment user, repo, nil
|
245
|
+
}.to raise_error(ArgumentError)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should remove resource successfully" do
|
249
|
+
github.pull_requests.delete_comment user, repo, comment_id
|
250
|
+
a_delete("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}").
|
251
|
+
should have_been_made
|
252
|
+
end
|
253
|
+
|
254
|
+
it "fails to delete resource" do
|
255
|
+
stub_delete("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}").
|
256
|
+
to_return(:body => '',
|
257
|
+
:status => 404,
|
258
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
259
|
+
expect {
|
260
|
+
github.pull_requests.delete_comment user, repo, comment_id
|
261
|
+
}.to raise_error(Github::Error::NotFound)
|
262
|
+
end
|
263
|
+
end # delete_gist
|
264
|
+
|
265
|
+
end # Github::PullRequests::Comments
|
@@ -0,0 +1,414 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Github::PullRequests, :type => :base do
|
4
|
+
|
5
|
+
let(:pull_request_id) { 1 }
|
6
|
+
|
7
|
+
describe "#pull_requests" do
|
8
|
+
context 'check aliases' do
|
9
|
+
it { github.pull_requests.should respond_to :pulls }
|
10
|
+
it { github.pull_requests.should respond_to :requests }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'resource found' do
|
14
|
+
let(:params) { { :state => 'closed', :unrelated => true } }
|
15
|
+
|
16
|
+
before do
|
17
|
+
stub_get("/repos/#{user}/#{repo}/pulls").
|
18
|
+
with(:query => params.except(:unrelated)).
|
19
|
+
to_return(:body => fixture('pull_requests/pull_requests.json'),
|
20
|
+
:status => 200,
|
21
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
22
|
+
end
|
23
|
+
|
24
|
+
it "throws error if pull_request id not provided" do
|
25
|
+
expect { github.pull_requests.pull_requests nil}.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should get the resources" do
|
29
|
+
github.pull_requests.pull_requests user, repo, params
|
30
|
+
a_get("/repos/#{user}/#{repo}/pulls").with(:query => params).should have_been_made
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return array of resources" do
|
34
|
+
pull_requests = github.pull_requests.pull_requests user, repo, params
|
35
|
+
pull_requests.should be_an Array
|
36
|
+
pull_requests.should have(1).items
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should be a mash type" do
|
40
|
+
pull_requests = github.pull_requests.pull_requests user, repo, params
|
41
|
+
pull_requests.first.should be_a Hashie::Mash
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should get pull request information" do
|
45
|
+
pull_requests = github.pull_requests.pull_requests user, repo, params
|
46
|
+
pull_requests.first.title.should == 'new-feature'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should yield to a block" do
|
50
|
+
github.pull_requests.should_receive(:pull_requests).with(user, repo).
|
51
|
+
and_yield('web')
|
52
|
+
github.pull_requests.pull_requests(user, repo) { |param| 'web' }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'resource not found' do
|
57
|
+
before do
|
58
|
+
stub_get("/repos/#{user}/#{repo}/pulls").
|
59
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return 404 with a message 'Not Found'" do
|
63
|
+
expect {
|
64
|
+
github.pull_requests.pull_requests user, repo
|
65
|
+
}.to raise_error(Github::Error::NotFound)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end # pull_requests
|
69
|
+
|
70
|
+
describe "#pull_request" do
|
71
|
+
context 'check aliases' do
|
72
|
+
it { github.pull_requests.should respond_to :pull_request }
|
73
|
+
it { github.pull_requests.should respond_to :get_pull_request }
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'resource found' do
|
77
|
+
before do
|
78
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").
|
79
|
+
to_return(:body => fixture('pull_requests/pull_request.json'),
|
80
|
+
:status => 200,
|
81
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should fail to get resource without pull_request id" do
|
85
|
+
expect { github.pull_requests.pull_request nil }.to raise_error(ArgumentError)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should get the resource" do
|
89
|
+
github.pull_requests.pull_request user, repo, pull_request_id
|
90
|
+
a_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").
|
91
|
+
should have_been_made
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should get pull_request information" do
|
95
|
+
pull_request = github.pull_requests.pull_request user, repo, pull_request_id
|
96
|
+
pull_request.number.should eq pull_request_id
|
97
|
+
pull_request.head.user.login.should == 'octocat'
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return mash" do
|
101
|
+
pull_request = github.pull_requests.pull_request user, repo, pull_request_id
|
102
|
+
pull_request.should be_a Hashie::Mash
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'resource not found' do
|
107
|
+
before do
|
108
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").
|
109
|
+
to_return(:body => fixture('pull_requests/pull_request.json'),
|
110
|
+
:status => 404,
|
111
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should fail to retrive resource" do
|
115
|
+
expect {
|
116
|
+
github.pull_requests.pull_request user, repo, pull_request_id
|
117
|
+
}.to raise_error(Github::Error::NotFound)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end # pull_request
|
121
|
+
|
122
|
+
describe "create_request" do
|
123
|
+
let(:inputs) {
|
124
|
+
{
|
125
|
+
"title" => "Amazing new feature",
|
126
|
+
"body" => "Please pull this in!",
|
127
|
+
"head" => "octocat:new-feature",
|
128
|
+
"base" => "master",
|
129
|
+
"state" => "open",
|
130
|
+
'unrelated' => 'giberrish'
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
context "resouce created" do
|
135
|
+
before do
|
136
|
+
stub_post("/repos/#{user}/#{repo}/pulls").
|
137
|
+
with(:body => JSON.generate(inputs.except('unrelated'))).
|
138
|
+
to_return(:body => fixture('pull_requests/pull_request.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should create resource successfully" do
|
142
|
+
github.pull_requests.create_request user, repo, inputs
|
143
|
+
a_post("/repos/#{user}/#{repo}/pulls").with(inputs).should have_been_made
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should return the resource" do
|
147
|
+
pull_request = github.pull_requests.create_request user, repo, inputs
|
148
|
+
pull_request.should be_a Hashie::Mash
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should get the request information" do
|
152
|
+
pull_request = github.pull_requests.create_request user, repo, inputs
|
153
|
+
pull_request.title.should eql "new-feature"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "failed to create resource" do
|
158
|
+
before do
|
159
|
+
stub_post("/repos/#{user}/#{repo}/pulls").with(inputs).
|
160
|
+
to_return(:body => fixture('pull_requests/pull_request.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should faile to retrieve resource" do
|
165
|
+
expect {
|
166
|
+
github.pull_requests.create_request user, repo, inputs
|
167
|
+
}.to raise_error(Github::Error::NotFound)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end # create_request
|
171
|
+
|
172
|
+
describe "#update_request" do
|
173
|
+
let(:inputs) {
|
174
|
+
{
|
175
|
+
"title" => "new title",
|
176
|
+
"body" => "updated body",
|
177
|
+
"state" => "open",
|
178
|
+
"unrelated" => true
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
context "resouce updateed" do
|
183
|
+
before do
|
184
|
+
stub_patch("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").
|
185
|
+
with(:body => JSON.generate(inputs.except('unrelated'))).
|
186
|
+
to_return(:body => fixture('pull_requests/pull_request.json'),
|
187
|
+
:status => 201,
|
188
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should create resource successfully" do
|
192
|
+
github.pull_requests.update_request user, repo, pull_request_id, inputs
|
193
|
+
a_patch("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").with(inputs).
|
194
|
+
should have_been_made
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should return the resource" do
|
198
|
+
pull_request = github.pull_requests.update_request user, repo,
|
199
|
+
pull_request_id, inputs
|
200
|
+
pull_request.should be_a Hashie::Mash
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should get the pull_request information" do
|
204
|
+
pull_request = github.pull_requests.update_request user, repo,
|
205
|
+
pull_request_id, inputs
|
206
|
+
pull_request.title.should == 'new-feature'
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context "failed to create resource" do
|
211
|
+
before do
|
212
|
+
stub_patch("/repos/#{user}/#{repo}/pulls/#{pull_request_id}").
|
213
|
+
with(inputs).
|
214
|
+
to_return(:body => fixture('pull_requests/pull_request.json'),
|
215
|
+
:status => 404,
|
216
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should faile to retrieve resource" do
|
220
|
+
expect {
|
221
|
+
github.pull_requests.update_request user, repo, pull_request_id, inputs
|
222
|
+
}.to raise_error(Github::Error::NotFound)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end # update_request
|
226
|
+
|
227
|
+
describe "#commits" do
|
228
|
+
context 'check aliases' do
|
229
|
+
it { github.pull_requests.should respond_to :commits }
|
230
|
+
it { github.pull_requests.should respond_to :request_commits }
|
231
|
+
end
|
232
|
+
|
233
|
+
context 'resource found' do
|
234
|
+
before do
|
235
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/commits").
|
236
|
+
to_return(:body => fixture('pull_requests/commits.json'),
|
237
|
+
:status => 200,
|
238
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
239
|
+
end
|
240
|
+
|
241
|
+
it "throws error if pull_request_id not provided" do
|
242
|
+
expect {
|
243
|
+
github.pull_requests.commits user, repo, nil
|
244
|
+
}.to raise_error(ArgumentError)
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should get the resources" do
|
248
|
+
github.pull_requests.commits user, repo, pull_request_id
|
249
|
+
a_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/commits").
|
250
|
+
should have_been_made
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should return array of resources" do
|
254
|
+
pull_requests = github.pull_requests.commits user, repo, pull_request_id
|
255
|
+
pull_requests.should be_an Array
|
256
|
+
pull_requests.should have(1).items
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should be a mash type" do
|
260
|
+
pull_requests = github.pull_requests.commits user, repo, pull_request_id
|
261
|
+
pull_requests.first.should be_a Hashie::Mash
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should get pull request information" do
|
265
|
+
pull_requests = github.pull_requests.commits user, repo, pull_request_id
|
266
|
+
pull_requests.first.committer.name.should == 'Scott Chacon'
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should yield to a block" do
|
270
|
+
github.pull_requests.should_receive(:commits).
|
271
|
+
with(user, repo, pull_request_id).and_yield('web')
|
272
|
+
github.pull_requests.commits(user, repo, pull_request_id) {|param| 'web' }
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context 'resource not found' do
|
277
|
+
before do
|
278
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/commits").
|
279
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should return 404 with a message 'Not Found'" do
|
283
|
+
expect {
|
284
|
+
github.pull_requests.commits user, repo, pull_request_id
|
285
|
+
}.to raise_error(Github::Error::NotFound)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end # commits
|
289
|
+
|
290
|
+
describe "#files" do
|
291
|
+
context 'check aliases' do
|
292
|
+
it { github.pull_requests.should respond_to :files }
|
293
|
+
it { github.pull_requests.should respond_to :request_files }
|
294
|
+
end
|
295
|
+
|
296
|
+
context 'resource found' do
|
297
|
+
before do
|
298
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/files").
|
299
|
+
to_return(:body => fixture('pull_requests/files.json'),
|
300
|
+
:status => 200,
|
301
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should get the resources" do
|
305
|
+
github.pull_requests.files user, repo, pull_request_id
|
306
|
+
a_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/files").
|
307
|
+
should have_been_made
|
308
|
+
end
|
309
|
+
|
310
|
+
it "should return array of resources" do
|
311
|
+
pull_requests = github.pull_requests.files user, repo, pull_request_id
|
312
|
+
pull_requests.should be_an Array
|
313
|
+
pull_requests.should have(1).items
|
314
|
+
end
|
315
|
+
|
316
|
+
it "should be a mash type" do
|
317
|
+
pull_requests = github.pull_requests.files user, repo, pull_request_id
|
318
|
+
pull_requests.first.should be_a Hashie::Mash
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should get pull request information" do
|
322
|
+
pull_requests = github.pull_requests.files user, repo, pull_request_id
|
323
|
+
pull_requests.first.filename.should == 'file1.txt'
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should yield to a block" do
|
327
|
+
github.pull_requests.should_receive(:files).with(user, repo, pull_request_id).
|
328
|
+
and_yield('web')
|
329
|
+
github.pull_requests.files(user, repo, pull_request_id) { |param| 'web' }
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context 'resource not found' do
|
334
|
+
before do
|
335
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/files").
|
336
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should return 404 with a message 'Not Found'" do
|
340
|
+
expect {
|
341
|
+
github.pull_requests.files user, repo, pull_request_id
|
342
|
+
}.to raise_error(Github::Error::NotFound)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end # files
|
346
|
+
|
347
|
+
describe "#merged?" do
|
348
|
+
context "checks whetehr pull request has been merged" do
|
349
|
+
before do
|
350
|
+
github.oauth_token = nil
|
351
|
+
github.user = nil
|
352
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
|
353
|
+
to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should fail validation " do
|
357
|
+
expect {
|
358
|
+
github.pull_requests.merged?(nil, nil, pull_request_id)
|
359
|
+
}.to raise_error(ArgumentError)
|
360
|
+
end
|
361
|
+
|
362
|
+
it "should return false if resource not found" do
|
363
|
+
merged = github.pull_requests.merged? user, repo, pull_request_id
|
364
|
+
merged.should be_false
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should return true if resoure found" do
|
368
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
|
369
|
+
to_return(:body => "", :status => 200,
|
370
|
+
:headers => {:user_agent => github.user_agent})
|
371
|
+
merged = github.pull_requests.merged? user, repo, pull_request_id
|
372
|
+
merged.should be_true
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end # merged?
|
376
|
+
|
377
|
+
describe "#merge" do
|
378
|
+
context 'successful' do
|
379
|
+
before do
|
380
|
+
stub_put("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
|
381
|
+
to_return(:body => fixture('pull_requests/merge_success.json'),
|
382
|
+
:status => 200,
|
383
|
+
:headers => {:user_agent => github.user_agent})
|
384
|
+
end
|
385
|
+
|
386
|
+
it 'performs request' do
|
387
|
+
github.pull_requests.merge user, repo, pull_request_id
|
388
|
+
a_put("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
|
389
|
+
should have_been_made
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'response contains merge success flag' do
|
393
|
+
response = github.pull_requests.merge(user, repo, pull_request_id)
|
394
|
+
response.merged.should be_true
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
context 'cannot be performed' do
|
399
|
+
before do
|
400
|
+
stub_put("/repos/#{user}/#{repo}/pulls/#{pull_request_id}/merge").
|
401
|
+
to_return(:body => fixture('pull_requests/merge_failure.json'),
|
402
|
+
:status => 200,
|
403
|
+
:headers => {:user_agent => github.user_agent})
|
404
|
+
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'response contains merge failure flag' do
|
408
|
+
response = github.pull_requests.merge(user, repo, pull_request_id)
|
409
|
+
response.merged.should be_false
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end # merge
|
413
|
+
|
414
|
+
end # Github::PullRequests
|