in new request spec helper, how do I test content_type (want to test underlying provides)

4 views
Skip to first unread message

lastobelus

unread,
Nov 12, 2008, 9:29:30 PM11/12/08
to merb
How would I do the equivalent of this test in Merb 1.0:

describe SageUsers, "(xml)" do

it "should not provide reset_password for xml" do
lambda { request('/reset_password/xxxyyy', :format =>
'xml', :method => 'GET')}.
should raise_error(Merb::ControllerExceptions::NotAcceptable)
end

end


I've tried

response = request('/reset_password/xxxyyy', :format =>
"xml", :method => 'GET')
and
response = request('/reset_password/xxxyyy', :content_type =>
"application/xml", :method => 'GET')

no error is thrown, and in the controller action content_type is :html

(I have many many more no-longer-working controller specs, but lets
start with this one)

Per Melin

unread,
Nov 12, 2008, 10:34:26 PM11/12/08
to me...@googlegroups.com
> describe SageUsers, "(xml)" do
>
> it "should not provide reset_password for xml" do
> lambda { request('/reset_password/xxxyyy', :format =>
> 'xml', :method => 'GET')}.
> should raise_error(Merb::ControllerExceptions::NotAcceptable)
> end
>
> end

How about this?

@response = request('/reset_password/xxxyyy', :format => 'xml',
:method => 'GET')
@response.status.should == 406

Yehuda Katz

unread,
Nov 12, 2008, 10:43:00 PM11/12/08
to me...@googlegroups.com
Try appending .xml to the path. Alternatively, you could directly
specify the Accept header.

Sent from my iPhone

Per Melin

unread,
Nov 12, 2008, 11:27:48 PM11/12/08
to me...@googlegroups.com
> Try appending .xml to the path. Alternatively, you could directly
> specify the Accept header.

And this is how you specify the Accept header to Rack, yes?

request('/reset_password/xxxyyy', :method => 'GET', 'HTTP_ACCEPT' =>
'application/xml')

lastobelus

unread,
Nov 13, 2008, 7:28:19 AM11/13/08
to merb
Ah, HTTP_ACCEPT is what I was looking for. Thanks!

:format => 'xml' does not work, and adding .xml gives me no route error

Michael Klishin

unread,
Nov 13, 2008, 2:44:45 PM11/13/08
to me...@googlegroups.com
2008/11/13 lastobelus <lasto...@gmail.com>:

> :format => 'xml' does not work, and adding .xml gives me no route error

url suffix works as well as directly setting Accept header.
If .:format segment in the url present, :format *always* taken from it,
and Accept header is ignored.
--
MK

Reply all
Reply to author
Forward
0 new messages