Sha256: 0dc77ccbba75d5fa530627523c303bacb8f6683f9ad609a1cd5abf697e522fd8

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

require 'test_helper'

module ActionController
  module Serialization
    class JsonApi
      class DeserializationTest < ActionController::TestCase
        class DeserializationTestController < ActionController::Base
          def render_parsed_payload
            parsed_hash = ActiveModelSerializers::Deserialization.jsonapi_parse(params)
            render json: parsed_hash
          end
        end

        tests DeserializationTestController

        def test_deserialization
          hash = {
            'data' => {
              'type' => 'photos',
              'id' => 'zorglub',
              'attributes' => {
                'title' => 'Ember Hamster',
                'src' => 'http://example.com/images/productivity.png'
              },
              'relationships' => {
                'author' => {
                  'data' => nil
                },
                'photographer' => {
                  'data' => { 'type' => 'people', 'id' => '9' }
                },
                'comments' => {
                  'data' => [
                    { 'type' => 'comments', 'id' => '1' },
                    { 'type' => 'comments', 'id' => '2' }
                  ]
                }
              }
            }
          }

          post :render_parsed_payload, hash

          response = JSON.parse(@response.body)
          expected = {
            'id' => 'zorglub',
            'title' => 'Ember Hamster',
            'src' => 'http://example.com/images/productivity.png',
            'author_id' => nil,
            'photographer_id' => '9',
            'comment_ids' => %w(1 2)
          }

          assert_equal(expected, response)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_model_serializers-0.10.0.rc4 test/action_controller/json_api/deserialization_test.rb