request.env['HTTPS'] = 'on' leads to NoMethodError #616

Closed
reiz opened this Issue Oct 6, 2012 · 7 comments

3 participants

@reiz

I am using rspec 2.11.0 with rails 3.2.8. In one of my controllers I am using the "force_ssl". In the testcase I am using "request.env['HTTPS'] = 'on'" to switch to https. Unfortunately I am getting always the same error message:

Failure/Error: request.env['HTTPS'] = 'on'
NoMethodError:
undefined method `env' for nil:NilClass

Any ideas?

@dchelimsky
RSpec member

See #596.

@dchelimsky dchelimsky closed this Oct 6, 2012
@reiz

It's still not working for me. I have a very simple testcase:

post "/users", :user => {:fullname => "test123", :email => "test@test.de", :password => "test123"}, "HTTPS" => "on"
assert_response :success

But instead of success I am getting a 301.
How can I force a post via https?

@dchelimsky
RSpec member

It always seems simple :)

Is this a request spec or controller spec?

@reiz

This is a request spec.

@reiz

Here are some additional informations. This test case works fine:

get "/signup", nil, "HTTPS" => "on"
assert_response :success

But the example with post doesn't work.

@dchelimsky
RSpec member

I think I see the problem - the way you have it formatted "HTTPS" is a key in the wrong hash. Try this:

post "/users", { :user => {:fullname => "test123", :email => "test@test.de", :password => "test123"} }, "HTTPS" => "on"
@dchelimsky dchelimsky reopened this Oct 6, 2012
@reiz

Yep. That's it :-)
Many Thanks for your help.

@alindeman alindeman closed this Oct 6, 2012
@kalmanh kalmanh referenced this issue in simplabs/rails_api_auth Mar 23, 2016
Closed

force_ssl by default unless the user opts out of it #33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment