github_api 0.3.5 → 0.3.6

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.
Files changed (147) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.rdoc +228 -0
  3. data/Rakefile +52 -0
  4. data/features/github_api.feature +50 -0
  5. data/features/options.feature +4 -0
  6. data/features/pagination.feature +4 -0
  7. data/features/step_definitions/github_api_steps.rb +11 -0
  8. data/features/support/env.rb +13 -0
  9. data/lib/github_api.rb +73 -0
  10. data/lib/github_api/api.rb +175 -0
  11. data/lib/github_api/api/utils.rb +9 -0
  12. data/lib/github_api/authorization.rb +73 -0
  13. data/lib/github_api/authorizations.rb +119 -0
  14. data/lib/github_api/cache_control.rb +19 -0
  15. data/lib/github_api/client.rb +55 -0
  16. data/lib/github_api/compatibility.rb +23 -0
  17. data/lib/github_api/configuration.rb +96 -0
  18. data/lib/github_api/connection.rb +75 -0
  19. data/lib/github_api/core_ext/array.rb +14 -0
  20. data/lib/github_api/core_ext/hash.rb +42 -0
  21. data/lib/github_api/error.rb +35 -0
  22. data/lib/github_api/events.rb +202 -0
  23. data/lib/github_api/gists.rb +200 -0
  24. data/lib/github_api/gists/comments.rb +86 -0
  25. data/lib/github_api/git_data.rb +26 -0
  26. data/lib/github_api/git_data/blobs.rb +51 -0
  27. data/lib/github_api/git_data/commits.rb +78 -0
  28. data/lib/github_api/git_data/references.rb +113 -0
  29. data/lib/github_api/git_data/tags.rb +78 -0
  30. data/lib/github_api/git_data/trees.rb +89 -0
  31. data/lib/github_api/issues.rb +215 -0
  32. data/lib/github_api/issues/comments.rb +123 -0
  33. data/lib/github_api/issues/events.rb +54 -0
  34. data/lib/github_api/issues/labels.rb +191 -0
  35. data/lib/github_api/issues/milestones.rb +140 -0
  36. data/lib/github_api/mime_type.rb +55 -0
  37. data/lib/github_api/orgs.rb +95 -0
  38. data/lib/github_api/orgs/members.rb +120 -0
  39. data/lib/github_api/orgs/teams.rb +245 -0
  40. data/lib/github_api/pull_requests.rb +224 -0
  41. data/lib/github_api/pull_requests/comments.rb +144 -0
  42. data/lib/github_api/repos.rb +286 -0
  43. data/lib/github_api/repos/collaborators.rb +81 -0
  44. data/lib/github_api/repos/commits.rb +180 -0
  45. data/lib/github_api/repos/downloads.rb +155 -0
  46. data/lib/github_api/repos/forks.rb +48 -0
  47. data/lib/github_api/repos/hooks.rb +174 -0
  48. data/lib/github_api/repos/keys.rb +104 -0
  49. data/lib/github_api/repos/pub_sub_hubbub.rb +102 -0
  50. data/lib/github_api/repos/watching.rb +94 -0
  51. data/lib/github_api/request.rb +84 -0
  52. data/lib/github_api/request/basic_auth.rb +31 -0
  53. data/lib/github_api/request/caching.rb +33 -0
  54. data/lib/github_api/request/oauth2.rb +33 -0
  55. data/lib/github_api/response.rb +28 -0
  56. data/lib/github_api/response/helpers.rb +14 -0
  57. data/lib/github_api/response/jsonize.rb +26 -0
  58. data/lib/github_api/response/mashify.rb +24 -0
  59. data/lib/github_api/response/raise_error.rb +33 -0
  60. data/lib/github_api/result.rb +42 -0
  61. data/lib/github_api/users.rb +84 -0
  62. data/lib/github_api/users/emails.rb +49 -0
  63. data/lib/github_api/users/followers.rb +98 -0
  64. data/lib/github_api/users/keys.rb +84 -0
  65. data/lib/github_api/version.rb +12 -0
  66. data/spec/README.rdoc +22 -0
  67. data/spec/coverage_adapter.rb +15 -0
  68. data/spec/fixtures/auths/authorization.json +14 -0
  69. data/spec/fixtures/auths/authorizations.json +16 -0
  70. data/spec/fixtures/events/events.json +29 -0
  71. data/spec/fixtures/issues/comment.json +13 -0
  72. data/spec/fixtures/issues/comments.json +15 -0
  73. data/spec/fixtures/issues/event.json +13 -0
  74. data/spec/fixtures/issues/events.json +15 -0
  75. data/spec/fixtures/issues/issue.json +56 -0
  76. data/spec/fixtures/issues/issues.json +58 -0
  77. data/spec/fixtures/issues/milestone.json +18 -0
  78. data/spec/fixtures/issues/milestones.json +20 -0
  79. data/spec/fixtures/orgs/members.json +9 -0
  80. data/spec/fixtures/orgs/org.json +18 -0
  81. data/spec/fixtures/orgs/orgs.json +8 -0
  82. data/spec/fixtures/orgs/team.json +8 -0
  83. data/spec/fixtures/orgs/team_repos.json +29 -0
  84. data/spec/fixtures/orgs/teams.json +7 -0
  85. data/spec/fixtures/repos/branches.json +9 -0
  86. data/spec/fixtures/repos/collaborators.json +8 -0
  87. data/spec/fixtures/repos/commit.json +53 -0
  88. data/spec/fixtures/repos/commit_comment.json +16 -0
  89. data/spec/fixtures/repos/commit_comments.json +18 -0
  90. data/spec/fixtures/repos/commits.json +27 -0
  91. data/spec/fixtures/repos/contributors.json +8 -0
  92. data/spec/fixtures/repos/download.json +10 -0
  93. data/spec/fixtures/repos/download_s3.json +21 -0
  94. data/spec/fixtures/repos/downloads.json +12 -0
  95. data/spec/fixtures/repos/fork.json +27 -0
  96. data/spec/fixtures/repos/forks.json +29 -0
  97. data/spec/fixtures/repos/hook.json +15 -0
  98. data/spec/fixtures/repos/hooks.json +10 -0
  99. data/spec/fixtures/repos/key.json +6 -0
  100. data/spec/fixtures/repos/keys.json +8 -0
  101. data/spec/fixtures/repos/languages.json +4 -0
  102. data/spec/fixtures/repos/repo.json +90 -0
  103. data/spec/fixtures/repos/repo_comments.json +18 -0
  104. data/spec/fixtures/repos/repos.json +29 -0
  105. data/spec/fixtures/repos/tags.json +11 -0
  106. data/spec/fixtures/repos/teams.json +7 -0
  107. data/spec/fixtures/repos/watched.json +29 -0
  108. data/spec/fixtures/repos/watchers.json +8 -0
  109. data/spec/fixtures/users/user.json +32 -0
  110. data/spec/github/api_spec.rb +25 -0
  111. data/spec/github/authorization_spec.rb +176 -0
  112. data/spec/github/authorizations_spec.rb +242 -0
  113. data/spec/github/client_spec.rb +50 -0
  114. data/spec/github/core_ext/hash_spec.rb +44 -0
  115. data/spec/github/events_spec.rb +491 -0
  116. data/spec/github/gists/comments_spec.rb +5 -0
  117. data/spec/github/gists_spec.rb +5 -0
  118. data/spec/github/git_data/blobs_spec.rb +5 -0
  119. data/spec/github/git_data/commits_spec.rb +5 -0
  120. data/spec/github/git_data/references_spec.rb +5 -0
  121. data/spec/github/git_data/tags_spec.rb +5 -0
  122. data/spec/github/git_data/trees_spec.rb +5 -0
  123. data/spec/github/git_data_spec.rb +5 -0
  124. data/spec/github/issues/comments_spec.rb +254 -0
  125. data/spec/github/issues/events_spec.rb +153 -0
  126. data/spec/github/issues/labels_spec.rb +5 -0
  127. data/spec/github/issues/milestones_spec.rb +260 -0
  128. data/spec/github/issues_spec.rb +287 -0
  129. data/spec/github/mime_type_spec.rb +70 -0
  130. data/spec/github/orgs/members_spec.rb +275 -0
  131. data/spec/github/orgs/teams_spec.rb +563 -0
  132. data/spec/github/orgs_spec.rb +160 -0
  133. data/spec/github/repos/collaborators_spec.rb +169 -0
  134. data/spec/github/repos/commits_spec.rb +424 -0
  135. data/spec/github/repos/downloads_spec.rb +247 -0
  136. data/spec/github/repos/forks_spec.rb +108 -0
  137. data/spec/github/repos/hooks_spec.rb +333 -0
  138. data/spec/github/repos/keys_spec.rb +217 -0
  139. data/spec/github/repos/pub_sub_hubbub_spec.rb +83 -0
  140. data/spec/github/repos/watching_spec.rb +222 -0
  141. data/spec/github/repos_spec.rb +571 -0
  142. data/spec/github/result_spec.rb +43 -0
  143. data/spec/github/users_spec.rb +140 -0
  144. data/spec/github_spec.rb +109 -0
  145. data/spec/spec_helper.rb +86 -0
  146. data/spec/support/base.rb +13 -0
  147. metadata +149 -4
