github_api 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/github_api/api.rb +1 -0
- data/lib/github_api/compatibility.rb +23 -0
- data/lib/github_api/connection.rb +6 -6
- data/lib/github_api/orgs.rb +6 -1
- data/lib/github_api/orgs/members.rb +14 -4
- data/lib/github_api/orgs/teams.rb +16 -7
- data/lib/github_api/repos/downloads.rb +110 -32
- data/lib/github_api/repos/hooks.rb +5 -0
- data/lib/github_api/version.rb +1 -1
- 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/download.json +10 -0
- data/spec/fixtures/repos/download_s3.json +21 -0
- data/spec/fixtures/repos/downloads.json +12 -0
- data/spec/github/orgs/members_spec.rb +272 -2
- data/spec/github/orgs/teams_spec.rb +560 -2
- data/spec/github/orgs_spec.rb +157 -2
- data/spec/github/repos/downloads_spec.rb +233 -2
- data/spec/github/repos/hooks_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- metadata +13 -3
@@ -51,6 +51,8 @@ module Github
|
|
51
51
|
return response unless block_given?
|
52
52
|
response.each { |el| yield el }
|
53
53
|
end
|
54
|
+
alias :repo_hooks :hooks
|
55
|
+
alias :respository_hooks :hooks
|
54
56
|
|
55
57
|
# Get a single hook
|
56
58
|
#
|
@@ -66,6 +68,9 @@ module Github
|
|
66
68
|
|
67
69
|
get("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
|
68
70
|
end
|
71
|
+
alias :get_hook :hook
|
72
|
+
alias :repo_hook :hook
|
73
|
+
alias :get_repo_hook :hook
|
69
74
|
|
70
75
|
# Create a hook
|
71
76
|
#
|
data/lib/github_api/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"login": "github",
|
3
|
+
"id": 1,
|
4
|
+
"url": "https://api.github.com/orgs/1",
|
5
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
6
|
+
"name": "github",
|
7
|
+
"company": "GitHub",
|
8
|
+
"blog": "https://github.com/blog",
|
9
|
+
"location": "San Francisco",
|
10
|
+
"email": "octocat@github.com",
|
11
|
+
"public_repos": 2,
|
12
|
+
"public_gists": 1,
|
13
|
+
"followers": 20,
|
14
|
+
"following": 0,
|
15
|
+
"html_url": "https://github.com/octocat",
|
16
|
+
"created_at": "2008-01-14T04:33:35Z",
|
17
|
+
"type": "Organization"
|
18
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"url": "https://api.github.com/repos/octocat/Hello-World",
|
4
|
+
"html_url": "https://github.com/octocat/Hello-World",
|
5
|
+
"clone_url": "https://github.com/octocat/Hello-World.git",
|
6
|
+
"git_url": "git://github.com/octocat/Hello-World.git",
|
7
|
+
"ssh_url": "git@github.com:octocat/Hello-World.git",
|
8
|
+
"owner": {
|
9
|
+
"login": "octocat",
|
10
|
+
"id": 1,
|
11
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
12
|
+
"gravatar_id": "somehexcode",
|
13
|
+
"url": "https://api.github.com/users/octocat"
|
14
|
+
},
|
15
|
+
"name": "github",
|
16
|
+
"description": "This your first repo!",
|
17
|
+
"homepage": "https://github.com",
|
18
|
+
"language": null,
|
19
|
+
"private": false,
|
20
|
+
"fork": false,
|
21
|
+
"forks": 9,
|
22
|
+
"watchers": 80,
|
23
|
+
"size": 108,
|
24
|
+
"master_branch": "master",
|
25
|
+
"open_issues": 0,
|
26
|
+
"pushed_at": "2011-01-26T19:06:43Z",
|
27
|
+
"created_at": "2011-01-26T19:01:12Z"
|
28
|
+
}
|
29
|
+
]
|
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/downloads/1",
|
3
|
+
"html_url": "https://github.com/repos/octocat/Hello-World/downloads/new_file.jpg",
|
4
|
+
"id": 1,
|
5
|
+
"name": "new_file.jpg",
|
6
|
+
"description": "Description of your download",
|
7
|
+
"size": 1024,
|
8
|
+
"download_count": 40,
|
9
|
+
"content_type": ".jpg"
|
10
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/downloads/1",
|
3
|
+
"html_url": "https://github.com/repos/octocat/Hello-World/downloads/new_file.jpg",
|
4
|
+
"id": 1,
|
5
|
+
"name": "new_file.jpg",
|
6
|
+
"description": "Description of your download",
|
7
|
+
"size": 1024,
|
8
|
+
"download_count": 40,
|
9
|
+
"content_type": ".jpg",
|
10
|
+
"policy": "ewogICAg...",
|
11
|
+
"signature": "mwnFDC...",
|
12
|
+
"bucket": "github",
|
13
|
+
"accesskeyid": "1ABCDEFG...",
|
14
|
+
"path": "downloads/ocotocat/Hello-World/new_file.jpg",
|
15
|
+
"acl": "public-read",
|
16
|
+
"expirationdate": "2011-04-14T16:00:49Z",
|
17
|
+
"prefix": "downloads/octocat/Hello-World/",
|
18
|
+
"mime_type": "image/jpeg",
|
19
|
+
"redirect": false,
|
20
|
+
"s3_url": "https://github.s3.amazonaws.com/"
|
21
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"url": "https://api.github.com/repos/octocat/Hello-World/downloads/1",
|
4
|
+
"html_url": "https://github.com/repos/octocat/Hello-World/downloads/new_file.jpg",
|
5
|
+
"id": 1,
|
6
|
+
"name": "new_file.jpg",
|
7
|
+
"description": "Description of your download",
|
8
|
+
"size": 1024,
|
9
|
+
"download_count": 40,
|
10
|
+
"content_type": ".jpg"
|
11
|
+
}
|
12
|
+
]
|
@@ -1,5 +1,275 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Github::Orgs::Members do
|
4
|
-
|
5
|
-
|
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
|
@@ -1,5 +1,563 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Github::Orgs::Teams do
|
4
|
-
|
5
|
-
|
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
|