github_api 0.8.4 → 0.8.5

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