Tôi đang thử nghiệm phương pháp này chuyển hướng đến cùng một trang nhưng với www. tiền tố nếu nó không có ở đó. Nó chuyển hướng, nhưng kiểm tra RSpec trả về "Phản hồi dự kiến là <: chuyển hướng>, nhưng là < 200>." Tại sao vậy?Kiểm tra RSpec cho trả về chuyển hướng 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
Khi tôi gỡ lỗi tôi nhận được: (
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>
Cậu gỡ lỗi phản ứng? Nội dung cho response.body là gì? – e3matheus
bạn có check_uri là 'before_filter' trong application_controller không? – dexter
Có, check_uri được gọi qua before_filter. Tôi đã thêm phản hồi gỡ lỗi vào bài đăng gốc. – 99miles