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