3

我运行集成测试,以确保我before_filter被重定向到root_path如果用户没有登录。似乎一切都工作正常,但我在log/test.log看到http://www.example.com/Redirected to消息,我只是想知道这是否正常,或者是否有配置,我错过了某个地方。谢谢!为什么`log/test.log`在`Redirected to`消息中显示`http:// www.example.com /`?

日志/ test.log中

Started PUT "https://stackoverflow.com/users/980190963" for 127.0.0.1 at 2012-07-29 13:31:39 -0700 
Processing by UsersController#update as HTML 
    Parameters: {"user"=>{"password"=>"[FILTERED]"}, "id"=>"980190963"} 
Redirected to http://www.example.com/ 
Filter chain halted as :reject_if_logged_out rendered or redirected 
Completed 302 Found in 1ms (ActiveRecord: 0.0ms) 

users_controller.rb

... 
before_filter :reject_if_logged_out, only: [:update] 
... 
private 
def reject_if_logged_out 
    redirect_to root_path unless @current_user 
end 

回答

1

因为这是默认的水豚,黄瓜和许多其他测试框架的轨道使用的库。见lib/capybara.rb

Capybara.configure do |config| 
    # ... 
    config.default_host = "http://www.example.com" 
    # ... 
end 

所以,如果你不指定任何东西在你的配置@request.host的默认值是www.example.com

相关问题