Sha256: 62e6ad35a9c29093e9566afe00996bbfa04625c4eaf44573010d845de8f0d995

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

RSpec.describe :register_type do
  link :build_mapper_factory, from: :ree_mapper
  link :build_mapper_strategy, from: :ree_mapper
  link :build_serializer_schema, from: :ree_swagger
  link :register_type, from: :ree_swagger

  class ReeSwagger::MyType < ReeMapper::AbstractType
    def serialize(obj, role: nil)
      obj.inspect
    end
  end

  let(:mapper_factory) {
    strategies = [
      build_mapper_strategy(method: :serialize, dto: Hash),
    ]

    build_mapper_factory(strategies: strategies)
      .register_type(:my_type, ReeSwagger::MyType.new)
  }

  let(:mapper) {
    mapper_factory.call.use(:serialize) do
      my_type :name
    end
  }

  before do
    register_type(
      :serializers,
      ReeSwagger::MyType,
      ->(my_type, build_serializer_schema) {
        {
          type: 'string'
        }
      }
    )
  end

  it {
    expect(build_serializer_schema(mapper)).to eq(
      {
        type: 'object',
        properties: {
          name: {
            type: 'string'
          }
        }
      }
    )
  }
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ree_lib-1.0.38 lib/ree_lib/packages/ree_swagger/spec/functions/register_type_spec.rb
ree_lib-1.0.37 lib/ree_lib/packages/ree_swagger/spec/functions/register_type_spec.rb
ree_lib-1.0.36 lib/ree_lib/packages/ree_swagger/spec/functions/register_type_spec.rb