2011-09-06 60 views
1

如果我換我需要SSL路線在這樣的塊:功能測試路線與HTTPS約束

scope :protocol => "https://", :constraints => { :protocol => 
"https://" } do 
    resources :users, :only => [:new, :create, :edit, :update] 
end 

然後引用這些路由我所有的功能測試,現在 吐出RoutingErrors。事情是這樣的:

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://", :action=>"update", :controller=>"users"} 

那麼,是什麼,我應該在我的功能測試 現在指定的協議?

回答

0

您可以在測試的設置開啓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