Sha256: 22615b020e314f62d6505820405ce492f945c91ae1fff4f860cbc1ac963403aa

Contents?: true

Size: 803 Bytes

Versions: 1

Compression:

Stored size: 803 Bytes

Contents

require 'spec_helper'

require 'ostruct'

describe ROM::Mapper do
  subject(:mapper) do
    ROM::Mapper.build(ROM::Header.coerce(relation.header.zip, user_model))
  end

  let(:relation) do
    ROM::Relation.new(dataset, dataset.header)
  end

  let(:dataset) do
    ROM::Adapter::Memory::Dataset.new(
      [{ id: 1, name: 'Jane' }, { id: 2, name: 'Joe' }], [:id, :name]
    )
  end

  let(:user_model) do
    Class.new(OpenStruct) { include Equalizer.new(:id, :name) }
  end

  let(:jane) { user_model.new(id: 1, name: 'Jane') }
  let(:joe) { user_model.new(id: 2, name: 'Joe') }

  describe "#each" do
    it "yields all mapped objects" do
      result = []

      mapper.process(relation).each do |tuple|
        result << tuple
      end

      expect(result).to eql([jane, joe])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-0.5.0 spec/unit/rom/mapper_spec.rb