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.
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,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::MimeType do
4
+
5
+ let(:github) { Github.new }
6
+
7
+ it "should lookup mime type for :full" do
8
+ github.lookup_mime(:full).should == 'full+json'
9
+ end
10
+
11
+ it "should lookup mime type for :html" do
12
+ github.lookup_mime(:html).should == 'html+json'
13
+ end
14
+
15
+ it "should lookup mime type for :html" do
16
+ github.lookup_mime(:text).should == 'text+json'
17
+ end
18
+
19
+ it "should lookup mime type for :raw" do
20
+ github.lookup_mime(:raw).should == 'raw+json'
21
+ end
22
+
23
+ it "should default to json if no parameters given" do
24
+ Github.should_receive(:parse).and_return 'application/json'
25
+ Github.parse.should == 'application/json'
26
+ end
27
+
28
+ it "should accept header for 'issue' request" do
29
+ Github.should_receive(:parse).with(:issue, :full).
30
+ and_return 'application/vnd.github-issue.full+json'
31
+ Github.parse(:issue, :full).should == 'application/vnd.github-issue.full+json'
32
+ end
33
+
34
+ it "should accept header for 'isssue comment' request" do
35
+ Github.should_receive(:parse).with(:issue_comment, :full).
36
+ and_return 'application/vnd.github-issuecomment.full+json'
37
+ Github.parse(:issue_comment, :full).should == 'application/vnd.github-issuecomment.full+json'
38
+ end
39
+
40
+ it "should accept header for 'commit comment' request" do
41
+ Github.should_receive(:parse).with(:commit_comment, :full).
42
+ and_return 'application/vnd.github-commitcomment.full+json'
43
+ Github.parse(:commit_comment, :full).should == 'application/vnd.github-commitcomment.full+json'
44
+ end
45
+
46
+ it "should accept header for 'pull requst' request" do
47
+ Github.should_receive(:parse).with(:pull_request, :full).
48
+ and_return 'application/vnd.github-pull.full+json'
49
+ Github.parse(:pull_request, :full).should == 'application/vnd.github-pull.full+json'
50
+ end
51
+
52
+ it "should accept header for 'pull comment' request" do
53
+ Github.should_receive(:parse).with(:pull_comment, :full).
54
+ and_return 'application/vnd.github-pullcomment.full+json'
55
+ Github.parse(:pull_comment, :full).should == 'application/vnd.github-pullcomment.full+json'
56
+ end
57
+
58
+ it "should accept header for 'gist comment' request" do
59
+ Github.should_receive(:parse).with(:gist_comment, :full).
60
+ and_return 'application/vnd.github-gistcomment.full+json'
61
+ Github.parse(:gist_comment, :full).should == 'application/vnd.github-gistcomment.full+json'
62
+ end
63
+
64
+ it "should accept header for 'blog' request" do
65
+ Github.should_receive(:parse).with(:blob, :blob).
66
+ and_return 'application/vnd.github-blob.raw'
67
+ Github.parse(:blob, :blob).should == 'application/vnd.github-blob.raw'
68
+ end
69
+
70
+ end # Github::MimeType
@@ -0,0 +1,275 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Orgs::Members do
4
+
5
+ let(:github) { Github.new }
6
+ let(:member) { 'peter-murach' }
7
+ let(:org) { 'github' }
8
+
9
+ describe "members" do
10
+ context "resource found" do
11
+ before do
12
+ stub_get("/orgs/#{org}/members").
13
+ to_return(:body => fixture('orgs/members.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "should fail to get resource without org name" do
17
+ expect { github.orgs.members }.to raise_error(ArgumentError)
18
+ end
19
+
20
+ it "should get the resources" do
21
+ github.orgs.members org
22
+ a_get("/orgs/#{org}/members").should have_been_made
23
+ end
24
+
25
+ it "should return array of resources" do
26
+ members = github.orgs.members org
27
+ members.should be_an Array
28
+ members.should have(1).items
29
+ end
30
+
31
+ it "should be a mash type" do
32
+ members = github.orgs.members org
33
+ members.first.should be_a Hashie::Mash
34
+ end
35
+
36
+ it "should get members information" do
37
+ members = github.orgs.members org
38
+ members.first.login.should == 'octocat'
39
+ end
40
+
41
+ it "should yield to a block" do
42
+ github.orgs.should_receive(:members).with(org).and_yield('web')
43
+ github.orgs.members(org) { |param| 'web' }
44
+ end
45
+ end
46
+
47
+ context "resource not found" do
48
+ before do
49
+ stub_get("/orgs/#{org}/members").
50
+ to_return(:body => fixture('orgs/members.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
51
+ end
52
+
53
+ it "should return 404 with a message 'Not Found'" do
54
+ expect {
55
+ github.orgs.members org
56
+ }.to raise_error(Github::ResourceNotFound)
57
+ end
58
+ end
59
+ end # members
60
+
61
+ describe "member?" do
62
+
63
+ context "with username ane reponame passed" do
64
+
65
+ context "this repo is being watched by the user"
66
+ before do
67
+ github.oauth_token = nil
68
+ github.user = nil
69
+ stub_get("/orgs/#{org}/members/#{member}").
70
+ to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
71
+ end
72
+
73
+ it "should return false if resource not found" do
74
+ membership = github.orgs.member? org, member
75
+ membership.should be_false
76
+ end
77
+
78
+ it "should return true if resoure found" do
79
+ stub_get("/orgs/#{org}/members/#{member}").
80
+ to_return(:body => "", :status => 204, :headers => {:user_agent => github.user_agent})
81
+ membership = github.orgs.member? org, member
82
+ membership.should be_true
83
+ end
84
+
85
+ end
86
+
87
+ context "without org name and member name passed" do
88
+ it "should fail validation " do
89
+ expect { github.orgs.member?(nil, nil) }.to raise_error(ArgumentError)
90
+ end
91
+ end
92
+ end # member?
93
+
94
+ describe "public_members" do
95
+ context "resource found" do
96
+ before do
97
+ stub_get("/orgs/#{org}/public_members").
98
+ to_return(:body => fixture('orgs/members.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
99
+ end
100
+
101
+ it "should fail to get resource without org name" do
102
+ expect { github.orgs.public_members }.to raise_error(ArgumentError)
103
+ end
104
+
105
+ it "should get the resources" do
106
+ github.orgs.public_members org
107
+ a_get("/orgs/#{org}/public_members").should have_been_made
108
+ end
109
+
110
+ it "should return array of resources" do
111
+ public_members = github.orgs.public_members org
112
+ public_members.should be_an Array
113
+ public_members.should have(1).items
114
+ end
115
+
116
+ it "should be a mash type" do
117
+ public_members = github.orgs.public_members org
118
+ public_members.first.should be_a Hashie::Mash
119
+ end
120
+
121
+ it "should get public_members information" do
122
+ public_members = github.orgs.public_members org
123
+ public_members.first.login.should == 'octocat'
124
+ end
125
+
126
+ it "should yield to a block" do
127
+ github.orgs.should_receive(:public_members).with(org).and_yield('web')
128
+ github.orgs.public_members(org) { |param| 'web' }
129
+ end
130
+ end
131
+
132
+ context "resource not found" do
133
+ before do
134
+ stub_get("/orgs/#{org}/public_members").
135
+ to_return(:body => fixture('orgs/members.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
136
+ end
137
+
138
+ it "should return 404 with a message 'Not Found'" do
139
+ expect {
140
+ github.orgs.public_members org
141
+ }.to raise_error(Github::ResourceNotFound)
142
+ end
143
+ end
144
+ end # public_members
145
+
146
+ describe "public_member?" do
147
+
148
+ context "with username ane reponame passed" do
149
+
150
+ context "this repo is being watched by the user"
151
+ before do
152
+ github.oauth_token = nil
153
+ github.user = nil
154
+ stub_get("/orgs/#{org}/public_members/#{member}").
155
+ to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
156
+ end
157
+
158
+ it "should return false if resource not found" do
159
+ public_member = github.orgs.public_member? org, member
160
+ public_member.should be_false
161
+ end
162
+
163
+ it "should return true if resoure found" do
164
+ stub_get("/orgs/#{org}/public_members/#{member}").
165
+ to_return(:body => "", :status => 204, :headers => {:user_agent => github.user_agent})
166
+ public_member = github.orgs.public_member? org, member
167
+ public_member.should be_true
168
+ end
169
+
170
+ end
171
+
172
+ context "without org name and member name passed" do
173
+ it "should fail validation " do
174
+ expect { github.orgs.public_member?(nil, nil) }.to raise_error(ArgumentError)
175
+ end
176
+ end
177
+ end # public_member?
178
+
179
+ describe "publicize" do
180
+ context "request perfomed successfully" do
181
+ before do
182
+ stub_put("/orgs/#{org}/public_members/#{member}").
183
+ to_return(:body => fixture('orgs/members.json'), :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
184
+ end
185
+
186
+ it "should fail to get resource without org name" do
187
+ expect { github.orgs.publicize }.to raise_error(ArgumentError)
188
+ end
189
+
190
+ it "should get the resources" do
191
+ github.orgs.publicize org, member
192
+ a_put("/orgs/#{org}/public_members/#{member}").should have_been_made
193
+ end
194
+ end
195
+
196
+ context "resource not found" do
197
+ before do
198
+ stub_put("/orgs/#{org}/public_members/#{member}").
199
+ to_return(:body => fixture('orgs/members.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
200
+ end
201
+
202
+ it "should return 404 with a message 'Not Found'" do
203
+ expect {
204
+ github.orgs.publicize org, member
205
+ }.to raise_error(Github::ResourceNotFound)
206
+ end
207
+ end
208
+ end # publicize
209
+
210
+ describe "conceal" do
211
+ context "request perfomed successfully" do
212
+ before do
213
+ stub_delete("/orgs/#{org}/public_members/#{member}").
214
+ to_return(:body => fixture('orgs/members.json'), :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
215
+ end
216
+
217
+ it "should fail to get resource without org name" do
218
+ expect { github.orgs.conceal nil, nil }.to raise_error(ArgumentError)
219
+ end
220
+
221
+ it "should get the resources" do
222
+ github.orgs.conceal org, member
223
+ a_delete("/orgs/#{org}/public_members/#{member}").should have_been_made
224
+ end
225
+ end
226
+
227
+ context "resource not found" do
228
+ before do
229
+ stub_delete("/orgs/#{org}/public_members/#{member}").
230
+ to_return(:body => fixture('orgs/members.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
231
+ end
232
+
233
+ it "should return 404 with a message 'Not Found'" do
234
+ expect {
235
+ github.orgs.conceal org, member
236
+ }.to raise_error(Github::ResourceNotFound)
237
+ end
238
+ end
239
+ end # conceal
240
+
241
+ describe "delete_member" do
242
+ let(:hook_id) { 1 }
243
+
244
+ context "resource deleted successfully" do
245
+ before do
246
+ stub_delete("/orgs/#{org}/members/#{member}").
247
+ to_return(:body => '', :status => 204, :headers => { :content_type => "application/json; charset=utf-8"})
248
+ end
249
+
250
+ it "should fail to delete without org and member parameters" do
251
+ expect { github.repos.delete_hook nil, nil }.to raise_error(ArgumentError)
252
+ end
253
+
254
+ it "should delete the resource" do
255
+ github.orgs.delete_member org, member
256
+ a_delete("/orgs/#{org}/members/#{member}").should have_been_made
257
+ end
258
+ end
259
+
260
+ context "failed to edit resource" do
261
+ before do
262
+ stub_delete("/orgs/#{org}/members/#{member}").
263
+ to_return(:body => '', :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
264
+
265
+ end
266
+
267
+ it "should fail to find resource" do
268
+ expect {
269
+ github.orgs.delete_member org, member
270
+ }.to raise_error(Github::ResourceNotFound)
271
+ end
272
+ end
273
+ end # delete_member
274
+
275
+ end # Github::Orgs::Members
@@ -0,0 +1,563 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Orgs::Teams do
4
+
5
+ let(:github) { Github.new }
6
+ let(:team) { 'github' }
7
+ let(:member) { 'github' }
8
+ let(:org) { 'github' }
9
+ let(:user) { 'peter-murach' }
10
+ let(:repo) { 'github' }
11
+
12
+ describe "teams" do
13
+ context "resource found" do
14
+ before do
15
+ stub_get("/orgs/#{org}/teams").
16
+ to_return(:body => fixture('orgs/teams.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
17
+ end
18
+
19
+ it "should fail to get resource without org name" do
20
+ expect { github.orgs.teams nil }.to raise_error(ArgumentError)
21
+ end
22
+
23
+ it "should get the resources" do
24
+ github.orgs.teams org
25
+ a_get("/orgs/#{org}/teams").should have_been_made
26
+ end
27
+
28
+ it "should return array of resources" do
29
+ teams = github.orgs.teams org
30
+ teams.should be_an Array
31
+ teams.should have(1).items
32
+ end
33
+
34
+ it "should be a mash type" do
35
+ teams = github.orgs.teams org
36
+ teams.first.should be_a Hashie::Mash
37
+ end
38
+
39
+ it "should get teams information" do
40
+ teams = github.orgs.teams org
41
+ teams.first.name.should == 'Owners'
42
+ end
43
+
44
+ it "should yield to a block" do
45
+ github.orgs.should_receive(:teams).with(org).and_yield('web')
46
+ github.orgs.teams(org) { |param| 'web' }
47
+ end
48
+ end
49
+
50
+ context "resource not found" do
51
+ before do
52
+ stub_get("/orgs/#{org}/teams").
53
+ to_return(:body => fixture('orgs/teams.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
54
+ end
55
+
56
+ it "should return 404 with a message 'Not Found'" do
57
+ expect {
58
+ github.orgs.teams org
59
+ }.to raise_error(Github::ResourceNotFound)
60
+ end
61
+ end
62
+ end # teams
63
+
64
+ describe "team" do
65
+ context "resource found" do
66
+ before do
67
+ stub_get("/teams/#{team}").
68
+ to_return(:body => fixture('orgs/team.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
69
+ end
70
+
71
+ it "should fail to get resource without org name" do
72
+ expect { github.orgs.team nil }.to raise_error(ArgumentError)
73
+ end
74
+
75
+ it "should get the resource" do
76
+ github.orgs.team team
77
+ a_get("/teams/#{team}").should have_been_made
78
+ end
79
+
80
+ it "should get team information" do
81
+ team_res = github.orgs.team team
82
+ team_res.id.should == 1
83
+ team_res.name.should == 'Owners'
84
+ end
85
+
86
+ it "should return mash" do
87
+ team_res = github.orgs.team team
88
+ team_res.should be_a Hashie::Mash
89
+ end
90
+ end
91
+
92
+ context "resource not found" do
93
+ before do
94
+ stub_get("/teams/#{team}").
95
+ to_return(:body => fixture('orgs/team.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
96
+ end
97
+
98
+ it "should fail to retrive resource" do
99
+ expect {
100
+ github.orgs.team team
101
+ }.to raise_error(Github::ResourceNotFound)
102
+ end
103
+ end
104
+ end # team
105
+
106
+ describe "create_team" do
107
+ let(:inputs) { { :name => 'new team', :permissions => 'push', :repo_names => [ 'github/dotfiles' ] }}
108
+
109
+ context "resouce created" do
110
+ before do
111
+ stub_post("/orgs/#{org}/teams").with(inputs).
112
+ to_return(:body => fixture('orgs/team.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
113
+
114
+ end
115
+
116
+ it "should fail to create resource if 'org_name' param is missing" do
117
+ expect { github.orgs.create_team nil, inputs }.to raise_error(ArgumentError)
118
+ end
119
+
120
+ it "should failt to create resource if 'name' input is missing" do
121
+ expect {
122
+ github.orgs.create_team org, inputs.except(:name)
123
+ }.to raise_error(ArgumentError)
124
+ end
125
+
126
+ it "should create resource successfully" do
127
+ github.orgs.create_team org, inputs
128
+ a_post("/orgs/#{org}/teams").with(inputs).should have_been_made
129
+ end
130
+
131
+ it "should return the resource" do
132
+ team = github.orgs.create_team org, inputs
133
+ team.should be_a Hashie::Mash
134
+ end
135
+
136
+ it "should get the team information" do
137
+ team = github.orgs.create_team org, inputs
138
+ team.name.should == 'Owners'
139
+ end
140
+ end
141
+
142
+ context "failed to create resource" do
143
+ before do
144
+ stub_post("/orgs/#{org}/teams").with(inputs).
145
+ to_return(:body => fixture('orgs/team.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
146
+
147
+ end
148
+
149
+ it "should faile to retrieve resource" do
150
+ expect {
151
+ github.orgs.create_team org, inputs
152
+ }.to raise_error(Github::ResourceNotFound)
153
+ end
154
+ end
155
+ end # create_team
156
+
157
+ describe "edit_team" do
158
+ let(:inputs) { { :name => 'new team', :permissions => 'push' } }
159
+
160
+ context "resouce edited" do
161
+ before do
162
+ stub_patch("/teams/#{team}").with(inputs).
163
+ to_return(:body => fixture('orgs/team.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
164
+
165
+ end
166
+
167
+ it "should fail to create resource if 'team name' param is missing" do
168
+ expect { github.orgs.edit_team nil, inputs }.to raise_error(ArgumentError)
169
+ end
170
+
171
+ it "should failt to create resource if 'name' input is missing" do
172
+ expect {
173
+ github.orgs.edit_team team, inputs.except(:name)
174
+ }.to raise_error(ArgumentError)
175
+ end
176
+
177
+ it "should create resource successfully" do
178
+ github.orgs.edit_team team, inputs
179
+ a_patch("/teams/#{team}").with(inputs).should have_been_made
180
+ end
181
+
182
+ it "should return the resource" do
183
+ edited_team = github.orgs.edit_team team, inputs
184
+ edited_team.should be_a Hashie::Mash
185
+ end
186
+
187
+ it "should get the team information" do
188
+ edited_team = github.orgs.edit_team team, inputs
189
+ edited_team.name.should == 'Owners'
190
+ end
191
+ end
192
+
193
+ context "failed to create resource" do
194
+ before do
195
+ stub_patch("/teams/#{team}").with(inputs).
196
+ to_return(:body => fixture('orgs/team.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
197
+
198
+ end
199
+
200
+ it "should faile to retrieve resource" do
201
+ expect {
202
+ github.orgs.edit_team team, inputs
203
+ }.to raise_error(Github::ResourceNotFound)
204
+ end
205
+ end
206
+ end # edit_team
207
+
208
+ describe "delete_team" do
209
+ let(:team_id) { 1 }
210
+
211
+ context "resource edited successfully" do
212
+ before do
213
+ stub_delete("/teams/#{team}").
214
+ to_return(:body => '', :status => 204, :headers => { :content_type => "application/json; charset=utf-8"})
215
+ end
216
+
217
+ it "should fail to delete without 'team_id' parameter" do
218
+ github.user, github.repo = nil, nil
219
+ expect { github.orgs.delete_team }.to raise_error(ArgumentError)
220
+ end
221
+
222
+ it "should delete the resource" do
223
+ github.orgs.delete_team team
224
+ a_delete("/teams/#{team}").should have_been_made
225
+ end
226
+ end
227
+
228
+ context "failed to edit resource" do
229
+ before do
230
+ stub_delete("/teams/#{team}").
231
+ to_return(:body => '', :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
232
+ end
233
+
234
+ it "should fail to find resource" do
235
+ expect { github.orgs.delete_team team }.to raise_error(Github::ResourceNotFound)
236
+ end
237
+ end
238
+ end # delete_team
239
+
240
+ describe "team_members" do
241
+ context "resource found" do
242
+ before do
243
+ stub_get("/teams/#{team}/members").
244
+ to_return(:body => fixture('orgs/teams.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
245
+ end
246
+
247
+ it "should fail to get resource without org name" do
248
+ expect { github.orgs.team_members }.to raise_error(ArgumentError)
249
+ end
250
+
251
+ it "should get the resources" do
252
+ github.orgs.team_members team
253
+ a_get("/teams/#{team}/members").should have_been_made
254
+ end
255
+
256
+ it "should return array of resources" do
257
+ teams = github.orgs.team_members team
258
+ teams.should be_an Array
259
+ teams.should have(1).items
260
+ end
261
+
262
+ it "should be a mash type" do
263
+ teams = github.orgs.team_members team
264
+ teams.first.should be_a Hashie::Mash
265
+ end
266
+
267
+ it "should get team members information" do
268
+ teams = github.orgs.team_members team
269
+ teams.first.name.should == 'Owners'
270
+ end
271
+
272
+ it "should yield to a block" do
273
+ github.orgs.should_receive(:team_members).with(team).and_yield('web')
274
+ github.orgs.team_members(team) { |param| 'web' }
275
+ end
276
+ end
277
+
278
+ context "resource not found" do
279
+ before do
280
+ stub_get("/teams/#{team}/members").
281
+ to_return(:body => fixture('orgs/teams.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
282
+ end
283
+
284
+ it "should return 404 with a message 'Not Found'" do
285
+ expect {
286
+ github.orgs.team_members team
287
+ }.to raise_error(Github::ResourceNotFound)
288
+ end
289
+ end
290
+ end # team_members
291
+
292
+ describe "team_member?" do
293
+ context "with teamname ane membername passed" do
294
+
295
+ context "this repo is being watched by the user"
296
+ before do
297
+ github.oauth_token = nil
298
+ github.user = nil
299
+ stub_get("/teams/#{team}/members/#{member}").
300
+ to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
301
+ end
302
+
303
+ it "should return false if resource not found" do
304
+ team_membership = github.orgs.team_member? team, member
305
+ team_membership.should be_false
306
+ end
307
+
308
+ it "should return true if resoure found" do
309
+ stub_get("/teams/#{team}/members/#{member}").
310
+ to_return(:body => "", :status => 204, :headers => {:user_agent => github.user_agent})
311
+ team_membership = github.orgs.team_member? team, member
312
+ team_membership.should be_true
313
+ end
314
+
315
+ end
316
+
317
+ context "without org name and member name passed" do
318
+ it "should fail validation " do
319
+ expect { github.orgs.team_member?(nil, nil) }.to raise_error(ArgumentError)
320
+ end
321
+ end
322
+ end # member?
323
+
324
+ describe "add_team_member" do
325
+ context "resouce added" do
326
+ before do
327
+ stub_put("/teams/#{team}/members/#{member}").
328
+ to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
329
+ end
330
+
331
+ it "should fail to add resource if 'team' input is nil" do
332
+ expect {
333
+ github.orgs.add_team_member nil, member
334
+ }.to raise_error(ArgumentError)
335
+ end
336
+
337
+ it "should fail to add resource if 'member' input is nil" do
338
+ expect {
339
+ github.orgs.add_team_member team, nil
340
+ }.to raise_error(ArgumentError)
341
+ end
342
+
343
+ it "should add resource successfully" do
344
+ github.orgs.add_team_member team, member
345
+ a_put("/teams/#{team}/members/#{member}").should have_been_made
346
+ end
347
+ end
348
+
349
+ context "failed to add resource" do
350
+ before do
351
+ stub_put("/teams/#{team}/members/#{member}").
352
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
353
+ end
354
+
355
+ it "should fail to add resource" do
356
+ expect {
357
+ github.orgs.add_team_member team, member
358
+ }.to raise_error(Github::ResourceNotFound)
359
+ end
360
+ end
361
+ end # add_team_member
362
+
363
+ describe "remove_team_member" do
364
+ context "resouce deleted" do
365
+ before do
366
+ stub_delete("/teams/#{team}/members/#{member}").
367
+ to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
368
+ end
369
+
370
+ it "should fail to delete resource if 'team' input is nil" do
371
+ expect {
372
+ github.orgs.remove_team_member nil, member
373
+ }.to raise_error(ArgumentError)
374
+ end
375
+
376
+ it "should fail to delete resource if 'member' input is nil" do
377
+ expect {
378
+ github.orgs.remove_team_member member, nil
379
+ }.to raise_error(ArgumentError)
380
+ end
381
+
382
+ it "should add resource successfully" do
383
+ github.orgs.remove_team_member team, member
384
+ a_delete("/teams/#{team}/members/#{member}").should have_been_made
385
+ end
386
+ end
387
+
388
+ context "failed to remove resource" do
389
+ before do
390
+ stub_delete("/teams/#{team}/members/#{member}").
391
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
392
+ end
393
+
394
+ it "should fail to remove resource" do
395
+ expect {
396
+ github.orgs.remove_team_member team, member
397
+ }.to raise_error(Github::ResourceNotFound)
398
+ end
399
+ end
400
+ end # remove_team_member
401
+
402
+ describe "team_repos" do
403
+ context "resource found" do
404
+ before do
405
+ stub_get("/teams/#{team}/repos").
406
+ to_return(:body => fixture('orgs/team_repos.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
407
+ end
408
+
409
+ it "should fail to get resource without team name" do
410
+ expect { github.orgs.team_repos nil }.to raise_error(ArgumentError)
411
+ end
412
+
413
+ it "should get the resources" do
414
+ github.orgs.team_repos team
415
+ a_get("/teams/#{team}/repos").should have_been_made
416
+ end
417
+
418
+ it "should return array of resources" do
419
+ team_repos = github.orgs.team_repos team
420
+ team_repos.should be_an Array
421
+ team_repos.should have(1).items
422
+ end
423
+
424
+ it "should be a mash type" do
425
+ team_repos = github.orgs.team_repos team
426
+ team_repos.first.should be_a Hashie::Mash
427
+ end
428
+
429
+ it "should get teams information" do
430
+ team_repos = github.orgs.team_repos team
431
+ team_repos.first.name.should == 'github'
432
+ end
433
+
434
+ it "should yield to a block" do
435
+ github.orgs.should_receive(:team_repos).with(team).and_yield('web')
436
+ github.orgs.team_repos(team) { |param| 'web' }
437
+ end
438
+ end
439
+
440
+ context "resource not found" do
441
+ before do
442
+ stub_get("/teams/#{team}/repos").
443
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
444
+ end
445
+
446
+ it "should return 404 with a message 'Not Found'" do
447
+ expect {
448
+ github.orgs.team_repos team
449
+ }.to raise_error(Github::ResourceNotFound)
450
+ end
451
+ end
452
+ end # team_repos
453
+
454
+ describe "team_repo?" do
455
+ context "with teamname, username ane reponame passed" do
456
+
457
+ context "this repo is managed by the team"
458
+ before do
459
+ github.oauth_token = nil
460
+ github.user = nil
461
+ stub_get("/teams/#{team}/repos/#{user}/#{repo}").
462
+ to_return(:body => "", :status => 404, :headers => {:user_agent => github.user_agent})
463
+ end
464
+
465
+ it "should return false if resource not found" do
466
+ team_managed = github.orgs.team_repo? team, user, repo
467
+ team_managed.should be_false
468
+ end
469
+
470
+ it "should return true if resoure found" do
471
+ stub_get("/teams/#{team}/repos/#{user}/#{repo}").
472
+ to_return(:body => "", :status => 204, :headers => {:user_agent => github.user_agent})
473
+ team_managed = github.orgs.team_repo? team, user, repo
474
+ team_managed.should be_true
475
+ end
476
+ end
477
+
478
+ context "without org name and member name passed" do
479
+ it "should fail validation " do
480
+ expect { github.orgs.team_repo?(nil, nil, nil) }.to raise_error(ArgumentError)
481
+ end
482
+ end
483
+ end # team_repo?
484
+
485
+ describe "add_team_repo" do
486
+ context "resouce added" do
487
+ before do
488
+ stub_put("/teams/#{team}/repos/#{user}/#{repo}").
489
+ to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
490
+ end
491
+
492
+ it "should fail to add resource if 'team' input is nil" do
493
+ expect {
494
+ github.orgs.add_team_member nil, user, repo
495
+ }.to raise_error(ArgumentError)
496
+ end
497
+
498
+ it "should fail to add resource if 'user' input is nil" do
499
+ expect {
500
+ github.orgs.add_team_member team, nil, repo
501
+ }.to raise_error(ArgumentError)
502
+ end
503
+
504
+ it "should add resource successfully" do
505
+ github.orgs.add_team_repo team, user, repo
506
+ a_put("/teams/#{team}/repos/#{user}/#{repo}").should have_been_made
507
+ end
508
+ end
509
+
510
+ context "failed to add resource" do
511
+ before do
512
+ stub_put("/teams/#{team}/repos/#{user}/#{repo}").
513
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
514
+ end
515
+
516
+ it "should fail to add resource" do
517
+ expect {
518
+ github.orgs.add_team_repo team, user, repo
519
+ }.to raise_error(Github::ResourceNotFound)
520
+ end
521
+ end
522
+ end # add_team_repo
523
+
524
+ describe "remove_team_member" do
525
+ context "resouce deleted" do
526
+ before do
527
+ stub_delete("/teams/#{team}/repos/#{user}/#{repo}").
528
+ to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
529
+ end
530
+
531
+ it "should fail to delete resource if 'team' input is nil" do
532
+ expect {
533
+ github.orgs.remove_team_repo nil, user, repo
534
+ }.to raise_error(ArgumentError)
535
+ end
536
+
537
+ it "should fail to delete resource if 'user' input is nil" do
538
+ expect {
539
+ github.orgs.remove_team_repo team, nil, repo
540
+ }.to raise_error(ArgumentError)
541
+ end
542
+
543
+ it "should add resource successfully" do
544
+ github.orgs.remove_team_repo team, user, repo
545
+ a_delete("/teams/#{team}/repos/#{user}/#{repo}").should have_been_made
546
+ end
547
+ end
548
+
549
+ context "failed to remove resource" do
550
+ before do
551
+ stub_delete("/teams/#{team}/repos/#{user}/#{repo}").
552
+ to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
553
+ end
554
+
555
+ it "should fail to remove resource" do
556
+ expect {
557
+ github.orgs.remove_team_repo team, user, repo
558
+ }.to raise_error(Github::ResourceNotFound)
559
+ end
560
+ end
561
+ end # remove_team_repo
562
+
563
+ end # Github::Orgs::Teams