mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Re-enable Routing optimisation code for _url methods, add defined?(request) to the guard conditions
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7673 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -44,7 +44,7 @@ module ActionController
|
||||
# Temporarily disabled :url optimisation pending proper solution to
|
||||
# Issues around request.host etc.
|
||||
def applicable?
|
||||
kind != :url
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,9 +60,9 @@ module ActionController
|
||||
# if they're using foo_url(:id=>2) it's one
|
||||
# argument, but we don't want to generate /foos/id2
|
||||
if number_of_arguments == 1
|
||||
"args.size == 1 && !args.first.is_a?(Hash)"
|
||||
"defined?(request) && args.size == 1 && !args.first.is_a?(Hash)"
|
||||
else
|
||||
"args.size == #{number_of_arguments}"
|
||||
"defined?(request) && args.size == #{number_of_arguments}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -97,7 +97,7 @@ module ActionController
|
||||
# argument
|
||||
class PositionalArgumentsWithAdditionalParams < PositionalArguments
|
||||
def guard_condition
|
||||
"args.size == #{route.segment_keys.size + 1}"
|
||||
"defined?(request) && args.size == #{route.segment_keys.size + 1}"
|
||||
end
|
||||
|
||||
# This case uses almost the Use the same code as positional arguments,
|
||||
|
||||
@@ -21,13 +21,9 @@ module ActionController
|
||||
self.default_url_options = {}
|
||||
|
||||
def self.included(base) #:nodoc:
|
||||
original_optimise = ActionController::Routing.optimise_named_routes
|
||||
ActionController::Routing.optimise_named_routes = false
|
||||
ActionController::Routing::Routes.install_helpers base, :regenerate
|
||||
ActionController::Routing::Routes.install_helpers base
|
||||
base.mattr_accessor :default_url_options
|
||||
base.default_url_options ||= default_url_options
|
||||
ensure
|
||||
ActionController::Routing.optimise_named_routes = original_optimise
|
||||
end
|
||||
|
||||
# Generate a url based on the options provided, default_url_options and the
|
||||
|
||||
@@ -175,6 +175,15 @@ class LegacyRouteSetTests < Test::Unit::TestCase
|
||||
x.send(:home_url))
|
||||
end
|
||||
|
||||
def test_basic_named_route_with_relative_url_root
|
||||
rs.add_named_route :home, '', :controller => 'content', :action => 'list'
|
||||
x = setup_for_named_route
|
||||
x.relative_url_root="/foo"
|
||||
assert_equal("http://named.route.test/foo/",
|
||||
x.send(:home_url))
|
||||
assert_equal "/foo/", x.send(:home_path)
|
||||
end
|
||||
|
||||
def test_named_route_with_option
|
||||
rs.add_named_route :page, 'page/:title', :controller => 'content', :action => 'show_page'
|
||||
x = setup_for_named_route
|
||||
@@ -228,7 +237,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
|
||||
end
|
||||
x = setup_for_named_route
|
||||
assert_equal("http://named.route.test/", x.send(:root_url))
|
||||
assert_equal("/relative/", x.send(:root_path))
|
||||
assert_equal("/", x.send(:root_path))
|
||||
end
|
||||
|
||||
def test_named_route_with_regexps
|
||||
@@ -281,7 +290,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase
|
||||
|
||||
# No / to %2F in URI, only for query params.
|
||||
x = setup_for_named_route
|
||||
assert_equal("/relative/file/hello/world", x.send(:path_path, 'hello/world'))
|
||||
assert_equal("/file/hello/world", x.send(:path_path, 'hello/world'))
|
||||
end
|
||||
|
||||
def test_non_controllers_cannot_be_matched
|
||||
@@ -899,11 +908,16 @@ uses_mocha 'RouteTest' do
|
||||
def request
|
||||
@request ||= MockRequest.new(:host => "named.route.test", :method => :get)
|
||||
end
|
||||
|
||||
def relative_url_root=(value)
|
||||
request.relative_url_root=value
|
||||
end
|
||||
end
|
||||
|
||||
class MockRequest
|
||||
attr_accessor :path, :path_parameters, :host, :subdomains, :domain, :method
|
||||
|
||||
attr_accessor :path, :path_parameters, :host, :subdomains, :domain,
|
||||
:method, :relative_url_root
|
||||
|
||||
def initialize(values={})
|
||||
values.each { |key, value| send("#{key}=", value) }
|
||||
if values[:host]
|
||||
@@ -919,10 +933,6 @@ uses_mocha 'RouteTest' do
|
||||
def host_with_port
|
||||
(subdomains * '.') + '.' + domain
|
||||
end
|
||||
|
||||
def relative_url_root
|
||||
'/relative'
|
||||
end
|
||||
end
|
||||
|
||||
class RouteTest < Test::Unit::TestCase
|
||||
|
||||
Reference in New Issue
Block a user