github_api 0.2.0 → 0.2.1
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/README.rdoc +51 -20
- data/lib/github_api.rb +3 -1
- data/lib/github_api/api.rb +8 -2
- data/lib/github_api/authorization.rb +52 -0
- data/lib/github_api/cache_control.rb +19 -0
- data/lib/github_api/configuration.rb +8 -11
- data/lib/github_api/connection.rb +18 -36
- data/lib/github_api/gists/comments.rb +17 -5
- data/lib/github_api/issues.rb +9 -1
- data/lib/github_api/issues/comments.rb +15 -4
- data/lib/github_api/mime_type.rb +55 -0
- data/lib/github_api/pull_requests.rb +14 -0
- data/lib/github_api/pull_requests/comments.rb +10 -0
- data/lib/github_api/repos/collaborators.rb +41 -19
- data/lib/github_api/repos/commits.rb +108 -43
- data/lib/github_api/repos/forks.rb +32 -13
- data/lib/github_api/request.rb +12 -3
- data/lib/github_api/request/caching.rb +33 -0
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/repos/collaborators.json +8 -0
- data/spec/fixtures/repos/commit.json +53 -0
- data/spec/fixtures/repos/commit_comment.json +16 -0
- data/spec/fixtures/repos/commit_comments.json +18 -0
- data/spec/fixtures/repos/commits.json +27 -0
- data/spec/fixtures/{repos_list.json → repos/fork.json} +0 -0
- data/spec/fixtures/repos/forks.json +29 -0
- data/spec/fixtures/repos/repo_comments.json +18 -0
- data/spec/github/authorization_spec.rb +71 -0
- data/spec/github/mime_type_spec.rb +70 -0
- data/spec/github/repos/collaborators_spec.rb +166 -3
- data/spec/github/repos/commits_spec.rb +421 -2
- data/spec/github/repos/forks_spec.rb +101 -3
- data/spec/github/repos/watching_spec.rb +6 -0
- data/spec/github_spec.rb +8 -4
- metadata +17 -9
- data/lib/github_api/api/extract_options.rb +0 -17
- data/lib/github_api/api/mime.rb +0 -5
- data/spec/fixtures/collaborators_list.json +0 -6
- data/spec/fixtures/commits_list.json +0 -25
- data/spec/fixtures/repos_branches_list.json +0 -7
|
@@ -1,6 +1,169 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Github::Repos::Collaborators do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
|
|
5
|
+
let(:github) { Github.new }
|
|
6
|
+
let(:user) { 'peter-murach' }
|
|
7
|
+
let(:repo) { 'github' }
|
|
8
|
+
let(:collaborator) { 'octocat' }
|
|
9
|
+
|
|
10
|
+
describe "collaborators" do
|
|
11
|
+
context "resource found" do
|
|
12
|
+
before do
|
|
13
|
+
stub_get("/repos/#{user}/#{repo}/collaborators").
|
|
14
|
+
to_return(:body => fixture('repos/collaborators.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should fail to get resource without username" do
|
|
18
|
+
github.user, github.repo = nil, nil
|
|
19
|
+
expect { github.repos.collaborators }.to raise_error(ArgumentError)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should get the resources" do
|
|
23
|
+
github.repos.collaborators user, repo
|
|
24
|
+
a_get("/repos/#{user}/#{repo}/collaborators").should have_been_made
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should return array of resources" do
|
|
28
|
+
collaborators = github.repos.collaborators user, repo
|
|
29
|
+
collaborators.should be_an Array
|
|
30
|
+
collaborators.should have(1).items
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should be a mash type" do
|
|
34
|
+
collaborators = github.repos.collaborators user, repo
|
|
35
|
+
collaborators.first.should be_a Hashie::Mash
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should get collaborator information" do
|
|
39
|
+
collaborators = github.repos.collaborators user, repo
|
|
40
|
+
collaborators.first.login.should == 'octocat'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should yield to a block" do
|
|
44
|
+
github.repos.should_receive(:collaborators).with(user, repo).and_yield('web')
|
|
45
|
+
github.repos.collaborators(user, repo) { |param| 'web' }
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "resource not found" do
|
|
50
|
+
before do
|
|
51
|
+
stub_get("/repos/#{user}/#{repo}/collaborators").
|
|
52
|
+
to_return(:body => "", :status => [404, "Not Found"], :headers => {:content_type => "application/json; charset=utf-8"})
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should return 404 with a message 'Not Found'" do
|
|
56
|
+
expect {
|
|
57
|
+
github.repos.collaborators user, repo
|
|
58
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end # collaborators
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
describe "collaborator?" do
|
|
65
|
+
context "resource found " do
|
|
66
|
+
before do
|
|
67
|
+
stub_get("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
|
|
68
|
+
to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should fail to get resource without collaborator name" do
|
|
72
|
+
expect {
|
|
73
|
+
github.repos.collaborator?(user, repo, nil)
|
|
74
|
+
}.to raise_error(ArgumentError)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should get the resource" do
|
|
78
|
+
github.repos.collaborator? user, repo, collaborator
|
|
79
|
+
a_get("/repos/#{user}/#{repo}/collaborators/#{collaborator}").should have_been_made
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should find collaborator" do
|
|
83
|
+
github.repos.should_receive(:collaborator?).with(user, repo, collaborator).and_return true
|
|
84
|
+
github.repos.collaborator? user, repo, collaborator
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context "resource not found" do
|
|
89
|
+
before do
|
|
90
|
+
stub_get("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
|
|
91
|
+
to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "should fail to retrieve resource" do
|
|
95
|
+
github.repos.should_receive(:collaborator?).with(user, repo, collaborator).and_return false
|
|
96
|
+
github.repos.collaborator? user, repo, collaborator
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end # collaborator?
|
|
100
|
+
|
|
101
|
+
describe "add_collaborator" do
|
|
102
|
+
|
|
103
|
+
context "resouce added" do
|
|
104
|
+
before do
|
|
105
|
+
stub_put("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
|
|
106
|
+
to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should fail to add resource if 'collaborator' input is missing" do
|
|
110
|
+
expect {
|
|
111
|
+
github.repos.add_collaborator user, repo, nil
|
|
112
|
+
}.to raise_error(ArgumentError)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "should add resource successfully" do
|
|
116
|
+
github.repos.add_collaborator user, repo, collaborator
|
|
117
|
+
a_put("/repos/#{user}/#{repo}/collaborators/#{collaborator}").should have_been_made
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context "failed to add resource" do
|
|
122
|
+
before do
|
|
123
|
+
stub_put("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
|
|
124
|
+
to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "should fail to add resource" do
|
|
128
|
+
expect {
|
|
129
|
+
github.repos.add_collaborator user, repo, collaborator
|
|
130
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end # add_collaborator
|
|
134
|
+
|
|
135
|
+
describe "remove_collaborator" do
|
|
136
|
+
|
|
137
|
+
context "resouce added" do
|
|
138
|
+
before do
|
|
139
|
+
stub_delete("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
|
|
140
|
+
to_return(:body => '', :status => 204, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "should fail to add resource if 'collaborator' input is missing" do
|
|
144
|
+
expect {
|
|
145
|
+
github.repos.remove_collaborator user, repo, nil
|
|
146
|
+
}.to raise_error(ArgumentError)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "should add resource successfully" do
|
|
150
|
+
github.repos.remove_collaborator user, repo, collaborator
|
|
151
|
+
a_delete("/repos/#{user}/#{repo}/collaborators/#{collaborator}").should have_been_made
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
context "failed to remove resource" do
|
|
156
|
+
before do
|
|
157
|
+
stub_delete("/repos/#{user}/#{repo}/collaborators/#{collaborator}").
|
|
158
|
+
to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "should fail to remove resource" do
|
|
162
|
+
expect {
|
|
163
|
+
github.repos.remove_collaborator user, repo, collaborator
|
|
164
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end # remove_collaborator
|
|
168
|
+
|
|
169
|
+
end # Github::Repos::Collaborators
|
|
@@ -1,5 +1,424 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Github::Repos::Commits do
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
let(:github) { Github.new }
|
|
6
|
+
let(:user) { 'peter-murach' }
|
|
7
|
+
let(:repo) { 'github' }
|
|
8
|
+
|
|
9
|
+
describe "commits" do
|
|
10
|
+
context "resource found" do
|
|
11
|
+
before do
|
|
12
|
+
stub_get("/repos/#{user}/#{repo}/commits").
|
|
13
|
+
to_return(:body => fixture('repos/commits.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should fail to get resource without username" do
|
|
17
|
+
github.user, github.repo = nil, nil
|
|
18
|
+
expect { github.repos.commits }.to raise_error(ArgumentError)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should get the resources" do
|
|
22
|
+
github.repos.commits user, repo
|
|
23
|
+
a_get("/repos/#{user}/#{repo}/commits").should have_been_made
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should return array of resources" do
|
|
27
|
+
commits = github.repos.commits user, repo
|
|
28
|
+
commits.should be_an Array
|
|
29
|
+
commits.should have(1).items
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should be a mash type" do
|
|
33
|
+
commits = github.repos.commits user, repo
|
|
34
|
+
commits.first.should be_a Hashie::Mash
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should get commit information" do
|
|
38
|
+
commits = github.repos.commits user, repo
|
|
39
|
+
commits.first.author.name.should == 'Scott Chacon'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should yield to a block" do
|
|
43
|
+
github.repos.should_receive(:commits).with(user, repo).and_yield('web')
|
|
44
|
+
github.repos.commits(user, repo) { |param| 'web' }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context "resource not found" do
|
|
49
|
+
before do
|
|
50
|
+
stub_get("/repos/#{user}/#{repo}/commits").
|
|
51
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should return 404 with a message 'Not Found'" do
|
|
55
|
+
expect {
|
|
56
|
+
github.repos.commits user, repo
|
|
57
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end # commits
|
|
61
|
+
|
|
62
|
+
describe "commit" do
|
|
63
|
+
let(:sha) { '23432dfosfsufd' }
|
|
64
|
+
|
|
65
|
+
context "resource found" do
|
|
66
|
+
before do
|
|
67
|
+
stub_get("/repos/#{user}/#{repo}/commits/#{sha}").
|
|
68
|
+
to_return(:body => fixture('repos/commit.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should fail to get resource without sha key" do
|
|
72
|
+
expect {
|
|
73
|
+
github.repos.commit(user, repo, nil)
|
|
74
|
+
}.to raise_error(ArgumentError)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should get the resource" do
|
|
78
|
+
github.repos.commit user, repo, sha
|
|
79
|
+
a_get("/repos/#{user}/#{repo}/commits/#{sha}").should have_been_made
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should get commit information" do
|
|
83
|
+
commit = github.repos.commit user, repo, sha
|
|
84
|
+
commit.commit.author.name.should == 'Monalisa Octocat'
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should return mash" do
|
|
88
|
+
commit = github.repos.commit user, repo, sha
|
|
89
|
+
commit.should be_a Hashie::Mash
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context "resource not found" do
|
|
95
|
+
before do
|
|
96
|
+
stub_get("/repos/#{user}/#{repo}/commits/#{sha}").
|
|
97
|
+
to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "should fail to retrive resource" do
|
|
101
|
+
expect {
|
|
102
|
+
github.repos.commit user, repo, sha
|
|
103
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end # commit
|
|
107
|
+
|
|
108
|
+
describe "commit comments" do
|
|
109
|
+
context "resource found" do
|
|
110
|
+
before do
|
|
111
|
+
stub_get("/repos/#{user}/#{repo}/comments").
|
|
112
|
+
to_return(:body => fixture('repos/repo_comments.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "should fail to get resource without username" do
|
|
116
|
+
github.user, github.repo = nil, nil
|
|
117
|
+
expect { github.repos.repo_comments }.to raise_error(ArgumentError)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "should get the resources" do
|
|
121
|
+
github.repos.repo_comments user, repo
|
|
122
|
+
a_get("/repos/#{user}/#{repo}/comments").should have_been_made
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "should return array of resources" do
|
|
126
|
+
repo_comments = github.repos.repo_comments user, repo
|
|
127
|
+
repo_comments.should be_an Array
|
|
128
|
+
repo_comments.should have(1).items
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "should be a mash type" do
|
|
132
|
+
repo_comments = github.repos.repo_comments user, repo
|
|
133
|
+
repo_comments.first.should be_a Hashie::Mash
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "should get commit comment information" do
|
|
137
|
+
repo_comments = github.repos.repo_comments user, repo
|
|
138
|
+
repo_comments.first.user.login.should == 'octocat'
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "should yield to a block" do
|
|
142
|
+
github.repos.should_receive(:repo_comments).with(user, repo).and_yield('web')
|
|
143
|
+
github.repos.repo_comments(user, repo) { |param| 'web' }
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
context "resource not found" do
|
|
148
|
+
before do
|
|
149
|
+
stub_get("/repos/#{user}/#{repo}/comments").
|
|
150
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it "should return 404 with a message 'Not Found'" do
|
|
154
|
+
expect {
|
|
155
|
+
github.repos.repo_comments user, repo
|
|
156
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end # repo comments
|
|
160
|
+
|
|
161
|
+
describe "commit_comments" do
|
|
162
|
+
let(:sha) { '23432dfosfsufd' }
|
|
163
|
+
|
|
164
|
+
context "resource found" do
|
|
165
|
+
before do
|
|
166
|
+
stub_get("/repos/#{user}/#{repo}/commits/#{sha}/comments").
|
|
167
|
+
to_return(:body => fixture('repos/commit_comments.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it "should fail to get resource without sha key" do
|
|
171
|
+
expect {
|
|
172
|
+
github.repos.commit_comments(user, repo, nil)
|
|
173
|
+
}.to raise_error(ArgumentError)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "should get the resource" do
|
|
177
|
+
github.repos.commit_comments user, repo, sha
|
|
178
|
+
a_get("/repos/#{user}/#{repo}/commits/#{sha}/comments").should have_been_made
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "should return array of resources" do
|
|
182
|
+
commit_comments = github.repos.commit_comments user, repo, sha
|
|
183
|
+
commit_comments.should be_an Array
|
|
184
|
+
commit_comments.should have(1).items
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it "should be a mash type" do
|
|
188
|
+
commit_comments = github.repos.commit_comments user, repo, sha
|
|
189
|
+
commit_comments.first.should be_a Hashie::Mash
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "should get commit comment information" do
|
|
193
|
+
commit_comments = github.repos.commit_comments user, repo, sha
|
|
194
|
+
commit_comments.first.user.login.should == 'octocat'
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it "should yield to a block" do
|
|
198
|
+
github.repos.should_receive(:commit_comments).with(user, repo, sha).and_yield('web')
|
|
199
|
+
github.repos.commit_comments(user, repo, sha) { |param| 'web' }
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
context "resource not found" do
|
|
204
|
+
before do
|
|
205
|
+
stub_get("/repos/#{user}/#{repo}/commits/#{sha}/comments").
|
|
206
|
+
to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it "should fail to retrive resource" do
|
|
210
|
+
expect {
|
|
211
|
+
github.repos.commit_comments user, repo, sha
|
|
212
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end # commit_comments
|
|
216
|
+
|
|
217
|
+
describe "commit_comment" do
|
|
218
|
+
let(:comment_id) { 1 }
|
|
219
|
+
|
|
220
|
+
context "resource found" do
|
|
221
|
+
before do
|
|
222
|
+
stub_get("/repos/#{user}/#{repo}/comments/#{comment_id}").
|
|
223
|
+
to_return(:body => fixture('repos/commit_comment.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it "should fail to get resource without comment id" do
|
|
227
|
+
expect {
|
|
228
|
+
github.repos.commit_comment user, repo, nil
|
|
229
|
+
}.to raise_error(ArgumentError)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
it "should get the resource" do
|
|
233
|
+
github.repos.commit_comment user, repo, comment_id
|
|
234
|
+
a_get("/repos/#{user}/#{repo}/comments/#{comment_id}").should have_been_made
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it "should get commit comment information" do
|
|
238
|
+
commit_comment = github.repos.commit_comment user, repo, comment_id
|
|
239
|
+
commit_comment.user.login.should == 'octocat'
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it "should return mash" do
|
|
243
|
+
commit_comment = github.repos.commit_comment user, repo, comment_id
|
|
244
|
+
commit_comment.should be_a Hashie::Mash
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
context "resource not found" do
|
|
250
|
+
before do
|
|
251
|
+
stub_get("/repos/#{user}/#{repo}/comments/#{comment_id}").
|
|
252
|
+
to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
it "should fail to retrive resource" do
|
|
256
|
+
expect {
|
|
257
|
+
github.repos.commit_comment user, repo, comment_id
|
|
258
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end # commit_comment
|
|
262
|
+
|
|
263
|
+
describe "create_comment" do
|
|
264
|
+
let(:sha) { '23432dfosfsufd' }
|
|
265
|
+
let(:inputs) { {'body'=> 'web', :commit_id => 1, :line => 1, :path => 'file1.txt', :position => 4 } }
|
|
266
|
+
|
|
267
|
+
context "resouce created" do
|
|
268
|
+
before do
|
|
269
|
+
stub_post("/repos/#{user}/#{repo}/commits/#{sha}/comments").with(inputs).
|
|
270
|
+
to_return(:body => fixture('repos/commit_comment.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
271
|
+
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
it "should fail to create resource if 'body' input is missing" do
|
|
275
|
+
expect {
|
|
276
|
+
github.repos.create_comment user, repo, sha, inputs.except('body')
|
|
277
|
+
}.to raise_error(ArgumentError)
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
it "should fail to create resource if 'commit_id' input is missing" do
|
|
281
|
+
expect {
|
|
282
|
+
github.repos.create_comment user, repo, sha, inputs.except(:commit_id)
|
|
283
|
+
}.to raise_error(ArgumentError)
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
it "should fail to create resource if 'line' input is missing" do
|
|
287
|
+
expect {
|
|
288
|
+
github.repos.create_comment user, repo, sha, inputs.except(:line)
|
|
289
|
+
}.to raise_error(ArgumentError)
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
it "should fail to create resource if 'path' input is missing" do
|
|
293
|
+
expect {
|
|
294
|
+
github.repos.create_comment user, repo, sha, inputs.except(:path)
|
|
295
|
+
}.to raise_error(ArgumentError)
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
it "should fail to create resource if 'position' input is missing" do
|
|
299
|
+
expect {
|
|
300
|
+
github.repos.create_comment user, repo, sha, inputs.except(:position)
|
|
301
|
+
}.to raise_error(ArgumentError)
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
it "should create resource successfully" do
|
|
305
|
+
github.repos.create_comment user, repo, sha, inputs
|
|
306
|
+
a_post("/repos/#{user}/#{repo}/commits/#{sha}/comments").with(inputs).should have_been_made
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
it "should return the resource" do
|
|
310
|
+
comment = github.repos.create_comment user, repo, sha, inputs
|
|
311
|
+
comment.should be_a Hashie::Mash
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
it "should get the commit comment information" do
|
|
315
|
+
comment = github.repos.create_comment user, repo, sha, inputs
|
|
316
|
+
comment.user.login.should == 'octocat'
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
context "failed to create resource" do
|
|
321
|
+
before do
|
|
322
|
+
stub_post("/repos/#{user}/#{repo}/commits/#{sha}/comments").with(inputs).
|
|
323
|
+
to_return(:body => fixture('repos/commit_comment.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
324
|
+
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
it "should fail to retrieve resource" do
|
|
328
|
+
expect {
|
|
329
|
+
github.repos.create_comment user, repo, sha, inputs
|
|
330
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
end # create_comment
|
|
334
|
+
|
|
335
|
+
describe "delete_comment" do
|
|
336
|
+
let(:comment_id) { 1 }
|
|
337
|
+
|
|
338
|
+
context "resource deleted successfully" do
|
|
339
|
+
before do
|
|
340
|
+
stub_delete("/repos/#{user}/#{repo}/comments/#{comment_id}").
|
|
341
|
+
to_return(:body => '', :status => 204, :headers => { :content_type => "application/json; charset=utf-8"})
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
it "should fail to delete without 'user/repo' parameters" do
|
|
345
|
+
github.user, github.repo = nil, nil
|
|
346
|
+
expect { github.repos.delete_comment }.to raise_error(ArgumentError)
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
it "should fail to delete resource without 'comment_id'" do
|
|
350
|
+
expect {
|
|
351
|
+
github.repos.delete_comment user, repo, nil
|
|
352
|
+
}.to raise_error(ArgumentError)
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
it "should delete the resource" do
|
|
356
|
+
github.repos.delete_comment user, repo, comment_id
|
|
357
|
+
a_delete("/repos/#{user}/#{repo}/comments/#{comment_id}").should have_been_made
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
context "failed to delete resource" do
|
|
362
|
+
before do
|
|
363
|
+
stub_delete("/repos/#{user}/#{repo}/comments/#{comment_id}").
|
|
364
|
+
to_return(:body => '', :status => 404, :headers => { :content_type => "application/json; charset=utf-8"})
|
|
365
|
+
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
it "should fail to find resource" do
|
|
369
|
+
expect {
|
|
370
|
+
github.repos.delete_comment user, repo, comment_id
|
|
371
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
end # delete_comment
|
|
375
|
+
|
|
376
|
+
describe "update_comment" do
|
|
377
|
+
let(:comment_id) { 1 }
|
|
378
|
+
let(:inputs) { {'body'=> 'web'} }
|
|
379
|
+
|
|
380
|
+
context "resouce created" do
|
|
381
|
+
before do
|
|
382
|
+
stub_patch("/repos/#{user}/#{repo}/comments/#{comment_id}").with(inputs).
|
|
383
|
+
to_return(:body => fixture('repos/commit_comment.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
384
|
+
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
it "should fail to create resource if 'body' input is missing" do
|
|
388
|
+
expect {
|
|
389
|
+
github.repos.update_comment user, repo, comment_id, inputs.except('body')
|
|
390
|
+
}.to raise_error(ArgumentError)
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
it "should create resource successfully" do
|
|
394
|
+
github.repos.update_comment user, repo, comment_id, inputs
|
|
395
|
+
a_patch("/repos/#{user}/#{repo}/comments/#{comment_id}").with(inputs).should have_been_made
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
it "should return the resource" do
|
|
399
|
+
comment = github.repos.update_comment user, repo, comment_id, inputs
|
|
400
|
+
comment.should be_a Hashie::Mash
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
it "should get the commit comment information" do
|
|
404
|
+
comment = github.repos.update_comment user, repo, comment_id, inputs
|
|
405
|
+
comment.user.login.should == 'octocat'
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
context "failed to update resource" do
|
|
410
|
+
before do
|
|
411
|
+
stub_patch("/repos/#{user}/#{repo}/comments/#{comment_id}").with(inputs).
|
|
412
|
+
to_return(:body => fixture('repos/commit_comment.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
|
|
413
|
+
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
it "should fail to retrieve resource" do
|
|
417
|
+
expect {
|
|
418
|
+
github.repos.update_comment user, repo, comment_id, inputs
|
|
419
|
+
}.to raise_error(Github::ResourceNotFound)
|
|
420
|
+
end
|
|
421
|
+
end
|
|
422
|
+
end # update_comment
|
|
423
|
+
|
|
424
|
+
end # Github::Repos::Commits
|