diff options
author | kennyj <kennyj@gmail.com> | 2012-10-30 23:44:32 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2012-10-31 00:08:36 +0900 |
commit | fcd19a13b703c64739402d79d07185a27caffa79 (patch) | |
tree | f940eebbbf5073fa53aaa398cc2b1fea605be7c5 | |
parent | b955939d55b71905fa3e5036149ee4c84943c599 (diff) | |
download | rails-fcd19a13b703c64739402d79d07185a27caffa79.tar.gz rails-fcd19a13b703c64739402d79d07185a27caffa79.tar.bz2 rails-fcd19a13b703c64739402d79d07185a27caffa79.zip |
include_root_in_json allows inheritance.
-rw-r--r-- | activerecord/lib/active_record/serialization.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/serialization_test.rb | 16 |
2 files changed, 16 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/serialization.rb b/activerecord/lib/active_record/serialization.rb index 6a511c307b..6b55af4205 100644 --- a/activerecord/lib/active_record/serialization.rb +++ b/activerecord/lib/active_record/serialization.rb @@ -5,7 +5,6 @@ module ActiveRecord #:nodoc: include ActiveModel::Serializers::JSON included do - mattr_accessor :include_root_in_json, instance_accessor: false self.include_root_in_json = true end diff --git a/activerecord/test/cases/serialization_test.rb b/activerecord/test/cases/serialization_test.rb index 25b860878a..eb9cb91e32 100644 --- a/activerecord/test/cases/serialization_test.rb +++ b/activerecord/test/cases/serialization_test.rb @@ -45,4 +45,20 @@ class SerializationTest < ActiveRecord::TestCase assert_equal @contact_attributes[:awesome], contact.awesome, "For #{format}" end end + + def test_include_root_in_json_allows_inheritance + original_root_in_json = ActiveRecord::Base.include_root_in_json + ActiveRecord::Base.include_root_in_json = true + + klazz = Class.new(ActiveRecord::Base) + klazz.table_name = 'topics' + assert klazz.include_root_in_json + + klazz.include_root_in_json = false + assert ActiveRecord::Base.include_root_in_json + assert !klazz.include_root_in_json + assert !klazz.new.include_root_in_json + ensure + ActiveRecord::Base.include_root_in_json = original_root_in_json + end end |