github_api 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/features/gists/comments.feature +8 -8
  2. data/lib/github_api/gists/comments.rb +15 -15
  3. data/lib/github_api/repos.rb +3 -1
  4. data/lib/github_api/repos/comments.rb +6 -5
  5. data/lib/github_api/requestable.rb +67 -0
  6. data/lib/github_api/version.rb +1 -1
  7. data/spec/github/activity/activity_spec.rb +2 -0
  8. data/spec/github/activity/events/issue_spec.rb +8 -20
  9. data/spec/github/activity/events/network_spec.rb +8 -20
  10. data/spec/github/activity/events/org_spec.rb +8 -18
  11. data/spec/github/activity/events/performed_spec.rb +13 -31
  12. data/spec/github/activity/events/public_spec.rb +7 -18
  13. data/spec/github/activity/events/received_spec.rb +12 -31
  14. data/spec/github/activity/events/repository_spec.rb +8 -20
  15. data/spec/github/activity/events/user_org_spec.rb +8 -20
  16. data/spec/github/activity/notifications/list_spec.rb +4 -11
  17. data/spec/github/activity/starring/list_spec.rb +8 -21
  18. data/spec/github/activity/watching/list_spec.rb +4 -18
  19. data/spec/github/gists/comments_spec.rb +24 -23
  20. data/spec/github/git_data/blobs/create_spec.rb +62 -0
  21. data/spec/github/git_data/blobs/get_spec.rb +49 -0
  22. data/spec/github/git_data/blobs_spec.rb +0 -116
  23. data/spec/github/repos/branch_spec.rb +3 -9
  24. data/spec/github/repos/branches_spec.rb +5 -13
  25. data/spec/github/repos/collaborators/add_spec.rb +37 -0
  26. data/spec/github/repos/collaborators/get_spec.rb +51 -0
  27. data/spec/github/repos/collaborators/list_spec.rb +51 -0
  28. data/spec/github/repos/collaborators/remove_spec.rb +37 -0
  29. data/spec/github/repos/collaborators_spec.rb +1 -176
  30. data/spec/github/repos/comments/create_spec.rb +2 -33
  31. data/spec/github/repos/comments/delete_spec.rb +3 -9
  32. data/spec/github/repos/comments/get_spec.rb +3 -9
  33. data/spec/github/repos/comments/list_spec.rb +16 -40
  34. data/spec/github/repos/comments/update_spec.rb +5 -11
  35. data/spec/github/repos/commits/get_spec.rb +3 -9
  36. data/spec/github/repos/commits/list_spec.rb +9 -20
  37. data/spec/github/repos/contributors_spec.rb +5 -13
  38. data/spec/github/repos/delete_spec.rb +3 -8
  39. data/spec/github/repos/downloads/create_spec.rb +3 -9
  40. data/spec/github/repos/downloads/delete_spec.rb +3 -9
  41. data/spec/github/repos/downloads/get_spec.rb +5 -12
  42. data/spec/github/repos/downloads/list_spec.rb +8 -18
  43. data/spec/github/repos/edit_spec.rb +3 -9
  44. data/spec/github/repos/forks/create_spec.rb +3 -9
  45. data/spec/github/repos/forks/list_spec.rb +8 -21
  46. data/spec/github/repos/get_spec.rb +3 -9
  47. data/spec/github/repos/list_spec.rb +8 -7
  48. data/spec/github/repos_spec.rb +2 -0
  49. data/spec/shared/api_interface_behaviour.rb +15 -0
  50. data/spec/shared/array_of_resources_behaviour.rb +15 -0
  51. data/spec/shared/request_failure_behaviour.rb +16 -0
  52. data/spec/spec_helper.rb +1 -1
  53. metadata +43 -33
@@ -26,15 +26,8 @@ describe Github::Activity::Events, '#received' do
26
26
  a_get(request_path).should have_been_made
27
27
  end
28
28
 
29
- it "should return array of resources" do
30
- events = subject.received user
31
- events.should be_an Array
32
- events.should have(1).items
33
- end
34
-
35
- it "should be a mash type" do
36
- events = subject.received user
37
- events.first.should be_a Hashie::Mash
29
+ it_should_behave_like 'an array of resources' do
30
+ let(:requestable) { subject.received user }
38
31
  end
39
32
 
40
33
  it "should get event information" do
@@ -43,8 +36,9 @@ describe Github::Activity::Events, '#received' do
43
36
  end
44
37
 
45
38
  it "should yield to a block" do
