diff options
author | Mikel Lindsaar <raasdnil@gmail.com> | 2010-06-08 00:10:11 -0400 |
---|---|---|
committer | Mikel Lindsaar <raasdnil@gmail.com> | 2010-06-08 00:10:11 -0400 |
commit | e404490f9bae102f8c7126917d59568e6d1fef79 (patch) | |
tree | 34a4fd7517026ab23498e7d2301f27ebd75cdee2 /activemodel/test/cases/serializeration/json_serialization_test.rb | |
parent | 80a044edb663e6bc619b0755e30f9db10e37e9e8 (diff) | |
parent | 8d576b51a12fdb19e3993f3678ec64b2ea60fada (diff) | |
download | rails-e404490f9bae102f8c7126917d59568e6d1fef79.tar.gz rails-e404490f9bae102f8c7126917d59568e6d1fef79.tar.bz2 rails-e404490f9bae102f8c7126917d59568e6d1fef79.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activemodel/test/cases/serializeration/json_serialization_test.rb')
-rw-r--r-- | activemodel/test/cases/serializeration/json_serialization_test.rb | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/activemodel/test/cases/serializeration/json_serialization_test.rb b/activemodel/test/cases/serializeration/json_serialization_test.rb index 7e89815c96..04b50e5bb8 100644 --- a/activemodel/test/cases/serializeration/json_serialization_test.rb +++ b/activemodel/test/cases/serializeration/json_serialization_test.rb @@ -22,35 +22,41 @@ class JsonSerializationTest < ActiveModel::TestCase end test "should include root in json" do + json = @contact.to_json + + assert_match %r{^\{"contact":\{}, json + assert_match %r{"name":"Konata Izumi"}, json + assert_match %r{"age":16}, json + assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))})) + assert_match %r{"awesome":true}, json + assert_match %r{"preferences":\{"shows":"anime"\}}, json + end + + test "should not include root in json" do begin - Contact.include_root_in_json = true + Contact.include_root_in_json = false json = @contact.to_json - assert_match %r{^\{"contact":\{}, json + assert_no_match %r{^\{"contact":\{}, json assert_match %r{"name":"Konata Izumi"}, json assert_match %r{"age":16}, json assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))})) assert_match %r{"awesome":true}, json assert_match %r{"preferences":\{"shows":"anime"\}}, json ensure - Contact.include_root_in_json = false + Contact.include_root_in_json = true end end test "should include custom root in json" do - begin - Contact.include_root_in_json = true - json = @contact.to_json(:root => 'json_contact') + json = @contact.to_json(:root => 'json_contact') - assert_match %r{^\{"json_contact":\{}, json - assert_match %r{"name":"Konata Izumi"}, json - assert_match %r{"age":16}, json - assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))})) - assert_match %r{"awesome":true}, json - assert_match %r{"preferences":\{"shows":"anime"\}}, json - ensure - Contact.include_root_in_json = false - end + assert_match %r{^\{"json_contact":\{}, json + assert_match %r{"name":"Konata Izumi"}, json + assert_match %r{"age":16}, json + assert json.include?(%("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))})) + assert_match %r{"awesome":true}, json + assert_match %r{"preferences":\{"shows":"anime"\}}, json end test "should encode all encodable attributes" do |