diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/lib/gitlab/usage_data_queries_spec.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/lib/gitlab/usage_data_queries_spec.rb')
-rw-r--r-- | spec/lib/gitlab/usage_data_queries_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/lib/gitlab/usage_data_queries_spec.rb b/spec/lib/gitlab/usage_data_queries_spec.rb new file mode 100644 index 00000000000..7fc77593265 --- /dev/null +++ b/spec/lib/gitlab/usage_data_queries_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::UsageDataQueries do + before do + allow(ActiveRecord::Base.connection).to receive(:transaction_open?).and_return(false) + end + + describe '.count' do + it 'returns the raw SQL' do + expect(described_class.count(User)).to start_with('SELECT COUNT("users"."id") FROM "users"') + end + end + + describe '.distinct_count' do + it 'returns the raw SQL' do + expect(described_class.distinct_count(Issue, :author_id)).to eq('SELECT COUNT(DISTINCT "issues"."author_id") FROM "issues"') + end + end + + describe '.redis_usage_data' do + subject(:redis_usage_data) { described_class.redis_usage_data { 42 } } + + it 'returns a class for redis_usage_data with a counter call' do + expect(described_class.redis_usage_data(Gitlab::UsageDataCounters::WikiPageCounter)) + .to eq(redis_usage_data_counter: Gitlab::UsageDataCounters::WikiPageCounter) + end + + it 'returns a stringified block for redis_usage_data with a block' do + is_expected.to include(:redis_usage_data_block) + expect(redis_usage_data[:redis_usage_data_block]).to start_with('#<Proc:') + end + end + + describe '.sum' do + it 'returns the raw SQL' do + expect(described_class.sum(Issue, :weight)).to eq('SELECT SUM("issues"."weight") FROM "issues"') + end + end +end |