diff options
author | Alex Kalderimis <akalderimis@gitlab.com> | 2019-07-21 04:26:19 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-07-21 04:26:19 +0300 |
commit | 7320758611b8d8c28fb179f970e015a72357b94d (patch) | |
tree | c74e9e90c6f0fd35f5b3cf08466c2947b39128ca /spec/lib/gitlab/usage_data_counters | |
parent | 66394bd1b7c98d7a6abbeade068b8b9c1b838ddf (diff) |
Count wiki page creation
This adds a counter to count page creation, which is reflected in the
usage-data we collect.
The number created is stored in Redis, avoiding DB access.
Diffstat (limited to 'spec/lib/gitlab/usage_data_counters')
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/wiki_page_counter_spec.rb | 69 |
2 files changed, 89 insertions, 0 deletions
diff --git a/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb index b5e32d1875f..7a01f7d1de8 100644 --- a/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb @@ -33,4 +33,24 @@ describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_st it_behaves_like 'counter examples' end + + describe '.totals' do + commits = 5 + merge_requests = 3 + views = 2 + + before do + commits.times { described_class.increment_commits_count } + merge_requests.times { described_class.increment_merge_requests_count } + views.times { described_class.increment_views_count } + end + + it 'can report all totals' do + expect(described_class.totals).to include( + web_ide_commits: commits, + web_ide_views: views, + web_ide_merge_requests: merge_requests + ) + end + end end diff --git a/spec/lib/gitlab/usage_data_counters/wiki_page_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/wiki_page_counter_spec.rb new file mode 100644 index 00000000000..41afbbb191c --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/wiki_page_counter_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::UsageDataCounters::WikiPageCounter, :clean_gitlab_redis_shared_state do + shared_examples :wiki_page_event do |event| + describe ".count(#{event})" do + it "increments the wiki page #{event} counter by 1" do + expect do + described_class.count(event) + end.to change { described_class.read(event) }.by 1 + end + end + + describe ".read(#{event})" do + event_count = 5 + + it "returns the total number of #{event} events" do + event_count.times do + described_class.count(event) + end + + expect(described_class.read(event)).to eq(event_count) + end + end + end + + include_examples :wiki_page_event, :create + include_examples :wiki_page_event, :update + include_examples :wiki_page_event, :delete + + describe 'totals' do + creations = 5 + edits = 3 + deletions = 2 + + before do + creations.times do + described_class.count(:create) + end + edits.times do + described_class.count(:update) + end + deletions.times do + described_class.count(:delete) + end + end + + it 'can report all totals' do + expect(described_class.totals).to include( + wiki_pages_update: edits, + wiki_pages_create: creations, + wiki_pages_delete: deletions + ) + end + end + + describe 'unknown events' do + error = described_class::UnknownEvent + + it 'cannot increment' do + expect { described_class.count(:wibble) }.to raise_error error + end + + it 'cannot read' do + expect { described_class.read(:wibble) }.to raise_error error + end + end +end |