次のフィルターを定義しています。
# 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
そして私のテストでは:
# users_controller_test.rb
class UsersControllerTest < ActionController::TestCase
setup do
@request.host = "test.myapp.local"
end
# ...
end
Nowtest
は、を使用するすべてのリクエストの前にロードするダミーアカウントのサブドメインとして定義されていますfactory_girl
。ただし、これは、@ requestがnilであるという、nilオブジェクトエラーをスローしています。セットアップブロックを削除すると、find_accountがアカウントを見つけることができず、RecordNotFound
エラーがスローされるため、すべてのテストが失敗します。
私は何が間違っているのですか?