感谢这个出色的问答,我发现了如何通过将以下代码放入我的应用程序控制器来保护我的 Rails 应用程序:
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "username" && password == "password"
end
end
这一切都很好,但我注意到我编写的所有测试(全部通过)现在都失败了。当我注释掉 before_filter 调用时,它们都会再次通过。
我该怎么办?有没有办法从 htaccess 保护中排除测试?