Sha256: f4dcfa4c6b49c7056b4f17bcc8c386074b5a23c64ccd15b550907233bd97fbf4

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require 'spec_helper'

RSpec.describe Yaks::Mapper::HasOne do
  AuthorMapper = Class.new(Yaks::Mapper) { attributes :name }

  let(:name)     { 'William S. Burroughs' }
  let(:mapper)   { AuthorMapper }
  let(:has_one)  { described_class.new(:author, mapper, 'http://rel', Yaks::Undefined) }
  let(:author)   { double(:name => name) }
  let(:policy)   {
    double(
      Yaks::DefaultPolicy,
      derive_type_from_mapper_class: 'author',
      derive_mapper_from_association: AuthorMapper
    )
  }
  let(:context) {{policy: policy, env: {}}}

  it 'should map to a single Resource' do
    expect(has_one.map_resource(author, context)).to eq Yaks::Resource.new(type: 'author', attributes: {name: name})
  end

  context 'with no mapper specified' do
    let(:mapper)   { Yaks::Undefined }

    it 'should derive one based on policy' do
      expect(has_one.create_subresource(nil, {author: author}, context)).to eql [
        'http://rel',
        Yaks::Resource.new(type: 'author', attributes: {name: name})
      ]
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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