Sha256: 44545f96e0f40831b4f33f23d00564dea59e743c9f41956c2e7eef73cfe85ae9

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

require 'test_helper'
module ForestRails
  class ResourceDeserializerTest < ActiveSupport::TestCase
    test 'JSONAPI payload should extract attributes' do
      json = { type: 'users', attributes: { name: 'forest' } }.as_json
      params = ActionController::Parameters.new(json)
      result = ResourceDeserializer.new(params).perform

      assert result.length == 1
      assert result[:name] = 'forest'
    end

    test 'JSONAPI payload should support relationships' do
      json = {
        type: 'users',
        attributes: {
          name: 'forest'
        },
        relationships: {
          organization: {
            data: {
              type: 'organizations',
              id: '42'
            }
          }
        }
      }.as_json
      params = ActionController::Parameters.new(json)
      result = ResourceDeserializer.new(params).perform

      assert result.length == 2
      assert result[:name] = 'forest'
      assert result[:organization_id] = '42'
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forest_rails-0.0.4 test/deserializers/forest_rails/resource_deserializer_test.rb