|
139 | 139 | let(:raw_post) { { :bill => params }.to_json } |
140 | 140 |
|
141 | 141 | it "should send the raw post body" do |
142 | | - client.should_receive(method).with(path, raw_post) |
| 142 | + client.should_receive(method).with(path, raw_post, nil) |
143 | 143 | do_request |
144 | 144 | end |
145 | 145 | end |
146 | 146 |
|
147 | 147 | context "when raw_post is not defined" do |
148 | 148 | it "should send the params hash" do |
149 | | - client.should_receive(method).with(path, params) |
| 149 | + client.should_receive(method).with(path, params, nil) |
150 | 150 | do_request |
151 | 151 | end |
152 | 152 | end |
153 | 153 |
|
154 | 154 | it "should allow extra parameters to be passed in" do |
155 | | - client.should_receive(method).with(path, params.merge("extra" => true)) |
| 155 | + client.should_receive(method).with(path, params.merge("extra" => true), nil) |
156 | 156 | do_request(:extra => true) |
157 | 157 | end |
158 | 158 |
|
159 | 159 | it "should overwrite parameters" do |
160 | | - client.should_receive(method).with(path, params.merge("size" => "large")) |
| 160 | + client.should_receive(method).with(path, params.merge("size" => "large"), nil) |
161 | 161 | do_request(:size => "large") |
162 | 162 | end |
163 | 163 |
|
164 | 164 | it "should overwrite path variables" do |
165 | | - client.should_receive(method).with("/orders/2", params) |
| 165 | + client.should_receive(method).with("/orders/2", params, nil) |
166 | 166 | do_request(:id => 2) |
167 | 167 | end |
168 | 168 | end |
|
203 | 203 | end |
204 | 204 | end |
205 | 205 |
|
206 | | - # parameter :type, "The type of drink you want." |
207 | | - # parameter :size, "The size of drink you want." |
208 | | - # parameter :note, "Any additional notes about your order." |
209 | | - |
210 | | - # required_parameters :type, :size |
211 | | - |
212 | | - # raw_post { { :bill => params }.to_json } |
213 | | - |
214 | | - # example_request "Ordering a cup of coffee" do |
215 | | - # param(:type) { "coffee" } |
216 | | - # param(:size) { "cup" } |
217 | | - |
218 | | - # should_respond_with_status eq(200) |
219 | | - # should_respond_with_body eq("Order created") |
220 | | - # end |
221 | | - |
222 | | - # example_request "An invalid order" do |
223 | | - # param(:type) { "caramel macchiato" } |
224 | | - # param(:note) { "whipped cream" } |
225 | | - |
226 | | - # should_respond_with_status eq(400) |
227 | | - # should_respond_with_body json_eql({:errors => {:size => ["can't be blank"]}}.to_json) |
228 | | - # end |
229 | | - #end |
230 | | - # |
231 | | - |
232 | 206 | describe "nested parameters" do |
233 | 207 | parameter :per_page, "Number of results on a page" |
234 | 208 |
|
|
309 | 283 |
|
310 | 284 | get "/users/:id/orders" do |
311 | 285 | example "Page should be in the query string" do |
312 | | - client.should_receive(method).with do |path, data| |
| 286 | + client.should_receive(method).with do |path, data, headers| |
313 | 287 | path.should =~ /^\/users\/1\/orders\?/ |
314 | 288 | path.split("?")[1].split("&").sort.should == "page=2&message=Thank+you".split("&").sort |
315 | 289 | data.should be_nil |
| 290 | + headers.should be_nil |
316 | 291 | end |
317 | 292 | do_request |
318 | 293 | end |
319 | 294 | end |
320 | 295 |
|
321 | 296 | post "/users/:id/orders" do |
322 | 297 | example "Page should be in the post body" do |
323 | | - client.should_receive(method).with("/users/1/orders", {"page" => 2, "message" => "Thank you"}) |
| 298 | + client.should_receive(method).with("/users/1/orders", {"page" => 2, "message" => "Thank you"}, nil) |
324 | 299 | do_request |
325 | 300 | end |
326 | 301 | end |
|
411 | 386 |
|
412 | 387 | context "no extra params" do |
413 | 388 | before do |
414 | | - client.should_receive(:post).with("/orders", {}) |
| 389 | + client.should_receive(:post).with("/orders", {}, nil) |
415 | 390 | end |
416 | 391 |
|
417 | 392 | example_request "Creating an order" |
|
423 | 398 |
|
424 | 399 | context "extra options for do_request" do |
425 | 400 | before do |
426 | | - client.should_receive(:post).with("/orders", {"order_type" => "big"}) |
| 401 | + client.should_receive(:post).with("/orders", {"order_type" => "big"}, nil) |
427 | 402 | end |
428 | 403 |
|
429 | 404 | example_request "should take an optional parameter hash", :order_type => "big" |
|
444 | 419 | end |
445 | 420 | end |
446 | 421 | end |
| 422 | + |
| 423 | + context "headers" do |
| 424 | + put "/orders" do |
| 425 | + header "Accept", "application/json" |
| 426 | + |
| 427 | + it "should be sent with the request" do |
| 428 | + example.metadata[:headers].should == { "Accept" => "application/json" } |
| 429 | + end |
| 430 | + |
| 431 | + context "nested headers" do |
| 432 | + header "Content-Type", "application/json" |
| 433 | + |
| 434 | + it "does not affect the outer context's assertions" do |
| 435 | + # pass |
| 436 | + end |
| 437 | + end |
| 438 | + end |
| 439 | + end |
447 | 440 | end |
448 | 441 |
|
449 | 442 | resource "top level parameters" do |
|
0 commit comments