46
- subject.should_receive(:received).with(user).and_yield('web')
47
- subject.received(user) { |param| 'web' }
39
+ yielded = []
40
+ result = subject.received(user) { |obj| yielded << obj }
41
+ yielded.should == result
48
42
  end
49
43
  end
50
44
 
@@ -56,15 +50,8 @@ describe Github::Activity::Events, '#received' do
56
50
  a_get(request_path).should have_been_made
57
51
  end
58
52
 
59
- it "should return array of resources" do
60
- events = subject.received user, :public => true
61
- events.should be_an Array
62
- events.should have(1).items
63
- end
64
-
65
- it "should be a mash type" do
66
- events = subject.received user, :public => true
67
- events.first.should be_a Hashie::Mash
53
+ it_should_behave_like 'an array of resources' do
54
+ let(:requestable) { subject.received user, :public => true }
68
55
  end
69
56
 
70
57
  it "should get event information" do
@@ -73,19 +60,13 @@ describe Github::Activity::Events, '#received' do
73
60
  end
74
61
 
75
62
  it "should yield to a block" do
76
- subject.should_receive(:received).with(user).and_yield('web')
77
- subject.received(user) { |param| 'web' }
63
+ yielded = []
64
+ result = subject.received(user, :public => true) { |obj| yielded << obj }
65
+ yielded.should == result
78
66
  end
79
67
  end
80
68
 
81
- context "resource not found" do
82
- let(:body) { '' }
83
- let(:status) { [404, "Not Found"] }
84
-
85
- it "should return 404 with a message 'Not Found'" do
86
- expect {
87
- subject.received user
88
- }.to raise_error(Github::Error::NotFound)
89
- end
69
+ it_should_behave_like 'request failure' do
70
+ let(:requestable) { subject.received user }
90
71
  end
91
72
  end # received
@@ -30,15 +30,8 @@ describe Github::Activity::Events, '#repository' do
30
30
  a_get(request_path).should have_been_made
31
31
  end
32
32
 
33
- it "should return array of resources" do
34
- events = subject.repository user, repo
35
- events.should be_an Array
36
- events.should have(1).items
37
- end
38
-
39
- it "should be a mash type" do
40
- events = subject.repository user, repo
41
- events.first.should be_a Hashie::Mash
33
+ it_should_behave_like 'an array of resources' do
34
+ let(:requestable) { subject.repository user, repo }
42
35
  end
43
36
 
44
37
  it "should get event information" do
@@ -47,19 +40,14 @@ describe Github::Activity::Events, '#repository' do
47
40
  end
48
41
 
49
42
  it "should yield to a block" do
50
- subject.should_receive(:repository).with(user, repo).and_yield('web')
51
- subject.repository(user, repo) { |param| 'web' }
43
+ yielded = []
44
+ result = subject.repository(user, repo) { |obj| yielded << obj }
45
+ yielded.should == result
52
46
  end
53
47
  end
54
48
 
55
- context "resource not found" do
56
- let(:body) { '' }
57
- let(:status) { [404, "Not Found"] }
58
-
59
- it "should return 404 with a message 'Not Found'" do
60
- expect {
61
- subject.repository user, repo
62
- }.to raise_error(Github::Error::NotFound)
63
- end
49
+ it_should_behave_like 'request failure' do
50
+ let(:requestable) { subject.repository user, repo }
64
51
  end
52
+
65
53
  end # repository
@@ -28,15 +28,8 @@ describe Github::Activity::Events, '#user_org' do
28
28
  a_get(request_path).should have_been_made
29
29
  end
30
30
 
31
- it "should return array of resources" do
32
- events = subject.user_org user, org
33
- events.should be_an Array
34
- events.should have(1).items
35
- end
36
-
37
- it "should be a mash type" do
38
- events = subject.user_org user, org
39
- events.first.should be_a Hashie::Mash
31
+ it_should_behave_like 'an array of resources' do
32
+ let(:requestable) { subject.user_org user, org }
40
33
  end
41
34
 
42
35
  it "should get event information" do
@@ -45,19 +38,14 @@ describe Github::Activity::Events, '#user_org' do
45
38
  end
46
39
 
47
40
  it "should yield to a block" do
48
- subject.should_receive(:user_org).with(user, org).and_yield('web')
49
- subject.user_org(user, org) { |param| 'web' }
41
+ yielded = []
42
+ result = subject.user_org(user, org) { |obj| yielded << obj }
43
+ yielded.should == result
50
44
  end
51
45
  end
52
46
 
