Sha256: ea529ee4adea9b3418a3f37cf5b8215e1af0c35d38435f0fb9659bd97b1e8309
Contents?: true
Size: 1.37 KB
Versions: 6
Compression:
Stored size: 1.37 KB
Contents
require 'spec_helper' RSpec.describe Yaks::Mapper::HasOne do include_context 'yaks context' AuthorMapper = Class.new(Yaks::Mapper) { attributes :name } subject(:has_one) do described_class.new( name: :author, mapper: association_mapper, rel: 'http://rel' ) end let(:association_mapper) { AuthorMapper } let(:name) { 'William S. Burroughs' } let(:author) { fake(:name => name) } fake(:policy, derive_type_from_mapper_class: 'author', derive_mapper_from_association: AuthorMapper ){ Yaks::DefaultPolicy } its(:singular_name) { should eq 'author' } it 'should map to a single Resource' do expect(has_one.map_resource(author, yaks_context)).to eq Yaks::Resource.new(type: 'author', attributes: {name: name}) end context 'with no mapper specified' do subject(:subresource) { has_one.add_to_resource(Yaks::Resource.new, parent_mapper, yaks_context) } let(:association_mapper) { Yaks::Undefined } fake(:parent_mapper) { Yaks::Mapper } before do stub(parent_mapper).load_association(:author) { author } end it 'should derive one based on policy' do expect(subresource).to eql( Yaks::Resource.new( subresources: { 'http://rel' => Yaks::Resource.new(type: 'author', attributes: {name: name}) } ) ) end end end
Version data entries
6 entries across 6 versions & 2 rubygems