Way*_*ina 6 testing ruby-on-rails functional-testing
我定义了以下过滤器:
# application_controller.rb
class ApplicationController < ActionController::Base
before_filter :find_account
private
def find_account
@current_account = Account.find_by_subdomain!(request.subdomains.first)
end
end
Run Code Online (Sandbox Code Playgroud)
在我的测试中:
# users_controller_test.rb
class UsersControllerTest < ActionController::TestCase
setup do
@request.host = "test.myapp.local"
end
# ...
end
Run Code Online (Sandbox Code Playgroud)
现在test
被定义为我在使用所有请求之前加载的虚拟帐户的子域factory_girl
.但是,这是抛出一个零对象错误,说@request是零.删除设置块会导致我的所有测试失败,因为find_account找不到帐户,因此会抛出RecordNotFound
错误.
我究竟做错了什么?