summaryrefslogtreecommitdiff
path: root/spec/models/concerns
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-17 00:09:12 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-17 00:09:12 +0000
commitd43aaf286fe6b8e8383e73ea580274d8841608d7 (patch)
treeca03542a55583538a1ec13023dffed20457407b5 /spec/models/concerns
parent87af6f2e0590af0ed1bb3e5de1bb5d21855a94d2 (diff)
downloadgitlab-ce-d43aaf286fe6b8e8383e73ea580274d8841608d7.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/concerns')
-rw-r--r--spec/models/concerns/usage_statistics_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/models/concerns/usage_statistics_spec.rb b/spec/models/concerns/usage_statistics_spec.rb
new file mode 100644
index 00000000000..f99f0a13317
--- /dev/null
+++ b/spec/models/concerns/usage_statistics_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe UsageStatistics do
+ describe '.distinct_count_by' do
+ let_it_be(:issue_1) { create(:issue) }
+ let_it_be(:issue_2) { create(:issue) }
+
+ context 'two records created by the same issue' do
+ let!(:models_created_by_issue) do
+ create(:zoom_meeting, :added_to_issue, issue: issue_1)
+ create(:zoom_meeting, :removed_from_issue, issue: issue_1)
+ end
+
+ it 'returns a count of 1' do
+ expect(::ZoomMeeting.distinct_count_by(:issue_id)).to eq(1)
+ end
+
+ context 'when given no column to count' do
+ it 'counts by :id and returns a count of 2' do
+ expect(::ZoomMeeting.distinct_count_by).to eq(2)
+ end
+ end
+ end
+
+ context 'one record created by each issue' do
+ let!(:model_created_by_issue_1) { create(:zoom_meeting, issue: issue_1) }
+ let!(:model_created_by_issue_2) { create(:zoom_meeting, issue: issue_2) }
+
+ it 'returns a count of 2' do
+ expect(::ZoomMeeting.distinct_count_by(:issue_id)).to eq(2)
+ end
+ end
+
+ context 'the count query times out' do
+ before do
+ allow_next_instance_of(ActiveRecord::Relation) do |instance|
+ allow(instance).to receive(:count).and_raise(ActiveRecord::StatementInvalid.new(''))
+ end
+ end
+
+ it 'does not raise an error' do
+ expect { ::ZoomMeeting.distinct_count_by(:issue_id) }.not_to raise_error
+ end
+
+ it 'returns -1' do
+ expect(::ZoomMeeting.distinct_count_by(:issue_id)).to eq(-1)
+ end
+ end
+ end
+end