Sha256: 4e413d3c19b4a5e5bf135915f6aad1da8fd6ee6e0d64d29c16bcd69c7b545d54

Contents?: true

Size: 1.21 KB

Versions: 16

Compression:

Stored size: 1.21 KB

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

    it 'supports selecting literal strings' do
      new_rel = relation.select { `'event'`.as(:type) }

      expect(new_rel.schema[:type].primitive).to be(String)
      expect(new_rel.first).to eql(type: 'event')
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rom-sql-1.3.5 spec/unit/relation/select_spec.rb
rom-sql-1.3.4 spec/unit/relation/select_spec.rb
rom-sql-2.0.0.beta2 spec/unit/relation/select_spec.rb
rom-sql-2.0.0.beta1 spec/unit/relation/select_spec.rb
rom-sql-1.3.3 spec/unit/relation/select_spec.rb
rom-sql-1.3.2 spec/unit/relation/select_spec.rb
rom-sql-1.3.1 spec/unit/relation/select_spec.rb
rom-sql-1.3.0 spec/unit/relation/select_spec.rb
rom-sql-1.2.2 spec/unit/relation/select_spec.rb
rom-sql-1.2.1 spec/unit/relation/select_spec.rb
rom-sql-1.2.0 spec/unit/relation/select_spec.rb
rom-sql-1.1.2 spec/unit/relation/select_spec.rb
rom-sql-1.1.1 spec/unit/relation/select_spec.rb
rom-sql-1.1.0 spec/unit/relation/select_spec.rb
rom-sql-1.0.3 spec/unit/relation/select_spec.rb
rom-sql-1.0.2 spec/unit/relation/select_spec.rb