Sha256: de7a8fe3977384f019d3e150b03e674ea0dc5837291abae6b162dcd6021250e4

Contents?: true

Size: 1.09 KB

Versions: 18

Compression:

Stored size: 1.09 KB

Contents

require 'spec_helper'
require 'rom/memory'

RSpec.describe 'Mapper definition DSL' do
  include_context 'container'

  before do
    configuration.relation(:users)

    users = configuration.default.dataset(:users)
    users.insert(
      user_id: 1,
      user_name: 'Joe',
      user_email: 'joe@doe.com',
      'user.skype' => 'joe',
      :'user.phone' => '1234567890'
    )
  end

  describe 'prefix' do
    subject(:mapped_users) { container.relation(:users).as(:users).to_a }

    it 'applies new separator to the attributes following it' do
      configuration.mappers do
        define(:users) do
          prefix :user
          attribute :id
          attribute :name
          wrap :contacts do
            attribute :email

            prefix_separator '.'
            attribute 'skype'
            attribute :phone
          end
        end
      end

      expect(mapped_users).to eql [
        {
          id: 1,
          name: 'Joe',
          contacts: {
            email: 'joe@doe.com',
            'skype' => 'joe',
            phone: '1234567890'
          }
        }
      ]
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rom-3.3.3 spec/integration/mappers/prefix_separator_spec.rb
rom-3.3.2 spec/integration/mappers/prefix_separator_spec.rb
rom-3.3.1 spec/integration/mappers/prefix_separator_spec.rb
rom-3.3.0 spec/integration/mappers/prefix_separator_spec.rb
rom-3.2.3 spec/integration/mappers/prefix_separator_spec.rb
rom-3.2.2 spec/integration/mappers/prefix_separator_spec.rb
rom-3.2.1 spec/integration/mappers/prefix_separator_spec.rb
rom-3.2.0 spec/integration/mappers/prefix_separator_spec.rb
rom-3.1.0 spec/integration/mappers/prefix_separator_spec.rb
rom-3.0.3 spec/integration/mappers/prefix_separator_spec.rb
rom-3.0.2 spec/integration/mappers/prefix_separator_spec.rb
rom-3.0.1 spec/integration/mappers/prefix_separator_spec.rb
rom-3.0.0 spec/integration/mappers/prefix_separator_spec.rb
rom-3.0.0.rc2 spec/integration/mappers/prefix_separator_spec.rb
rom-3.0.0.rc1 spec/integration/mappers/prefix_separator_spec.rb
rom-3.0.0.beta3 spec/integration/mappers/prefix_separator_spec.rb
rom-3.0.0.beta2 spec/integration/mappers/prefix_separator_spec.rb
rom-3.0.0.beta1 spec/integration/mappers/prefix_separator_spec.rb