@@ -0,0 +1,247 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Repos::Downloads do
4
+
5
+ let(:github) { Github.new }
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+
9
+ it { described_class::VALID_DOWNLOAD_PARAM_NAMES.should_not be_nil }
10
+ it { described_class::REQUIRED_PARAMS.should_not be_nil }
11
+ it { described_class::REQUIRED_S3_PARAMS.should_not be_nil }
12
+
13
+ describe "downloads" do
14
+ it { github.repos.should respond_to :downloads }
15
+ it { github.repos.should respond_to :list_downloads }
16
+ it { github.repos.should respond_to :get_downloads }
17
+
18
+ context "resource found" do
19
+ before do
20
+ stub_get("/repos/#{user}/#{repo}/downloads").
21
+ to_return(:body => fixture('repos/downloads.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
22
+ end
23
+
24
+ it "should fail to get resource without username" do
25
+ github.user, github.repo = nil, nil
26
+ expect { github.repos.downloads }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it "should get the resources" do
30
+ github.repos.downloads user, repo
31
+ a_get("/repos/#{user}/#{repo}/downloads").should have_been_made
32
+ end
33
+
34
+ it "should return array of resources" do
35
+ downloads = github.repos.downloads user, repo
36
+ downloads.should be_an Array
37
+ downloads.should have(1).items
38
+ end
39
+
40
+ it "should be a mash type" do
41
+ downloads = github.repos.downloads user, repo
42
+ downloads.first.should be_a Hashie::Mash
43
+ end
44
+
45
+ it "should get download information" do
46
+ downloads = github.repos.downloads user, repo
47
+ downloads.first.name.should == 'new_file.jpg'
48
+ end
49
+
50
+ it "should yield to a block" do
51
+ github.repos.should_receive(:downloads).with(user, repo).and_yield('web')
52
+ github.repos.downloads(user, repo) { |param| 'web' }
53
+ end
54
+ end
55
+
56
+ context "resource not found" do
57
+ before do
58
+ stub_get("/repos/#{user}/#{repo}/downloads").
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.repos.downloads user, repo
65
+ }.to raise_error(Github::ResourceNotFound)
66
+ end
67
+ end
68
+ end # downloads
69
+
70
+ describe "download" do
71
+ let(:download_id) { 1 }
72
+
73
+ it { github.repos.should respond_to :download }
74
+ it { github.repos.should respond_to :get_download }
75
+
76
+ context "resource found" do
77
+ before do
78
+ stub_get("/repos/#{user}/#{repo}/downloads/#{download_id}").
79
+ to_return(:body => fixture('repos/download.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
80
+ end
81
+
82
+ it "should fail to get resource without download id" do
83
+ expect { github.repos.download(user, repo, nil)}.to raise_error(ArgumentError)
84
+ end
85
+
86
+ it "should get the resource" do
87
+ github.repos.download user, repo, download_id
88
+ a_get("/repos/#{user}/#{repo}/downloads/#{download_id}").should have_been_made
89
+ end
90
+
91
+ it "should get download information" do
92
+ download = github.repos.download user, repo, download_id
93
+ download.id.should == download_id
94
+ download.name.should == 'new_file.jpg'
95
+ end
96
+
97
+ it "should return mash" do
98
+ download = github.repos.download user, repo, download_id
99
+ download.should be_a Hashie::Mash
100
+ end
101
+ end
102
+
103
+ context "resource not found" do
104
+ before do
105
+ stub_get("/repos/#{user}/#{repo}/downloads/#{download_id}").
106
+ to_return(:body => fixture('repos/download.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
107
+ end
108
+
109
+ it "should fail to retrive resource" do
110
+ expect {
111
+ github.repos.download user, repo, download_id
112
+ }.to raise_error(Github::ResourceNotFound)
113
+ end
114
+ end
115
+ end # download
116
+
117
+ describe "delete_download" do
118
+ let(:download_id) { 1 }
119
+
120
+ context "resource edited successfully" do
121
+ before do
122
+ stub_delete("/repos/#{user}/#{repo}/downloads/#{download_id}").
123
+ to_return(:body => '', :status => 204, :headers => { :content_type => "application/json; charset=utf-8"})
124
+ end
125
+
126
+ it "should fail to delete without 'user/repo' parameters" do
127
+ github.user, github.repo = nil, nil
128
+ expect { github.repos.delete_download }.to raise_error(ArgumentError)
129
+ end
130
+
131
+ it "should fail to delete resource without 'download_id'" do
132
+ expect {
133
+ github.repos.delete_download user, repo
134
+ }.to raise_error(ArgumentError)
135
+ end
136
+
137
+ it "should delete the resource" do
138
+ github.repos.delete_download user, repo, download_id
139
+ a_delete("/repos/#{user}/#{repo}/downloads/#{download_id}").should have_been_made
140
+ end
141
+ end
142
+
143
+ context "failed to edit resource" do
144
+ before do
145
+ stub_delete("/repos/#{user}/#{repo}/downloads/#{download_id}").
146
+ to_return(:body => fixture("repos/download.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
147
+
148
+ end
149
+
150
+ it "should fail to find resource" do
151
+ expect {
152
+ github.repos.delete_download user, repo, download_id
153
+ }.to raise_error(Github::ResourceNotFound)
154
+ end
155
+ end
156
+ end # delete_download
157
+
158
+ describe "create_download" do
159
+ let(:inputs) { {:name => 'new_file.jpg', :size => 114034, :description => "Latest release", :content_type => 'text/plain'} }
160
+
161
+ context "resouce created" do
162
+ before do
163
+ stub_post("/repos/#{user}/#{repo}/downloads").with(inputs).
164
+ to_return(:body => fixture('repos/download_s3.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
165
+
166
+ end
167
+
168
+ it "should fail to create resource if 'name' input is missing" do
169
+ expect {
170
+ github.repos.create_download user, repo, inputs.except(:name)
171
+ }.to raise_error(ArgumentError)
172
+ end
173
+
174
+ it "should failt to create resource if 'size' input is missing" do
175
+ expect {
176
+ github.repos.create_download user, repo, inputs.except(:size)
177
+ }.to raise_error(ArgumentError)
178
+ end
179
+
180
+ it "should create resource successfully" do
181
+ github.repos.create_download user, repo, inputs
182
+ a_post("/repos/#{user}/#{repo}/downloads").with(inputs).should have_been_made
183
+ end
184
+
185
+ it "should return the resource" do
186
+ download = github.repos.create_download user, repo, inputs
187
+ download.should be_a Hashie::Mash
188
+ end
189
+
190
+ it "should get the download information" do
191
+ download = github.repos.create_download user, repo, inputs
192
+ download.name.should == 'new_file.jpg'
193
+ end
194
+ end
195
+
196
+ context "failed to create resource" do
197
+ before do
198
+ stub_post("/repos/#{user}/#{repo}/downloads").with(inputs).
199
+ to_return(:body => fixture('repos/download_s3.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
200
+
201
+ end
202
+
203
+ it "should faile to retrieve resource" do
204
+ expect {
205
+ github.repos.create_download(user, repo, inputs)
206
+ }.to raise_error(Github::ResourceNotFound)
207
+ end
208
+ end
209
+ end # create_download
210
+
211
+ describe 'upload' do
212
+ let(:inputs) { {:name => 'new_file.jpg', :size => 114034, :description => "Latest release", :content_type => 'text/plain'} }
213
+ let(:resource) { Hashie::Mash.new ::JSON.parse(fixture('repos/download_s3.json').read) }
214
+ let(:file) { 'filename' }
215
+
216
+ context 'resource uploaded' do
217
+ before do
218
+ stub_post('', 'https://github.s3.amazonaws.com/').with(resource).
219
+ to_return(:body => '', :status => 200, :headers => {})
220
+ end
221
+
222
+ it "should fail if resource is of incorrect type" do
223
+ expect { github.repos.upload file, file }.to raise_error(ArgumentError)
224
+ end
225
+
226
+ it "should upload resource successfully" do
227
+ github.repos.upload resource, file
228
+ a_post('', 'https://github.s3.amazonaws.com').with(resource).should have_been_made
229
+ end
230
+
231
+ end
232
+ context 'failed to upload resource' do
233
+ before do
234
+ stub_post('', 'https://github.s3.amazonaws.com/').with(resource).
235
+ to_return(:body => '', :status => 404, :headers => {})
236
+ end
237
+
238
+ it "should faile to retrieve resource" do
239
+ expect {
240
+ github.repos.upload resource, file
241
+ }.to raise_error(Github::ResourceNotFound)
242
+ end
243
+
244
+ end
245
+ end # upload
246
+
247
+ end # Github::Repos::Downloads
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Repos::Forks do
4
+
5
+ let(:github) { Github.new }
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+
9
+ describe "forks" do
10
+
11
+ it { github.repos.should respond_to :forks }
12
+ it { github.repos.should respond_to :repo_forks }
13
+ it { github.repos.should respond_to :repository_forks }
14
+
15
+ context "resource found" do
16
+ before do
17
+ stub_get("/repos/#{user}/#{repo}/forks").
18
+ to_return(:body => fixture('repos/forks.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.repos.forks }.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should get the resources" do
27
+ github.repos.forks user, repo
28
+ a_get("/repos/#{user}/#{repo}/forks").should have_been_made
29
+ end
30
+
31
+ it "should return array of resources" do
32
+ forks = github.repos.forks user, repo
33
+ forks.should be_an Array
34
+ forks.should have(1).items
35
+ end
36
+
37
+ it "should be a mash type" do
38
+ forks = github.repos.forks user, repo
39
+ forks.first.should be_a Hashie::Mash
40
+ end
41
+
42
+ it "should get fork information" do
43
+ forks = github.repos.forks user, repo
44
+ forks.first.name.should == 'Hello-World'
45
+ end
46
+
47
+ it "should yield to a block" do
48
+ github.repos.should_receive(:forks).with(user, repo).and_yield('web')
49
+ github.repos.forks(user, repo) { |param| 'web' }
50
+ end
51
+ end
52
+
53
+ context "resource not found" do
54
+ before do
55
+ stub_get("/repos/#{user}/#{repo}/forks").
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.repos.forks user, repo
62
+ }.to raise_error(Github::ResourceNotFound)
63
+ end
64
+ end
65
+ end # forks
66
+
67
+ describe "create_hook" do
68
+ let(:inputs) { {:org => 'github'} }
69
+
70
+ context "resouce created" do
71
+ before do
72
+ stub_post("/repos/#{user}/#{repo}/forks").with(inputs).
73
+ to_return(:body => fixture('repos/fork.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
74
+
75
+ end
76
+
77
+ it "should create resource successfully" do
78
+ github.repos.create_fork(user, repo, inputs)
79
+ a_post("/repos/#{user}/#{repo}/forks").with(inputs).should have_been_made
80
+ end
81
+
82
+ it "should return the resource" do
83
+ fork = github.repos.create_fork user, repo, inputs
84
+ fork.should be_a Hashie::Mash
85
+ end
86
+
87
+ it "should get the fork information" do
88
+ fork = github.repos.create_fork(user, repo, inputs)
89
+ fork.name.should == 'Hello-World'
90
+ end
91
+ end
92
+
93
+ context "failed to create resource" do
94
+ before do
95
+ stub_post("/repos/#{user}/#{repo}/forks").with(inputs).
96
+ to_return(:body => fixture('repos/fork.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
97
+
98
+ end
99
+
100
+ it "should faile to retrieve resource" do
101
+ expect {
102
+ github.repos.create_fork user, repo, inputs
103
+ }.to raise_error(Github::ResourceNotFound)
104
+ end
105
+ end
106
+ end # create_fork
107
+
108
+ end # Github::Repos::Forks
@@ -0,0 +1,333 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Repos::Hooks do
4
+
5
+ let(:hooks_api) { Github::Repos::Hooks }
6
+ let(:github) { Github.new }
7
+ let(:user) { 'peter-murach' }
8
+ let(:repo) { 'github' }
9
+
10
+ it { hooks_api::VALID_HOOK_PARAM_NAMES.should_not be_nil }
11
+ it { hooks_api::VALID_HOOK_PARAM_VALUES.should_not be_nil }
12
+ it { hooks_api::REQUIRED_PARAMS.should_not be_nil }
13
+
14
+ describe "hooks" do
15
+ context 'check aliases' do
16
+ it { github.repos.should respond_to :hooks }
17
+ it { github.repos.should respond_to :repo_hooks }
18
+ it { github.repos.should respond_to :repository_hooks }
19
+ end
20
+
21
+ context "resource found" do
22
+ before do
23
+ stub_get("/repos/#{user}/#{repo}/hooks").
24
+ to_return(:body => fixture('repos/hooks.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
25
+ end
26
+
27
+ it "should fail to get resource without username" do
28
+ github.user, github.repo = nil, nil
29
+ expect { github.repos.hooks }.to raise_error(ArgumentError)
30
+ end
31
+
32
+ it "should get the resources" do
33
+ github.repos.hooks user, repo
34
+ a_get("/repos/#{user}/#{repo}/hooks").should have_been_made
35
+ end
36
+
37
+ it "should return array of resources" do
38
+ hooks = github.repos.hooks user, repo
39
+ hooks.should be_an Array
40
+ hooks.should have(1).items
41
+ end
42
+
43
+ it "should be a mash type" do
44
+ hooks = github.repos.hooks user, repo
45
+ hooks.first.should be_a Hashie::Mash
46
+ end
47
+
48
+ it "should get hook information" do
49
+ hooks = github.repos.hooks user, repo
50
+ hooks.first.name.should == 'web'
51
+ end
52
+
53
+ it "should yield to a block" do
54
+ github.repos.should_receive(:hooks).with(user, repo).and_yield('web')
55
+ github.repos.hooks(user, repo) { |param| 'web' }
56
+ end
57
+ end
58
+
59
+ context "resource not found" do
60
+ before do
61
+ stub_get("/repos/#{user}/#{repo}/hooks").
62
+ to_return(:body => "", :status => [404, "Not Found"])
63
+ end
64
+
65
+ it "should return 404 with a message 'Not Found'" do
66
+ expect {
67
+ github.repos.hooks user, repo
68
+ }.to raise_error(Github::ResourceNotFound)
69
+ end
70
+ end
71
+ end # hooks
72
+
73
+ describe "hook" do
74
+ let(:hook_id) { 1 }
75
+
76
+ context 'check aliases' do
77
+ it { github.repos.should respond_to :hook }
78
+ it { github.repos.should respond_to :get_hook }
79
+ it { github.repos.should respond_to :repo_hook }
80
+ it { github.repos.should respond_to :get_repo_hook }
81
+ it { github.repos.should respond_to :repository_hook }
82
+ end
83
+
84
+ context "resource found" do
85
+ before do
86
+ stub_get("/repos/#{user}/#{repo}/hooks/#{hook_id}").
87
+ to_return(:body => fixture('repos/hook.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
88
+ end
89
+
90
+ it "should fail to get resource without hook id" do
91
+ expect { github.repos.hook(user, repo, nil)}.to raise_error(ArgumentError)
92
+ end
93
+
94
+ it "should get the resource" do
95
+ github.repos.hook user, repo, hook_id
96
+ a_get("/repos/#{user}/#{repo}/hooks/#{hook_id}").should have_been_made
97
+ end
98
+
99
+ it "should get hook information" do
100
+ hook = github.repos.hook user, repo, hook_id
101
+ hook.id.should == hook_id
102
+ hook.name.should == 'web'
103
+ end
104
+
105
+ it "should return mash" do
106
+ hook = github.repos.hook user, repo, hook_id
107
+ hook.should be_a Hashie::Mash
108
+ end
109
+ end
110
+
111
+ context "resource not found" do
112
+ before do
113
+ stub_get("/repos/#{user}/#{repo}/hooks/#{hook_id}").
114
+ to_return(:body => fixture('repos/hook.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
115
+ end
116
+
117
+ it "should fail to retrive resource" do
118
+ expect {
119
+ github.repos.hook user, repo, hook_id
120
+ }.to raise_error(Github::ResourceNotFound)
121
+ end
122
+ end
123
+ end # hook
124
+
125
+ describe "create_hook" do
126
+ let(:inputs) {
127
+ {
128
+ :name => 'web',
129
+ :config => { :url => "http://something.com/webhook" },
130
+ :active => true
131
+ }
132
+ }
133
+
134
+ context "resouce created" do
135
+ before do
136
+ stub_post("/repos/#{user}/#{repo}/hooks").with(inputs).
137
+ to_return(:body => fixture('repos/hook.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
138
+ end
139
+
140
+ it "should fail to create resource if 'name' input is missing" do
141
+ expect {
142
+ github.repos.create_hook user, repo, inputs.except(:name)
143
+ }.to raise_error(ArgumentError)
144
+ end
145
+
146
+ it "should failt to create resource if 'config' input is missing" do
147
+ expect {
148
+ github.repos.create_hook user, repo, inputs.except(:config)
149
+ }.to raise_error(ArgumentError)
150
+ end
151
+
152
+ it "should create resource successfully" do
153
+ github.repos.create_hook user, repo, inputs
154
+ a_post("/repos/#{user}/#{repo}/hooks").with(inputs).should have_been_made
155
+ end
156
+
157
+ it "should return the resource" do
158
+ hook = github.repos.create_hook user, repo, inputs
159
+ hook.should be_a Hashie::Mash
160
+ end
161
+
162
+ it "should get the hook information" do
163
+ hook = github.repos.create_hook(user, repo, inputs)
164
+ hook.name.should == 'web'
165
+ end
166
+ end
167
+
168
+ context "fail to create resource" do
169
+ before do
170
+ stub_post("/repos/#{user}/#{repo}/hooks").with(inputs).
171
+ to_return(:body => fixture('repos/hook.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
172
+ end
173
+
174
+ it "should fail to retrieve resource" do
175
+ expect {
176
+ github.repos.create_hook user, repo, inputs
177
+ }.to raise_error(Github::ResourceNotFound)
178
+ end
179
+ end
180
+ end # create_hook
181
+
182
+ describe "edit_hook" do
183
+ let(:hook_id) { 1 }
184
+ let(:inputs) {
185
+ {
186
+ :name => 'web',
187
+ :config => { :url => "http://something.com/webhook" },
188
+ :active => true
189
+ }
190
+ }
191
+
192
+ context "resource edited successfully" do
193
+ before do
194
+ stub_patch("/repos/#{user}/#{repo}/hooks/#{hook_id}").with(inputs).
195
+ to_return(:body => fixture("repos/hook.json"), :status => 200, :headers => { :content_type => "application/json; charset=utf-8"})
196
+ end
197
+
198
+ it "should fail to edit without 'user/repo' parameters" do
199
+ github.user, github.repo = nil, nil
200
+ expect { github.repos.edit_hook }.to raise_error(ArgumentError)
201
+ end
202
+
203
+ it "should fail to edit resource without 'name' parameter" do
204
+ expect{
205
+ github.repos.edit_hook user, repo, inputs.except(:name)
206
+ }.to raise_error(ArgumentError)
207
+ end
208
+
209
+ it "should fail to edit resource without 'hook_id'" do
210
+ expect {
211
+ github.repos.edit_hook user, repo
212
+ }.to raise_error(ArgumentError)
213
+ end
214
+
215
+ it "should fail to edit resource without 'config' parameter" do
216
+ expect {
217
+ github.repos.edit_hook user, repo, hook_id, inputs.except(:config)
218
+ }.to raise_error(ArgumentError)
219
+ end
220
+
221
+ it "should edit the resource" do
222
+ github.repos.edit_hook user, repo, hook_id, inputs
223
+ a_patch("/repos/#{user}/#{repo}/hooks/#{hook_id}").with(inputs).should have_been_made
224
+ end
225
+
226
+ it "should return resource" do
227
+ hook = github.repos.edit_hook user, repo, hook_id, inputs
228
+ hook.should be_a Hashie::Mash
229
+ end
230
+
231
+ it "should be able to retrieve information" do
232
+ hook = github.repos.edit_hook user, repo, hook_id, inputs
233
+ hook.name.should == 'web'
234
+ end
235
+
236
+ end
237
+
238
+ context "failed to edit resource" do
239
+ before do
240
+ stub_patch("/repos/#{user}/#{repo}/hooks/#{hook_id}").with(inputs).
241
+ to_return(:body => fixture("repos/hook.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
242
+ end
243
+
244
+ it "should fail to find resource" do
245
+ expect {
246
+ github.repos.edit_hook user, repo, hook_id, inputs
247
+ }.to raise_error(Github::ResourceNotFound)
248
+ end
249
+ end
250
+ end # edit_hook
251
+
252
+ describe "delete_hook" do
253
+ let(:hook_id) { 1 }
254
+
255
+ context "resource removed successfully" do
256
+ before do
257
+ stub_delete("/repos/#{user}/#{repo}/hooks/#{hook_id}").
258
+ to_return(:body => '', :status => 204, :headers => { :content_type => "application/json; charset=utf-8"})
259
+ end
260
+
261
+ it "should fail to delete without 'user/repo' parameters" do
262
+ github.user, github.repo = nil, nil
263
+ expect { github.repos.delete_hook }.to raise_error(ArgumentError)
264
+ end
265
+
266
+ it "should fail to delete resource without 'hook_id'" do
267
+ expect {
268
+ github.repos.delete_hook user, repo
269
+ }.to raise_error(ArgumentError)
270
+ end
271
+
272
+ it "should delete the resource" do
273
+ github.repos.delete_hook user, repo, hook_id
274
+ a_delete("/repos/#{user}/#{repo}/hooks/#{hook_id}").should have_been_made
275
+ end
276
+ end
277
+
278
+ context "failed to edit resource" do
279
+ before do
280
+ stub_delete("/repos/#{user}/#{repo}/hooks/#{hook_id}").
281
+ to_return(:body => fixture("repos/hook.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
282
+ end
283
+
284
+ it "should fail to find resource" do
285
+ expect {
286
+ github.repos.delete_hook user, repo, hook_id
287
+ }.to raise_error(Github::ResourceNotFound)
288
+ end
289
+ end
290
+ end # delete_hook
291
+
292
+ describe "test_hook" do
293
+ let(:hook_id) { 1 }
294
+
295
+ context "resource tested successfully" do
296
+ before do
297
+ stub_post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test").
298
+ to_return(:body => '', :status => 204, :headers => { :content_type => "application/json; charset=utf-8"})
299
+ end
300
+
301
+ it "should fail to test without 'user/repo' parameters" do
302
+ github.user, github.repo = nil, nil
303
+ expect { github.repos.test_hook }.to raise_error(ArgumentError)
304
+ end
305
+
306
+ it "should fail to test resource without 'hook_id'" do
307
+ expect {
308
+ github.repos.test_hook user, repo
309
+ }.to raise_error(ArgumentError)
310
+ end
311
+
312
+ it "should trigger test for the resource" do
313
+ github.repos.test_hook user, repo, hook_id
314
+ a_post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test").should have_been_made
315
+ end
316
+ end
317
+
318
+ context "failed to test resource" do
319
+ before do
320
+ stub_post("/repos/#{user}/#{repo}/hooks/#{hook_id}/test").
321
+ to_return(:body => '', :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
322
+
323
+ end
324
+
325
+ it "should fail to find resource" do
326
+ expect {
327
+ github.repos.test_hook user, repo, hook_id
328
+ }.to raise_error(Github::ResourceNotFound)
329
+ end
330
+ end
331
+ end # test_hook
332
+
333
+ end # Github::Repos::Hooks