From 74fd291571c8196b26febd968938097f5414303d Mon Sep 17 00:00:00 2001 From: Shin-ichiro OGAWA Date: Wed, 4 Aug 2010 16:02:40 +0900 Subject: [PATCH] Use default_url_options in polymorphic_url Signed-off-by: Shin-ichiro OGAWA --- .../action_dispatch/routing/polymorphic_routes.rb | 1 + .../test/activerecord/polymorphic_routes_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 31dba83..0d36a83 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -107,6 +107,7 @@ module ActionDispatch named_route = build_named_route_call(record_or_hash_or_array, inflection, options) url_options = options.except(:action, :routing_type) + url_options = url_options.merge(default_url_options) unless default_url_options.empty? unless url_options.empty? args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options end diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index 90a1ef9..e0cb2ac 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -46,6 +46,14 @@ class PolymorphicRoutesTest < ActionController::TestCase end end + def test_with_record_and_default_url_options + self.default_url_options[:v] = 'rails' + with_test_routes do + @project.save + assert_equal "http://example.com/projects/#{@project.id}?v=rails", polymorphic_url(@project) + end + end + def test_with_class with_test_routes do assert_equal "http://example.com/projects", polymorphic_url(@project.class) -- 1.7.1