functional testing routes with a https constraint
If I wrap my SSL required routes in a block like this:
scope :protocol => "https://", :constraints => { :protocol =>
"https://" } do
resources :users, :only => [:new, :create, :edit, :update]
end
then all my functional tests that reference those routes are now spitting out RoutingErrors. Something like this:
put :update, :id => 123
ActionController::RoutingError: No route matches
{:id=>"123", :controller=>"users", :action=>"update"}
FWIW:
rake routes | grep update
user PUT /users/:id(.:format)
{:protocol=>"http://", :acti开发者_运维知识库on=>"update", :controller=>"users"}
So, what, I'm supposed to specify the protocol in my functional tests now?
You can turn HTTPS on in your test's setup:
setup do
@request.env['HTTPS'] = 'on'
end
Or you can change your routes.rb to use http in the test environment:
scope :constraints => { :protocol => Rails.env.test? "http" : "https" } do
resources :users, :only => [:new, :create, :edit, :update]
end
精彩评论