Sha256: 88059e04b876552b98bafac72dab0d4a304533a71ef643a69f0d2f5a86cf1e5f

Contents?: true

Size: 665 Bytes

Versions: 7

Compression:

Stored size: 665 Bytes

Contents

require 'spec_helper'

describe 'Registering Custom Mappers' do
  include_context 'container'
  include_context 'users and tasks'

  it 'allows registering arbitrary objects as mappers' do
    model = Struct.new(:name, :email)

    mapper = -> users {
      users.map { |tuple| model.new(*tuple.values_at(:name, :email)) }
    }

    configuration.relation(:users) do
      def by_name(name)
        restrict(name: name)
      end
    end

    configuration.mappers do
      register(:users, entity: mapper)
    end

    users = container.relation(:users).by_name('Jane').as(:entity)

    expect(users).to match_array([model.new('Jane', 'jane@doe.org')])
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rom-2.0.2 spec/integration/mappers/registering_custom_mappers_spec.rb
rom-2.0.1 spec/integration/mappers/registering_custom_mappers_spec.rb
rom-2.0.0 spec/integration/mappers/registering_custom_mappers_spec.rb
rom-1.0.0 spec/integration/mappers/registering_custom_mappers_spec.rb
rom-1.0.0.rc1 spec/integration/mappers/registering_custom_mappers_spec.rb
rom-1.0.0.beta2 spec/integration/mappers/registering_custom_mappers_spec.rb
rom-1.0.0.beta1 spec/integration/mappers/registering_custom_mappers_spec.rb