53
- context "resource not found" do
54
- let(:body) { '' }
55
- let(:status) { [404, "Not Found"] }
56
-
57
- it "should return 404 with a message 'Not Found'" do
58
- expect {
59
- subject.user_org user, org
60
- }.to raise_error(Github::Error::NotFound)
61
- end
47
+ it_should_behave_like 'request failure' do
48
+ let(:requestable) { subject.user_org user, org }
62
49
  end
50
+
63
51
  end # user_org
@@ -35,10 +35,8 @@ describe Github::Activity::Notifications, '#list' do
35
35
  should have_been_made
36
36
  end
37
37
 
38
- it "should return array of resources" do
39
- notifications = subject.list
40
- notifications.should be_an Array
41
- notifications.should have(1).items
38
+ it_should_behave_like 'an array of resources' do
39
+ let(:requestable) { subject.list }
42
40
  end
43
41
 
44
42
  it "should get resource information" do
@@ -51,13 +49,8 @@ describe Github::Activity::Notifications, '#list' do
51
49
  subject.list { |repo| 'octocat' }
52
50
  end
53
51
 
54
- context "resource not found for a user" do
55
- let(:body) { '' }
56
- let(:status) { [404, "Not Found"] }
57
-
58
- it "should return 404 with a message 'Not Found'" do
59
- expect { subject.list }.to raise_error(Github::Error::NotFound)
60
- end
52
+ it_should_behave_like 'request failure' do
53
+ let(:requestable) { subject.list }
61
54
  end
62
55
  end
63
56
 
@@ -25,8 +25,9 @@ describe Github::Activity::Starring, '#list' do
25
25
  end
26
26
 
27
27
  it "should yield iterator if block given" do
28
- subject.should_receive(:list).with(user, repo).and_yield('github')
29
- subject.list(user, repo) { |param| 'github' }
28
+ yielded = []
29
+ result = subject.list(user, repo) { |obj| yielded << obj }
30
+ yielded.should == result
30
31
  end
31
32
 
32
33
  it "should get the resources" do
@@ -34,31 +35,17 @@ describe Github::Activity::Starring, '#list' do
34
35
  a_get(request_path).should have_been_made
35
36
  end
36
37
 
37
- it "should return array of resources" do
38
- stargazers = subject.list user, repo
39
- stargazers.should be_an Array
40
- stargazers.should have(1).items
41
- end
42
-
43
- it "should return result of mash type" do
44
- stargazers = subject.list user, repo
45
- stargazers.first.should be_a Hashie::Mash
38
+ it_should_behave_like 'an array of resources' do
39
+ let(:requestable) { subject.list user, repo }
46
40
  end
47
41
 
48
42
  it "should get watcher information" do
49
43
  stargazers = subject.list user, repo
50
44
  stargazers.first.login.should == 'octocat'
51
45
  end
46
+ end
52
47
 
53
- context "fail to find resource" do
54
- let(:body) { '' }
55
- let(:status) { 404 }
56
-
57
- it "should return 404 not found message" do
58
- expect {
59
- subject.list user, repo
60
- }.to raise_error(Github::Error::NotFound)
61
- end
62
- end
48
+ it_should_behave_like 'request failure' do
49
+ let(:requestable) { subject.list user, repo }
63
50
  end
64
51
  end # list
@@ -30,15 +30,8 @@ describe Github::Activity::Watching, '#list' do
30
30
  a_get(request_path).should have_been_made
31
31
  end
32
32
 
33
- it "should return array of resources" do
34
- watchers = subject.list user, repo
35
- watchers.should be_an Array
36
- watchers.should have(1).items
37
- end
38
-
39
- it "should return result of mash type" do
40
- watchers = subject.list user, repo
41
- watchers.first.should be_a Hashie::Mash
33
+ it_should_behave_like 'an array of resources' do
34
+ let(:requestable) { subject.list user, repo }
42
35
  end
43
36
 
44
37
  it "should get watcher information" do
@@ -46,14 +39,7 @@ describe Github::Activity::Watching, '#list' do
46
39
  watchers.first.login.should == 'octocat'
47
40
  end
48
41
 
49
- context "fail to find resource" do
50
- let(:body) { '' }
51
- let(:status) { 404 }
52
-
53
- it "should return 404 not found message" do
54
- expect {
55
- subject.list user, repo
56
- }.to raise_error(Github::Error::NotFound)
57
- end
42
+ it_should_behave_like 'request failure' do
43
+ let(:requestable) { subject.list user, repo }
58
44
  end
59
45
  end # list
@@ -70,36 +70,36 @@ describe Github::Gists::Comments do
70
70
 
71
71
  context 'resource found' do
