Require explicit adapter/serializer to render JSON API errors

- Separate collection errors from resource errors in adapter
- Refactor to ErrorsSerializer; first-class json error methods
- DOCS
- Rails 4.0 requires assert exact exception class, boo
This commit is contained in:
Benjamin Fleischer
2015-12-02 11:56:15 -06:00
parent dfe162638c
commit 96107c56aa
11 changed files with 196 additions and 88 deletions

View File

@@ -37,9 +37,13 @@ module ActiveModel
options = nil
resource = ModelWithErrors.new
resource.errors.add(:name, 'must be awesome')
serializable_resource = ActiveModel::SerializableResource.new(resource)
serializable_resource = ActiveModel::SerializableResource.new(
resource, {
serializer: ActiveModel::Serializer::ErrorSerializer,
adapter: 'json_api/error'
})
expected_response_document =
{ 'errors'.freeze =>
{ :errors =>
[
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be awesome' }
]
@@ -53,9 +57,14 @@ module ActiveModel
resources << resource = ModelWithErrors.new
resource.errors.add(:title, 'must be amazing')
resources << ModelWithErrors.new
serializable_resource = ActiveModel::SerializableResource.new(resources)
serializable_resource = ActiveModel::SerializableResource.new(
resources, {
serializer: ActiveModel::Serializer::ErrorsSerializer,
each_serializer: ActiveModel::Serializer::ErrorSerializer,
adapter: 'json_api/error'
})
expected_response_document =
{ 'errors'.freeze =>
{ :errors =>
[
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be amazing' }
]