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:
41
test/action_controller/json_api/errors_test.rb
Normal file
41
test/action_controller/json_api/errors_test.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
require 'test_helper'
|
||||
|
||||
module ActionController
|
||||
module Serialization
|
||||
class JsonApi
|
||||
class ErrorsTest < ActionController::TestCase
|
||||
def test_active_model_with_multiple_errors
|
||||
get :render_resource_with_errors
|
||||
|
||||
expected_errors_object =
|
||||
{ 'errors'.freeze =>
|
||||
[
|
||||
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
|
||||
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
|
||||
{ :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' }
|
||||
]
|
||||
}.to_json
|
||||
assert_equal json_reponse_body.to_json, expected_errors_object
|
||||
end
|
||||
|
||||
def json_reponse_body
|
||||
JSON.load(@response.body)
|
||||
end
|
||||
|
||||
class ErrorsTestController < ActionController::Base
|
||||
def render_resource_with_errors
|
||||
resource = Profile.new(name: 'Name 1',
|
||||
description: 'Description 1',
|
||||
comments: 'Comments 1')
|
||||
resource.errors.add(:name, 'cannot be nil')
|
||||
resource.errors.add(:name, 'must be longer')
|
||||
resource.errors.add(:id, 'must be a uuid')
|
||||
render json: resource, adapter: :json_api
|
||||
end
|
||||
end
|
||||
|
||||
tests ErrorsTestController
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user