我正在使用rack-rewrite重定向旧版网址。重定向到新内部路径的旧路径,我可以测试得很好,像这样:
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
它现在将映射到以下外部网址:http://blog.far.far.away.com/12345/something-cool-to-say
通过:
$BLOG_URL = 'http://blog.far.far.away-example.com'
r301 %r{^/blog/([0-9]{5})/(.*)\.php}, "#{BLOG_URL}/$1/$2" # token, slug
答案 0 :(得分:1)
试试这个:
assert_redirected_to 'http://some.host/with/a/path'