質問

私は、以下のフィルタの定義:

# 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

現在 test として定義されsubdomainのためのダミーのアカウントし負荷前の全ての要求を factory_girl.しかし、これは投nilオブジェクトエラー、という@の要求は無料。削除の設定ブロックの原因すべての試験に失敗しfind_accountを見つけることができな口座で投げ RecordNotFound エラーになります。

なぜですか?

役に立ちましたか?

解決

してみてください:

@request.env['HTTP_HOST'] = 'test.myapp.local'
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top