github_api 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +228 -0
- data/Rakefile +52 -0
- data/features/github_api.feature +50 -0
- data/features/options.feature +4 -0
- data/features/pagination.feature +4 -0
- data/features/step_definitions/github_api_steps.rb +11 -0
- data/features/support/env.rb +13 -0
- data/lib/github_api.rb +73 -0
- data/lib/github_api/api.rb +175 -0
- data/lib/github_api/api/utils.rb +9 -0
- data/lib/github_api/authorization.rb +73 -0
- data/lib/github_api/authorizations.rb +119 -0
- data/lib/github_api/cache_control.rb +19 -0
- data/lib/github_api/client.rb +55 -0
- data/lib/github_api/compatibility.rb +23 -0
- data/lib/github_api/configuration.rb +96 -0
- data/lib/github_api/connection.rb +75 -0
- data/lib/github_api/core_ext/array.rb +14 -0
- data/lib/github_api/core_ext/hash.rb +42 -0
- data/lib/github_api/error.rb +35 -0
- data/lib/github_api/events.rb +202 -0
- data/lib/github_api/gists.rb +200 -0
- data/lib/github_api/gists/comments.rb +86 -0
- data/lib/github_api/git_data.rb +26 -0
- data/lib/github_api/git_data/blobs.rb +51 -0
- data/lib/github_api/git_data/commits.rb +78 -0
- data/lib/github_api/git_data/references.rb +113 -0
- data/lib/github_api/git_data/tags.rb +78 -0
- data/lib/github_api/git_data/trees.rb +89 -0
- data/lib/github_api/issues.rb +215 -0
- data/lib/github_api/issues/comments.rb +123 -0
- data/lib/github_api/issues/events.rb +54 -0
- data/lib/github_api/issues/labels.rb +191 -0
- data/lib/github_api/issues/milestones.rb +140 -0
- data/lib/github_api/mime_type.rb +55 -0
- data/lib/github_api/orgs.rb +95 -0
- data/lib/github_api/orgs/members.rb +120 -0
- data/lib/github_api/orgs/teams.rb +245 -0
- data/lib/github_api/pull_requests.rb +224 -0
- data/lib/github_api/pull_requests/comments.rb +144 -0
- data/lib/github_api/repos.rb +286 -0
- data/lib/github_api/repos/collaborators.rb +81 -0
- data/lib/github_api/repos/commits.rb +180 -0
- data/lib/github_api/repos/downloads.rb +155 -0
- data/lib/github_api/repos/forks.rb +48 -0
- data/lib/github_api/repos/hooks.rb +174 -0
- data/lib/github_api/repos/keys.rb +104 -0
- data/lib/github_api/repos/pub_sub_hubbub.rb +102 -0
- data/lib/github_api/repos/watching.rb +94 -0
- data/lib/github_api/request.rb +84 -0
- data/lib/github_api/request/basic_auth.rb +31 -0
- data/lib/github_api/request/caching.rb +33 -0
- data/lib/github_api/request/oauth2.rb +33 -0
- data/lib/github_api/response.rb +28 -0
- data/lib/github_api/response/helpers.rb +14 -0
- data/lib/github_api/response/jsonize.rb +26 -0
- data/lib/github_api/response/mashify.rb +24 -0
- data/lib/github_api/response/raise_error.rb +33 -0
- data/lib/github_api/result.rb +42 -0
- data/lib/github_api/users.rb +84 -0
- data/lib/github_api/users/emails.rb +49 -0
- data/lib/github_api/users/followers.rb +98 -0
- data/lib/github_api/users/keys.rb +84 -0
- data/lib/github_api/version.rb +12 -0
- data/spec/README.rdoc +22 -0
- data/spec/coverage_adapter.rb +15 -0
- data/spec/fixtures/auths/authorization.json +14 -0
- data/spec/fixtures/auths/authorizations.json +16 -0
- data/spec/fixtures/events/events.json +29 -0
- data/spec/fixtures/issues/comment.json +13 -0
- data/spec/fixtures/issues/comments.json +15 -0
- data/spec/fixtures/issues/event.json +13 -0
- data/spec/fixtures/issues/events.json +15 -0
- data/spec/fixtures/issues/issue.json +56 -0
- data/spec/fixtures/issues/issues.json +58 -0
- data/spec/fixtures/issues/milestone.json +18 -0
- data/spec/fixtures/issues/milestones.json +20 -0
- data/spec/fixtures/orgs/members.json +9 -0
- data/spec/fixtures/orgs/org.json +18 -0
- data/spec/fixtures/orgs/orgs.json +8 -0
- data/spec/fixtures/orgs/team.json +8 -0
- data/spec/fixtures/orgs/team_repos.json +29 -0
- data/spec/fixtures/orgs/teams.json +7 -0
- data/spec/fixtures/repos/branches.json +9 -0
- data/spec/fixtures/repos/collaborators.json +8 -0
- data/spec/fixtures/repos/commit.json +53 -0
- data/spec/fixtures/repos/commit_comment.json +16 -0
- data/spec/fixtures/repos/commit_comments.json +18 -0
- data/spec/fixtures/repos/commits.json +27 -0
- data/spec/fixtures/repos/contributors.json +8 -0
- data/spec/fixtures/repos/download.json +10 -0
- data/spec/fixtures/repos/download_s3.json +21 -0
- data/spec/fixtures/repos/downloads.json +12 -0
- data/spec/fixtures/repos/fork.json +27 -0
- data/spec/fixtures/repos/forks.json +29 -0
- data/spec/fixtures/repos/hook.json +15 -0
- data/spec/fixtures/repos/hooks.json +10 -0
- data/spec/fixtures/repos/key.json +6 -0
- data/spec/fixtures/repos/keys.json +8 -0
- data/spec/fixtures/repos/languages.json +4 -0
- data/spec/fixtures/repos/repo.json +90 -0
- data/spec/fixtures/repos/repo_comments.json +18 -0
- data/spec/fixtures/repos/repos.json +29 -0
- data/spec/fixtures/repos/tags.json +11 -0
- data/spec/fixtures/repos/teams.json +7 -0
- data/spec/fixtures/repos/watched.json +29 -0
- data/spec/fixtures/repos/watchers.json +8 -0
- data/spec/fixtures/users/user.json +32 -0
- data/spec/github/api_spec.rb +25 -0
- data/spec/github/authorization_spec.rb +176 -0
- data/spec/github/authorizations_spec.rb +242 -0
- data/spec/github/client_spec.rb +50 -0
- data/spec/github/core_ext/hash_spec.rb +44 -0
- data/spec/github/events_spec.rb +491 -0
- data/spec/github/gists/comments_spec.rb +5 -0
- data/spec/github/gists_spec.rb +5 -0
- data/spec/github/git_data/blobs_spec.rb +5 -0
- data/spec/github/git_data/commits_spec.rb +5 -0
- data/spec/github/git_data/references_spec.rb +5 -0
- data/spec/github/git_data/tags_spec.rb +5 -0
- data/spec/github/git_data/trees_spec.rb +5 -0
- data/spec/github/git_data_spec.rb +5 -0
- data/spec/github/issues/comments_spec.rb +254 -0
- data/spec/github/issues/events_spec.rb +153 -0
- data/spec/github/issues/labels_spec.rb +5 -0
- data/spec/github/issues/milestones_spec.rb +260 -0
- data/spec/github/issues_spec.rb +287 -0
- data/spec/github/mime_type_spec.rb +70 -0
- data/spec/github/orgs/members_spec.rb +275 -0
- data/spec/github/orgs/teams_spec.rb +563 -0
- data/spec/github/orgs_spec.rb +160 -0
- data/spec/github/repos/collaborators_spec.rb +169 -0
- data/spec/github/repos/commits_spec.rb +424 -0
- data/spec/github/repos/downloads_spec.rb +247 -0
- data/spec/github/repos/forks_spec.rb +108 -0
- data/spec/github/repos/hooks_spec.rb +333 -0
- data/spec/github/repos/keys_spec.rb +217 -0
- data/spec/github/repos/pub_sub_hubbub_spec.rb +83 -0
- data/spec/github/repos/watching_spec.rb +222 -0
- data/spec/github/repos_spec.rb +571 -0
- data/spec/github/result_spec.rb +43 -0
- data/spec/github/users_spec.rb +140 -0
- data/spec/github_spec.rb +109 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/support/base.rb +13 -0
- metadata +149 -4
@@ -0,0 +1,260 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Github::Issues::Milestones do
|
4
|
+
include SpecHelpers::Base
|
5
|
+
|
6
|
+
let(:milestones_api) { Github::Issues::Milestones }
|
7
|
+
|
8
|
+
it { milestones_api::VALID_MILESTONE_OPTIONS.should_not be_nil }
|
9
|
+
it { milestones_api::VALID_MILESTONE_INPUTS.should_not be_nil }
|
10
|
+
|
11
|
+
describe 'milestones' do
|
12
|
+
it { github.issues.should respond_to :milestones }
|
13
|
+
it { github.issues.should respond_to :list_milestones }
|
14
|
+
|
15
|
+
context "resource found" do
|
16
|
+
before do
|
17
|
+
stub_get("/repos/#{user}/#{repo}/milestones").
|
18
|
+
to_return(:body => fixture('issues/milestones.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should fail to get resource without username" do
|
22
|
+
github.user, github.repo = nil, nil
|
23
|
+
expect { github.issues.milestones nil, repo }.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should get the resources" do
|
27
|
+
github.issues.milestones user, repo
|
28
|
+
a_get("/repos/#{user}/#{repo}/milestones").should have_been_made
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return array of resources" do
|
32
|
+
milestones = github.issues.milestones user, repo
|
33
|
+
milestones.should be_an Array
|
34
|
+
milestones.should have(1).items
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be a mash type" do
|
38
|
+
milestones = github.issues.milestones user, repo
|
39
|
+
milestones.first.should be_a Hashie::Mash
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should get issue information" do
|
43
|
+
milestones = github.issues.milestones user, repo
|
44
|
+
milestones.first.title.should == 'v1.0'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should yield to a block" do
|
48
|
+
github.issues.should_receive(:milestones).with(user, repo).and_yield('web')
|
49
|
+
github.issues.milestones(user, repo) { |param| 'web' }.should == 'web'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "resource not found" do
|
54
|
+
before do
|
55
|
+
stub_get("/repos/#{user}/#{repo}/milestones").
|
56
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return 404 with a message 'Not Found'" do
|
60
|
+
expect {
|
61
|
+
github.issues.milestones user, repo
|
62
|
+
}.to raise_error(Github::ResourceNotFound)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end # milestones
|
66
|
+
|
67
|
+
describe "milestone" do
|
68
|
+
let(:milestone_id) { 1 }
|
69
|
+
|
70
|
+
it { github.issues.should respond_to :milestone }
|
71
|
+
it { github.issues.should respond_to :get_milestone }
|
72
|
+
|
73
|
+
context "resource found" do
|
74
|
+
before do
|
75
|
+
stub_get("/repos/#{user}/#{repo}/milestones/#{milestone_id}").
|
76
|
+
to_return(:body => fixture('issues/milestone.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should fail to get resource without milestone id" do
|
80
|
+
expect { github.issues.milestone(user, repo, nil)}.to raise_error(ArgumentError)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should get the resource" do
|
84
|
+
github.issues.milestone user, repo, milestone_id
|
85
|
+
a_get("/repos/#{user}/#{repo}/milestones/#{milestone_id}").should have_been_made
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should get milestone information" do
|
89
|
+
milestone = github.issues.milestone user, repo, milestone_id
|
90
|
+
milestone.number.should == milestone_id
|
91
|
+
milestone.title.should == 'v1.0'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return mash" do
|
95
|
+
milestone = github.issues.milestone user, repo, milestone_id
|
96
|
+
milestone.should be_a Hashie::Mash
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "resource not found" do
|
101
|
+
before do
|
102
|
+
stub_get("/repos/#{user}/#{repo}/milestones/#{milestone_id}").
|
103
|
+
to_return(:body => fixture('issues/milestone.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should fail to retrive resource" do
|
107
|
+
expect {
|
108
|
+
github.issues.milestone user, repo, milestone_id
|
109
|
+
}.to raise_error(Github::ResourceNotFound)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end # milestone
|
113
|
+
|
114
|
+
describe "create_milestone" do
|
115
|
+
let(:inputs) {
|
116
|
+
{
|
117
|
+
"title" => "String",
|
118
|
+
"state" => "open or closed",
|
119
|
+
"description" => "String",
|
120
|
+
"due_on" => "Time"
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
context "resouce created" do
|
125
|
+
before do
|
126
|
+
stub_post("/repos/#{user}/#{repo}/milestones").with(inputs).
|
127
|
+
to_return(:body => fixture('issues/milestone.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should fail to create resource if 'title' input is missing" do
|
131
|
+
expect {
|
132
|
+
github.issues.create_milestone user, repo, inputs.except('title')
|
133
|
+
}.to raise_error(ArgumentError)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should create resource successfully" do
|
137
|
+
github.issues.create_milestone user, repo, inputs
|
138
|
+
a_post("/repos/#{user}/#{repo}/milestones").with(inputs).should have_been_made
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should return the resource" do
|
142
|
+
milestone = github.issues.create_milestone user, repo, inputs
|
143
|
+
milestone.should be_a Hashie::Mash
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should get the milestone information" do
|
147
|
+
milestone = github.issues.create_milestone user, repo, inputs
|
148
|
+
milestone.title.should == 'v1.0'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "failed to create resource" do
|
153
|
+
before do
|
154
|
+
stub_post("/repos/#{user}/#{repo}/milestones").with(inputs).
|
155
|
+
to_return(:body => fixture('issues/milestone.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should faile to retrieve resource" do
|
160
|
+
expect {
|
161
|
+
github.issues.create_milestone user, repo, inputs
|
162
|
+
}.to raise_error(Github::ResourceNotFound)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end # create_milestone
|
166
|
+
|
167
|
+
describe "update_milestone" do
|
168
|
+
let(:milestone_id) { 1 }
|
169
|
+
let(:inputs) {
|
170
|
+
{
|
171
|
+
"title" => "String",
|
172
|
+
"state" => "open or closed",
|
173
|
+
"description" => "String",
|
174
|
+
"due_on" => "Time"
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
context "resouce updated" do
|
179
|
+
before do
|
180
|
+
stub_patch("/repos/#{user}/#{repo}/milestones/#{milestone_id}").with(inputs).
|
181
|
+
to_return(:body => fixture('issues/milestone.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should fail to create resource if 'title' input is missing" do
|
185
|
+
expect {
|
186
|
+
github.issues.update_milestone user, repo, milestone_id, inputs.except('title')
|
187
|
+
}.to raise_error(ArgumentError)
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should update resource successfully" do
|
191
|
+
github.issues.update_milestone user, repo, milestone_id, inputs
|
192
|
+
a_patch("/repos/#{user}/#{repo}/milestones/#{milestone_id}").with(inputs).should have_been_made
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should return the resource" do
|
196
|
+
milestone = github.issues.update_milestone user, repo, milestone_id, inputs
|
197
|
+
milestone.should be_a Hashie::Mash
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should get the milestone information" do
|
201
|
+
milestone = github.issues.update_milestone user, repo, milestone_id, inputs
|
202
|
+
milestone.title.should == 'v1.0'
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "failed to create resource" do
|
207
|
+
before do
|
208
|
+
stub_patch("/repos/#{user}/#{repo}/milestones/#{milestone_id}").with(inputs).
|
209
|
+
to_return(:body => fixture('issues/milestone.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should faile to retrieve resource" do
|
214
|
+
expect {
|
215
|
+
github.issues.update_milestone user, repo, milestone_id, inputs
|
216
|
+
}.to raise_error(Github::ResourceNotFound)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end # update_milestone
|
220
|
+
|
221
|
+
describe "delete_milestone" do
|
222
|
+
let(:milestone_id) { 1 }
|
223
|
+
|
224
|
+
context "resouce removed" do
|
225
|
+
before do
|
226
|
+
stub_delete("/repos/#{user}/#{repo}/milestones/#{milestone_id}").
|
227
|
+
to_return(:body => fixture('issues/milestone.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should remove resource successfully" do
|
231
|
+
github.issues.delete_milestone user, repo, milestone_id
|
232
|
+
a_delete("/repos/#{user}/#{repo}/milestones/#{milestone_id}").should have_been_made
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should return the resource" do
|
236
|
+
milestone = github.issues.delete_milestone user, repo, milestone_id
|
237
|
+
milestone.should be_a Hashie::Mash
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should get the milestone information" do
|
241
|
+
milestone = github.issues.delete_milestone user, repo, milestone_id
|
242
|
+
milestone.title.should == 'v1.0'
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context "failed to remove resource" do
|
247
|
+
before do
|
248
|
+
stub_delete("/repos/#{user}/#{repo}/milestones/#{milestone_id}").
|
249
|
+
to_return(:body => fixture('issues/milestone.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should faile to retrieve resource" do
|
253
|
+
expect {
|
254
|
+
github.issues.delete_milestone user, repo, milestone_id
|
255
|
+
}.to raise_error(Github::ResourceNotFound)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end # delete_milestone
|
259
|
+
|
260
|
+
end # Github::Issues::Milestones
|
@@ -0,0 +1,287 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Issues do
|
6
|
+
|
7
|
+
let(:issues_api) { Github::Issues }
|
8
|
+
let(:github) { Github.new }
|
9
|
+
let(:user) { 'peter-murach' }
|
10
|
+
let(:repo) { 'github' }
|
11
|
+
|
12
|
+
describe 'modules inclusion' do
|
13
|
+
it { issues_api.included_modules.should include Github::Issues::Comments }
|
14
|
+
it { issues_api.included_modules.should include Github::Issues::Events }
|
15
|
+
it { issues_api.included_modules.should include Github::Issues::Labels }
|
16
|
+
it { issues_api.included_modules.should include Github::Issues::Milestones }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'issues' do
|
20
|
+
it { github.issues.should respond_to :issues }
|
21
|
+
it { github.issues.should respond_to :list_issues }
|
22
|
+
|
23
|
+
context "resource found" do
|
24
|
+
before do
|
25
|
+
stub_get("/issues").
|
26
|
+
to_return(:body => fixture('issues/issues.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should get the resources" do
|
30
|
+
github.issues.issues
|
31
|
+
a_get("/issues").should have_been_made
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return array of resources" do
|
35
|
+
issues = github.issues.issues
|
36
|
+
issues.should be_an Array
|
37
|
+
issues.should have(1).items
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be a mash type" do
|
41
|
+
issues = github.issues.issues
|
42
|
+
issues.first.should be_a Hashie::Mash
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should get issue information" do
|
46
|
+
issues = github.issues.issues
|
47
|
+
issues.first.title.should == 'Found a bug'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should yield to a block" do
|
51
|
+
github.issues.should_receive(:issues).and_yield('web')
|
52
|
+
github.issues.issues { |param| 'web' }.should == 'web'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "resource not found" do
|
57
|
+
before do
|
58
|
+
stub_get("/issues").
|
59
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return 404 with a message 'Not Found'" do
|
63
|
+
expect { github.issues.issues }.to raise_error(Github::ResourceNotFound)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end # issues
|
67
|
+
|
68
|
+
describe 'repo_issues' do
|
69
|
+
it { github.issues.should respond_to :repo_issues }
|
70
|
+
it { github.issues.should respond_to :list_repo_issues }
|
71
|
+
it { github.issues.should respond_to :list_repository_issues }
|
72
|
+
|
73
|
+
context "resource found" do
|
74
|
+
before do
|
75
|
+
github.user, github.repo = nil, nil
|
76
|
+
stub_get("/repos/#{user}/#{repo}/issues").
|
77
|
+
to_return(:body => fixture('issues/issues.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should raise error if user-name empty" do
|
81
|
+
expect {
|
82
|
+
github.issues.repo_issues nil, repo
|
83
|
+
}.should raise_error(ArgumentError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should get the resources" do
|
87
|
+
github.issues.repo_issues user, repo
|
88
|
+
a_get("/repos/#{user}/#{repo}/issues").should have_been_made
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return array of resources" do
|
92
|
+
repo_issues = github.issues.repo_issues user, repo
|
93
|
+
repo_issues.should be_an Array
|
94
|
+
repo_issues.should have(1).items
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should be a mash type" do
|
98
|
+
repo_issues = github.issues.repo_issues user, repo
|
99
|
+
repo_issues.first.should be_a Hashie::Mash
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should get repository issue information" do
|
103
|
+
repo_issues = github.issues.repo_issues user, repo
|
104
|
+
repo_issues.first.title.should == 'Found a bug'
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should yield to a block" do
|
108
|
+
github.issues.should_receive(:issues).with(user, repo).and_yield('web')
|
109
|
+
github.issues.issues(user, repo) { |param| 'web' }.should == 'web'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "resource not found" do
|
114
|
+
before do
|
115
|
+
stub_get("/repos/#{user}/#{repo}/issues").
|
116
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return 404 with a message 'Not Found'" do
|
120
|
+
expect {
|
121
|
+
github.issues.repo_issues user, repo
|
122
|
+
}.to raise_error(Github::ResourceNotFound)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end # repo_issues
|
126
|
+
|
127
|
+
describe "get_issue" do
|
128
|
+
let(:issue_id) { 1347 }
|
129
|
+
|
130
|
+
it { github.issues.should respond_to :issue }
|
131
|
+
it { github.issues.should respond_to :get_issue }
|
132
|
+
|
133
|
+
context "resource found" do
|
134
|
+
before do
|
135
|
+
stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}").
|
136
|
+
to_return(:body => fixture('issues/issue.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should fail to get resource without issue id" do
|
140
|
+
expect { github.issues.issue(user, repo, nil)}.to raise_error(ArgumentError)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should get the resource" do
|
144
|
+
github.issues.issue user, repo, issue_id
|
145
|
+
a_get("/repos/#{user}/#{repo}/issues/#{issue_id}").should have_been_made
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should get issue information" do
|
149
|
+
issue = github.issues.issue user, repo, issue_id
|
150
|
+
issue.number.should == issue_id
|
151
|
+
issue.title.should == 'Found a bug'
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should return mash" do
|
155
|
+
issue = github.issues.issue user, repo, issue_id
|
156
|
+
issue.should be_a Hashie::Mash
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "resource not found" do
|
161
|
+
before do
|
162
|
+
stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}").
|
163
|
+
to_return(:body => fixture('issues/issue.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should fail to retrive resource" do
|
167
|
+
expect {
|
168
|
+
github.issues.issue user, repo, issue_id
|
169
|
+
}.to raise_error(Github::ResourceNotFound)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end # get_issue
|
173
|
+
|
174
|
+
describe "create_issue" do
|
175
|
+
let(:inputs) {
|
176
|
+
{
|
177
|
+
"title" => "Found a bug",
|
178
|
+
"body" => "I'm having a problem with this.",
|
179
|
+
"assignee" => "octocat",
|
180
|
+
"milestone" => 1,
|
181
|
+
"labels" => [
|
182
|
+
"Label1",
|
183
|
+
"Label2"
|
184
|
+
]
|
185
|
+
}
|
186
|
+
}
|
187
|
+
context "resouce created" do
|
188
|
+
before do
|
189
|
+
stub_post("/repos/#{user}/#{repo}/issues").with(inputs).
|
190
|
+
to_return(:body => fixture('issues/issue.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should fail to create resource if 'title' input is missing" do
|
194
|
+
expect {
|
195
|
+
github.issues.create_issue user, repo, inputs.except('title')
|
196
|
+
}.to raise_error(ArgumentError)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should create resource successfully" do
|
200
|
+
github.issues.create_issue user, repo, inputs
|
201
|
+
a_post("/repos/#{user}/#{repo}/issues").with(inputs).should have_been_made
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should return the resource" do
|
205
|
+
issue = github.issues.create_issue user, repo, inputs
|
206
|
+
issue.should be_a Hashie::Mash
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should get the issue information" do
|
210
|
+
issue = github.issues.create_issue(user, repo, inputs)
|
211
|
+
issue.title.should == 'Found a bug'
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context "failed to create resource" do
|
216
|
+
before do
|
217
|
+
stub_post("/repos/#{user}/#{repo}/issues").with(inputs).
|
218
|
+
to_return(:body => fixture('issues/issue.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should faile to retrieve resource" do
|
222
|
+
expect {
|
223
|
+
github.issues.create_issue user, repo, inputs
|
224
|
+
}.to raise_error(Github::ResourceNotFound)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end # create_issue
|
228
|
+
|
229
|
+
describe "edit_issue" do
|
230
|
+
let(:issue_id) { 1349 }
|
231
|
+
let(:inputs) {
|
232
|
+
{
|
233
|
+
"title" => "Found a bug",
|
234
|
+
"body" => "I'm having a problem with this.",
|
235
|
+
"assignee" => "octocat",
|
236
|
+
"milestone" => 1,
|
237
|
+
"labels" => [
|
238
|
+
"Label1",
|
239
|
+
"Label2"
|
240
|
+
]
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
context "resource edited successfully" do
|
245
|
+
before do
|
246
|
+
stub_patch("/repos/#{user}/#{repo}/issues/#{issue_id}").with(inputs).
|
247
|
+
to_return(:body => fixture("issues/issue.json"), :status => 200, :headers => { :content_type => "application/json; charset=utf-8"})
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should fail to edit without 'user/repo' parameters" do
|
251
|
+
github.user, github.repo = nil, nil
|
252
|
+
expect {
|
253
|
+
github.issues.edit_issue nil, repo, issue_id
|
254
|
+
}.to raise_error(ArgumentError)
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should edit the resource" do
|
258
|
+
github.issues.edit_issue user, repo, issue_id, inputs
|
259
|
+
a_patch("/repos/#{user}/#{repo}/issues/#{issue_id}").with(inputs).should have_been_made
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should return resource" do
|
263
|
+
issue = github.issues.edit_issue user, repo, issue_id, inputs
|
264
|
+
issue.should be_a Hashie::Mash
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should be able to retrieve information" do
|
268
|
+
issue = github.issues.edit_issue user, repo, issue_id, inputs
|
269
|
+
issue.title.should == 'Found a bug'
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
context "failed to edit resource" do
|
274
|
+
before do
|
275
|
+
stub_patch("/repos/#{user}/#{repo}/issues/#{issue_id}").with(inputs).
|
276
|
+
to_return(:body => fixture("issues/issue.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should fail to find resource" do
|
280
|
+
expect {
|
281
|
+
github.issues.edit_issue user, repo, issue_id, inputs
|
282
|
+
}.to raise_error(Github::ResourceNotFound)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end # edit_issue
|
286
|
+
|
287
|
+
end # Github::Issues
|