Sha256: 79b1dd890468d8c3e3282ce81ecc5b1094e7d21ab9608974a77a2ce10cb3b6aa

Contents?: true

Size: 774 Bytes

Versions: 3

Compression:

Stored size: 774 Bytes

Contents

require 'spec_helper'
require 'rom/memory'

describe 'Mappers / Prefixing attributes' do
  let(:setup) { ROM.setup(:memory) }

  before do
    setup.relation(:users)
  end

  it 'automatically maps all attributes using the provided prefix' do
    class Test::UserMapper < ROM::Mapper
      relation :users
      prefix :user

      model name: 'Test::User'

      attribute :id
      attribute :name
      attribute :email
    end

    rom = setup.finalize

    Test::User.send(:include, Equalizer.new(:id, :name, :email))

    rom.relations.users << {
      user_id: 123,
      user_name: 'Jane',
      user_email: 'jane@doe.org'
    }

    jane = rom.read(:users).to_a.first

    expect(jane).to eql(Test::User.new(id: 123, name: 'Jane', email: 'jane@doe.org'))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-0.6.0.beta3 spec/integration/mappers/prefixing_attributes_spec.rb
rom-0.6.0.beta2 spec/integration/mappers/prefixing_attributes_spec.rb
rom-0.6.0.beta1 spec/integration/mappers/prefixing_attributes_spec.rb