mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Extract attributes filtering from serializer into adapter.
This commit is contained in:
@@ -58,8 +58,10 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_limiting_fields
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, fields: ['title'])
|
||||
|
||||
actual = ActiveModel::SerializableResource.new(
|
||||
[@first_post, @second_post], adapter: :json_api,
|
||||
fields: { posts: ['title'] })
|
||||
.serializable_hash
|
||||
expected = [
|
||||
{
|
||||
id: '1',
|
||||
@@ -86,7 +88,7 @@ module ActiveModel
|
||||
}
|
||||
}
|
||||
]
|
||||
assert_equal(expected, @adapter.serializable_hash[:data])
|
||||
assert_equal(expected, actual[:data])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,11 +18,6 @@ module ActiveModel
|
||||
@profile_serializer.class._attributes)
|
||||
end
|
||||
|
||||
def test_attributes_with_fields_option
|
||||
assert_equal({ name: 'Name 1' },
|
||||
@profile_serializer.attributes(fields: [:name]))
|
||||
end
|
||||
|
||||
def test_attributes_inheritance_definition
|
||||
assert_equal([:id, :body], @serializer_klass._attributes)
|
||||
end
|
||||
|
||||
@@ -4,22 +4,11 @@ module ActiveModel
|
||||
class Serializer
|
||||
class FieldsetTest < Minitest::Test
|
||||
def test_fieldset_with_hash
|
||||
fieldset = ActiveModel::Serializer::Fieldset.new({ 'post' => %w(id title), 'coment' => ['body'] })
|
||||
fieldset = ActiveModel::Serializer::Fieldset.new('post' => %w(id title), 'comment' => ['body'])
|
||||
expected = { :post => [:id, :title], :comment => [:body] }
|
||||
|
||||
assert_equal(
|
||||
{ :post => [:id, :title], :coment => [:body] },
|
||||
fieldset.fields
|
||||
)
|
||||
end
|
||||
|
||||
def test_fieldset_with_array_of_fields_and_root_name
|
||||
fieldset = ActiveModel::Serializer::Fieldset.new(['title'], 'post')
|
||||
|
||||
assert_equal(
|
||||
{ :post => [:title] },
|
||||
fieldset.fields
|
||||
)
|
||||
assert_equal(expected, fieldset.fields)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user