Merge pull request #468 from stas/attrs_and_assoc_inheritance

Serializers now inherit attributes and associations.
This commit is contained in:
Santiago Pastorino
2013-12-16 11:14:16 -08:00
3 changed files with 26 additions and 2 deletions

View File

@@ -24,6 +24,18 @@ module ActiveModel
'profile' => { name: 'Name 1', description: 'Description 1' }
}, @profile_serializer.as_json)
end
def test_attributes_inheritance
inherited_serializer_klass = Class.new(ProfileSerializer) do
attributes :comments
end
another_inherited_serializer_klass = Class.new(ProfileSerializer)
assert_equal([:name, :description, :comments],
inherited_serializer_klass._attributes)
assert_equal([:name, :description],
another_inherited_serializer_klass._attributes)
end
end
end
end

View File

@@ -21,6 +21,18 @@ module ActiveModel
assert_equal 'comments', @association.name
end
def test_associations_inheritance
inherited_serializer_klass = Class.new(PostSerializer) do
has_many :some_associations
end
another_inherited_serializer_klass = Class.new(PostSerializer)
assert_equal(PostSerializer._associations.length + 1,
inherited_serializer_klass._associations.length)
assert_equal(PostSerializer._associations.length,
another_inherited_serializer_klass._associations.length)
end
def test_associations_embedding_ids_serialization_using_serializable_hash
@association.embed = :ids