github_api 0.4.5 → 0.4.6
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.
- data/Rakefile +4 -43
- data/features/cassettes/pagination/repos.yml +129 -0
- data/features/cassettes/pagination/repos/commits.yml +133 -0
- data/features/cassettes/pagination/repos/commits/sha/next.yml +129 -0
- data/features/cassettes/pagination/repos/diff/next.yml +130 -0
- data/lib/github_api/gists/comments.rb +5 -5
- data/lib/github_api/issues.rb +5 -5
- data/lib/github_api/issues/comments.rb +5 -5
- data/lib/github_api/issues/events.rb +1 -1
- data/lib/github_api/pull_requests.rb +8 -8
- data/lib/github_api/pull_requests/comments.rb +5 -5
- data/lib/github_api/repos/collaborators.rb +1 -1
- data/lib/github_api/users/followers.rb +2 -2
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/users/emails.json +4 -0
- data/spec/fixtures/users/followers.json +9 -0
- data/spec/fixtures/users/key.json +6 -0
- data/spec/fixtures/users/keys.json +8 -0
- data/spec/github/gists_spec.rb +5 -0
- data/spec/github/issues/comments_spec.rb +3 -3
- data/spec/github/issues/events_spec.rb +8 -11
- data/spec/github/pull_requests_spec.rb +7 -7
- data/spec/github/result_spec.rb +1 -1
- data/spec/github/users/followers_spec.rb +238 -1
- data/spec/github/users_spec.rb +6 -14
- data/spec/github_spec.rb +2 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/authentication.rb +9 -0
- data/spec/support/base.rb +10 -5
- metadata +23 -18
data/spec/github/gists_spec.rb
CHANGED
@@ -378,6 +378,11 @@ describe Github::Gists, :type => :base do
|
|
378
378
|
}.to raise_error(ArgumentError)
|
379
379
|
end
|
380
380
|
|
381
|
+
it 'should perform request' do
|
382
|
+
github.gists.starred? gist_id
|
383
|
+
a_get("/gists/#{gist_id}/star").should have_been_made
|
384
|
+
end
|
385
|
+
|
381
386
|
it 'should return true if gist is already starred' do
|
382
387
|
github.gists.starred?(gist_id).should be_true
|
383
388
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Github::Issues::Comments, :type => :base do
|
4
|
+
let!(:comment_id) { 1 }
|
5
|
+
let!(:issue_id) { 1 }
|
4
6
|
|
5
7
|
it { described_class::VALID_ISSUE_COMMENT_PARAM_NAME.should_not be_nil }
|
6
8
|
|
7
9
|
describe 'comments' do
|
8
|
-
let(:issue_id) { 1 }
|
9
10
|
|
10
11
|
it { github.issues.should respond_to :comments }
|
11
12
|
it { github.issues.should respond_to :issue_comments }
|
@@ -65,7 +66,6 @@ describe Github::Issues::Comments, :type => :base do
|
|
65
66
|
end # comments
|
66
67
|
|
67
68
|
describe "comment" do
|
68
|
-
let(:comment_id) { 1 }
|
69
69
|
|
70
70
|
it { github.issues.should respond_to :comment }
|
71
71
|
it { github.issues.should respond_to :issue_comment }
|
@@ -121,7 +121,7 @@ describe Github::Issues::Comments, :type => :base do
|
|
121
121
|
|
122
122
|
context "resouce created" do
|
123
123
|
before do
|
124
|
-
stub_post("/repos/#{user}/#{repo}/issues/#{issue_id}/comments").with(inputs).
|
124
|
+
stub_post("/repos/#{user}/#{repo}/issues/#{issue_id}/comments").with(:body => inputs).
|
125
125
|
to_return(:body => fixture('issues/comment.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
126
126
|
end
|
127
127
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Github::Issues::Events, :type => :base do
|
4
|
+
let(:issue_id) { 1 }
|
4
5
|
|
5
6
|
describe 'events' do
|
6
7
|
it { github.issues.should respond_to :events }
|
@@ -9,8 +10,6 @@ describe Github::Issues::Events, :type => :base do
|
|
9
10
|
it { github.issues.should respond_to :repo_events }
|
10
11
|
|
11
12
|
context 'without issue_id' do
|
12
|
-
let(:issue_id) { nil }
|
13
|
-
|
14
13
|
context "resource found" do
|
15
14
|
before do
|
16
15
|
stub_get("/repos/#{user}/#{repo}/issues/events").
|
@@ -23,29 +22,29 @@ describe Github::Issues::Events, :type => :base do
|
|
23
22
|
end
|
24
23
|
|
25
24
|
it "should get the resources" do
|
26
|
-
github.issues.events user, repo
|
25
|
+
github.issues.events user, repo
|
27
26
|
a_get("/repos/#{user}/#{repo}/issues/events").should have_been_made
|
28
27
|
end
|
29
28
|
|
30
29
|
it "should return array of resources" do
|
31
|
-
events = github.issues.events user, repo
|
30
|
+
events = github.issues.events user, repo
|
32
31
|
events.should be_an Array
|
33
32
|
events.should have(1).items
|
34
33
|
end
|
35
34
|
|
36
35
|
it "should be a mash type" do
|
37
|
-
events = github.issues.events user, repo
|
36
|
+
events = github.issues.events user, repo
|
38
37
|
events.first.should be_a Hashie::Mash
|
39
38
|
end
|
40
39
|
|
41
40
|
it "should get issue information" do
|
42
|
-
events = github.issues.events user, repo
|
41
|
+
events = github.issues.events user, repo
|
43
42
|
events.first.actor.login.should == 'octocat'
|
44
43
|
end
|
45
44
|
|
46
45
|
it "should yield to a block" do
|
47
|
-
github.issues.should_receive(:events).with(user, repo
|
48
|
-
github.issues.events(user, repo
|
46
|
+
github.issues.should_receive(:events).with(user, repo).and_yield('web')
|
47
|
+
github.issues.events(user, repo) { |param| 'web' }.should == 'web'
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
@@ -57,7 +56,7 @@ describe Github::Issues::Events, :type => :base do
|
|
57
56
|
|
58
57
|
it "should return 404 with a message 'Not Found'" do
|
59
58
|
expect {
|
60
|
-
github.issues.events user, repo
|
59
|
+
github.issues.events user, repo
|
61
60
|
}.to raise_error(Github::Error::NotFound)
|
62
61
|
end
|
63
62
|
end
|
@@ -65,8 +64,6 @@ describe Github::Issues::Events, :type => :base do
|
|
65
64
|
end # without issue_id
|
66
65
|
|
67
66
|
context 'with issue_id' do
|
68
|
-
let(:issue_id) { 123 }
|
69
|
-
|
70
67
|
context "resource found" do
|
71
68
|
before do
|
72
69
|
stub_get("/repos/#{user}/#{repo}/issues/#{issue_id}/events").
|
@@ -11,11 +11,11 @@ describe Github::PullRequests, :type => :base do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'resource found' do
|
14
|
-
let(:
|
14
|
+
let(:inputs) { { 'state'=> 'closed', 'unrelated' => true } }
|
15
15
|
|
16
16
|
before do
|
17
17
|
stub_get("/repos/#{user}/#{repo}/pulls").
|
18
|
-
with(:query =>
|
18
|
+
with(:query => inputs.except('unrelated')).
|
19
19
|
to_return(:body => fixture('pull_requests/pull_requests.json'),
|
20
20
|
:status => 200,
|
21
21
|
:headers => {:content_type => "application/json; charset=utf-8"})
|
@@ -26,23 +26,23 @@ describe Github::PullRequests, :type => :base do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should get the resources" do
|
29
|
-
github.pull_requests.pull_requests user, repo,
|
30
|
-
a_get("/repos/#{user}/#{repo}/pulls").with(:query =>
|
29
|
+
github.pull_requests.pull_requests user, repo, inputs
|
30
|
+
a_get("/repos/#{user}/#{repo}/pulls").with(:query => inputs).should have_been_made
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should return array of resources" do
|
34
|
-
pull_requests = github.pull_requests.pull_requests user, repo,
|
34
|
+
pull_requests = github.pull_requests.pull_requests user, repo, inputs
|
35
35
|
pull_requests.should be_an Array
|
36
36
|
pull_requests.should have(1).items
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should be a mash type" do
|
40
|
-
pull_requests = github.pull_requests.pull_requests user, repo,
|
40
|
+
pull_requests = github.pull_requests.pull_requests user, repo, inputs
|
41
41
|
pull_requests.first.should be_a Hashie::Mash
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should get pull request information" do
|
45
|
-
pull_requests = github.pull_requests.pull_requests user, repo,
|
45
|
+
pull_requests = github.pull_requests.pull_requests user, repo, inputs
|
46
46
|
pull_requests.first.title.should == 'new-feature'
|
47
47
|
end
|
48
48
|
|
data/spec/github/result_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Github::Result do
|
|
4
4
|
|
5
5
|
let(:github) { Github.new }
|
6
6
|
let(:user) { 'wycats' }
|
7
|
-
let(:res) { github.events.public
|
7
|
+
let(:res) { github.events.public({ 'per_page' => 20 }) }
|
8
8
|
let(:pages) { ['1', '5', '6'] }
|
9
9
|
let(:link) {
|
10
10
|
"<https://api.github.com/users/wycats/repos?page=6&per_page=20>; rel=\"last\", <https://api.github.com/users/wycats/repos?page=1&per_page=20>; rel=\"first\""
|
@@ -1,5 +1,242 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Github::Users::Followers, :type => :base do
|
4
|
-
|
4
|
+
|
5
|
+
before do
|
6
|
+
reset_authentication_for github
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
reset_authentication_for github
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#followers" do
|
14
|
+
context "resource found for a user" do
|
15
|
+
before do
|
16
|
+
stub_get("/users/#{user}/followers").
|
17
|
+
to_return(:body => fixture('users/followers.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.followers user
|
24
|
+
a_get("/users/#{user}/followers").should have_been_made
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return resource" do
|
28
|
+
followers = github.users.followers user
|
29
|
+
followers.should be_an Array
|
30
|
+
followers.should have(1).items
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be a mash type" do
|
34
|
+
followers = github.users.followers user
|
35
|
+
followers.first.should be_a Hashie::Mash
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should get followers information" do
|
39
|
+
followers = github.users.followers user
|
40
|
+
followers.first.login.should == 'octocat'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should yield to a block" do
|
44
|
+
github.users.should_receive(:followers).with(user).and_yield('web')
|
45
|
+
github.users.followers(user) { |param| 'web' }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "resource found for an authenticated user" do
|
50
|
+
before do
|
51
|
+
github.oauth_token = OAUTH_TOKEN
|
52
|
+
stub_get("/user/followers").
|
53
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
54
|
+
to_return(:body => fixture('users/followers.json'),
|
55
|
+
:status => 200,
|
56
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should get the resources" do
|
60
|
+
github.users.followers
|
61
|
+
a_get("/user/followers").
|
62
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
63
|
+
should have_been_made
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "resource not found for a user" do
|
68
|
+
before do
|
69
|
+
stub_get("/users/#{user}/followers").
|
70
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return 404 with a message 'Not Found'" do
|
74
|
+
expect {
|
75
|
+
github.users.followers user
|
76
|
+
}.to raise_error(Github::Error::NotFound)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end # followers
|
80
|
+
|
81
|
+
describe "#following" do
|
82
|
+
context "resource found for a user" do
|
83
|
+
before do
|
84
|
+
stub_get("/users/#{user}/following").
|
85
|
+
to_return(:body => fixture('users/followers.json'),
|
86
|
+
:status => 200,
|
87
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should get the resources" do
|
91
|
+
github.users.following user
|
92
|
+
a_get("/users/#{user}/following").should have_been_made
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should return resource" do
|
96
|
+
followings = github.users.following user
|
97
|
+
followings.should be_an Array
|
98
|
+
followings.should have(1).items
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should be a mash type" do
|
102
|
+
followings = github.users.following user
|
103
|
+
followings.first.should be_a Hashie::Mash
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should get following users information" do
|
107
|
+
followings = github.users.following user
|
108
|
+
followings.first.login.should == 'octocat'
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should yield to a block" do
|
112
|
+
github.users.should_receive(:following).with(user).and_yield('web')
|
113
|
+
github.users.following(user) { |param| 'web' }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "resource found for an authenticated user" do
|
118
|
+
before do
|
119
|
+
github.oauth_token = OAUTH_TOKEN
|
120
|
+
stub_get("/user/following").
|
121
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
122
|
+
to_return(:body => fixture('users/followers.json'),
|
123
|
+
:status => 200,
|
124
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should get the resources" do
|
128
|
+
github.users.following
|
129
|
+
a_get("/user/following").
|
130
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
131
|
+
should have_been_made
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "resource not found for a user" do
|
136
|
+
before do
|
137
|
+
stub_get("/users/#{user}/following").
|
138
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should return 404 with a message 'Not Found'" do
|
142
|
+
expect {
|
143
|
+
github.users.following user
|
144
|
+
}.to raise_error(Github::Error::NotFound)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end # following
|
148
|
+
|
149
|
+
context '#following?' do
|
150
|
+
before do
|
151
|
+
github.oauth_token = OAUTH_TOKEN
|
152
|
+
stub_get("/user/following/#{user}").
|
153
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
154
|
+
to_return(:body => '',
|
155
|
+
:status => 204,
|
156
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should raise error if username not present' do
|
160
|
+
expect {
|
161
|
+
github.users.following? nil
|
162
|
+
}.to raise_error(ArgumentError)
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should perform request' do
|
166
|
+
github.users.following?(user)
|
167
|
+
a_get("/user/following/#{user}").
|
168
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
169
|
+
should have_been_made
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should return true if user is being followed' do
|
173
|
+
github.users.following?(user).should be_true
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should return false if user is not being followed' do
|
177
|
+
stub_get("/user/following/#{user}").
|
178
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
179
|
+
to_return(:body => '',
|
180
|
+
:status => 404,
|
181
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
182
|
+
github.users.following?(user).should be_false
|
183
|
+
end
|
184
|
+
end # following?
|
185
|
+
|
186
|
+
context '#follow' do
|
187
|
+
before do
|
188
|
+
github.oauth_token = OAUTH_TOKEN
|
189
|
+
stub_put("/user/following/#{user}").
|
190
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
191
|
+
to_return(:body => '',
|
192
|
+
:status => 204,
|
193
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should raise error if gist id not present" do
|
197
|
+
expect {
|
198
|
+
github.users.follow nil
|
199
|
+
}.to raise_error(ArgumentError)
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'successfully unfollows a user' do
|
203
|
+
github.users.follow(user)
|
204
|
+
a_put("/user/following/#{user}").
|
205
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
206
|
+
should have_been_made
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should return 204 with a message 'Not Found'" do
|
210
|
+
github.users.follow(user).status.should be 204
|
211
|
+
end
|
212
|
+
end # follow
|
213
|
+
|
214
|
+
context '#unfollow' do
|
215
|
+
before do
|
216
|
+
github.oauth_token = OAUTH_TOKEN
|
217
|
+
stub_delete("/user/following/#{user}").
|
218
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
219
|
+
to_return(:body => '',
|
220
|
+
:status => 204,
|
221
|
+
:headers => {:content_type => "application/json; charset=utf-8"})
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should raise error if gist id not present" do
|
225
|
+
expect {
|
226
|
+
github.users.unfollow nil
|
227
|
+
}.to raise_error(ArgumentError)
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'successfully unfollows a user' do
|
231
|
+
github.users.unfollow(user)
|
232
|
+
a_delete("/user/following/#{user}").
|
233
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
234
|
+
should have_been_made
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should return 204 with a message 'Not Found'" do
|
238
|
+
github.users.unfollow(user).status.should be 204
|
239
|
+
end
|
240
|
+
end # unfollow
|
241
|
+
|
5
242
|
end # Github::Users::Followers
|
data/spec/github/users_spec.rb
CHANGED
@@ -14,7 +14,8 @@ describe Github::Users, :type => :base do
|
|
14
14
|
context "resource found for a user" do
|
15
15
|
before do
|
16
16
|
stub_get("/users/#{user}").
|
17
|
-
to_return(:body => fixture('users/user.json'),
|
17
|
+
to_return(:body => fixture('users/user.json'),
|
18
|
+
:status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
18
19
|
end
|
19
20
|
|
20
21
|
it "should get the resources" do
|
@@ -45,19 +46,16 @@ describe Github::Users, :type => :base do
|
|
45
46
|
|
46
47
|
context "resource found for an authenticated user" do
|
47
48
|
before do
|
48
|
-
reset_authentication_for github
|
49
49
|
github.oauth_token = OAUTH_TOKEN
|
50
|
-
stub_get("/user
|
50
|
+
stub_get("/user").
|
51
|
+
with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
|
51
52
|
to_return(:body => fixture('users/user.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
52
53
|
end
|
53
54
|
|
54
|
-
after do
|
55
|
-
reset_authentication_for github
|
56
|
-
end
|
57
|
-
|
58
55
|
it "should get the resources" do
|
59
56
|
github.users.get_user
|
60
|
-
a_get("/user
|
57
|
+
a_get("/user").with(:query => {:access_token => "#{OAUTH_TOKEN}"}).
|
58
|
+
should have_been_made
|
61
59
|
end
|
62
60
|
end
|
63
61
|
|
@@ -90,17 +88,12 @@ describe Github::Users, :type => :base do
|
|
90
88
|
|
91
89
|
context "resouce updated" do
|
92
90
|
before do
|
93
|
-
reset_authentication_for github
|
94
91
|
github.oauth_token = OAUTH_TOKEN
|
95
92
|
stub_patch("/user?access_token=#{OAUTH_TOKEN}").with(user_params).
|
96
93
|
to_return(:body => fixture('users/user.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
97
94
|
|
98
95
|
end
|
99
96
|
|
100
|
-
after do
|
101
|
-
reset_authentication_for github
|
102
|
-
end
|
103
|
-
|
104
97
|
it "should create resource successfully" do
|
105
98
|
github.users.update_user
|
106
99
|
a_patch("/user?access_token=#{OAUTH_TOKEN}").with(user_params).should have_been_made
|
@@ -119,7 +112,6 @@ describe Github::Users, :type => :base do
|
|
119
112
|
|
120
113
|
context "failed to update resource" do
|
121
114
|
before do
|
122
|
-
reset_authentication_for github
|
123
115
|
github.oauth_token = OAUTH_TOKEN
|
124
116
|
stub_patch("/user?access_token=#{OAUTH_TOKEN}").with(user_params).
|
125
117
|
to_return(:body => fixture('users/user.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|