【问题标题】:How to test redirection to an external URL?如何测试重定向到外部 URL?
【发布时间】:2012-12-02 22:22:30
【问题描述】:

我正在使用 rack-rewrite 重定向旧版 URL。重定向到新内部路径的旧路径,我可以很好地测试,如下所示:

require 'test_helper'

class MiscellaneousTest < ActionDispatch::IntegrationTest

    test 'redirect about.php' do
        get_via_redirect '/about.php?country=US'
        assert_equal '/us/about', path

        get_via_redirect '/about.php?country=CA'
        assert_equal '/ca/about', path

        # default
        get_via_redirect '/about.php'
        assert_equal '/ca/about', path
    end
end

但我想知道的是:如何测试旧路径现在映射到外部 URL 的案例?

例如,如果检测到以下旧路由:/blog/12345/something-cool-to-say,它现在将映射到以下外部 URL:http://blog.far.far.away.com/12345/something-cool-to-say via:

$BLOG_URL = 'http://blog.far.far.away-example.com'
r301 %r{^/blog/([0-9]{5})/(.*)\.php}, "#{BLOG_URL}/$1/$2" # token, slug

【问题讨论】:

  • 嗨,您是否设法测试到外部 URL 的路由?

标签: ruby-on-rails url testing ruby-on-rails-3.2 http-redirect


【解决方案1】:

试试这个:

assert_redirected_to 'http://some.host/with/a/path'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-11
    • 2012-01-10
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多