Skip to content

Commit

Permalink
Serializers now inherit root
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Mugnolo and Santiago Pastorino authored and spastorino committed Dec 16, 2013
1 parent f72115f commit 700e6b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Serializer

class << self
def inherited(base)
base._root = _root
base._attributes = (_attributes || []).dup
base._associations = (_associations || {}).dup
end
Expand Down
14 changes: 14 additions & 0 deletions test/unit/active_model/serializer/root_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ def test_using_false_root_in_initializer_takes_precedence
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
Expand Down

0 comments on commit 700e6b8

Please sign in to comment.