Permalink
Browse files

Merge pull request #8072 from kennyj/remove_mattr_include_root_in_json

Allow include_root_in_json to be inheritable by using the class_attribute created by Active Model serialization module.
  • Loading branch information...
2 parents 0ad6c08 + fcd19a1 commit 48fe4f131b6afafbd92e4209217a2edb82237805 @carlosantoniodasilva carlosantoniodasilva committed Oct 30, 2012
Showing with 16 additions and 1 deletion.
  1. +0 −1 activerecord/lib/active_record/serialization.rb
  2. +16 −0 activerecord/test/cases/serialization_test.rb
@@ -5,7 +5,6 @@ module Serialization
include ActiveModel::Serializers::JSON
included do
- mattr_accessor :include_root_in_json, instance_accessor: false
self.include_root_in_json = true
end
@@ -45,4 +45,20 @@ def test_serialize_should_allow_attribute_except_filtering
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

0 comments on commit 48fe4f1

Please sign in to comment.