Sha256: 42d6cf370613b1792a86040d95316464a2d7b3f1c4e2a28c1d2e48b8efeb7e62

Contents?: true

Size: 1.23 KB

Versions: 16

Compression:

Stored size: 1.23 KB

Contents

require 'rom/relation'

RSpec.describe ROM::Relation, '#call' do
  subject(:relation) do
    relation_class.new(data)
  end

  context 'without read types in schema' do
    let(:relation_class) do
      Class.new(ROM::Relation[:memory]) do
        schema do
          attribute :id, ROM::Types::Int
          attribute :name, ROM::Types::String
        end
      end
    end

    let(:data) do
      [{ id: '1', name: 'Jane' }, { id: '2', name: 'John'} ]
    end

    it 'has noop output_schema' do
      expect(relation.output_schema).to be(ROM::Relation::NOOP_OUTPUT_SCHEMA)
    end

    it 'returns loaded relation with data' do
      expect(relation.call.collection).
        to eql(data)
    end
  end

  context 'with read types in schema' do
    let(:relation_class) do
      Class.new(ROM::Relation[:memory]) do
        schema do
          attribute :id, ROM::Types::String, read: ROM::Types::Coercible::Int
          attribute :name, ROM::Types::String
        end
      end
    end

    let(:data) do
      [{ id: '1', name: 'Jane' }, { id: '2', name: 'John'} ]
    end

    it 'returns loaded relation with coerced data' do
      expect(relation.call.collection).
        to eql([{ id: 1, name: 'Jane' }, { id: 2, name: 'John'} ])
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rom-3.3.3 spec/unit/rom/relation/call_spec.rb
rom-3.3.2 spec/unit/rom/relation/call_spec.rb
rom-3.3.1 spec/unit/rom/relation/call_spec.rb
rom-3.3.0 spec/unit/rom/relation/call_spec.rb
rom-3.2.3 spec/unit/rom/relation/call_spec.rb
rom-3.2.2 spec/unit/rom/relation/call_spec.rb
rom-3.2.1 spec/unit/rom/relation/call_spec.rb
rom-3.2.0 spec/unit/rom/relation/call_spec.rb
rom-3.1.0 spec/unit/rom/relation/call_spec.rb
rom-3.0.3 spec/unit/rom/relation/call_spec.rb
rom-3.0.2 spec/unit/rom/relation/call_spec.rb
rom-3.0.1 spec/unit/rom/relation/call_spec.rb
rom-3.0.0 spec/unit/rom/relation/call_spec.rb
rom-3.0.0.rc2 spec/unit/rom/relation/call_spec.rb
rom-3.0.0.rc1 spec/unit/rom/relation/call_spec.rb
rom-3.0.0.beta3 spec/unit/rom/relation/call_spec.rb