Sha256: 26186835a6a206b3dd6f53ebcf700fc2d4327e927fd851087954ace9c4ee9b15

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'

RSpec.describe Yaks::Resource do
  subject(:resource) { described_class.new(init_opts) }
  let(:init_opts) { {} }

  its(:type)         { should be_nil }
  its(:attributes)   { should eql({}) }
  its(:links)        { should eql [] }
  its(:subresources) { should eql({}) }

  context 'with a type' do
    let(:init_opts) { { type: 'post' } }
    its(:type) { should eql 'post' }
  end

  context 'with attributes' do
    let(:init_opts) { { attributes: {name: 'Arne', age: 31} } }

    it 'should delegate [] to attribute access' do
      expect(resource[:name]).to eql 'Arne'
    end
  end

  context 'with links' do
    let(:init_opts) { { links: [Yaks::Resource::Link.new(:self, '/foo/bar', {})] } }
    its(:links) { should eql [Yaks::Resource::Link.new(:self, '/foo/bar', {})] }
  end

  context 'with subresources' do
    let(:init_opts) { { subresources: { 'comments' => [Yaks::Resource.new(type: 'comment')] } } }
    its(:subresources) { should eql 'comments' => [Yaks::Resource.new(type: 'comment')]  }
  end

  its(:collection?) { should equal false }

  it 'should act as a collection of one' do
    expect(resource.each.to_a).to eql [resource]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yaks-0.4.1 spec/unit/yaks/resource_spec.rb
yaks-0.4.0 spec/unit/yaks/resource_spec.rb
yaks-0.4.0.rc1 spec/unit/yaks/resource_spec.rb