2011-09-12 6 views
5

동일한 페이지로 리다이렉트되지만 www가있는이 방법을 테스트하려고합니다. 접두어가 없으면 접두사를 붙이십시오. 리디렉션을 수행하지만 RSpec 테스트는 "< : 예상 리디렉션> : < 200>"을 반환합니다. 왜 그런가요?리디렉션에 대한 RSpec 테스트가 반환됩니다. 200

application_controller.rb

def check_uri 
    if request.subdomain.present? and request.subdomain.first != "www" 
     redirect_to request.protocol + "www." + request.host_with_port + request.fullpath if !/^www/.match(request.host) 
    end 
    end 

application_controller_spec.rb 번호

describe :check_uri do 
    it "should redirect to www" do 
     { :get => "http://sub.lvh.me:3000/accounts/sign_up" }. 
     should redirect_to "http://www.sub.lvh.me:3000/accounts/sign_up" 
    end 
    end 

내가 얻을 디버깅 : (

rdb:1) p response 
#<ActionController::TestResponse:0x0000010277d988 @writer=#<Proc:[email protected]/Users/mm/.rvm/gems/[email protected]/gems/actionpack-3.0.7/lib/action_dispatch/http/response.rb:43 (lambda)>, @block=nil, @length=0, @header={}, @status=200, @body=[], @cookie=[], @sending_file=false, @blank=false, @cache_control={}, @etag=nil> 
+0

당신이 응답을 디버깅나요 : 당신은 당신의 응용 프로그램 컨트롤러에 존재하는 액션 호출하고이 같은 요청 호스트 및 포트를 스텁해야 80

포트에 "test.host"? 응답 내용은 뭐죠? – e3matheus

+0

application_controller에서 check_uri를'before_filter'로 사용하고 있습니까? – dexter

+0

예, before_filter를 통해 check_uri가 호출됩니다. 나는 원래 게시물에 디버그 응답을 추가했다. – 99miles

답변

0

당신은 응답의 헤더 위치를 테스트 할 수 있을까요?

response.header["Location"].should eq("http://www.sub.lvh.me:3000/accounts/sign_up" 

) RSpec에는 기본 테스트 호스트, 예를 들어, 함께 실행되기 때문에

0

당신의 테스트, 당신은 application_controller.rb에 정의 된 방법 check_uri를 타격하지 않습니다

describe :check_uri do 
    it "should redirect to www" do 
    @request.host = 'sub.lvh.me' 
    @request.port = 3000 

    get :index 

    expect(response).to redirect_to "http://www.sub.lvh.me:3000/accounts/sign_up" 
    end 
end 
관련 문제