Testing 具有https约束的功能测试路由
如果我将SSL所需的路由包装在如下块中:Testing 具有https约束的功能测试路由,testing,ssl,ruby-on-rails-3.1,Testing,Ssl,Ruby On Rails 3.1,如果我将SSL所需的路由包装在如下块中: scope :protocol => "https://", :constraints => { :protocol => "https://" } do resources :users, :only => [:new, :create, :edit, :update] end put :update, :id => 123 ActionController::RoutingError: No route
scope :protocol => "https://", :constraints => { :protocol =>
"https://" } do
resources :users, :only => [:new, :create, :edit, :update]
end
put :update, :id => 123
ActionController::RoutingError: No route matches
{:id=>"123", :controller=>"users", :action=>"update"}
然后我所有引用这些路径的功能测试现在
吐出路线错误。大概是这样的:
scope :protocol => "https://", :constraints => { :protocol =>
"https://" } do
resources :users, :only => [:new, :create, :edit, :update]
end
put :update, :id => 123
ActionController::RoutingError: No route matches
{:id=>"123", :controller=>"users", :action=>"update"}
FWIW:
那么,我应该在功能测试中指定协议吗
现在?您可以在测试设置中打开HTTPS:
setup do
@request.env['HTTPS'] = 'on'
end
或者,您可以将routes.rb更改为在测试环境中使用http:
scope :constraints => { :protocol => Rails.env.test? "http" : "https" } do
resources :users, :only => [:new, :create, :edit, :update]
end