Sha256: 3fa2df17259bf6a7a35a1c5c20ef7e17a1d95b39b2280c4975fda21eb75555bd

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

# 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

7 entries across 7 versions & 1 rubygems

Version Path
yaks-0.8.3 spec/unit/yaks/format/json_api_spec.rb
yaks-0.8.2 spec/unit/yaks/format/json_api_spec.rb
yaks-0.8.1 spec/unit/yaks/format/json_api_spec.rb
yaks-0.8.0 spec/unit/yaks/format/json_api_spec.rb
yaks-0.8.0.beta2 spec/unit/yaks/format/json_api_spec.rb
yaks-0.8.0.beta1 spec/unit/yaks/format/json_api_spec.rb
yaks-0.8.0.alpha spec/unit/yaks/format/json_api_spec.rb