72
72
  before do
73
- stub_get("/gists/comments/#{comment_id}").
73
+ stub_get("/gists/#{gist_id}/comments/#{comment_id}").
74
74
  to_return(:body => fixture('gists/comment.json'),
75
75
  :status => 200,
76
76
  :headers => {:content_type => "application/json; charset=utf-8"})
77
77
  end
78
78
 
79
79
  it "should fail to get resource without comment id" do
80
- expect { github.gists.comments.get nil }.to raise_error(ArgumentError)
80
+ expect { github.gists.comments.get nil, nil }.to raise_error(ArgumentError)
81
81
  end
82
82
 
83
83
  it "should get the resource" do
84
- github.gists.comments.get comment_id
85
- a_get("/gists/comments/#{comment_id}").should have_been_made
84
+ github.gists.comments.get gist_id, comment_id
85
+ a_get("/gists/#{gist_id}/comments/#{comment_id}").should have_been_made
86
86
  end
87
87
 
88
88
  it "should get comment information" do
89
- comment = github.gists.comments.get comment_id
89
+ comment = github.gists.comments.get gist_id, comment_id
90
90
  comment.id.should eq comment_id
91
91
  comment.user.login.should == 'octocat'
92
92
  end
93
93
 
94
94
  it "should return mash" do
95
- comment = github.gists.comments.get comment_id
95
+ comment = github.gists.comments.get gist_id, comment_id
96
96
  comment.should be_a Hashie::Mash
97
97
  end
98
98
  end
99
99
 
100
100
  context 'resource not found' do
101
101
  before do
102
- stub_get("/gists/comments/#{comment_id}").
102
+ stub_get("/gists/#{gist_id}/comments/#{comment_id}").
103
103
  to_return(:body => fixture('gists/comment.json'),
104
104
  :status => 404,
105
105
  :headers => {:content_type => "application/json; charset=utf-8"})
@@ -107,7 +107,7 @@ describe Github::Gists::Comments do
107
107
 
108
108
  it "should fail to retrive resource" do
109
109
  expect {
110
- github.gists.comments.get comment_id
110
+ github.gists.comments.get gist_id, comment_id
111
111
  }.to raise_error(Github::Error::NotFound)
112
112
  end
113
113
  end
@@ -115,7 +115,8 @@ describe Github::Gists::Comments do
115
115
 
116
116
  describe "#create" do
117
117
  let(:inputs) {
118
- { "body" =>"Just commenting for the sake of commenting", "unrelated" => true }
118
+ { "body" =>"Just commenting for the sake of commenting",
119
+ "unrelated" => true }
119
120
  }
120
121
 
121
122
  context "resouce created" do
@@ -172,7 +173,7 @@ describe Github::Gists::Comments do
172
173
 
173
174
  context "resouce edited" do
174
175
  before do
175
- stub_patch("/gists/comments/#{comment_id}").
176
+ stub_patch("/gists/#{gist_id}/comments/#{comment_id}").
176
177
  with(inputs.except('unrelated')).
