문제

다음 필터가 정의되어 있습니다.

# 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 모든 요청을 사용하기 전에로드하는 더미 계정의 하위 도메인으로 정의됩니다. factory_girl. 그러나 이것은 @request가 nil이라고 말하면서 nil 객체 오류를 던지고 있습니다. 설정 블록을 제거하면 find_account가 계정을 찾을 수 없으므로 모든 테스트가 실패하게됩니다. RecordNotFound 오류.

내가 뭘 잘못하고 있죠?

도움이 되었습니까?

해결책

이 시도:

@request.env['HTTP_HOST'] = 'test.myapp.local'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top