diff options
Diffstat (limited to 'spec/lib/gitlab/usage/metrics/names_suggestions')
-rw-r--r-- | spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/having_constraints_spec.rb | 19 | ||||
-rw-r--r-- | spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/where_constraints_spec.rb (renamed from spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/constraints_spec.rb) | 7 |
2 files changed, 23 insertions, 3 deletions
diff --git a/spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/having_constraints_spec.rb b/spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/having_constraints_spec.rb new file mode 100644 index 00000000000..492acf2a902 --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/having_constraints_spec.rb @@ -0,0 +1,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 diff --git a/spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/constraints_spec.rb b/spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/where_constraints_spec.rb index 68016e760e4..42a776478a4 100644 --- a/spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/constraints_spec.rb +++ b/spec/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/where_constraints_spec.rb @@ -2,14 +2,15 @@ require 'spec_helper' -RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::RelationParsers::Constraints do +RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::RelationParsers::WhereConstraints do describe '#accept' do - let(:collector) { Arel::Collectors::SubstituteBinds.new(ActiveRecord::Base.connection, Arel::Collectors::SQLString.new) } + 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') arel = table.from.project(table['id'].count).where(table[:attribute].eq(true).and(table[:some_value].gt(5))) - described_class.new(ApplicationRecord.connection).accept(arel, collector) + described_class.new(connection).accept(arel, collector) expect(collector.value).to eql '(records.attribute = true AND records.some_value > 5)' end |