Sha256: 72669d1c6bb6dad26a984d0839ab5a25946685c20c792c7835e21a92e30204e4

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

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:               [
              { 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_response_body.to_json, expected_errors_object
        end

        def json_response_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, serializer: ActiveModel::Serializer::ErrorSerializer
          end
        end

        tests ErrorsTestController
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
active_model_serializers-0.10.8 test/action_controller/json_api/errors_test.rb
active_model_serializers-0.10.7 test/action_controller/json_api/errors_test.rb
active_model_serializers-0.10.6 test/action_controller/json_api/errors_test.rb
active_model_serializers-0.10.5 test/action_controller/json_api/errors_test.rb
active_model_serializers-0.10.4 test/action_controller/json_api/errors_test.rb
agi_active_model_serializers-0.10.9 test/action_controller/json_api/errors_test.rb
agi_active_model_serializers-0.10.8 test/action_controller/json_api/errors_test.rb
agi_active_model_serializers-0.10.7 test/action_controller/json_api/errors_test.rb