github_api 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/README.md +2 -1
  2. data/features/README.rdoc +4 -4
  3. data/features/cassettes/gitignore/get.yml +60 -0
  4. data/features/cassettes/gitignore/get_raw.yml +224 -0
  5. data/features/cassettes/gitignore/list.yml +67 -0
  6. data/features/cassettes/issues/comments/get.yml +71 -0
  7. data/features/cassettes/issues/comments/list_issue.yml +82 -0
  8. data/features/cassettes/issues/comments/list_repo.yml +266 -0
  9. data/features/cassettes/pull_requests/comments/get.yml +159 -0
  10. data/features/cassettes/pull_requests/comments/list_pull.yml +54 -0
  11. data/features/cassettes/pull_requests/comments/list_repo.yml +54 -0
  12. data/features/cassettes/repos/list_repos.yml +129 -0
  13. data/features/cassettes/users/all.yml +256 -0
  14. data/features/gitignore.feature +37 -0
  15. data/features/issues/comments.feature +37 -0
  16. data/features/pull_requests/comments.feature +27 -0
  17. data/features/repos.feature +8 -0
  18. data/features/step_definitions/common_steps.rb +2 -0
  19. data/features/users.feature +8 -0
  20. data/lib/github_api.rb +1 -0
  21. data/lib/github_api/client.rb +5 -0
  22. data/lib/github_api/git_data/tags.rb +4 -4
  23. data/lib/github_api/gitignore.rb +56 -0
  24. data/lib/github_api/issues/comments.rb +23 -9
  25. data/lib/github_api/pull_requests/comments.rb +24 -6
  26. data/lib/github_api/repos.rb +14 -1
  27. data/lib/github_api/repos/keys.rb +4 -4
  28. data/lib/github_api/users.rb +21 -0
  29. data/lib/github_api/users/keys.rb +6 -6
  30. data/lib/github_api/version.rb +1 -1
  31. data/spec/fixtures/gitignore/template.json +4 -0
  32. data/spec/fixtures/gitignore/template_raw +1 -0
  33. data/spec/fixtures/gitignore/templates.json +9 -0
  34. data/spec/fixtures/users/users.json +9 -0
  35. data/spec/github/activity/notifications/mark_spec.rb +1 -1
  36. data/spec/github/activity/starring/starring_spec.rb +2 -2
  37. data/spec/github/activity/watching/watching_spec.rb +2 -2
  38. data/spec/github/git_data/commits/create_spec.rb +75 -0
  39. data/spec/github/git_data/commits/get_spec.rb +50 -0
  40. data/spec/github/git_data/commits_spec.rb +1 -126
  41. data/spec/github/git_data/references/create_spec.rb +67 -0
  42. data/spec/github/git_data/references/delete_spec.rb +38 -0
  43. data/spec/github/git_data/references/get_spec.rb +54 -0
  44. data/spec/github/git_data/references/list_spec.rb +77 -0
  45. data/spec/github/git_data/references/update_spec.rb +62 -0
  46. data/spec/github/git_data/references_spec.rb +1 -298
  47. data/spec/github/git_data/tags/create_spec.rb +61 -0
  48. data/spec/github/git_data/tags/get_spec.rb +48 -0
  49. data/spec/github/git_data/tags_spec.rb +0 -108
  50. data/spec/github/git_data/trees/create_spec.rb +62 -0
  51. data/spec/github/git_data/trees/get_spec.rb +69 -0
  52. data/spec/github/git_data/trees_spec.rb +0 -133
  53. data/spec/github/gitignore/get_spec.rb +54 -0
  54. data/spec/github/gitignore/list_spec.rb +42 -0
  55. data/spec/github/issues/comments_spec.rb +46 -11
  56. data/spec/github/pull_requests/comments_spec.rb +46 -11
  57. data/spec/github/pull_requests_spec.rb +3 -3
  58. data/spec/github/repos/contents/archive_spec.rb +26 -0
  59. data/spec/github/repos/contents/get_spec.rb +30 -0
  60. data/spec/github/repos/contents/readme_spec.rb +30 -0
  61. data/spec/github/repos/hooks/create_spec.rb +68 -0
  62. data/spec/github/repos/hooks/delete_spec.rb +40 -0
  63. data/spec/github/repos/hooks/edit_spec.rb +77 -0
  64. data/spec/github/repos/hooks/get_spec.rb +49 -0
  65. data/spec/github/repos/hooks/list_spec.rb +54 -0
  66. data/spec/github/repos/hooks/test_spec.rb +40 -0
  67. data/spec/github/repos/hooks_spec.rb +2 -337
  68. data/spec/github/repos/keys/create_spec.rb +50 -0
  69. data/spec/github/repos/keys/delete_spec.rb +40 -0
  70. data/spec/github/repos/keys/edit_spec.rb +40 -0
  71. data/spec/github/repos/keys/get_spec.rb +43 -0
  72. data/spec/github/repos/keys/list_spec.rb +52 -0
  73. data/spec/github/repos/keys_spec.rb +2 -213
  74. data/spec/github/repos/list_spec.rb +19 -3
  75. data/spec/github/repos/merging/merge_spec.rb +58 -0
  76. data/spec/github/repos/pub_sub_hubbub_spec.rb +16 -14
  77. data/spec/github/repos/statuses/create_spec.rb +54 -0
  78. data/spec/github/repos/statuses/list_spec.rb +53 -0
  79. data/spec/github/repos/statuses_spec.rb +1 -114
  80. data/spec/github/users/emails/add_spec.rb +33 -0
  81. data/spec/github/users/emails/delete_spec.rb +33 -0
  82. data/spec/github/users/emails/list_spec.rb +52 -0
  83. data/spec/github/users/followers/list_spec.rb +68 -0
  84. data/spec/github/users/followers_spec.rb +0 -70
  85. data/spec/github/users/get_spec.rb +66 -0
  86. data/spec/github/users/keys/create_spec.rb +51 -0
  87. data/spec/github/users/keys/delete_spec.rb +37 -0
  88. data/spec/github/users/keys/get_spec.rb +50 -0
  89. data/spec/github/users/keys/list_spec.rb +50 -0
  90. data/spec/github/users/keys/update_spec.rb +56 -0
  91. data/spec/github/users/list_spec.rb +45 -0
  92. data/spec/github/users/update_spec.rb +56 -0
  93. metadata +96 -43
  94. data/spec/github/repos/contents_spec.rb +0 -65
  95. data/spec/github/repos/merging_spec.rb +0 -71
  96. data/spec/github/repos/starring_spec.rb +0 -4
  97. data/spec/github/users/emails_spec.rb +0 -110
  98. data/spec/github/users/keys_spec.rb +0 -256
  99. data/spec/github/users_spec.rb +0 -128
