mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Prevent possible duplicated attributes
Calling ActiveModel::Serializer.attributes or ActiveModel::Serializer.attribute methods multiple times won't create duplicated attributes anymore.
This commit is contained in:
@@ -24,6 +24,15 @@ module ActiveModel
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(blog_serializer)
|
||||
assert_equal({:id=>1, :title=>"AMS Hints"}, adapter.serializable_hash)
|
||||
end
|
||||
|
||||
def test_multiple_calls_with_the_same_attribute
|
||||
serializer_class = Class.new(ActiveModel::Serializer) do
|
||||
attribute :title
|
||||
attribute :title
|
||||
end
|
||||
|
||||
assert_equal([:title], serializer_class._attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,6 +49,15 @@ module ActiveModel
|
||||
assert_equal({id: 1, body: "ZOMG!!", date: "2015", likes: nil},
|
||||
serializer.attributes)
|
||||
end
|
||||
|
||||
def test_multiple_calls_with_the_same_attribute
|
||||
serializer_class = Class.new(ActiveModel::Serializer) do
|
||||
attributes :id, :title
|
||||
attributes :id, :title, :title, :body
|
||||
end
|
||||
|
||||
assert_equal([:id, :title, :body], serializer_class._attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user