Functional tests "get" and https protocol

I am trying to write a functional test for an action that should be run through https. I do not test HTTPS redirection - I already know what works from another test.

What I'm trying to do is:

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

But this does not trigger a request over https. Is there a get option that allows me to change the protocol?

Also, if I try to specify a URL (for example: get "https: /test.host/do/something"), I get a routing error, since there is no route at my rail level for https - it took care at my level web server.

+4
source share
2 answers

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

What should be the following line: (a) at the beginning of each functional test where SSL is required, or (b) in the "setup" method, if each action in the controller uses SSL.

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

This adds all requests using https

+7
source

In functional testing, there is no routing from HTTP or anything else; it uses the controller directly. Therefore, you cannot test this from HTTP or HTTPS.

But you can scoff at the request. protocole dans defines it as "https"

 request.stub(:protocol).and_return("https://") get :new 
+1
source

All Articles