私は同じページにリダイレクトするこのメソッドをテストしようとしていますが、www。プレフィックスがない場合はプレフィックスを付けます。 リダイレクトを行いますが、RSpecテストでは "<:redirect>になると期待される応答が返されましたが、< 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>
あなたが応答をデバッグしましたか? response.bodyの内容は何ですか? – e3matheus
application_controllerの 'before_filter'としてcheck_uriがありますか? – dexter
はい、before_filter経由でcheck_uriが呼び出されます。元の投稿にデバッグレスポンスを追加しました。 – 99miles