github_api 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/README.md +20 -1
  2. data/features/cassettes/issues/events/get.yml +139 -0
  3. data/features/cassettes/issues/events/list_issue.yml +71 -0
  4. data/features/cassettes/issues/events/list_repo.yml +222 -0
  5. data/features/cassettes/issues/labels/list_repo.yml +65 -0
  6. data/features/cassettes/issues/milestones/create.yml +55 -0
  7. data/features/cassettes/issues/milestones/delete.yml +46 -0
  8. data/features/cassettes/issues/milestones/get.yml +175 -0
  9. data/features/cassettes/issues/milestones/list.yml +54 -0
  10. data/features/cassettes/issues/milestones/update.yml +53 -0
  11. data/features/cassettes/repos/contents/archive.yml +43 -84
  12. data/features/cassettes/say/custom.yml +60 -0
  13. data/features/cassettes/say/random.yml +60 -0
  14. data/features/issues/events.feature +38 -0
  15. data/features/issues/labels.feature +14 -0
  16. data/features/issues/milestones.feature +62 -0
  17. data/features/say.feature +68 -0
  18. data/features/step_definitions/common_steps.rb +6 -0
  19. data/features/support/helpers.rb +4 -0
  20. data/lib/github_api.rb +2 -0
  21. data/lib/github_api/client.rb +8 -0
  22. data/lib/github_api/constants.rb +4 -0
  23. data/lib/github_api/issues.rb +74 -46
  24. data/lib/github_api/issues/assignees.rb +2 -1
  25. data/lib/github_api/issues/events.rb +3 -3
  26. data/lib/github_api/issues/milestones.rb +0 -1
  27. data/lib/github_api/rate_limit.rb +2 -0
  28. data/lib/github_api/result.rb +13 -0
  29. data/lib/github_api/say.rb +24 -0
  30. data/lib/github_api/scopes.rb +19 -0
  31. data/lib/github_api/version.rb +1 -1
  32. data/spec/github/git_data/git_data_spec.rb +19 -0
  33. data/spec/github/issues/assignees/check_spec.rb +46 -0
  34. data/spec/github/issues/assignees/list_spec.rb +47 -0
  35. data/spec/github/issues/assignees_spec.rb +0 -96
  36. data/spec/github/issues/create_spec.rb +60 -0
  37. data/spec/github/issues/edit_spec.rb +61 -0
  38. data/spec/github/issues/events_spec.rb +4 -4
  39. data/spec/github/issues/get_spec.rb +49 -0
  40. data/spec/github/issues/issues_spec.rb +19 -0
  41. data/spec/github/issues/list_spec.rb +90 -0
  42. data/spec/github/issues/milestones/create_spec.rb +56 -0
  43. data/spec/github/issues/milestones/delete_spec.rb +42 -0
  44. data/spec/github/issues/milestones/get_spec.rb +49 -0
  45. data/spec/github/issues/milestones/list_spec.rb +52 -0
  46. data/spec/github/issues/milestones/update_spec.rb +57 -0
  47. data/spec/github/issues/milestones_spec.rb +1 -276
  48. data/spec/github/scopes/list_spec.rb +33 -0
  49. data/spec/github/users/followers/follow_spec.rb +33 -0
  50. data/spec/github/users/followers/following_spec.rb +65 -0
  51. data/spec/github/users/followers/is_following_spec.rb +41 -0
  52. data/spec/github/users/followers/list_spec.rb +2 -8
  53. data/spec/github/users/followers/unfollow_spec.rb +33 -0
  54. data/spec/github/users/users_spec.rb +16 -0
  55. metadata +68 -35
  56. data/spec/github/git_data_spec.rb +0 -11
  57. data/spec/github/issues_spec.rb +0 -284
  58. data/spec/github/users/followers_spec.rb +0 -172
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Github::GitData do
4
-
5
- its(:blobs) { should be_a Github::GitData::Blobs }
6
- its(:commits) { should be_a Github::GitData::Commits }
7
- its(:references) { should be_a Github::GitData::References }
8
- its(:tags) { should be_a Github::GitData::Tags }
9
- its(:trees) { should be_a Github::GitData::Trees }
10
-
11
- end # Github::GitData
@@ -1,284 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Github::Issues do
6
- let(:issues_api) { Github::Issues }
7
- let(:github) { Github.new }
8
- let(:user) { 'peter-murach' }
9
- let(:repo) { 'github' }
10
- let(:issue_id) { 1347 }
11
-
12
- after { reset_authentication_for github }
13
-
14
- its(:comments) { should be_a Github::Issues::Comments }
15
- its(:events) { should be_a Github::Issues::Events }
16
- its(:labels) { should be_a Github::Issues::Labels }
17
- its(:milestones) { should be_a Github::Issues::Milestones }
18
-
19
- context '#list' do
20
- it { should respond_to(:all) }
21
-
22
- context "resource found" do
23
- before do
24
- stub_get("/issues").
25
- to_return(:body => fixture('issues/issues.json'), :status => 200,
26
- :headers => {:content_type => "application/json; charset=utf-8"})
27
- end
28
-
29
- it "should get the resources" do
30
- github.issues.list
31
- a_get("/issues").should have_been_made
32
- end
33
-
34
- it "should return array of resources" do
35
- issues = github.issues.list
36
- issues.should be_an Array
37
- issues.should have(1).items
38
- end
39
-
40
- it "should be a mash type" do
41
- issues = github.issues.list
42
- issues.first.should be_a Hashie::Mash
43
- end
44
-
45
- it "should get issue information" do
46
- issues = github.issues.list
47
- issues.first.title.should == 'Found a bug'
48
- end
49
-
50
- it "should yield to a block" do
51
- github.issues.should_receive(:list).and_yield('web')
52
- github.issues.list { |param| 'web' }.should == 'web'
53
- end
54
- end
55
-
56
- context "resource not found" do
57
- before do
58
- stub_get("/issues").
59
- to_return(:body => "", :status => [404, "Not Found"])
60
- end
61
-
62
- it "should return 404 with a message 'Not Found'" do
63
- expect { github.issues.list }.to raise_error(Github::Error::NotFound)
64
- end
65
- end
66
- end # list
67
-
68
- describe '#list_repo' do
69
- it { should respond_to :list_repository }
70
-
71
- context "resource found" do
72
- before do
73
- stub_get("/repos/#{user}/#{repo}/issues").
74
- to_return(:body => fixture('issues/issues.json'), :status => 200,
75
- :headers => {:content_type => "application/json; charset=utf-8"})
76
- end
77
-
78
- it "should raise error if user-name empty" do
79
- expect {
80
- github.issues.list_repo nil, repo
81
- }.to raise_error(ArgumentError)
82
- end
83
-
84
- it "should get the resources" do
85
- github.issues.list_repo user, repo
86
- a_get("/repos/#{user}/#{repo}/issues").should have_been_made
87
- end
88
-
89
- it "should return array of resources" do
90
- repo_issues = github.issues.list_repo user, repo
91
- repo_issues.should be_an Array
92
- repo_issues.should have(1).items
93
- end
94
-
95
- it "should be a mash type" do
96
- repo_issues = github.issues.list_repo user, repo
97
- repo_issues.first.should be_a Hashie::Mash
98
- end
99
-
100
- it "should get repository issue information" do
101
- repo_issues = github.issues.list_repo user, repo
102
- repo_issues.first.title.should == 'Found a bug'
103
- end
104
-
105
- it "should yield to a block" do
106
- github.issues.should_receive(:list_repo).with(user, repo).and_yield('web')
107
- github.issues.list_repo(user, repo) { |param| 'web' }.should == 'web'
108
- end
109
- end
110
-
111
- context "resource not found" do
112
- before do
113
- stub_get("/repos/#{user}/#{repo}/issues").
114
- to_return(:body => "", :status => [404, "Not Found"])
115
- end
116
-
117
- it "should return 404 with a message 'Not Found'" do
118
- expect {
119
- github.issues.list_repo user, repo
120
- }.to raise_error(Github::Error::NotFound)
121
- end
122
- end
123
- end # list_repo
124
-
125
- describe "#get" do
126
- it { should respond_to :find }
127
-
128
- context "resource found" do
129
- before do
130
- stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}").
131
- to_return(:body => fixture('issues/issue.json'),
132
- :status => 200,
133
- :headers => {:content_type => "application/json; charset=utf-8"})
134
- end
135
-
136
- it "should fail to get resource without issue id" do
137
- expect { github.issues.get(user, repo, nil)}.to raise_error(ArgumentError)
138
- end
139
-
140
- it "should get the resource" do
141
- github.issues.get user, repo, issue_id
142
- a_get("/repos/#{user}/#{repo}/issues/#{issue_id}").should have_been_made
143
- end
144
-
145
- it "should get issue information" do
146
- issue = github.issues.get user, repo, issue_id
147
- issue.number.should == issue_id
148
- issue.title.should == 'Found a bug'
149
- end
150
-
151
- it "should return mash" do
152
- issue = github.issues.get user, repo, issue_id
153
- issue.should be_a Hashie::Mash
154
- end
155
- end
156
-
157
- context "resource not found" do
158
- before do
159
- stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}").
160
- to_return(:body => fixture('issues/issue.json'),
161
- :status => 404,
162
- :headers => {:content_type => "application/json; charset=utf-8"})
163
- end
164
-
165
- it "should fail to retrive resource" do
166
- expect {
167
- github.issues.get user, repo, issue_id
168
- }.to raise_error(Github::Error::NotFound)
169
- end
170
- end
171
- end # get_issue
172
-
173
- describe "#create" do
174
- let(:inputs) {
175
- {
176
- "title" => "Found a bug",
177
- "body" => "I'm having a problem with this.",
178
- "assignee" => "octocat",
179
- "milestone" => 1,
180
- "labels" => [
181
- "Label1",
182
- "Label2"
183
- ]
184
- }
185
- }
186
- context "resouce created" do
187
- before do
188
- stub_post("/repos/#{user}/#{repo}/issues").with(inputs).
189
- to_return(:body => fixture('issues/issue.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
190
- end
191
-
192
- it "should fail to create resource if 'title' input is missing" do
193
- expect {
194
- github.issues.create user, repo, inputs.except('title')
195
- }.to raise_error(Github::Error::RequiredParams)
196
- end
197
-
198
- it "should create resource successfully" do
199
- github.issues.create user, repo, inputs
200
- a_post("/repos/#{user}/#{repo}/issues").with(inputs).should have_been_made
201
- end
202
-
203
- it "should return the resource" do
204
- issue = github.issues.create user, repo, inputs
205
- issue.should be_a Hashie::Mash
206
- end
207
-
208
- it "should get the issue information" do
209
- issue = github.issues.create(user, repo, inputs)
210
- issue.title.should == 'Found a bug'
211
- end
212
- end
213
-
214
- context "failed to create resource" do
215
- before do
216
- stub_post("/repos/#{user}/#{repo}/issues").with(inputs).
217
- to_return(:body => fixture('issues/issue.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
218
- end
219
-
220
- it "should faile to retrieve resource" do
221
- expect {
222
- github.issues.create user, repo, inputs
223
- }.to raise_error(Github::Error::NotFound)
224
- end
225
- end
226
- end # create
227
-
228
- describe "#edit" do
229
- let(:inputs) {
230
- {
231
- "title" => "Found a bug",
232
- "body" => "I'm having a problem with this.",
233
- "assignee" => "octocat",
234
- "milestone" => 1,
235
- "labels" => [
236
- "Label1",
237
- "Label2"
238
- ]
239
- }
240
- }
241
-
242
- context "resource edited successfully" do
243
- before do
244
- stub_patch("/repos/#{user}/#{repo}/issues/#{issue_id}").with(inputs).
245
- to_return(:body => fixture("issues/issue.json"), :status => 200, :headers => { :content_type => "application/json; charset=utf-8"})
246
- end
247
-
248
- it "should fail to edit without 'user/repo' parameters" do
249
- expect {
250
- github.issues.edit nil, repo, issue_id
251
- }.to raise_error(ArgumentError)
252
- end
253
-
254
- it "should edit the resource" do
255
- github.issues.edit user, repo, issue_id, inputs
256
- a_patch("/repos/#{user}/#{repo}/issues/#{issue_id}").with(inputs).should have_been_made
257
- end
258
-
259
- it "should return resource" do
260
- issue = github.issues.edit user, repo, issue_id, inputs
261
- issue.should be_a Hashie::Mash
262
- end
263
-
264
- it "should be able to retrieve information" do
265
- issue = github.issues.edit user, repo, issue_id, inputs
266
- issue.title.should == 'Found a bug'
267
- end
268
- end
269
-
270
- context "failed to edit resource" do
271
- before do
272
- stub_patch("/repos/#{user}/#{repo}/issues/#{issue_id}").with(inputs).
273
- to_return(:body => fixture("issues/issue.json"), :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
274
- end
275
-
276
- it "should fail to find resource" do
277
- expect {
278
- github.issues.edit user, repo, issue_id, inputs
279
- }.to raise_error(Github::Error::NotFound)
280
- end
281
- end
282
- end # edit
283
-
284
- end # Github::Issues
@@ -1,172 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Github::Users::Followers do
6
- let(:github) { Github.new }
7
- let(:user) { 'peter-murach' }
8
-
9
- after { reset_authentication_for github }
10
-
11
- describe "#following" do
12
- context "resource found for a user" do
13
- before do
14
- stub_get("/users/#{user}/following").
15
- to_return(:body => fixture('users/followers.json'),
16
- :status => 200,
17
- :headers => {:content_type => "application/json; charset=utf-8"})
18
- end
19
-
20
- it "should get the resources" do
21
- github.users.followers.following user
22
- a_get("/users/#{user}/following").should have_been_made
23
- end
24
-
25
- it "should return resource" do
26
- followings = github.users.followers.following user
27
- followings.should be_an Array
28
- followings.should have(1).items
29
- end
30
-
31
- it "should be a mash type" do
32
- followings = github.users.followers.following user
33
- followings.first.should be_a Hashie::Mash
34
- end
35
-
36
- it "should get following users information" do
37
- followings = github.users.followers.following user
38
- followings.first.login.should == 'octocat'
39
- end
40
-
41
- it "should yield to a block" do
42
- github.users.followers.should_receive(:following).with(user).and_yield('web')
43
- github.users.followers.following(user) { |param| 'web' }
44
- end
45
- end
46
-
47
- context "resource found for an authenticated user" do
48
- before do
49
- github.oauth_token = OAUTH_TOKEN
50
- stub_get("/user/following").
51
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
52
- to_return(:body => fixture('users/followers.json'),
53
- :status => 200,
54
- :headers => {:content_type => "application/json; charset=utf-8"})
55
- end
56
-
57
- it "should get the resources" do
58
- github.users.followers.following
59
- a_get("/user/following").
60
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
61
- should have_been_made
62
- end
63
- end
64
-
65
- context "resource not found for a user" do
66
- before do
67
- stub_get("/users/#{user}/following").
68
- to_return(:body => "", :status => [404, "Not Found"])
69
- end
70
-
71
- it "should return 404 with a message 'Not Found'" do
72
- expect {
73
- github.users.followers.following user
74
- }.to raise_error(Github::Error::NotFound)
75
- end
76
- end
77
- end # following
78
-
79
- context '#following?' do
80
- before do
81
- github.oauth_token = OAUTH_TOKEN
82
- stub_get("/user/following/#{user}").
83
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
84
- to_return(:body => '',
85
- :status => 204,
86
- :headers => {:content_type => "application/json; charset=utf-8"})
87
- end
88
-
89
- it 'should raise error if username not present' do
90
- expect {
91
- github.users.followers.following? nil
92
- }.to raise_error(ArgumentError)
93
- end
94
-
95
- it 'should perform request' do
96
- github.users.followers.following?(user)
97
- a_get("/user/following/#{user}").
98
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
99
- should have_been_made
100
- end
101
-
102
- it 'should return true if user is being followed' do
103
- github.users.followers.following?(user).should be_true
104
- end
105
-
106
- it 'should return false if user is not being followed' do
107
- stub_get("/user/following/#{user}").
108
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
109
- to_return(:body => '',
110
- :status => 404,
111
- :headers => {:content_type => "application/json; charset=utf-8"})
112
- github.users.followers.following?(user).should be_false
113
- end
114
- end # following?
115
-
116
- context '#follow' do
117
- before do
118
- github.oauth_token = OAUTH_TOKEN
119
- stub_put("/user/following/#{user}").
120
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
121
- to_return(:body => '',
122
- :status => 204,
123
- :headers => {:content_type => "application/json; charset=utf-8"})
124
- end
125
-
126
- it "should raise error if gist id not present" do
127
- expect {
128
- github.users.followers.follow nil
129
- }.to raise_error(ArgumentError)
130
- end
131
-
132
- it 'successfully unfollows a user' do
133
- github.users.followers.follow(user)
134
- a_put("/user/following/#{user}").
135
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
136
- should have_been_made
137
- end
138
-
139
- it "should return 204 with a message 'Not Found'" do
140
- github.users.followers.follow(user).status.should be 204
141
- end
142
- end # follow
143
-
144
- context '#unfollow' do
145
- before do
146
- github.oauth_token = OAUTH_TOKEN
147
- stub_delete("/user/following/#{user}").
148
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
149
- to_return(:body => '',
150
- :status => 204,
151
- :headers => {:content_type => "application/json; charset=utf-8"})
152
- end
153
-
154
- it "should raise error if gist id not present" do
155
- expect {
156
- github.users.followers.unfollow nil
157
- }.to raise_error(ArgumentError)
158
- end
159
-
160
- it 'successfully unfollows a user' do
161
- github.users.followers.unfollow(user)
162
- a_delete("/user/following/#{user}").
163
- with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
164
- should have_been_made
165
- end
166
-
167
- it "should return 204 with a message 'Not Found'" do
168
- github.users.followers.unfollow(user).status.should be 204
169
- end
170
- end # unfollow
171
-
172
- end # Github::Users::Followers