diff options
Diffstat (limited to 'spec/lib/gitlab/usage/metrics/instrumentations')
-rw-r--r-- | spec/lib/gitlab/usage/metrics/instrumentations/count_merge_request_authors_metric_spec.rb | 25 | ||||
-rw-r--r-- | spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb | 16 |
2 files changed, 16 insertions, 25 deletions
diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_merge_request_authors_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_merge_request_authors_metric_spec.rb deleted file mode 100644 index 92459e92eac..00000000000 --- a/spec/lib/gitlab/usage/metrics/instrumentations/count_merge_request_authors_metric_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountMergeRequestAuthorsMetric do - let(:expected_value) { 1 } - let(:start) { 30.days.ago.to_s(:db) } - let(:finish) { 2.days.ago.to_s(:db) } - - let(:expected_query) do - "SELECT COUNT(DISTINCT \"merge_requests\".\"author_id\") FROM \"merge_requests\"" \ - " WHERE \"merge_requests\".\"created_at\" BETWEEN '#{start}' AND '#{finish}'" - end - - before do - user = create(:user) - user2 = create(:user) - - create(:merge_request, created_at: 1.year.ago, author: user) - create(:merge_request, created_at: 1.week.ago, author: user2) - create(:merge_request, created_at: 1.week.ago, author: user2) - end - - it_behaves_like 'a correct instrumented metric value and query', { time_frame: '28d' } -end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb index f1ecc8c8ab5..8ca42a6f007 100644 --- a/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb +++ b/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb @@ -196,6 +196,22 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric do end end + context 'with 7 days time frame' do + subject do + database_metric_class.tap do |metric_class| + metric_class.relation { Issue } + metric_class.operation :count + end.new(time_frame: '7d') + end + + it 'calculates a correct result' do + create(:issue, created_at: 10.days.ago) + create(:issue, created_at: 5.days.ago) + + expect(subject.value).to eq(1) + end + end + context 'with additional parameters passed via options' do subject do database_metric_class.tap do |metric_class| |