Sha256: 3c032563a0530badca5aedeb2eb3a3af47477d5b8f64aa2e69fd2d29a7b0b90f

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

require 'jsonapi/include_directive'

describe JSONAPI::IncludeDirective::Parser, '.parse_include_args' do
  it 'handles arrays of symbols and hashes' do
    args = [:friends,
            comments: [:author],
            posts: [:author,
                    comments: [:author]]]
    hash = JSONAPI::IncludeDirective::Parser.parse_include_args(args)
    expected = {
      friends: {},
      comments: { author: {} },
      posts: { author: {}, comments: { author: {} } }
    }

    expect(hash).to eq expected
  end

  it 'handles strings with spaces' do
    str = 'friends, comments.author, posts.author, posts.comments.author'
    hash = JSONAPI::IncludeDirective::Parser.parse_include_args(str)
    expected = {
      friends: {},
      comments: { author: {} },
      posts: { author: {}, comments: { author: {} } }
    }

    expect(hash).to eq expected
  end

  it 'handles common prefixes in strings' do
    args = ['friends', 'comments.author', 'posts.author',
            'posts.comments.author']
    hash = JSONAPI::IncludeDirective::Parser.parse_include_args(args)
    expected = {
      friends: {},
      comments: { author: {} },
      posts: { author: {}, comments: { author: {} } }
    }

    expect(hash).to eq expected
  end

  it 'handles an empty string' do
    args = ''
    hash = JSONAPI::IncludeDirective::Parser.parse_include_args(args)
    expected = {}

    expect(hash).to eq expected
  end

  it 'handles an empty array' do
    args = []
    hash = JSONAPI::IncludeDirective::Parser.parse_include_args(args)
    expected = {}

    expect(hash).to eq expected
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jsonapi-0.1.1.beta2 spec/include_directive/parser_spec.rb
jsonapi-0.1.1.beta1 spec/include_directive/parser_spec.rb