Sha256: 4afe27da196fa087fc16b9601fdbe18f12d61f87e244b26951cb07a5bb339310

Contents?: true

Size: 588 Bytes

Versions: 2

Compression:

Stored size: 588 Bytes

Contents

RSpec.describe ROM::Relation, '#having' do
  subject(:relation) do
    container.relations.users
      .inner_join(:tasks, user_id: :id)
      .select_group(:users__id, :users__name)
      .select_append { count(:tasks).as(:task_count) }
  end

  include_context 'users and tasks'

  with_adapters :postgres do
    before do
      conn[:tasks].insert(id: 3, user_id: 2, title: "Joe's another task")
    end

    it 'restricts a relation using HAVING clause' do
      expect(relation.having { count(:tasks__id) >= 2 }.to_a).to eq([{ id: 2, name: 'Joe', task_count: 2 }])
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rom-sql-0.9.1 spec/unit/relation/having_spec.rb
rom-sql-0.9.0 spec/unit/relation/having_spec.rb