diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2013-11-15 10:26:12 -0800 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2013-11-26 09:50:59 -0800 |
commit | cfaa2aa99fbd2149872af1c43673cff97673f138 (patch) | |
tree | 333515fafb68de2e25ccd4270309920232077de2 /activesupport | |
parent | 499b602c8eb032cb2bbae1cfa01cecdb549ea583 (diff) | |
download | rails-cfaa2aa99fbd2149872af1c43673cff97673f138.tar.gz rails-cfaa2aa99fbd2149872af1c43673cff97673f138.tar.bz2 rails-cfaa2aa99fbd2149872af1c43673cff97673f138.zip |
Added some failing tests where the JSON encoder is not resolving as_json correctly
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 00f43be6d4..c28a8a6c24 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -18,8 +18,12 @@ class TestJSONEncoding < ActiveSupport::TestCase end class Custom + def initialize(serialized) + @serialized = serialized + end + def as_json(options) - 'custom' + @serialized end end @@ -81,7 +85,13 @@ class TestJSONEncoding < ActiveSupport::TestCase ObjectTests = [[ Foo.new(1, 2), %({\"a\":1,\"b\":2}) ]] HashlikeTests = [[ Hashlike.new, %({\"bar\":\"world\",\"foo\":\"hello\"}) ]] - CustomTests = [[ Custom.new, '"custom"' ]] + CustomTests = [[ Custom.new("custom"), '"custom"' ], + [ Custom.new(nil), 'null' ], + [ Custom.new(:a), '"a"' ], + [ Custom.new([ :foo, "bar" ]), '["foo","bar"]' ], + [ Custom.new({ :foo => "hello", :bar => "world" }), '{"bar":"world","foo":"hello"}' ], + [ Custom.new(Hashlike.new), '{"bar":"world","foo":"hello"}' ], + [ Custom.new(Custom.new(Custom.new(:a))), '"a"' ]] RegexpTests = [[ /^a/, '"(?-mix:^a)"' ], [/^\w{1,2}[a-z]+/ix, '"(?ix-m:^\\\\w{1,2}[a-z]+)"']] |