Sha256: a248d74583686ee47d887a88a23aa0c01ae94565a5e4a825b93d1adebab93698

Contents?: true

Size: 1.24 KB

Versions: 17

Compression:

Stored size: 1.24 KB

Contents

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

  include_context 'users and tasks'

  let(:dataset) { container.gateways[:default].dataset(:users) }

  with_adapters do
    context 'with schema' do
      before do
        conf.relation(:users) do
          schema do
            attribute :id, ROM::SQL::Types::Serial
            attribute :name, ROM::SQL::Types::String
          end
        end
      end

      it 'uses schema to infer default dataset' do
        expect(relation.dataset.sql).to eql(dataset.select(:id, :name).order(:users__id).sql)
      end
    end

    context 'with cherry-picked attributes in schema' do
      before do
        conf.relation(:users) do
          schema do
            attribute :id, ROM::SQL::Types::Serial
          end
        end
      end

      it 'uses schema to infer default dataset' do
        expect(relation.dataset.sql).to eql(dataset.select(:id).order(:users__id).sql)
      end
    end

    context 'without schema' do
      before do
        conf.relation(:users)
      end

      it 'selects all qualified columns and sorts by pk' do
        expect(relation.dataset.sql).to eql(dataset.select(*relation.columns).order(:users__id).sql)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rom-sql-1.3.1 spec/unit/relation/dataset_spec.rb
rom-sql-1.3.0 spec/unit/relation/dataset_spec.rb
rom-sql-1.2.2 spec/unit/relation/dataset_spec.rb
rom-sql-1.2.1 spec/unit/relation/dataset_spec.rb
rom-sql-1.2.0 spec/unit/relation/dataset_spec.rb
rom-sql-1.1.2 spec/unit/relation/dataset_spec.rb
rom-sql-1.1.1 spec/unit/relation/dataset_spec.rb
rom-sql-1.1.0 spec/unit/relation/dataset_spec.rb
rom-sql-1.0.3 spec/unit/relation/dataset_spec.rb
rom-sql-1.0.2 spec/unit/relation/dataset_spec.rb
rom-sql-1.0.1 spec/unit/relation/dataset_spec.rb
rom-sql-1.0.0 spec/unit/relation/dataset_spec.rb
rom-sql-1.0.0.rc2 spec/unit/relation/dataset_spec.rb
rom-sql-1.0.0.rc1 spec/unit/relation/dataset_spec.rb
rom-sql-1.0.0.beta3 spec/unit/relation/dataset_spec.rb
rom-sql-1.0.0.beta2 spec/unit/relation/dataset_spec.rb
rom-sql-1.0.0.beta1 spec/unit/relation/dataset_spec.rb