Sha256: 7dcf3a7e5debd69ccc126cfd31ab406900a2496cd5210cf4ce0f55a9d84eb57a

Contents?: true

Size: 789 Bytes

Versions: 1

Compression:

Stored size: 789 Bytes

Contents

RSpec.describe ROM::Relation, '#by_pk' do
  include_context 'users and tasks'

  with_adapters do
    context 'with a single PK' do
      subject(:relation) { relations[:users] }

      it 'restricts a relation by its PK' do
        expect(relation.by_pk(1).to_a).to eql([id: 1, name: 'Jane'])
      end

      it 'is available as a view' do
        expect(relation.by_pk).to be_curried
      end

      it 'qualifies pk attr' do
        expect(relation.qualified.by_pk(1).select(:id).join(:tasks, user_id: :id).one).to eql(id: 1)
      end
    end

    context 'with a composite PK' do
      subject(:relation) { relations[:task_tags] }

      it 'restricts a relation by is PK' do
        expect(relation.by_pk(1, 1).to_a).to eql([{ tag_id: 1, task_id: 1 }])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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