Sha256: 7d3e2962cb4e2ed53ff760adc881d6e93c1f7dd85e372c2c094cf9c208b8385d

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

RSpec.describe 'SQL Relation extensions' do
  include_context 'database'

  shared_context 'valid view' do
    let(:users) { rom.relation(:users) }

    it 'has valid column names' do
      expect(users.columns).to eql([:id, :name])

      expect(users.by_id.columns).to eql([:name])
      expect(users.by_id(1).columns).to eql([:name])
    end

    it 'defines a valid method with correct arity' do
      expect(users.relation.method(:by_id).arity).to be(1)
    end
  end

  describe '.view' do
    context 'using short syntax' do
      before do
        setup.relation(:users) do
          view(:by_id, [:name]) do |name|
            where(name: name).select(:name)
          end
        end
      end

      include_context 'valid view'
    end

    context 'with multi-block syntax' do
      before do
        setup.relation(:users) do
          view(:by_id) do
            header [:name]

            relation do |name|
              where(name: name).select(:name)
            end
          end
        end
      end

      include_context 'valid view'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-repository-0.0.1 spec/unit/sql/relation_spec.rb