diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/lib/gitlab/usage/metrics/query_spec.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/lib/gitlab/usage/metrics/query_spec.rb')
-rw-r--r-- | spec/lib/gitlab/usage/metrics/query_spec.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/lib/gitlab/usage/metrics/query_spec.rb b/spec/lib/gitlab/usage/metrics/query_spec.rb new file mode 100644 index 00000000000..60c8d044a64 --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/query_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Query do + describe '.count' do + it 'returns the raw SQL' do + expect(described_class.for(:count, User)).to eq('SELECT COUNT("users"."id") FROM "users"') + end + + it 'does not mix a nil column with keyword arguments' do + expect(described_class.for(:count, User, nil)).to eq('SELECT COUNT("users"."id") FROM "users"') + end + end + + describe '.distinct_count' do + it 'returns the raw SQL' do + expect(described_class.for(:distinct_count, Issue, :author_id)).to eq('SELECT COUNT(DISTINCT "issues"."author_id") FROM "issues"') + end + + it 'does not mix a nil column with keyword arguments' do + expect(described_class.for(:distinct_count, Issue, nil)).to eq('SELECT COUNT(DISTINCT "issues"."id") FROM "issues"') + end + end + + describe '.sum' do + it 'returns the raw SQL' do + expect(described_class.for(:sum, Issue, :weight)).to eq('SELECT SUM("issues"."weight") FROM "issues"') + end + end + + describe 'estimate_batch_distinct_count' do + it 'returns the raw SQL' do + expect(described_class.for(:estimate_batch_distinct_count, Issue, :author_id)).to eq('SELECT COUNT(DISTINCT "issues"."author_id") FROM "issues"') + end + end + + describe '.histogram' do + it 'returns the histogram sql' do + expect(described_class.for(:histogram, AlertManagement::HttpIntegration.active, + :project_id, buckets: 1..2, bucket_size: 101)) + .to match(/^WITH "count_cte" AS #{Gitlab::Database::AsWithMaterialized.materialized_if_supported}/) + end + end + + describe 'other' do + it 'raise ArgumentError error' do + expect { described_class.for(:other, nil) }.to raise_error(ArgumentError, 'other operation not supported') + end + end +end |