Sha256: 471b9843e827c4323bc3b39d63f874327b00907bbe712fd08251b9db6a7eb5e6

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

require 'spec_helper'
require 'rom/memory'

describe 'Mappers / Attributes value' do
  include_context 'container'

  before do
    configuration.relation(:users)
  end

  it 'allows to manipulate attribute value' do
    class Test::UserMapper < ROM::Mapper
      relation :users

      attribute :id
      attribute :name, from: :first_name do
        'John'
      end
      attribute :age do
        9+9
      end
      attribute :weight do |t|
        t+15
      end
    end

    configuration.register_mapper(Test::UserMapper)

    container.relations.users << {
      id: 123,
      first_name: 'Jane',
      weight: 75
    }

    jane = container.relation(:users).as(:users).first

    expect(jane).to eql(id: 123, name: 'John', weight: 90, age: 18)
  end

  it 'raise ArgumentError if type and block used at the same time' do
    expect {
      class Test::UserMapper < ROM::Mapper
        relation :users

        attribute :name, type: :string do
          'John'
        end
      end
    }.to raise_error(ArgumentError, "can't specify type and block at the same time")
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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