github_api 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::GitData::References, '#get' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:ref) { "heads/master" }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/git/refs/#{ref}" }
10
+
11
+ before {
12
+ stub_get(request_path).to_return(:body => body, :status => status,
13
+ :headers => {:content_type => "application/json; charset=utf-8"})
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
17
+
18
+ context "resource found" do
19
+ let(:body) { fixture('git_data/reference.json') }
20
+ let(:status) { 200 }
21
+
22
+ it { should respond_to :find }
23
+
24
+ it "should fail to get resource without ref" do
25
+ expect { subject.get user, repo, nil }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it "should fail to get resource with wrong ref" do
29
+ expect {
30
+ subject.get user, repo, '/branch'
31
+ }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it "should get the resource" do
35
+ subject.get user, repo, ref
36
+ a_get(request_path).should have_been_made
37
+ end
38
+
39
+ it "should get reference information" do
40
+ reference = subject.get user, repo, ref
41
+ reference.first.ref.should eql "refs/heads/sc/featureA"
42
+ end
43
+
44
+ it "should return mash" do
45
+ reference = subject.get user, repo, ref
46
+ reference.first.should be_a Hashie::Mash
47
+ end
48
+ end
49
+
50
+ it_should_behave_like 'request failure' do
51
+ let(:requestable) { subject.get user, repo, ref }
52
+ end
53
+
54
+ end # get
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::GitData::References, '#list' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:ref) { "heads/master" }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/git/refs/#{ref}" }
10
+
11
+ before {
12
+ stub_get(request_path).to_return(:body => body, :status => status,
13
+ :headers => {:content_type => "application/json; charset=utf-8"})
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
17
+
18
+ context "get all the refernces based on sub-namespace" do
19
+ let(:body) { fixture('git_data/references.json') }
20
+ let(:status) { 200 }
21
+
22
+ it { should respond_to :all }
23
+
24
+ it "should fail to get resource without username" do
25
+ expect { subject.list nil, repo }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it "should fail to call with invalid reference" do
29
+ expect {
30
+ subject.list user, repo, :ref => '/branch/featureA'
31
+ }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it "should get the resources" do
35
+ subject.list user, repo, :ref => ref
36
+ a_get(request_path).should have_been_made
37
+ end
38
+
39
+ it "should return array of resources" do
40
+ references = subject.list user, repo, :ref => ref
41
+ references.should be_an Array
42
+ references.should have(3).items
43
+ end
44
+
45
+ it "should be a mash type" do
46
+ references = subject.list user, repo, :ref => ref
47
+ references.first.should be_a Hashie::Mash
48
+ end
49
+
50
+ it "should get reference information" do
51
+ references = subject.list user, repo, :ref => ref
52
+ references.first.ref.should eql 'refs/heads/master'
53
+ end
54
+
55
+ it "should yield to a block" do
56
+ yielded = []
57
+ result = subject.list(user, repo, :ref => ref) { |obj| yielded << obj }
58
+ yielded.should == result
59
+ end
60
+ end
61
+
62
+ context "get all the references on the system" do
63
+ let(:request_path) { "/repos/#{user}/#{repo}/git/refs" }
64
+ let(:body) { fixture('git_data/references.json') }
65
+ let(:status) { 200 }
66
+
67
+ it "should get the resources" do
68
+ subject.list user, repo
69
+ a_get(request_path).should have_been_made
70
+ end
71
+ end
72
+
73
+ it_should_behave_like 'request failure' do
74
+ let(:requestable) { subject.list user, repo, :ref => ref }
75
+ end
76
+
77
+ end # list
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::GitData::References, '#update' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:ref) { "heads/master" }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/git/refs/#{ref}" }
10
+ let(:inputs) {
11
+ {
12
+ "sha" => "827efc6d56897b048c772eb4087f854f46256132",
13
+ "force" => true,
14
+ "unrelated" => 'giberrish'
15
+ }
16
+ }
17
+
18
+ before {
19
+ stub_patch(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 updated" do
27
+ let(:body) { fixture('git_data/reference.json') }
28
+ let(:status) { 201 }
29
+
30
+ it "should fail to update resource if 'sha' input is missing" do
31
+ expect {
32
+ subject.update user, repo, ref, inputs.except('sha')
33
+ }.to raise_error(Github::Error::RequiredParams)
34
+ end
35
+
36
+ it "should fail to update resource if 'ref' is wrong" do
37
+ expect {
38
+ subject.update user, repo, nil, inputs
39
+ }.to raise_error(ArgumentError)
40
+ end
41
+
42
+ it "should update resource successfully" do
43
+ subject.update user, repo, ref, inputs
44
+ a_patch(request_path).with(inputs).should have_been_made
45
+ end
46
+
47
+ it "should return the resource" do
48
+ reference = subject.update user, repo, ref, inputs
49
+ reference.first.should be_a Hashie::Mash
50
+ end
51
+
52
+ it "should get the reference information" do
53
+ reference = subject.update user, repo, ref, inputs
54
+ reference.first.ref.should eql 'refs/heads/sc/featureA'
55
+ end
56
+ end
57
+
58
+ it_should_behave_like 'request failure' do
59
+ let(:requestable) { subject.update user, repo, ref, inputs }
60
+ end
61
+
62
+ end # update
@@ -3,306 +3,9 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Github::GitData::References do
6
- let(:github) { Github.new }
7
- let(:user) { 'peter-murach' }
8
- let(:repo) { 'github' }
9
- let(:ref) { "heads/master" }
10
- let(:sha) { "3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15" }
11
-
12
- after { reset_authentication_for github }
13
6
 
14
7
  it { described_class::VALID_REF_PARAM_NAMES.should_not be_nil }
15
- it { described_class::VALID_REF_PARAM_VALUES.should_not be_nil }
16
-
17
- describe "#list" do
18
- it { github.git_data.references.should respond_to :all }
19
-
20
-
21
- context "get all the refernces based on sub-namespace" do
22
- before do
23
- stub_get("/repos/#{user}/#{repo}/git/refs/#{ref}").
24
- to_return(:body => fixture('git_data/references.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
25
- end
26
-
27
- it "should fail to get resource without username" do
28
- expect {
29
- github.git_data.references.list nil, repo
30
- }.to raise_error(ArgumentError)
31
- end
32
-
33
- it "should fail to call with invalid reference" do
34
- expect {
35
- github.git_data.references.list user, repo, :ref => '/branch/featureA'
36
- }.to raise_error(ArgumentError)
37
- end
38
-
39
- it "should get the resources" do
40
- github.git_data.references.list user, repo, :ref => ref
41
- a_get("/repos/#{user}/#{repo}/git/refs/#{ref}").should have_been_made
42
- end
43
-
44
- it "should return array of resources" do
45
- references = github.git_data.references.list user, repo, :ref => ref
46
- references.should be_an Array
47
- references.should have(3).items
48
- end
49
-
50
- it "should be a mash type" do
51
- references = github.git_data.references.list user, repo, :ref => ref
52
- references.first.should be_a Hashie::Mash
53
- end
54
-
55
- it "should get reference information" do
56
- references = github.git_data.references.list user, repo, :ref => ref
57
- references.first.ref.should eql 'refs/heads/master'
58
- end
59
-
60
- it "should yield to a block" do
61
- github.git_data.references.should_receive(:list).
62
- with(user, repo, :ref => ref).and_yield('web')
63
- github.git_data.references.list(user, repo, :ref => ref) { |param| 'web' }
64
- end
65
- end
66
-
67
- context "get all the references on the system" do
68
- before do
69
- stub_get("/repos/#{user}/#{repo}/git/refs").
70
- to_return(:body => fixture('git_data/references.json'), :status => 200,
71
- :headers => {:content_type => "application/json; charset=utf-8"})
72
- end
73
-
74
- it "should get the resources" do
75
- github.git_data.references.list user, repo
76
- a_get("/repos/#{user}/#{repo}/git/refs").should have_been_made
77
- end
78
- end
79
-
80
- context "resource not found" do
81
- before do
82
- stub_get("/repos/#{user}/#{repo}/git/refs/#{ref}").
83
- to_return(:body => "", :status => [404, "Not Found"])
84
- end
85
-
86
- it "should return 404 with a message 'Not Found'" do
87
- expect {
88
- github.git_data.references.list user, repo, :ref => ref
89
- }.to raise_error(Github::Error::NotFound)
90
- end
91
- end
92
- end # list
93
-
94
- describe "#get" do
95
- it { github.git_data.references.should respond_to :find }
96
-
97
- context "resource found" do
98
- before do
99
- stub_get("/repos/#{user}/#{repo}/git/refs/#{ref}").
100
- to_return(:body => fixture('git_data/reference.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
101
- end
102
-
103
- it "should fail to get resource without ref" do
104
- expect {
105
- github.git_data.references.get user, repo, nil
106
- }.to raise_error(ArgumentError)
107
- end
108
-
109
- it "should fail to get resource with wrong ref" do
110
- expect {
111
- github.git_data.references.get user, repo, '/branch'
112
- }.to raise_error(ArgumentError)
113
- end
114
-
115
- it "should get the resource" do
116
- github.git_data.references.get user, repo, ref
117
- a_get("/repos/#{user}/#{repo}/git/refs/#{ref}").should have_been_made
118
- end
119
-
120
- it "should get reference information" do
121
- reference = github.git_data.references.get user, repo, ref
122
- reference.first.ref.should eql "refs/heads/sc/featureA"
123
- end
124
-
125
- it "should return mash" do
126
- reference = github.git_data.references.get user, repo, ref
127
- reference.first.should be_a Hashie::Mash
128
- end
129
- end
130
-
131
- context "resource not found" do
132
- before do
133
- stub_get("/repos/#{user}/#{repo}/git/refs/#{ref}").
134
- to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
135
- end
136
-
137
- it "should fail to retrive resource" do
138
- expect {
139
- github.git_data.references.get user, repo, ref
140
- }.to raise_error(Github::Error::NotFound)
141
- end
142
- end
143
- end # get
144
8
 
145
- describe "#create" do
146
- let(:inputs) {
147
- {
148
- "ref" => "refs/heads/master",
149
- "sha" => "827efc6d56897b048c772eb4087f854f46256132",
150
- "unrelated" => 'giberrish'
151
- }
152
- }
153
-
154
- context "resouce created" do
155
- before do
156
- stub_post("/repos/#{user}/#{repo}/git/refs").
157
- with(inputs.except('unrelated')).
158
- to_return(:body => fixture('git_data/reference.json'), :status => 201,
159
- :headers => {:content_type => "application/json; charset=utf-8"})
160
- end
161
-
162
- it "should fail to create resource if 'ref' input is missing" do
163
- expect {
164
- github.git_data.references.create user, repo, inputs.except('ref')
165
- }.to raise_error(ArgumentError)
166
- end
167
-
168
- it "should fail to create resource if 'sha' input is missing" do
169
- expect {
170
- github.git_data.references.create user, repo, inputs.except('sha')
171
- }.to raise_error(Github::Error::RequiredParams)
172
- end
173
-
174
- it "should fail to create resource if 'ref' is wrong" do
175
- expect {
176
- github.git_data.references.create user, repo, :ref => '/heads/master', :sha => '13t2a1r3'
177
- }.to raise_error(ArgumentError)
178
- end
179
-
180
- it "should create resource successfully" do
181
- github.git_data.references.create user, repo, inputs
182
- a_post("/repos/#{user}/#{repo}/git/refs").with(inputs).should have_been_made
183
- end
184
-
185
- it "should return the resource" do
186
- reference = github.git_data.references.create user, repo, inputs
187
- reference.first.should be_a Hashie::Mash
188
- end
189
-
190
- it "should get the reference information" do
191
- reference = github.git_data.references.create user, repo, inputs
192
- reference.first.ref.should eql 'refs/heads/sc/featureA'
193
- end
194
- end
195
-
196
- context "failed to create resource" do
197
- before do
198
- stub_post("/repos/#{user}/#{repo}/git/refs").with(inputs).
199
- to_return(:body => '', :status => 404,
200
- :headers => {:content_type => "application/json; charset=utf-8"})
201
- end
202
-
203
- it "should faile to retrieve resource" do
204
- expect {
205
- github.git_data.references.create user, repo, inputs
206
- }.to raise_error(Github::Error::NotFound)
207
- end
208
- end
209
- end # create
210
-
211
- describe "#update" do
212
- let(:inputs) {
213
- {
214
- "sha" => "827efc6d56897b048c772eb4087f854f46256132",
215
- "force" => true,
216
- "unrelated" => 'giberrish'
217
- }
218
- }
219
-
220
- context "resouce updated" do
221
- before do
222
- stub_patch("/repos/#{user}/#{repo}/git/refs/#{ref}").
223
- with(inputs.except('unrelated')).
224
- to_return(:body => fixture('git_data/reference.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
225
- end
226
-
227
- it "should fail to update resource if 'sha' input is missing" do
228
- expect {
229
- github.git_data.references.update user, repo, ref, inputs.except('sha')
230
- }.to raise_error(Github::Error::RequiredParams)
231
- end
232
-
233
- it "should fail to update resource if 'ref' is wrong" do
234
- expect {
235
- github.git_data.references.update user, repo, nil, inputs
236
- }.to raise_error(ArgumentError)
237
- end
238
-
239
- it "should update resource successfully" do
240
- github.git_data.references.update user, repo, ref, inputs
241
- a_patch("/repos/#{user}/#{repo}/git/refs/#{ref}").
242
- with(inputs).should have_been_made
243
- end
244
-
245
- it "should return the resource" do
246
- reference = github.git_data.references.update user, repo, ref, inputs
247
- reference.first.should be_a Hashie::Mash
248
- end
249
-
250
- it "should get the reference information" do
251
- reference = github.git_data.references.update user, repo, ref, inputs
252
- reference.first.ref.should eql 'refs/heads/sc/featureA'
253
- end
254
- end
255
-
256
- context "failed to update resource" do
257
- before do
258
- stub_patch("/repos/#{user}/#{repo}/git/refs/#{ref}").with(inputs).
259
- to_return(:body => '', :status => 404,
260
- :headers => {:content_type => "application/json; charset=utf-8"})
261
- end
262
-
263
- it "should faile to retrieve resource" do
264
- expect {
265
- github.git_data.references.update user, repo, ref, inputs
266
- }.to raise_error(Github::Error::NotFound)
267
- end
268
- end
269
- end # update
270
-
271
- describe "#delete" do
272
- it { github.git_data.references.should respond_to :remove }
273
-
274
- context "resouce delete" do
275
- before do
276
- stub_delete("/repos/#{user}/#{repo}/git/refs/#{ref}").
277
- to_return(:body => '', :status => 204,
278
- :headers => {:content_type => "application/json; charset=utf-8"})
279
- end
280
-
281
- it "should fail to delete resource if 'ref' input is missing" do
282
- expect {
283
- github.git_data.references.delete user, repo, nil
284
- }.to raise_error(ArgumentError)
285
- end
286
-
287
- it "should delete resource successfully" do
288
- github.git_data.references.delete user, repo, ref
289
- a_delete("/repos/#{user}/#{repo}/git/refs/#{ref}").should have_been_made
290
- end
291
- end
292
-
293
- context "failed to create resource" do
294
- before do
295
- stub_delete("/repos/#{user}/#{repo}/git/refs/#{ref}").
296
- to_return(:body => '', :status => 404,
297
- :headers => {:content_type => "application/json; charset=utf-8"})
298
- end
299
-
300
- it "should faile to retrieve resource" do
301
- expect {
302
- github.git_data.references.delete user, repo, ref
303
- }.to raise_error(Github::Error::NotFound)
304
- end
305
- end
306
- end # delete
9
+ it { described_class::VALID_REF_PARAM_VALUES.should_not be_nil }
307
10
 
308
11
  end # Github::GitData::References