From 700e6b83c178168c369df1cad358eab483e1a8df Mon Sep 17 00:00:00 2001 From: Adrian Mugnolo and Santiago Pastorino Date: Mon, 16 Dec 2013 17:55:41 -0200 Subject: [PATCH] Serializers now inherit root --- lib/active_model/serializer.rb | 1 + test/unit/active_model/serializer/root_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 871e3a76..1bacab29 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -13,6 +13,7 @@ module ActiveModel class << self def inherited(base) + base._root = _root base._attributes = (_attributes || []).dup base._associations = (_associations || {}).dup end diff --git a/test/unit/active_model/serializer/root_test.rb b/test/unit/active_model/serializer/root_test.rb index 6cf2c546..e3a160ce 100644 --- a/test/unit/active_model/serializer/root_test.rb +++ b/test/unit/active_model/serializer/root_test.rb @@ -54,6 +54,20 @@ module ActiveModel name: 'Name 1', description: 'Description 1' }, @serializer.as_json) end + + def test_root_inheritance + ProfileSerializer._root = 'profile' + + inherited_serializer_klass = Class.new(ProfileSerializer) + inherited_serializer_klass._root = 'inherited_profile' + + another_inherited_serializer_klass = Class.new(ProfileSerializer) + + assert_equal('inherited_profile', + inherited_serializer_klass._root) + assert_equal('profile', + another_inherited_serializer_klass._root) + end end class RootInSerializerTest < ActiveModel::TestCase