Sha256: e3fb991c6c7fe20033de9194041ff650ad461fea04edfe1309fdb03127324f66

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

package_require('ree_mapper/dsl')

RSpec.describe ReeMapper::DSL do
  before {
    Ree.enable_irb_mode
  }

  after {
    Ree.disable_irb_mode
  }

  it {
    class ReeMapper::UserCaster
      include ReeMapper::DSL

      mapper :user_caster

      build_mapper(register_as: :user).use(:cast) do
        integer :id
        string  :name
        user    :created_by, null: true
      end
    end

    class ReeMapper::ProductCaster
      include ReeMapper::DSL

      mapper :product_caster do
        link :user_caster
      end

      build_mapper.use(:cast) do
        integer :id
        string  :title
        user    :creator
      end
    end

    result = ReeMapper::ProductCaster.new.cast(
      OpenStruct.new(
        {
          id: 1,
          title: 'Product',
          creator: {
            id: 1,
            name: 'John',
            created_by: {
              id: 2,
              name: 'Jane',
              created_by: nil
            }
          }
        }
      )
    )

    expect(result).to eq({
      id: 1,
      title: 'Product',
      creator: {
        id: 1,
        name: 'John',
        created_by: {
          id: 2,
          name: 'Jane',
          created_by: nil
        }
      }
    })
  }
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ree_lib-1.0.100 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.99 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb