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.
@@ -1,5 +1,160 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Github::Orgs do
4
- pending
5
- end
4
+
5
+ let(:github) { Github.new }
6
+ let(:user) { 'peter-murach' }
7
+ let(:org) { 'github' }
8
+
9
+ describe "orgs" do
10
+ context "resource found for a user" do
11
+ before do
12
+ stub_get("/users/#{user}/orgs").
13
+ to_return(:body => fixture('orgs/orgs.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "should get the resources" do
17
+ github.orgs.orgs user
18
+ a_get("/users/#{user}/orgs").should have_been_made
19
+ end
20
+
21
+ it "should return array of resources" do
22
+ orgs = github.orgs.orgs user
23
+ orgs.should be_an Array
24
+ orgs.should have(1).items
25
+ end
26
+
27
+ it "should be a mash type" do
28
+ orgs = github.orgs.orgs user
29
+ orgs.first.should be_a Hashie::Mash
30
+ end
31
+
32
+ it "should get org information" do
33
+ orgs = github.orgs.orgs user
34
+ orgs.first.login.should == 'github'
35
+ end
36
+
37
+ it "should yield to a block" do
38
+ github.orgs.should_receive(:orgs).with(user).and_yield('web')
39
+ github.orgs.orgs(user) { |param| 'web' }
40
+ end
41
+ end
42
+
43
+ context "resource found for an au user" do
44
+ before do
45
+ github.user = nil
46
+ github.oauth_token = OAUTH_TOKEN
47
+ stub_get("/user/orgs?access_token=#{OAUTH_TOKEN}").
48
+ to_return(:body => fixture('orgs/orgs.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
49
+ end
50
+
51
+ after do
52
+ github.user, github.oauth_token = nil, nil
53
+ end
54
+
55
+ it "should get the resources" do
56
+ github.orgs.orgs
57
+ a_get("/user/orgs?access_token=#{OAUTH_TOKEN}").should have_been_made
58
+ end
59
+ end
60
+
61
+ context "resource not found for a user" do
62
+ before do
63
+ stub_get("/users/#{user}/orgs").
64
+ to_return(:body => "", :status => [404, "Not Found"])
65
+ end
66
+
67
+ it "should return 404 with a message 'Not Found'" do
68
+ expect {
69
+ github.orgs.orgs user
70
+ }.to raise_error(Github::ResourceNotFound)
71
+ end
72
+ end
73
+ end # orgs
74
+
75
+ describe "org" do
76
+ context "resource found" do
77
+ before do
78
+ stub_get("/orgs/#{org}").
79
+ to_return(:body => fixture('orgs/org.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
80
+ end
81
+
82
+ it "should fail to get resource without org name" do
83
+ expect { github.orgs.org }.to raise_error(ArgumentError)
84
+ end
85
+
86
+ it "should get the resource" do
87
+ github.orgs.org org
88
+ a_get("/orgs/#{org}").should have_been_made
89
+ end
90
+
91
+ it "should get org information" do
92
+ organisation = github.orgs.org org
93
+ organisation.id.should == 1
94
+ organisation.login.should == 'github'
95
+ end
96
+
97
+ it "should return mash" do
98
+ organisation = github.orgs.org org
99
+ organisation.should be_a Hashie::Mash
100
+ end
101
+ end
102
+
103
+ context "resource not found" do
104
+ before do
105
+ stub_get("/orgs/#{org}").
106
+ to_return(:body => fixture('orgs/org.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.orgs.org org
112
+ }.to raise_error(Github::ResourceNotFound)
113
+ end
114
+ end
115
+ end # org
116
+
117
+ describe "edit_org" do
118
+ let(:inputs) { { :billing_email => 'support@github.com', :blog => "https://github.com/blog", :company => "GitHub", :email => "support@github.com", :location => "San Francisco", :name => "github" } }
119
+
120
+ context "resource edited successfully" do
121
+ before do
122
+ stub_patch("/orgs/#{org}").with(inputs).
123
+ to_return(:body => fixture("orgs/org.json"), :status => 200, :headers => { :content_type => "application/json; charset=utf-8"})
124
+ end
125
+
126
+ it "should fail to edit without 'user/repo' parameters" do
127
+ expect { github.orgs.edit_org }.to raise_error(ArgumentError)
128
+ end
129
+
130
+ it "should edit the resource" do
131
+ github.orgs.edit_org org
132
+ a_patch("/orgs/#{org}").with(inputs).should have_been_made
133
+ end
134
+
135
+ it "should return resource" do
136
+ organisation = github.orgs.edit_org org
137
+ organisation.should be_a Hashie::Mash
138
+ end
139
+
140
+ it "should be able to retrieve information" do
141
+ organisation = github.orgs.edit_org org
142
+ organisation.name.should == 'github'
143
+ end
144
+ end
145
+
146
+ context "failed to edit resource" do
147
+ before do
148
+ stub_patch("/orgs/#{org}").with(inputs).
149
+ to_return(:body => fixture("orgs/org.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
150
+ end
151
+
152
+ it "should fail to find resource" do
153
+ expect {
154
+ github.orgs.edit_org org
155
+ }.to raise_error(Github::ResourceNotFound)
156
+ end
157
+ end
158
+ end # edit_org
159
+
160
+ end # Github::Orgs
@@ -1,5 +1,236 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Github::Repos::Downloads do
4
- pending
5
- end
4
+
5
+ let(:github) { Github.new }
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+
9
+ describe "downloads" do
10
+ context "resource found" do
11
+ before do
12
+ stub_get("/repos/#{user}/#{repo}/downloads").
13
+ to_return(:body => fixture('repos/downloads.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "should fail to get resource without username" do
17
+ github.user, github.repo = nil, nil
18
+ expect { github.repos.downloads }.to raise_error(ArgumentError)
19
+ end
20
+
21
+ it "should get the resources" do
22
+ github.repos.downloads user, repo
23
+ a_get("/repos/#{user}/#{repo}/downloads").should have_been_made
24
+ end
25
+
26
+ it "should return array of resources" do
27
+ downloads = github.repos.downloads user, repo
28
+ downloads.should be_an Array
29
+ downloads.should have(1).items
30
+ end
31
+
32
+ it "should be a mash type" do
33
+ downloads = github.repos.downloads user, repo
34
+ downloads.first.should be_a Hashie::Mash
35
+ end
36
+
37
+ it "should get download information" do
38
+ downloads = github.repos.downloads user, repo
39
+ downloads.first.name.should == 'new_file.jpg'
40
+ end
41
+
42
+ it "should yield to a block" do
43
+ github.repos.should_receive(:downloads).with(user, repo).and_yield('web')
44
+ github.repos.downloads(user, repo) { |param| 'web' }
45
+ end
46
+ end
47
+
48
+ context "resource not found" do
49
+ before do
50
+ stub_get("/repos/#{user}/#{repo}/downloads").
51
+ to_return(:body => "", :status => [404, "Not Found"])
52
+ end
53
+
54
+ it "should return 404 with a message 'Not Found'" do
55
+ expect {
56
+ github.repos.downloads user, repo
57
+ }.to raise_error(Github::ResourceNotFound)
58
+ end
59
+ end
60
+ end # downloads
61
+
62
+ describe "download" do
63
+ let(:download_id) { 1 }
64
+
65
+ context "resource found" do
66
+ before do
67
+ stub_get("/repos/#{user}/#{repo}/downloads/#{download_id}").
68
+ to_return(:body => fixture('repos/download.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
69
+ end
70
+
71
+ it "should fail to get resource without download id" do
72
+ expect { github.repos.download(user, repo, nil)}.to raise_error(ArgumentError)
73
+ end
74
+
75
+ it "should get the resource" do
76
+ github.repos.download user, repo, download_id
77
+ a_get("/repos/#{user}/#{repo}/downloads/#{download_id}").should have_been_made
78
+ end
79
+
80
+ it "should get download information" do
81
+ download = github.repos.download user, repo, download_id
82
+ download.id.should == download_id
83
+ download.name.should == 'new_file.jpg'
84
+ end
85
+
86
+ it "should return mash" do
87
+ download = github.repos.download user, repo, download_id
88
+ download.should be_a Hashie::Mash
89
+ end
90
+ end
91
+
92
+ context "resource not found" do
93
+ before do
94
+ stub_get("/repos/#{user}/#{repo}/downloads/#{download_id}").
95
+ to_return(:body => fixture('repos/download.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.repos.download user, repo, download_id
101
+ }.to raise_error(Github::ResourceNotFound)
102
+ end
103
+ end
104
+ end # download
105
+
106
+ describe "delete_download" do
107
+ let(:download_id) { 1 }
108
+
109
+ context "resource edited successfully" do
110
+ before do
111
+ stub_delete("/repos/#{user}/#{repo}/downloads/#{download_id}").
112
+ to_return(:body => '', :status => 204, :headers => { :content_type => "application/json; charset=utf-8"})
113
+ end
114
+
115
+ it "should fail to delete without 'user/repo' parameters" do
116
+ github.user, github.repo = nil, nil
117
+ expect { github.repos.delete_download }.to raise_error(ArgumentError)
118
+ end
119
+
120
+ it "should fail to delete resource without 'download_id'" do
121
+ expect {
122
+ github.repos.delete_download user, repo
123
+ }.to raise_error(ArgumentError)
124
+ end
125
+
126
+ it "should delete the resource" do
127
+ github.repos.delete_download user, repo, download_id
128
+ a_delete("/repos/#{user}/#{repo}/downloads/#{download_id}").should have_been_made
129
+ end
130
+ end
131
+
132
+ context "failed to edit resource" do
133
+ before do
134
+ stub_delete("/repos/#{user}/#{repo}/downloads/#{download_id}").
135
+ to_return(:body => fixture("repos/download.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
136
+
137
+ end
138
+
139
+ it "should fail to find resource" do
140
+ expect {
141
+ github.repos.delete_download user, repo, download_id
142
+ }.to raise_error(Github::ResourceNotFound)
143
+ end
144
+ end
145
+ end # delete_download
146
+
147
+ describe "create_download" do
148
+ let(:inputs) { {:name => 'new_file.jpg', :size => 114034, :description => "Latest release", :content_type => 'text/plain'} }
149
+
150
+ context "resouce created" do
151
+ before do
152
+ stub_post("/repos/#{user}/#{repo}/downloads").with(inputs).
153
+ to_return(:body => fixture('repos/download_s3.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
154
+
155
+ end
156
+
157
+ it "should fail to create resource if 'name' input is missing" do
158
+ expect {
159
+ github.repos.create_download user, repo, inputs.except(:name)
160
+ }.to raise_error(ArgumentError)
161
+ end
162
+
163
+ it "should failt to create resource if 'size' input is missing" do
164
+ expect {
165
+ github.repos.create_download user, repo, inputs.except(:size)
166
+ }.to raise_error(ArgumentError)
167
+ end
168
+
169
+ it "should create resource successfully" do
170
+ github.repos.create_download user, repo, inputs
171
+ a_post("/repos/#{user}/#{repo}/downloads").with(inputs).should have_been_made
172
+ end
173
+
174
+ it "should return the resource" do
175
+ download = github.repos.create_download user, repo, inputs
176
+ download.should be_a Hashie::Mash
177
+ end
178
+
179
+ it "should get the download information" do
180
+ download = github.repos.create_download user, repo, inputs
181
+ download.name.should == 'new_file.jpg'
182
+ end
183
+ end
184
+
185
+ context "failed to create resource" do
186
+ before do
187
+ stub_post("/repos/#{user}/#{repo}/downloads").with(inputs).
188
+ to_return(:body => fixture('repos/download_s3.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
189
+
190
+ end
191
+
192
+ it "should faile to retrieve resource" do
193
+ expect {
194
+ github.repos.create_download(user, repo, inputs)
195
+ }.to raise_error(Github::ResourceNotFound)
196
+ end
197
+ end
198
+ end # create_download
199
+
200
+ describe 'upload' do
201
+ let(:inputs) { {:name => 'new_file.jpg', :size => 114034, :description => "Latest release", :content_type => 'text/plain'} }
202
+ let(:resource) { Hashie::Mash.new ::JSON.parse(fixture('repos/download_s3.json').read) }
203
+ let(:file) { 'filename' }
204
+
205
+ context 'resource uploaded' do
206
+ before do
207
+ stub_post('', 'https://github.s3.amazonaws.com/').with(resource).
208
+ to_return(:body => '', :status => 200, :headers => {})
209
+ end
210
+
211
+ it "should fail if resource is of incorrect type" do
212
+ expect { github.repos.upload file, file }.to raise_error(ArgumentError)
213
+ end
214
+
215
+ it "should upload resource successfully" do
216
+ github.repos.upload resource, file
217
+ a_post('', 'https://github.s3.amazonaws.com').with(resource).should have_been_made
218
+ end
219
+
220
+ end
221
+ context 'failed to upload resource' do
222
+ before do
223
+ stub_post('', 'https://github.s3.amazonaws.com/').with(resource).
224
+ to_return(:body => '', :status => 404, :headers => {})
225
+ end
226
+
227
+ it "should faile to retrieve resource" do
228
+ expect {
229
+ github.repos.upload resource, file
230
+ }.to raise_error(Github::ResourceNotFound)
231
+ end
232
+
233
+ end
234
+ end # upload
235
+
236
+ end # Github::Repos::Downloads
@@ -19,7 +19,7 @@ describe Github::Repos::Hooks do
19
19
  end
20
20
 
21
21
  it "should get the resources" do
22
- github.repos.hooks(user, repo)
22
+ github.repos.hooks user, repo
23
23
  a_get("/repos/#{user}/#{repo}/hooks").should have_been_made
24
24
  end
25
25
 
@@ -222,7 +222,7 @@ describe Github::Repos::Hooks do
222
222
  end
223
223
  end # edit_hook
224
224
 
225
- describe "delete_key" do
225
+ describe "delete_hook" do
226
226
  let(:hook_id) { 1 }
227
227
 
228
228
  context "resource edited successfully" do
@@ -238,7 +238,7 @@ describe Github::Repos::Hooks do
238
238
 
239
239
  it "should fail to delete resource without 'hook_id'" do
240
240
  expect {
241
- github.repos.edit_hook user, repo
241
+ github.repos.delete_hook user, repo
242
242
  }.to raise_error(ArgumentError)
243
243
  end
244
244
 
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
5
 
6
6
  require 'rspec'
7
+ require 'json'
7
8
  require 'webmock/rspec'
8
9
  require 'github_api'
9
10
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Piotr Murach
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-10-29 00:00:00 +01:00
17
+ date: 2011-11-26 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -198,6 +198,7 @@ files:
198
198
  - lib/github_api/authorization.rb
199
199
  - lib/github_api/cache_control.rb
200
200
  - lib/github_api/client.rb
201
+ - lib/github_api/compatibility.rb
201
202
  - lib/github_api/configuration.rb
202
203
  - lib/github_api/connection.rb
203
204
  - lib/github_api/core_ext/array.rb
@@ -245,6 +246,12 @@ files:
245
246
  - lib/github_api/users.rb
246
247
  - lib/github_api/version.rb
247
248
  - lib/github_api.rb
249
+ - spec/fixtures/orgs/members.json
250
+ - spec/fixtures/orgs/org.json
251
+ - spec/fixtures/orgs/orgs.json
252
+ - spec/fixtures/orgs/team.json
253
+ - spec/fixtures/orgs/team_repos.json
254
+ - spec/fixtures/orgs/teams.json
248
255
  - spec/fixtures/repos/branches.json
249
256
  - spec/fixtures/repos/collaborators.json
250
257
  - spec/fixtures/repos/commit.json
@@ -252,6 +259,9 @@ files:
252
259
  - spec/fixtures/repos/commit_comments.json
253
260
  - spec/fixtures/repos/commits.json
254
261
  - spec/fixtures/repos/contributors.json
262
+ - spec/fixtures/repos/download.json
263
+ - spec/fixtures/repos/download_s3.json
264
+ - spec/fixtures/repos/downloads.json
255
265
  - spec/fixtures/repos/fork.json
256
266
  - spec/fixtures/repos/forks.json
257
267
  - spec/fixtures/repos/hook.json