Skip to content

Commit

Permalink
Merge pull request rails#4808 from route/mb_chars_as_json
Browse files Browse the repository at this point in the history
Added as_json method for multibyte strings
  • Loading branch information
José Valim committed Feb 1, 2012
2 parents d613d60 + 705a1d5 commit 7179fad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions activesupport/lib/active_support/multibyte/chars.rb
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions activesupport/test/multibyte_chars_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 7179fad

Please sign in to comment.