Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added as_json method for multibyte strings #4808

Merged
merged 1 commit into from

2 participants

@route

For multibyte strings we need as_json method. Multibyte strings are object and if we are calling "text".mb_chars.as_json then result will be {"wrapped_string"=>"text"} although I've expected a string.

@josevalim josevalim merged commit 7179fad into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 31, 2012
  1. @route
This page is out of date. Refresh to see the latest.
View
4 activesupport/lib/active_support/multibyte/chars.rb
@@ -188,6 +188,10 @@ def tidy_bytes(force = false)
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
View
3  activesupport/test/multibyte_chars_test.rb
@@ -88,6 +88,9 @@ def test_concatenate_should_return_proxy_instance
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
Something went wrong with that request. Please try again.