Welcome to mirror list, hosted at ThFree Co, Russian Federation.

having_constraints_spec.rb « relation_parsers « names_suggestions « metrics « usage « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 492acf2a90206211005ca6b689d53b290de83ba7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::RelationParsers::HavingConstraints do
  describe '#accept' do
    let(:connection) { ApplicationRecord.connection }
    let(:collector) { Arel::Collectors::SubstituteBinds.new(connection, Arel::Collectors::SQLString.new) }

    it 'builds correct constraints description' do
      table = Arel::Table.new('records')
      havings = table[:attribute].sum.eq(6).and(table[:attribute].count.gt(5))
      arel = table.from.project(table['id'].count).having(havings).group(table[:attribute2])
      described_class.new(connection).accept(arel, collector)

      expect(collector.value).to eql '(SUM(records.attribute) = 6 AND COUNT(records.attribute) > 5)'
    end
  end
end