github_api 0.1.1 → 0.1.2

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,11 @@
1
+ [
2
+ {
3
+ "name": "v0.1",
4
+ "commit": {
5
+ "sha": "c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc",
6
+ "url": "https://api.github.com/octocat/Hello-World/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc"
7
+ },
8
+ "zipball_url": "https://github.com/octocat/Hello-World/zipball/v0.1",
9
+ "tarball_url": "https://github.com/octocat/Hello-World/tarball/v0.1"
10
+ }
11
+ ]
@@ -0,0 +1,7 @@
1
+ [
2
+ {
3
+ "url": "https://api.github.com/teams/1",
4
+ "name": "Owners",
5
+ "id": 1
6
+ }
7
+ ]
@@ -1,6 +1,50 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Github::Client do
4
-
5
- it "should have some tests"
4
+
5
+ let(:github) { Github.new }
6
+
7
+ it "should return Github::Gists instance" do
8
+ github.gists.should be_a Github::Gists
9
+ end
10
+
11
+ it "should return Github::GitData instance" do
12
+ github.git_data.should be_a Github::GitData
13
+ end
14
+
15
+ it "should return Github::Issues instance" do
16
+ github.issues.should be_a Github::Issues
17
+ end
18
+
19
+ it "should return Github::Orgs instance" do
20
+ github.orgs.should be_a Github::Orgs
21
+ end
22
+
23
+ it "should return Github::PullRequests instance" do
24
+ github.pull_requests.should be_a Github::PullRequests
25
+ end
26
+
27
+ it "should return Github::Repos instance" do
28
+ github.repos.should be_a Github::Repos
29
+ end
30
+
31
+ it "should return Github::Users instance" do
32
+ github.users.should be_a Github::Users
33
+ end
34
+
35
+ it "should respond to repos" do
36
+ github.should respond_to :repos
37
+ end
38
+
39
+ it "should respond to repositories" do
40
+ github.should respond_to :repositories
41
+ end
42
+
43
+ it "should respond to git_data" do
44
+ github.should respond_to :git_data
45
+ end
46
+
47
+ it "should respond to git" do
48
+ github.should respond_to :git
49
+ end
6
50
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hash do
4
+
5
+ before do
6
+ Github.new
7
+ @nested_hash = { 'a' => { 'b' => {'c' => 1 } } }
8
+ @symbols = { :a => { :b => { :c => 1 } } }
9
+ end
10
+
11
+ it "should respond to except" do
12
+ @nested_hash.should respond_to :except
13
+ end
14
+
15
+ it "should respond to except!" do
16
+ @nested_hash.should respond_to :except!
17
+ end
18
+
19
+ it "should respond to symbolize_keys!" do
20
+ @nested_hash.should respond_to :symbolize_keys!
21
+ end
22
+
23
+ it "should respond to symbolize_keys" do
24
+ @nested_hash.should respond_to :symbolize_keys
25
+ end
26
+
27
+ it "should remove key from the hash" do
28
+ @nested_hash.except('a').should be_empty
29
+ end
30
+
31
+ it "should convert nested keys to symbols" do
32
+ @nested_hash.symbolize_keys!.should == @symbols
33
+ end
34
+ end
@@ -1,5 +1,307 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Github::Repos::Hooks do
4
- pending
5
- end
4
+
5
+ let(:github) { Github.new }
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+
9
+ describe "hooks" do
10
+ context "resource found" do
11
+ before do
12
+ stub_get("/repos/#{user}/#{repo}/hooks").
13
+ to_return(:body => fixture('repos/hooks.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "should fail to get resource without username" do
17
+ github.user, github.repo = nil, nil
18
+ expect { github.repos.hooks }.to raise_error(ArgumentError)
19
+ end
20
+
21
+ it "should get the resources" do
22
+ github.repos.hooks(user, repo)
23
+ a_get("/repos/#{user}/#{repo}/hooks").should have_been_made
24
+ end
25
+
26
+ it "should return array of resources" do
27
+ hooks = github.repos.hooks user, repo
28
+ hooks.should be_an Array
29
+ hooks.should have(1).items
30
+ end
31
+
32
+ it "should be a mash type" do
33
+ hooks = github.repos.hooks user, repo
34
+ hooks.first.should be_a Hashie::Mash
35
+ end
36
+
37
+ it "should get hook information" do
38
+ hooks = github.repos.hooks(user, repo)
39
+ hooks.first.name.should == 'web'
40
+ end
41
+
42
+ it "should yield to a block" do
43
+ github.repos.should_receive(:hooks).with(user, repo).and_yield('web')
44
+ github.repos.hooks(user, repo) { |param| 'web' }
45
+ end
46
+ end
47
+
48
+ context "resource not found" do
49
+ before do
50
+ stub_get("/repos/#{user}/#{repo}/hooks").
51
+ to_return(:body => "", :status => [404, "Not Found"])
52
+ end
53
+
54
+ it "should return 404 with a message 'Not Found'" do
55
+ expect {
56
+ github.repos.hooks user, repo
57
+ }.to raise_error(Github::ResourceNotFound)
58
+ end
59
+ end
60
+ end # hooks
61
+
62
+ describe "hook" do
63
+ let(:hook_id) { 1 }
64
+
65
+ context "resource found" do
66
+ before do
67
+ stub_get("/repos/#{user}/#{repo}/hooks/#{hook_id}").
68
+ to_return(:body => fixture('repos/hook.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
69
+ end
70
+
71
+ it "should fail to get resource without hook id" do
72
+ expect { github.repos.hook(user, repo, nil)}.to raise_error(ArgumentError)
73
+ end
74
+
75
+ it "should get the resource" do
76
+ github.repos.hook user, repo, hook_id
77
+ a_get("/repos/#{user}/#{repo}/hooks/#{hook_id}").should have_been_made
78
+ end
79
+
80
+ it "should get hook information" do
81
+ hook = github.repos.hook user, repo, hook_id
82
+ hook.id.should == hook_id
83
+ hook.name.should == 'web'
84
+ end
85
+
86
+ it "should return mash" do
87
+ hook = github.repos.hook user, repo, hook_id
88
+ hook.should be_a Hashie::Mash
89
+ end
90
+
91
+ end
92
+
93
+ context "resource not found" do
94
+ before do
95
+ stub_get("/repos/#{user}/#{repo}/hooks/#{hook_id}").
96
+ to_return(:body => fixture('repos/hook.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
97
+ end
98
+
99
+ it "should fail to retrive resource" do
100
+ expect {
101
+ github.repos.hook(user, repo, hook_id)
102
+ }.to raise_error(Github::ResourceNotFound)
103
+ end
104
+ end
105
+ end # hook
106
+
107
+ describe "create_hook" do
108
+ let(:inputs) { {:name => 'web', :config => {:url => "http://something.com/webhook"}, :active => true}}
109
+
110
+ context "resouce created" do
111
+ before do
112
+ stub_post("/repos/#{user}/#{repo}/hooks").with(inputs).
113
+ to_return(:body => fixture('repos/hook.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
114
+
115
+ end
116
+
117
+ it "should fail to create resource if 'name' input is missing" do
118
+ expect {
119
+ github.repos.create_hook(user, repo, inputs.except(:name) )
120
+ }.to raise_error(ArgumentError)
121
+ end
122
+
123
+ it "should failt to create resource if 'config' input is missing" do
124
+ expect {
125
+ github.repos.create_hook(user, repo, inputs.except(:config) )
126
+ }.to raise_error(ArgumentError)
127
+ end
128
+
129
+ it "should create resource successfully" do
130
+ github.repos.create_hook(user, repo, inputs)
131
+ a_post("/repos/#{user}/#{repo}/hooks").with(inputs).should have_been_made
132
+ end
133
+
134
+ it "should return the resource" do
135
+ hook = github.repos.create_hook user, repo, inputs
136
+ hook.should be_a Hashie::Mash
137
+ end
138
+
139
+ it "should get the hook information" do
140
+ hook = github.repos.create_hook(user, repo, inputs)
141
+ hook.name.should == 'web'
142
+ end
143
+ end
144
+
145
+ context "failed to create resource" do
146
+ before do
147
+ stub_post("/repos/#{user}/#{repo}/hooks").with(inputs).
148
+ to_return(:body => fixture('repos/hook.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
149
+
150
+ end
151
+
152
+ it "should faile to retrieve resource" do
153
+ expect {
154
+ github.repos.create_hook(user, repo, inputs)
155
+ }.to raise_error(Github::ResourceNotFound)
156
+ end
157
+ end
158
+ end # create_hook
159
+
160
+ describe "edit_hook" do
161
+ let(:hook_id) { 1 }
162
+ let(:inputs) { {:name => 'web', :config => {:url => "http://something.com/webhook"}, :active => true}}
163
+
164
+ context "resource edited successfully" do
165
+ before do
166
+ stub_patch("/repos/#{user}/#{repo}/hooks/#{hook_id}").with(inputs).
167
+ to_return(:body => fixture("repos/hook.json"), :status => 200, :headers => { :content_type => "application/json; charset=utf-8"})
168
+ end
169
+
170
+ it "should fail to edit without 'user/repo' parameters" do
171
+ github.user, github.repo = nil, nil
172
+ expect { github.repos.edit_hook }.to raise_error(ArgumentError)
173
+ end
174
+
175
+ it "should fail to edit resource without 'name' parameter" do
176
+ expect{
177
+ github.repos.edit_hook user, repo, inputs.except(:name)
178
+ }.to raise_error(ArgumentError)
179
+ end
180
+
181
+ it "should fail to edit resource without 'hook_id'" do
182
+ expect {
183
+ github.repos.edit_hook user, repo
184
+ }.to raise_error(ArgumentError)
185
+ end
186
+
187
+ it "should fail to edit resource without 'config' parameter" do
188
+ expect {
189
+ github.repos.edit_hook user, repo, hook_id, inputs.except(:config)
190
+ }.to raise_error(ArgumentError)
191
+ end
192
+
193
+ it "should edit the resource" do
194
+ github.repos.edit_hook user, repo, hook_id, inputs
195
+ a_patch("/repos/#{user}/#{repo}/hooks/#{hook_id}").with(inputs).should have_been_made
196
+ end
197
+
198
+ it "should return resource" do
199
+ hook = github.repos.edit_hook user, repo, hook_id, inputs
200
+ hook.should be_a Hashie::Mash
201
+ end
202
+
203
+ it "should be able to retrieve information" do
204
+ hook = github.repos.edit_hook user, repo, hook_id, inputs
205
+ hook.name.should == 'web'
206
+ end
207
+
208
+ end
209
+
210
+ context "failed to edit resource" do
211
+ before do
212
+ stub_patch("/repos/#{user}/#{repo}/hooks/#{hook_id}").with(inputs).
213
+ to_return(:body => fixture("repos/hook.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
214
+
215
+ end
216
+
217
+ it "should fail to find resource" do
218
+ expect {
219
+ github.repos.edit_hook user, repo, hook_id, inputs
220
+ }.to raise_error(Github::ResourceNotFound)
221
+ end
222
+ end
223
+ end # edit_hook
224
+
225
+ describe "delete_key" do
226
+ let(:hook_id) { 1 }
227
+
228
+ context "resource edited successfully" do
229
+ before do
230
+ stub_delete("/repos/#{user}/#{repo}/hooks/#{hook_id}").
231
+ to_return(:body => '', :status => 204, :headers => { :content_type => "application/json; charset=utf-8"})
232
+ end
233
+
234
+ it "should fail to delete without 'user/repo' parameters" do
235
+ github.user, github.repo = nil, nil
236
+ expect { github.repos.delete_hook }.to raise_error(ArgumentError)
237
+ end
238
+
239
+ it "should fail to delete resource without 'hook_id'" do
240
+ expect {
241
+ github.repos.edit_hook user, repo
242
+ }.to raise_error(ArgumentError)
243
+ end
244
+
245
+ it "should delete the resource" do
246
+ github.repos.delete_hook user, repo, hook_id
247
+ a_delete("/repos/#{user}/#{repo}/hooks/#{hook_id}").should have_been_made
248
+ end
249
+ end
250
+
251
+ context "failed to edit resource" do
252
+ before do
253
+ stub_delete("/repos/#{user}/#{repo}/hooks/#{hook_id}").
254
+ to_return(:body => fixture("repos/hook.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
255
+
256
+ end
257
+
258
+ it "should fail to find resource" do
259
+ expect {
260
+ github.repos.delete_hook user, repo, hook_id
261
+ }.to raise_error(Github::ResourceNotFound)
262
+ end
263
+ end
264
+ end # delete_hook
265
+
266
+ describe "test_hook" do
267
+ let(:hook_id) { 1 }
268
+
269
+ context "resource edited successfully" do
270
+ before do
271
+ stub_post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test").
272
+ to_return(:body => '', :status => 204, :headers => { :content_type => "application/json; charset=utf-8"})
273
+ end
274
+
275
+ it "should fail to test without 'user/repo' parameters" do
276
+ github.user, github.repo = nil, nil
277
+ expect { github.repos.test_hook }.to raise_error(ArgumentError)
278
+ end
279
+
280
+ it "should fail to test resource without 'hook_id'" do
281
+ expect {
282
+ github.repos.test_hook user, repo
283
+ }.to raise_error(ArgumentError)
284
+ end
285
+
286
+ it "should trigger test for the resource" do
287
+ github.repos.test_hook user, repo, hook_id
288
+ a_post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test").should have_been_made
289
+ end
290
+ end
291
+
292
+ context "failed to test resource" do
293
+ before do
294
+ stub_post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test").
295
+ to_return(:body => '', :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
296
+
297
+ end
298
+
299
+ it "should fail to find resource" do
300
+ expect {
301
+ github.repos.test_hook user, repo, hook_id
302
+ }.to raise_error(Github::ResourceNotFound)
303
+ end
304
+ end
305
+ end # test_hook
306
+
307
+ end # Github::Repos::Hooks
@@ -96,7 +96,7 @@ describe Github::Repos::Keys do
96
96
 
97
97
  context "resource created" do
98
98
  before do
99
- stub_post("/repos/#{user}/#{repo}/keys").
99
+ stub_post("/repos/#{user}/#{repo}/keys").with(inputs).
100
100
  to_return(:body => fixture("repos/key.json"), :status => 201)
101
101
  end
102
102
 
@@ -114,7 +114,7 @@ describe Github::Repos::Keys do
114
114
 
115
115
  it "should create the resource" do
116
116
  github.repos.create_key(user, repo, inputs)
117
- a_post("/repos/#{user}/#{repo}/keys").should have_been_made
117
+ a_post("/repos/#{user}/#{repo}/keys").with(inputs).should have_been_made
118
118
  end
119
119
 
120
120
  it "should get the key information back" do
@@ -180,7 +180,18 @@ describe Github::Repos::Keys do
180
180
  context "resource found successfully" do
181
181
  before do
182
182
  stub_delete("/repos/#{user}/#{repo}/keys/#{key_id}").
183
- to_return(:body => "", :status => 204)
183
+ to_return(:body => "", :status => 204, :headers => { :content_type => "application/json; charset=utf-8"} )
184
+ end
185
+
186
+ it "should fail to delete without 'user/repo' parameters" do
187
+ github.user, github.repo = nil, nil
188
+ expect { github.repos.delete_key }.to raise_error(ArgumentError)
189
+ end
190
+
191
+ it "should fail to delete resource without key id" do
192
+ expect {
193
+ github.repos.delete_key user, repo, nil
194
+ }.to raise_error(ArgumentError)
184
195
  end
185
196
 
186
197
  it "should delete the resource" do