aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManfred Stienstra <manfred@fngtps.com>2008-09-21 17:29:22 +0200
committerManfred Stienstra <manfred@fngtps.com>2008-09-21 17:29:22 +0200
commit809af7f5586cb3f2f913b21be168fbf72d58cbfe (patch)
tree6b961ab0925be177dfb4d1e269ca966db5a70dfa
parentb8eec5ac33d6f421fe5a2c757794ed2e4965f81d (diff)
downloadrails-809af7f5586cb3f2f913b21be168fbf72d58cbfe.tar.gz
rails-809af7f5586cb3f2f913b21be168fbf72d58cbfe.tar.bz2
rails-809af7f5586cb3f2f913b21be168fbf72d58cbfe.zip
Non-string results from forwarded methods should be returned vertabim.
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb5
-rw-r--r--activesupport/test/multibyte_chars_test.rb19
2 files changed, 15 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index c61367968e..b3fdcdc650 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -106,10 +106,11 @@ module ActiveSupport #:nodoc:
@wrapped_string.__send__(method, *args, &block)
self
else
- chars(@wrapped_string.__send__(method, *args, &block))
+ result = @wrapped_string.__send__(method, *args, &block)
+ result.kind_of?(String) ? chars(result) : result
end
end
-
+
# Returns +true+ if _obj_ responds to the given method. Private methods are included in the search
# only if the optional second parameter evaluates to +true+.
def respond_to?(method, include_private=false)
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 6400707222..2fde4d3e30 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -21,8 +21,9 @@ module MultibyteTest
end
class String
- def __string_for_multibyte_testing; self; end
- def __string_for_multibyte_testing!; self; end
+ def __method_for_multibyte_testing_with_integer_result; 1; end
+ def __method_for_multibyte_testing; 'result'; end
+ def __method_for_multibyte_testing!; 'result'; end
end
class MultibyteCharsTest < Test::Unit::TestCase
@@ -40,7 +41,7 @@ class MultibyteCharsTest < Test::Unit::TestCase
def test_should_allow_method_calls_to_string
assert_nothing_raised do
- @chars.__string_for_multibyte_testing
+ @chars.__method_for_multibyte_testing
end
assert_raises NoMethodError do
@chars.__unknown_method
@@ -48,19 +49,23 @@ class MultibyteCharsTest < Test::Unit::TestCase
end
def test_forwarded_method_calls_should_return_new_chars_instance
- assert @chars.__string_for_multibyte_testing.kind_of?(@proxy_class)
- assert_not_equal @chars.object_id, @chars.__string_for_multibyte_testing.object_id
+ assert @chars.__method_for_multibyte_testing.kind_of?(@proxy_class)
+ assert_not_equal @chars.object_id, @chars.__method_for_multibyte_testing.object_id
end
def test_forwarded_bang_method_calls_should_return_the_original_chars_instance
- assert @chars.__string_for_multibyte_testing!.kind_of?(@proxy_class)
- assert_equal @chars.object_id, @chars.__string_for_multibyte_testing!.object_id
+ assert @chars.__method_for_multibyte_testing!.kind_of?(@proxy_class)
+ assert_equal @chars.object_id, @chars.__method_for_multibyte_testing!.object_id
end
def test_methods_are_forwarded_to_wrapped_string_for_byte_strings
assert_equal BYTE_STRING.class, BYTE_STRING.mb_chars.class
end
+ def test_forwarded_method_with_non_string_result_should_be_returned_vertabim
+ assert_equal ''.__method_for_multibyte_testing_with_integer_result, @chars.__method_for_multibyte_testing_with_integer_result
+ end
+
def test_should_concatenate
assert_equal 'ab', 'a'.mb_chars + 'b'
assert_equal 'ab', 'a' + 'b'.mb_chars