aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorDmitriy Vorotilin <mydeeptown@gmail.com>2012-02-01 02:01:00 +0400
committerDmitriy Vorotilin <mydeeptown@gmail.com>2012-02-01 02:06:46 +0400
commit705a1d5b881604364a6891d16ae0ae43592b1c9c (patch)
tree567c3d17dbb83a9021f16422e3e98dd0a1c81d13 /activesupport
parentc4469e6c39f68eee97d6cc21412b685eaeb59dce (diff)
downloadrails-705a1d5b881604364a6891d16ae0ae43592b1c9c.tar.gz
rails-705a1d5b881604364a6891d16ae0ae43592b1c9c.tar.bz2
rails-705a1d5b881604364a6891d16ae0ae43592b1c9c.zip
Added as_json method for multibyte strings
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb4
-rw-r--r--activesupport/test/multibyte_chars_test.rb3
2 files changed, 7 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index ac61870871..7a0e1d458b 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -188,6 +188,10 @@ module ActiveSupport #:nodoc:
chars(Unicode.tidy_bytes(@wrapped_string, force))
end
+ def as_json(options = nil) #:nodoc:
+ to_s.as_json(options)
+ end
+
%w(capitalize downcase reverse tidy_bytes upcase).each do |method|
define_method("#{method}!") do |*args|
@wrapped_string = send(method, *args).to_s
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 63e7a35c01..90aa13b3e6 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -88,6 +88,9 @@ class MultibyteCharsTest < ActiveSupport::TestCase
assert(('a'.mb_chars << 'b'.mb_chars).kind_of?(@proxy_class))
end
+ def test_should_return_string_as_json
+ assert_equal UNICODE_STRING, @chars.as_json
+ end
end
class MultibyteCharsUTF8BehaviourTest < ActiveSupport::TestCase