Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 48fe4f131b6afafbd92e4209217a2edb82237805 2 parents 0ad6c08 + fcd19a1
@carlosantoniodasilva carlosantoniodasilva authored
View
1  activerecord/lib/active_record/serialization.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
View
16 activerecord/test/cases/serialization_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.