Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testing 具有https约束的功能测试路由_Testing_Ssl_Ruby On Rails 3.1 - Fatal编程技术网

Testing 具有https约束的功能测试路由

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

如果我将SSL所需的路由包装在如下块中:

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