diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2010-04-26 18:27:16 -0300 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-04-26 15:00:26 -0700 |
commit | 7cd1d37a51f5f53f8fc1360f886d26cabf12d969 (patch) | |
tree | cdbc079bb7d025e37efbf5effa6a0fca6b032dd9 /activeresource/test | |
parent | 76d6a993647f3bbe39f31faa0b8ed8767a228301 (diff) | |
download | rails-7cd1d37a51f5f53f8fc1360f886d26cabf12d969.tar.gz rails-7cd1d37a51f5f53f8fc1360f886d26cabf12d969.tar.bz2 rails-7cd1d37a51f5f53f8fc1360f886d26cabf12d969.zip |
Reuse Active Model serialization in Active Resource. [#2584 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/cases/base_test.rb | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb index 0f10a0e4d7..2ed7e1c95f 100644 --- a/activeresource/test/cases/base_test.rb +++ b/activeresource/test/cases/base_test.rb @@ -4,20 +4,22 @@ require "fixtures/customer" require "fixtures/street_address" require "fixtures/beast" require "fixtures/proxy" +require 'active_support/json' require 'active_support/core_ext/hash/conversions' require 'mocha' class BaseTest < Test::Unit::TestCase def setup - @matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person') - @david = { :id => 2, :name => 'David' }.to_xml(:root => 'person') - @greg = { :id => 3, :name => 'Greg' }.to_xml(:root => 'person') - @addy = { :id => 1, :street => '12345 Street', :country => 'Australia' }.to_xml(:root => 'address') @default_request_headers = { 'Content-Type' => 'application/xml' } - @rick = { :name => "Rick", :age => 25 }.to_xml(:root => "person") + @matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person') + @david = { :id => 2, :name => 'David' }.to_xml(:root => 'person') + @greg = { :id => 3, :name => 'Greg' }.to_xml(:root => 'person') + @addy = { :id => 1, :street => '12345 Street', :country => 'Australia' }.to_xml(:root => 'address') + @rick = { :name => "Rick", :age => 25 }.to_xml(:root => "person") + @joe = { 'person' => { :id => 6, :name => 'Joe' }}.to_json @people = [{ :id => 1, :name => 'Matz' }, { :id => 2, :name => 'David' }].to_xml(:root => 'people') @people_david = [{ :id => 2, :name => 'David' }].to_xml(:root => 'people') - @addresses = [{ :id => 1, :street => '12345 Street', :country => 'Australia' }].to_xml(:root => 'addresses') + @addresses = [{ :id => 1, :street => '12345 Street', :country => 'Australia' }].to_xml(:root => 'addresses') # - deep nested resource - # - Luis (Customer) @@ -66,6 +68,7 @@ class BaseTest < Test::Unit::TestCase ActiveResource::HttpMock.respond_to do |mock| mock.get "/people/1.xml", {}, @matz mock.get "/people/2.xml", {}, @david + mock.get "/people/6.json", {}, @joe mock.get "/people/5.xml", {}, @marty mock.get "/people/Greg.xml", {}, @greg mock.get "/people/4.xml", {'key' => 'value'}, nil, 404 @@ -1012,6 +1015,19 @@ class BaseTest < Test::Unit::TestCase assert xml.include?('<id type="integer">1</id>') end + def test_to_json + Person.include_root_in_json = true + Person.format = :json + joe = Person.find(6) + json = joe.encode + Person.format = :xml + + assert_match %r{^\{"person":\{"person":\{}, json + assert_match %r{"id":6}, json + assert_match %r{"name":"Joe"}, json + assert_match %r{\}\}\}$}, json + end + def test_to_param_quacks_like_active_record new_person = Person.new assert_nil new_person.to_param |