2011-09-12 22 views
5

मैं इस विधि का परीक्षण करने की कोशिश कर रहा हूं जो एक ही पृष्ठ पर रीडायरेक्ट करता है लेकिन www के साथ। उपसर्ग अगर यह वहां नहीं है। यह रीडायरेक्ट करता है, लेकिन आरएसपीसी परीक्षण "< होने की अपेक्षित प्रतिक्रिया देता है: रीडायरेक्ट>, लेकिन < 200> था।" ऐसा क्यों है?रीडायरेक्ट रिटर्न के लिए आरएसपीसी परीक्षण 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

आप प्रतिक्रिया डिबग किया? प्रतिक्रिया के लिए सामग्री क्या है? – e3matheus

+0

क्या आपके पास application_controller में 'first_filter' के रूप में check_uri है? – dexter

+0

हां, check_uri को पहले_फिल्टर के माध्यम से बुलाया जाता है। मैंने मूल पोस्ट में डीबग प्रतिक्रिया जोड़ा। – 99miles

उत्तर

0

आप प्रतिक्रिया के शीर्षक स्थान का परीक्षण कर सकता है?

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

)

0

आपका परीक्षण, विधि check_uri कि आप application_controller.rb में परिभाषित मार नहीं है, क्योंकि RSpec एक डिफ़ॉल्ट परीक्षण मेजबान, उदा चलाता है बंदरगाह पर "test.host" 80

आप एक कार्रवाई है कि आपके आवेदन नियंत्रक में मौजूद है फोन और अनुरोध मेजबान और इस तरह बंदरगाह ठूंठ चाहिए:

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 
संबंधित मुद्दे