aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2010-04-25 21:02:35 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-04-25 21:04:19 -0700
commit2a6e0f34ad6b48dcf41989e0d7555cda46492b34 (patch)
treee66d0d1fc3d0a8470f7cf3f914707b68f1def4b2 /activeresource
parent490a3335d56c124c8113aac0b63ad367f81bb450 (diff)
downloadrails-2a6e0f34ad6b48dcf41989e0d7555cda46492b34.tar.gz
rails-2a6e0f34ad6b48dcf41989e0d7555cda46492b34.tar.bz2
rails-2a6e0f34ad6b48dcf41989e0d7555cda46492b34.zip
Revert "create option to include_root_in_json for ActiveResource [#2584 state:committed]"
This reverts commits 72f89b5d971b48a133c4c0af56fbeda35d738dae, 137d8e0b2fe9fcc4fdac6cbbd44ca010784e5972. Should reuse Active Model. [#2584 state:incomplete]
Diffstat (limited to 'activeresource')
-rw-r--r--activeresource/lib/active_resource/base.rb9
-rw-r--r--activeresource/test/cases/base_test.rb29
2 files changed, 6 insertions, 32 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 1dd5af8098..bf775a14c8 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -251,9 +251,6 @@ module ActiveResource
# The logger for diagnosing and tracing Active Resource calls.
cattr_accessor :logger
- # Controls the top-level behavior of JSON serialization
- cattr_accessor :include_root_in_json, :instance_writer => false
-
class << self
# Creates a schema for this resource - setting the attributes that are
# known prior to fetching an instance from the remote system.
@@ -1243,12 +1240,6 @@ module ActiveResource
case self.class.format
when ActiveResource::Formats::XmlFormat
self.class.format.encode(attributes, {:root => self.class.element_name}.merge(options))
- when ActiveResource::Formats::JsonFormat
- if ActiveResource::Base.include_root_in_json
- self.class.format.encode({self.class.element_name => attributes}, options)
- else
- self.class.format.encode(attributes, options)
- end
else
self.class.format.encode(attributes, options)
end
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb
index a424b2baf3..0f10a0e4d7 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -4,22 +4,20 @@ 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' }
- @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
+ @rick = { :name => "Rick", :age => 25 }.to_xml(:root => "person")
@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)
@@ -68,7 +66,6 @@ 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
@@ -1015,20 +1012,6 @@ class BaseTest < Test::Unit::TestCase
assert xml.include?('<id type="integer">1</id>')
end
-
- def test_to_json_including_root
- 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