177
178
  to_return(:body => fixture('gists/comment.json'),
178
179
  :status => 201,
@@ -181,29 +182,29 @@ describe Github::Gists::Comments do
181
182
 
182
183
  it "should fail to create resource if 'content' input is missing" do
183
184
  expect {
184
- github.gists.comments.edit comment_id, inputs.except('body')
185
+ github.gists.comments.edit gist_id, comment_id, inputs.except('body')
185
186
  }.to raise_error(Github::Error::RequiredParams)
186
187
  end
187
188
 
188
189
  it "should create resource successfully" do
189
- github.gists.comments.edit comment_id, inputs
190
- a_patch("/gists/comments/#{comment_id}").with(inputs).should have_been_made
190
+ github.gists.comments.edit gist_id, comment_id, inputs
191
+ a_patch("/gists/#{gist_id}/comments/#{comment_id}").with(inputs).should have_been_made
191
192
  end
192
193
 
193
194
  it "should return the resource" do
194
- comment = github.gists.comments.edit comment_id, inputs
195
+ comment = github.gists.comments.edit gist_id, comment_id, inputs
195
196
  comment.should be_a Hashie::Mash
196
197
  end
197
198
 
198
199
  it "should get the comment information" do
199
- comment = github.gists.comments.edit comment_id, inputs
200
+ comment = github.gists.comments.edit gist_id, comment_id, inputs
200
201
  comment.user.login.should == 'octocat'
201
202
  end
202
203
  end
203
204
 
204
205
  context "failed to create resource" do
205
206
  before do
206
- stub_patch("/gists/comments/#{comment_id}").with(inputs).
207
+ stub_patch("/gists/#{gist_id}/comments/#{comment_id}").with(inputs).
207
208
  to_return(:body => fixture('gists/comment.json'),
208
209
  :status => 404,
209
210
  :headers => {:content_type => "application/json; charset=utf-8"})
@@ -211,7 +212,7 @@ describe Github::Gists::Comments do
211
212
 
212
213
  it "should faile to retrieve resource" do
213
214
  expect {
214
- github.gists.comments.edit comment_id, inputs
215
+ github.gists.comments.edit gist_id, comment_id, inputs
215
216
  }.to raise_error(Github::Error::NotFound)
216
217
  end
217
218
  end
@@ -220,25 +221,25 @@ describe Github::Gists::Comments do
220
221
  describe "#delete" do
221
222
  context "resouce deleted" do
222
223
  before do
223
- stub_delete("/gists/comments/#{comment_id}").
224
+ stub_delete("/gists/#{gist_id}/comments/#{comment_id}").
224
225
  to_return(:body => '',
225
226
  :status => 204,
226
227
  :headers => {:content_type => "application/json; charset=utf-8"})
227
228
  end
228
229
 
229
230
  it "should fail to create resource if 'content' input is missing" do
230
- expect { github.gists.comments.delete nil }.to raise_error(ArgumentError)
231
+ expect { github.gists.comments.delete gist_id, nil }.to raise_error(ArgumentError)
231
232
  end
232
233
 
233
234
  it "should create resource successfully" do
234
- github.gists.comments.delete comment_id
235
- a_delete("/gists/comments/#{comment_id}").should have_been_made
235
+ github.gists.comments.delete gist_id, comment_id
236
+ a_delete("/gists/#{gist_id}/comments/#{comment_id}").should have_been_made
236
237
  end
237
238
  end
238
239
 
239
240
  context "failed to create resource" do
240
241
  before do
241
- stub_delete("/gists/comments/#{comment_id}").
242
+ stub_delete("/gists/#{gist_id}/comments/#{comment_id}").
242
243
  to_return(:body => fixture('gists/comment.json'),
243
244
  :status => 404,
244
245
  :headers => {:content_type => "application/json; charset=utf-8"})
@@ -246,7 +247,7 @@ describe Github::Gists::Comments do
246
247
 
247
248
  it "should faile to retrieve resource" do
248
249
  expect {
249
- github.gists.comments.delete comment_id
250
+ github.gists.comments.delete gist_id, comment_id
250
251
  }.to raise_error(Github::Error::NotFound)
251
252
  end
252
253
  end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::GitData::Blobs, '#create' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:sha) { "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15" }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/git/blobs" }
10
+ let(:inputs) {
11
+ {
12
+ "content" => "Content of the blob",
13
+ "encoding" => "utf-8",
14
+ "unrelated" => 'giberrish'
15
+ }
16
+ }
17
+
18
+ before {
19
+ stub_post(request_path).with(inputs.except('unrelated')).
20
+ to_return(:body => body, :status => status,
21
+ :headers => {:content_type => "application/json; charset=utf-8"})
22
+ }
23
+
24
+ after { reset_authentication_for(subject) }
25
+
26
+ context "resouce created" do
27
+ let(:body) { fixture('git_data/blob_sha.json') }
28
+ let(:status) { 201 }
29
+
30
+ it "should fail to create resource if 'content' input is missing" do
31
+ expect {
32
+ subject.create user, repo, inputs.except('content')
33
+ }.to raise_error(Github::Error::RequiredParams)
34
+ end
35
+
36
+ it "should fail to create resource if 'encoding' input is missing" do
37
+ expect {
38
+ subject.create user, repo, inputs.except('encoding')
39
+ }.to raise_error(Github::Error::RequiredParams)
40
+ end
41
+
42
+ it "should create resource successfully" do
43
+ subject.create user, repo, inputs
44
+ a_post(request_path).with(inputs).should have_been_made
45
+ end
46
+
47
+ it "should return the resource" do
48
+ blob_sha = subject.create user, repo, inputs
49
+ blob_sha.should be_a Hashie::Mash
50
+ end
51
+
52
+ it "should get the blob information" do
53
+ blob_sha = subject.create user, repo, inputs
54
+ blob_sha.sha.should == sha
55
+ end
56
+ end
57
+
58
+ it_should_behave_like 'request failure' do
59
+ let(:requestable) { subject.create user, repo, inputs }
60
+ end
61
+
62
+ end # create