Sha256: e689226134677b4bcc5963ac5cbc31fa09905ffa0a0564176c8f31ffca9a5d55

Contents?: true

Size: 932 Bytes

Versions: 48

Compression:

Stored size: 932 Bytes

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
      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'
          }
        }
      )
    )
    expect(result).to eq({id: 1, title: 'Product', creator: { id: 1, name: 'John' }})
  }
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
ree_lib-1.0.48 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.47 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.46 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.45 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.44 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.43 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.42 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.41 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.40 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.39 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.38 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.37 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.36 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.35 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.34 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.33 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.32 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.31 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.30 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb
ree_lib-1.0.29 lib/ree_lib/packages/ree_mapper/spec/ree_mapper/dsl/dsl_spec.rb