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

相關問題