Sha256: 9cb69ad73d6cbe00180f231ba766cfea073432ddaa53c9c3a4dad15f92e7c9bc

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

require 'spec_helper'

# Mainly tested through the acceptance tests, here covering a few specific edge cases
RSpec.describe Yaks::Format::JsonAPI do
  let(:format) { Yaks::Format::JsonAPI.new }

  context 'with no subresources' do
    let(:resource) { Yaks::Resource.new(type: 'wizard', attributes: {foo: :bar}) }

    it 'should not include a "linked" key' do
      expect(format.call(resource)).to eql(
        {'wizards' => [{foo: :bar}]}
      )
    end
  end

  context 'with both a "href" attribute and a self link' do
    let(:resource) {
      Yaks::Resource.new(
        type: 'wizard',
        attributes: {
          href: '/the/href'
        },
        links: [
          Yaks::Resource::Link.new(rel: :self, uri: '/the/self/link')
        ]
      )
    }

    # TODO should it really behave this way? better to give preference to self link.
    it 'should give preference to the href attribute' do
      expect(format.call(resource)).to eql(
        {'wizards' => [
            {
              href: '/the/href'
            }
          ]
        }
      )
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yaks-0.7.7 spec/unit/yaks/format/json_api_spec.rb
yaks-0.7.6 spec/unit/yaks/format/json_api_spec.rb