Sha256: c563414d85654075e0593450b2a345004670e55ece01414cf61819fffa09732e

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require 'jsonapi/include_directive'

describe JSONAPI::IncludeDirective, '.key?' do
  it 'handles existing keys' do
    str = 'posts.comments'
    include_directive = JSONAPI::IncludeDirective.new(str)

    expect(include_directive.key?(:posts)).to be_truthy
  end

  it 'handles absent keys' do
    str = 'posts.comments'
    include_directive = JSONAPI::IncludeDirective.new(str)

    expect(include_directive.key?(:author)).to be_falsy
  end

  it 'handles wildcards' do
    str = 'posts.*'
    include_directive = JSONAPI::IncludeDirective.new(
      str, allow_wildcard: true)

    expect(include_directive[:posts].key?(:author)).to be_truthy
    expect(include_directive[:posts][:author].key?(:comments)).to be_falsy
  end

  it 'handles wildcards' do
    str = 'posts.**'
    include_directive = JSONAPI::IncludeDirective.new(
      str, allow_wildcard: true)

    expect(include_directive[:posts].key?(:author)).to be_truthy
    expect(include_directive[:posts][:author].key?(:comments)).to be_truthy
  end
end

describe JSONAPI::IncludeDirective, '.to_string' do
  it 'works' do
    str = 'friends,comments.author,posts.author,posts.comments.author'
    include_directive = JSONAPI::IncludeDirective.new(str)
    expected = include_directive.to_hash
    actual = JSONAPI::IncludeDirective.new(include_directive.to_string)
                                        .to_hash

    expect(actual).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_spec.rb
jsonapi-0.1.1.beta1 spec/include_directive_spec.rb