diff options
author | Xinjiang Lu <xinjiang.lu@gmail.com> | 2013-05-12 12:10:02 -0400 |
---|---|---|
committer | Xinjiang Lu <xinjiang.lu@gmail.com> | 2013-05-15 20:22:18 -0400 |
commit | ec55866e398feb1a52701027ab86857b62622ab6 (patch) | |
tree | 1ec15a25f77abf0f04efdd64a4d38fe7cc2f97e0 /activeresource/test | |
parent | 5919a552e4e4203b8d5eb5234428bc00dd462c49 (diff) | |
download | rails-ec55866e398feb1a52701027ab86857b62622ab6.tar.gz rails-ec55866e398feb1a52701027ab86857b62622ab6.tar.bz2 rails-ec55866e398feb1a52701027ab86857b62622ab6.zip |
Support include_root_in_json for ActiveResource properly.
This commit is a backport from
https://github.com/rails/activeresource/pull/29. The
ActiveResource's include_root_in_json option is broken for 3.2.x.
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/cases/base_test.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index 983f0541a8..9176b5db93 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -1020,7 +1020,6 @@ class BaseTest < Test::Unit::TestCase end def test_to_json - Person.include_root_in_json = true joe = Person.find(6) encode = joe.encode json = joe.to_json @@ -1032,6 +1031,21 @@ class BaseTest < Test::Unit::TestCase assert_match %r{\}\}$}, json end + def test_to_json_without_root + ActiveResource::Base.include_root_in_json = false + joe = Person.find(6) + encode = joe.encode + json = joe.to_json + + assert_equal encode, json + assert_no_match %r{^\{"person":\}}, json + assert_match %r{"id":6}, json + assert_match %r{"name":"Joe"}, json + assert_match %r{\}$}, json + ensure + ActiveResource::Base.include_root_in_json = true + end + def test_to_json_with_element_name old_elem_name = Person.element_name Person.include_root_in_json = true |