Search code examples
ruby-on-railsgetfunctional-testing

Functional test "get" requests and the https protocol


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.


Solution

  • 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