Sha256: 24e6f6c6691db9d43a5ad6898f8386735b95665fc888bb9d366afe9fb9adb79c

Contents?: true

Size: 1.07 KB

Versions: 18

Compression:

Stored size: 1.07 KB

Contents

require 'spec_helper'
require 'rom/memory'

RSpec.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

18 entries across 18 versions & 1 rubygems

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