Sha256: 4ace3a7e7ed2355d9d5c062965c1869dd53fa8837869270c29388ab5de925113

Contents?: true

Size: 1013 Bytes

Versions: 2

Compression:

Stored size: 1013 Bytes

Contents

RSpec.describe ROM::Relation, '#select' do
  subject(:relation) { container.relations.tasks }

  include_context 'users and tasks'

  before do
    conf.relation(:tasks) { schema(infer: true) }
  end

  with_adapters do
    it 'projects a relation using a list of symbols' do
      expect(relation.select(:id, :title).to_a)
        .to eql([{ id: 1, title: "Joe's task" }, { id: 2, title: "Jane's task"}])
    end

    it 'projects a relation using a schema' do
      expect(relation.select(*relation.schema.project(:id, :title)).to_a)
        .to eql([{ id: 1, title: "Joe's task" }, { id: 2, title: "Jane's task"}])
    end

    it 'maintains schema' do
      expect(relation.select(:id, :title).schema.map(&:name)).to eql(%i[id title])
    end

    it 'supports args and blocks' do
      expect(relation.select(:id) { [title] }.schema.map(&:name)).to eql(%i[id title])
    end

    it 'supports blocks' do
      expect(relation.select { [id, title] }.schema.map(&:name)).to eql(%i[id title])
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rom-sql-1.0.1 spec/unit/relation/select_spec.rb
rom-sql-1.0.0 spec/unit/relation/select_spec.rb