From 6534021ec088ebb90db45ad17054f3e58c5632f1 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 21 Apr 2010 11:56:07 -0300 Subject: [PATCH] url_for now works with HashWithIndifferentAccess ht jay [#4391 state:committed] --- actionpack/test/template/url_helper_test.rb | 10 ++++++++++ .../active_support/hash_with_indifferent_access.rb | 4 ++++ activesupport/test/core_ext/hash_ext_test.rb | 8 +++++++- 3 files changed, 21 insertions(+), 1 deletions(-) diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 4474949..314ed91 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -421,6 +421,11 @@ class UrlHelperControllerTest < ActionController::TestCase render :inline => "<%= url_for :controller => 'url_helper_controller_test/url_helper', :action => 'show_url_for' %>" end + def show_overriden_url_for + params = { :controller => 'c', :action => 'a' } + render :inline => "<%= url_for params.merge(:controller => 'url_helper_controller_test/url_helper', :action => 'show_url_for') %>" + end + def show_named_route render :inline => "<%= show_named_route_#{params[:kind]} %>" end @@ -439,6 +444,11 @@ class UrlHelperControllerTest < ActionController::TestCase assert_equal '/url_helper_controller_test/url_helper/show_url_for', @response.body end + def test_overriden_url_for_shows_only_path + get :show_overriden_url_for + assert_equal '/url_helper_controller_test/url_helper/show_url_for', @response.body + end + def test_named_route_url_shows_host_and_path get :show_named_route, :kind => 'url' assert_equal 'http://test.host/url_helper_controller_test/url_helper/show_named_route', diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 8241b69..651acfe 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -115,6 +115,10 @@ module ActiveSupport def symbolize_keys!; self end def to_options!; self end + def symbolize_keys + to_hash.symbolize_keys + end + # Convert to a Hash with String keys. def to_hash Hash.new(default).merge!(self) diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 86272a2..7ca5734 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -210,7 +210,7 @@ class HashExtTest < Test::Unit::TestCase assert_equal "1", hash[:urls][:url].first[:address] end - def test_stringify_and_symbolize_keys_on_indifferent_preserves_hash + def test_stringify_and_symbolize_keys_bang_on_indifferent_preserves_hash h = HashWithIndifferentAccess.new h[:first] = 1 h.stringify_keys! @@ -221,6 +221,12 @@ class HashExtTest < Test::Unit::TestCase assert_equal 1, h[:first] end + def test_symbolize_keys_on_indifferent + assert_equal @symbols, @symbols.with_indifferent_access.symbolize_keys + assert_equal @symbols, @strings.with_indifferent_access.symbolize_keys + assert_equal @symbols, @mixed.with_indifferent_access.symbolize_keys + end + def test_to_options_on_indifferent_preserves_hash h = HashWithIndifferentAccess.new h['first'] = 1 -- 1.7.0