@@ -1,65 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Github::Repos::Contents do
6
- let(:github) { Github.new }
7
- let(:user) { 'octokit' }
8
- let(:repo) { 'github' }
9
-
10
- after { reset_authentication_for(github) }
11
-
12
- context "#readme" do
13
- before do
14
- stub_get("/repos/#{user}/#{repo}/readme").
15
- to_return(:body => fixture('repos/readme.json'), :status => 200,
16
- :headers => {:content_type => "application/json; charset=utf-8"})
17
- end
18
-
19
- it "should get the resources" do
20
- github.repos.contents.readme user, repo
21
- a_get("/repos/#{user}/#{repo}/readme").should have_been_made
22
- end
23
-
24
- it "should get readme information" do
25
- readme= github.repos.contents.readme user, repo
26
- readme.name.should == 'README.md'
27
- end
28
- end
29
-
30
- context "#get" do
31
- let(:path) { 'README.md' }
32
-
33
- before do
34
- stub_get("/repos/#{user}/#{repo}/contents/#{path}").
35
- to_return(:body => fixture('repos/content.json'), :status => 200,
36
- :headers => {:content_type => "application/json; charset=utf-8"})
37
- end
38
-
39
- it "should get the resources" do
40
- github.repos.contents.get user, repo, path
41
- a_get("/repos/#{user}/#{repo}/contents/#{path}").should have_been_made
42
- end
43
-
44
- it "should get repository information" do
45
- content = github.repos.contents.get user, repo, path
46
- content.name.should == 'README.md'
47
- end
48
- end
49
-
50
- context "#users" do
51
- let(:archive_format) { 'tarball' }
52
- let(:ref) { 'master' }
53
-
54
- before do
55
- stub_get("/repos/#{user}/#{repo}/#{archive_format}/#{ref}").
56
- to_return(:body => '', :status => 302)
57
- end
58
-
59
- it "should get the resources" do
60
- github.repos.contents.archive user, repo, :archive_format => archive_format, :ref => ref
61
- a_get("/repos/#{user}/#{repo}/#{archive_format}/#{ref}").should have_been_made
62
- end
63
- end
64
-
65
- end # Github::Repos::Contents
@@ -1,71 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Github::Repos::Merging do
4
- let(:github) { Github.new }
5
- let(:user) { 'peter-murach' }
6
- let(:repo) { 'github' }
7
-
8
- after { github.user, github.repo, github.oauth_token = nil, nil, nil }
9
-
10
- describe "#merge" do
11
- let(:inputs) do
12
- {
13
- "base" => "master",
14
- "head" => "cool_feature",
15
- "commit_message" => "Shipped cool_feature!"
16
- }
17
- end
18
-
19
- context "resouce merged" do
20
- before do
21
- stub_post("/repos/#{user}/#{repo}/merges").with(inputs).
22
- to_return(:body => fixture('repos/merge.json'),
23
- :status => 201,
24
- :headers => {:content_type => "application/json; charset=utf-8"})
25
- end
26
-
27
- it "should fail to merge resource if 'base' input is missing" do
28
- expect {
29
- github.repos.merging.merge user, repo, inputs.except('base')
30
- }.to raise_error(Github::Error::RequiredParams)
31
- end
32
-
33
- it "should fail to create resource if 'head' input is missing" do
34
- expect {
35
- github.repos.merging.merge user, repo, inputs.except('head')
36
- }.to raise_error(Github::Error::RequiredParams)
37
- end
38
-
39
- it "should merge resource successfully" do
40
- github.repos.merging.merge user, repo, inputs
41
- a_post("/repos/#{user}/#{repo}/merges").with(inputs).should have_been_made
42
- end
43
-
44
- it "should return the resource" do
45
- merge = github.repos.merging.merge user, repo, inputs
46
- merge.should be_a Hashie::Mash
47
- end
48
-
49
- it "should get the commit comment information" do
50
- merge = github.repos.merging.merge user, repo, inputs
51
- merge.commit.author.login.should == 'octocat'
52
- end
53
- end
54
-
55
- context "failed to create resource" do
56
- before do
57
- stub_post("/repos/#{user}/#{repo}/merges").with(inputs).
58
- to_return(:body => fixture('repos/merge.json'),
59
- :status => 404,
60
- :headers => {:content_type => "application/json; charset=utf-8"})
61
- end
62
-
63
- it "should fail to retrieve resource" do
64
- expect {
65
- github.repos.merging.merge user, repo, inputs
66
- }.to raise_error(Github::Error::NotFound)
67
- end
68
- end
69
- end # merge
70
-
71
- end # Github::Repos::Merging
@@ -1,4 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
@@ -1,110 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Github::Users::Emails do
4
- let(:github) { Github.new }
5
- let(:email) { "octocat@github.com" }
6
-
7
- before { github.oauth_token = OAUTH_TOKEN }
8
- after { reset_authentication_for github }
9
-
10
- describe "#list" do
11
- it { github.users.emails.should respond_to :all }
12
-
13
- context "resource found for an authenticated user" do
14
- before do
15
- stub_get("/user/emails").
16
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
17
- to_return(:body => fixture('users/emails.json'),
18
- :status => 200,
19
- :headers => {:content_type => "application/json; charset=utf-8"})
20
- end
21
-
22
- it "should get the resources" do
23
- github.users.emails.list
24
- a_get("/user/emails").
25
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
26
- should have_been_made
27
- end
28
-
29
- it "should return resource" do
30
- emails = github.users.emails.list
31
- emails.should be_an Array
32
- emails.should have(2).items
33
- end
34
-
35
- it "should get emails information" do
36
- emails = github.users.emails.list
37
- emails.first.should == email
38
- end
39
-
40
- it "should yield to a block" do
41
- github.users.emails.should_receive(:list).and_yield('web')
42
- github.users.emails.list { |param| 'web' }
43
- end
44
- end
45
-
46
- context "resource not found for a user" do
47
- before do
48
- stub_get("/user/emails").
49
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
50
- to_return(:body => "", :status => [404, "Not Found"])
51
- end
52
-
53
- it "should return 404 with a message 'Not Found'" do
54
- expect {
55
- github.users.emails.list
56
- }.to raise_error(Github::Error::NotFound)
57
- end
58
- end
59
- end # emails
60
-
61
- context '#add' do
62
- let(:params) { { :per_page => 21, :page => 1 }}
63
-
64
- before do
65
- stub_post("/user/emails").
66
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
67
- to_return(:body => fixture('users/emails.json'),
68
- :status => 200,
69
- :headers => {:content_type => "application/json; charset=utf-8"})
70
- end
71
-
72
- it 'extracts request parameters and email data' do
73
- github.users.emails.should_receive(:post_request).
74
- with("/user/emails", { "per_page" => 21, "page" => 1, "data" => [email] })
75
- github.users.emails.add email, params
76
- end
77
-
78
- it 'submits request successfully' do
79
- github.users.emails.add email
80
- a_post("/user/emails").
81
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
82
- should have_been_made
83
- end
84
- end # add
85
-
86
- context '#delete' do
87
- let(:params) { { :per_page => 21, :page => 1 }}
88
-
89
- before do
90
- stub_delete("/user/emails").
91
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
92
- to_return(:body => fixture('users/emails.json'), :status => 204,
93
- :headers => {:content_type => "application/json; charset=utf-8"})
94
- end
95
-
96
- it 'extracts request parameters and email data' do
97
- github.users.emails.should_receive(:delete_request).
98
- with("/user/emails", { "per_page" => 21, "page" => 1, 'data' => [email] })
99
- github.users.emails.delete email, params
100
- end
101
-
102
- it 'submits request successfully' do
103
- github.users.emails.delete email
104
- a_delete("/user/emails").
105
- with(:query => { :access_token => "#{OAUTH_TOKEN}" } ).
106
- should have_been_made
107
- end
108
- end # delete
109
-
110
- end # Github::Users::Emails
@@ -1,256 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Github::Users::Keys do
4
- let(:github) { Github.new }
5
- let(:key_id) { 1 }
6
-
7
- before { github.oauth_token = OAUTH_TOKEN }
8
- after { reset_authentication_for github }
9
-
10
- describe "#list" do
11
- it { github.users.keys.should respond_to :all }
12
-
13
- context "resource found for an authenticated user" do
14
- before do
15
- stub_get("/user/keys").
16
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
17
- to_return(:body => fixture('users/keys.json'),
18
- :status => 200,
19
- :headers => {:content_type => "application/json; charset=utf-8"})
20
- end
21
-
22
- it "should get the resources" do
23
- github.users.keys.list
24
- a_get("/user/keys").
25
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
26
- should have_been_made
27
- end
28
-
29
- it "should return resource" do
30
- keys = github.users.keys.list
31
- keys.should be_an Array
32
- keys.should have(1).item
33
- end
34
-
35
- it "should get keys information" do
36
- keys = github.users.keys.list
37
- keys.first.id.should == key_id
38
- end
39
-
40
- it "should yield to a block" do
41
- github.users.keys.should_receive(:list).and_yield('web')
42
- github.users.keys.list { |param| 'web' }
43
- end
44
- end
45
-
46
- context "resource not found for a user" do
47
- before do
48
- stub_get("/user/keys").
49
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
50
- to_return(:body => "", :status => [404, "Not Found"])
51
- end
52
-
53
- it "should return 404 with a message 'Not Found'" do
54
- expect {
55
- github.users.keys.list
56
- }.to raise_error(Github::Error::NotFound)
57
- end
58
- end
59
- end # list
60
-
61
- describe "#get" do
62
- it { github.users.keys.should respond_to :find }
63
-
64
- context "resource found for an authenticated user" do
65
- before do
66
- stub_get("/user/keys/#{key_id}").
67
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
68
- to_return(:body => fixture('users/key.json'),
69
- :status => 200,
70
- :headers => {:content_type => "application/json; charset=utf-8"})
71
- end
72
-
73
- it "should fail to get resource without key id" do
74
- expect { github.users.keys.get nil }.to raise_error(ArgumentError)
75
- end
76
-
77
- it "should get the resource" do
78
- github.users.keys.get key_id
79
- a_get("/user/keys/#{key_id}").
80
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
81
- should have_been_made
82
- end
83
-
84
- it "should get public key information" do
85
- key = github.users.keys.get key_id
86
- key.id.should == key_id
87
- key.title.should == 'octocat@octomac'
88
- end
89
-
90
- it "should return mash" do
91
- key = github.users.keys.get key_id
92
- key.should be_a Hashie::Mash
93
- end
94
- end
95
-
96
- context "resource not found" do
97
- before do
98
- stub_get("/user/keys/#{key_id}").
99
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
100
- to_return(:body => fixture('users/key.json'),
101
- :status => 404,
102
- :headers => {:content_type => "application/json; charset=utf-8"})
103
- end
104
-
105
- it "should fail to retrive resource" do
106
- expect {
107
- github.users.keys.get key_id
108
- }.to raise_error(Github::Error::NotFound)
109
- end
110
- end
111
- end # get
112
-
113
- describe "#create" do
114
- let(:inputs) {
115
- {
116
- :title => "octocat@octomac",
117
- :key => "ssh-rsa AAA...",
118
- :unrelated => true
119
- }
120
- }
121
-
122
- context "resouce created" do
123
- before do
124
- stub_post("/user/keys?access_token=#{OAUTH_TOKEN}").
125
- with(inputs.except(:unrelated)).
126
- to_return(:body => fixture('users/key.json'),
127
- :status => 201,
128
- :headers => {:content_type => "application/json; charset=utf-8"})
129
- end
130
-
131
- it "should create resource successfully" do
132
- github.users.keys.create inputs
133
- a_post("/user/keys?access_token=#{OAUTH_TOKEN}").
134
- with(inputs).should have_been_made
135
- end
136
-
137
- it "should return the resource" do
138
- key = github.users.keys.create inputs
139
- key.should be_a Hashie::Mash
140
- end
141
-
142
- it "should get the key information" do
143
- key = github.users.keys.create inputs
144
- key.title.should == 'octocat@octomac'
145
- end
146
- end
147
-
148
- context "fail to create resource" do
149
- before do
150
- stub_post("/user/keys?access_token=#{OAUTH_TOKEN}").with(inputs).
151
- to_return(:body => fixture('users/key.json'),
152
- :status => 404,
153
- :headers => {:content_type => "application/json; charset=utf-8"})
154
- end
155
-
156
- it "should fail to retrieve resource" do
157
- expect {
158
- github.users.keys.create inputs
159
- }.to raise_error(Github::Error::NotFound)
160
- end
161
- end
162
- end # create
163
-
164
- describe "#update" do
165
- let(:inputs) {
166
- {
167
- :title => "octocat@octomac",
168
- :key => "ssh-rsa AAA...",
169
- :unrelated => true
170
- }
171
- }
172
-
173
- context "resouce updated" do
174
- before do
175
- stub_patch("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
176
- with(inputs.except(:unrelated)).
177
- to_return(:body => fixture('users/key.json'),
178
- :status => 201,
179
- :headers => {:content_type => "application/json; charset=utf-8"})
180
- end
181
-
182
- it "should fail to get resource without key id" do
183
- expect { github.users.keys.update nil }.to raise_error(ArgumentError)
184
- end
185
-
186
- it "should create resource successfully" do
187
- github.users.keys.update key_id, inputs
188
- a_patch("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
189
- with(inputs).should have_been_made
190
- end
191
-
192
- it "should return the resource" do
193
- key = github.users.keys.update key_id, inputs
194
- key.should be_a Hashie::Mash
195
- end
196
-
197
- it "should get the key information" do
198
- key = github.users.keys.update key_id, inputs
199
- key.title.should == 'octocat@octomac'
200
- end
201
- end
202
-
203
- context "fail to update resource" do
204
- before do
205
- stub_patch("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
206
- with(inputs).
207
- to_return(:body => fixture('users/key.json'),
208
- :status => 404,
209
- :headers => {:content_type => "application/json; charset=utf-8"})
210
- end
211
-
212
- it "should fail to retrieve resource" do
213
- expect {
214
- github.users.keys.update key_id, inputs
215
- }.to raise_error(Github::Error::NotFound)
216
- end
217
- end
218
- end # update
219
-
220
- describe "#delete" do
221
- context "resouce deleted" do
222
- before do
223
- stub_delete("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
224
- to_return(:body => fixture('users/key.json'),
225
- :status => 204,
226
- :headers => {:content_type => "application/json; charset=utf-8"})
227
- end
228
-
229
- it "should fail to get resource without key id" do
230
- expect { github.users.keys.delete nil }.to raise_error(ArgumentError)
231
- end
232
-
233
- it "should create resource successfully" do
234
- github.users.keys.delete key_id
235
- a_delete("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
236
- should have_been_made
237
- end
238
- end
239
-
240
- context "fail to delete resource" do
241
- before do
242
- stub_delete("/user/keys/#{key_id}?access_token=#{OAUTH_TOKEN}").
243
- to_return(:body => fixture('users/key.json'),
244
- :status => 404,
245
- :headers => {:content_type => "application/json; charset=utf-8"})
246
- end
247
-
248
- it "should fail to delete resource" do
249
- expect {
250
- github.users.keys.delete key_id
251
- }.to raise_error(Github::Error::NotFound)
252
- end
253
- end
254
- end # delete
255
-
256
- end # Github::Users::Keys