Sha256: a10278e82ce70730cfa72ac7d53e64678d8d697deec10d3e12e92789620da642

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe FunWithJsonApi do
  it 'should have a Semantic Versioning compatible VERSION' do
    # based on https://github.com/npm/node-semver/issues/32
    version_regex = /
      \A([0-9]+) # major
      \.([0-9]+) # minor
      \.([0-9]+) # patch
      (?:-([0-9A-Za-z-]+(?:\.[0-9a-z-]+)*))? # build
      (?:\+[0-9a-z-]+)?\z # tag
    /x
    expect(FunWithJsonApi::VERSION).to match(version_regex)
  end

  describe '.deserialize' do
    context 'with an PostDeserializer' do
      it 'should convert a json api to post params' do
        ARModels::Author.create(id: 9)
        ARModels::Comment.create(id: 5)
        ARModels::Comment.create(id: 12)

        post_json = {
          'data': {
            'type': 'posts',
            'id': '1',
            'attributes': {
              'title': 'Rails is Omakase',
              'body': 'This is my post body'
            },
            'relationships': {
              'author': {
                'data': { 'type': 'people', 'id': '9' }
              },
              'comments': {
                'data': [
                  { 'type': 'comments', 'id': '5' },
                  { 'type': 'comments', 'id': '12' }
                ]
              }
            }
          }
        }

        post_params = FunWithJsonApi.deserialize(post_json, ARModels::PostDeserializer)
        expect(post_params).to eq(
          title: 'Rails is Omakase',
          body: 'This is my post body',
          author_id: 9,
          comment_ids: [5, 12]
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fun_with_json_api-0.0.2 spec/fun_with_json_api_spec.rb
fun_with_json_api-0.0.1 spec/fun_with_json_api_spec.rb