Disable the routing optimisation code when dealing with foo_url helpers. Add test to actionmailer to expose the problem they introduced. References #9450 [Koz]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7572 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Michael Koziarski
2007-09-22 19:20:06 +00:00
parent defb4d08dc
commit 7573791284
4 changed files with 17 additions and 11 deletions

View File

@@ -1,3 +1,3 @@
Hello there,
Mr. <%= @recipient %>. Please see our greeting at <%= @welcome_url %>
Mr. <%= @recipient %>. Please see our greeting at <%= @welcome_url %> <%= welcome_url %>

View File

@@ -1,6 +1,9 @@
require "#{File.dirname(__FILE__)}/abstract_unit"
class TestMailer < ActionMailer::Base
default_url_options[:host] = 'www.basecamphq.com'
def signed_up_with_url(recipient)
@recipients = recipient
@subject = "[Signed up] Welcome #{recipient}"
@@ -47,12 +50,13 @@ class ActionMailerUrlTest < Test::Unit::TestCase
def test_signed_up_with_url
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
map.welcome 'welcome', :controller=>"foo", :action=>"bar"
end
expected = new_mail
expected.to = @recipient
expected.subject = "[Signed up] Welcome #{@recipient}"
expected.body = "Hello there, \n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting"
expected.body = "Hello there, \n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting http://www.basecamphq.com/welcome"
expected.from = "system@loudthinking.com"
expected.date = Time.local(2004, 12, 12)

View File

@@ -41,8 +41,10 @@ module ActionController
end
end
# Temporarily disabled :url optimisation pending proper solution to
# Issues around request.host etc.
def applicable?
true
kind != :url
end
end
@@ -76,7 +78,7 @@ module ActionController
# The last entry in route.segments appears to # *always* be a
# 'divider segment' for '/' but we have assertions to ensure that
# we don't include the trailing slashes, so skip them.
((route.segments.size == 1 && kind == :path) ? route.segments : route.segments[0..-2]).each do |segment|
(route.segments.size == 1 ? route.segments : route.segments[0..-2]).each do |segment|
if segment.is_a?(DynamicSegment)
elements << segment.interpolation_chunk("args[#{idx}].to_param")
idx += 1
@@ -105,7 +107,7 @@ module ActionController
# To avoid generating http://localhost/?host=foo.example.com we
# can't use this optimisation on routes without any segments
def applicable?
route.segment_keys.size > 0
super && route.segment_keys.size > 0
end
end

View File

@@ -169,7 +169,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
def test_basic_named_route
rs.add_named_route :home, '', :controller => 'content', :action => 'list'
x = setup_for_named_route
assert_equal("http://named.route.test",
assert_equal("http://named.route.test/",
x.send(:home_url))
end
@@ -189,7 +189,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
end
def test_named_route_with_nested_controller
rs.add_named_route :users, '/admin/user', :controller => '/admin/user', :action => 'index'
rs.add_named_route :users, 'admin/user', :controller => 'admin/user', :action => 'index'
x = setup_for_named_route
assert_equal("http://named.route.test/admin/user",
x.send(:users_url))
@@ -201,9 +201,9 @@ class LegacyRouteSetTests < Test::Unit::TestCase
rs.add_named_route :user, 'admin/user/:id', :controller=>'/admin/user', :action=>'show'
x = setup_for_named_route
x.expects(:url_for).never
x.send(:users_url)
# x.send(:users_url)
x.send(:users_path)
x.send(:user_url, 2, :foo=>"bar")
# x.send(:user_url, 2, :foo=>"bar")
x.send(:user_path, 3, :bar=>"foo")
end
end
@@ -225,7 +225,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
map.root :controller => "hello"
end
x = setup_for_named_route
assert_equal("http://named.route.test", x.send(:root_url))
assert_equal("http://named.route.test/", x.send(:root_url))
assert_equal("/", x.send(:root_path))
end
@@ -485,7 +485,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
assert_equal '/', rs.generate(:controller => 'content')
x = setup_for_named_route
assert_equal("http://named.route.test",
assert_equal("http://named.route.test/",
x.send(:home_url))
end