views:

34

answers:

2

I'm trying to write a functional test for an action that must run over https. I'm not testing the HTTPS redirect - I already know that works from another test.

What I'm trying to do is:

get :new, :protocol => "https://"
assert_redirected_to :root

But this does not issue the request over https. Is there a "get" option that will allow me to change the protocol?

Also, if I try to specify the url (e.g.: get "https:/test.host/do/something") I get a routing error, since there's no route at my rails level for https - it's taken care of at my web server level.

+1  A: 

In functionnal test, there are no routing from HTTP or anything else, it's use directly the controller. So you can't test that become from HTTP or HTTPS.

But you can mock the request.protocole dans define it like 'https'

request.stub(:protocol).and_return("https://")
get :new
shingara
Thanks. I wound up taking a stub approach to remove the SSL requirement for this class, but only in the 'test' environment. I see how this option could work as well.
normalocity
A: 

I found a much simpler answer here: http://railspikes.com/2008/9/12/testing-ssl

Which is to put the following line either (a) at the beginning of each functional test where SSL is needed, or (b) in the 'setup' method if every action in a controller uses SSL.

@request.env['HTTPS'] = 'on'

This prepends all requests with https

normalocity