【发布时间】:2010-09-22 11:25:40
【问题描述】:
这是我在应用程序控制器文件 (application_controller.rb) 中的 http 基本身份验证
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "username" && password == "password"
end
end
以及我家控制器的索引操作的默认测试(spec/controllers/home_controller_spec.rb)
require 'spec_helper'
describe HomeController do
describe "GET 'index'" do
it "should be successful" do
get 'index'
response.should be_success
end
end
由于身份验证方法,测试未运行。我可以评论“before_filter :authenticate”来运行它们,但我想知道是否有办法让它们与该方法一起工作。
谢谢!
【问题讨论】:
-
从 Rails 6 开始,看起来this answer 是可行的。
标签: ruby-on-rails rspec http-authentication