mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
RFC: Json Api Errors (WIP)
- ActiveModelSerializers::JsonPointer - ActiveModel::Serializer::Adapter::JsonApi::Error - ActiveModel::Serializer::Adapter::JsonApi::Error.attributes - Fix rubocop config
This commit is contained in:
@@ -31,5 +31,37 @@ module ActiveModel
|
||||
def test_use_adapter_with_adapter_option_as_false
|
||||
refute ActiveModel::SerializableResource.new(@resource, { adapter: false }).use_adapter?
|
||||
end
|
||||
|
||||
class SerializableResourceErrorsTest < Minitest::Test
|
||||
def test_serializable_resource_with_errors
|
||||
options = nil
|
||||
resource = ModelWithErrors.new
|
||||
resource.errors.add(:name, 'must be awesome')
|
||||
serializable_resource = ActiveModel::SerializableResource.new(resource)
|
||||
expected_response_document =
|
||||
{ 'errors'.freeze =>
|
||||
[
|
||||
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be awesome' }
|
||||
]
|
||||
}
|
||||
assert_equal serializable_resource.as_json(options), expected_response_document
|
||||
end
|
||||
|
||||
def test_serializable_resource_with_collection_containing_errors
|
||||
options = nil
|
||||
resources = []
|
||||
resources << resource = ModelWithErrors.new
|
||||
resource.errors.add(:title, 'must be amazing')
|
||||
resources << ModelWithErrors.new
|
||||
serializable_resource = ActiveModel::SerializableResource.new(resources)
|
||||
expected_response_document =
|
||||
{ 'errors'.freeze =>
|
||||
[
|
||||
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be amazing' }
|
||||
]
|
||||
}
|
||||
assert_equal serializable_resource.as_json(options), expected_response_document
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user