diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/usage_data_counters | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/usage_data_counters')
12 files changed, 93 insertions, 11 deletions
diff --git a/spec/lib/gitlab/usage_data_counters/cycle_analytics_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/cycle_analytics_counter_spec.rb index 71be37692e2..18c21ef7eba 100644 --- a/spec/lib/gitlab/usage_data_counters/cycle_analytics_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/cycle_analytics_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::CycleAnalyticsCounter do +RSpec.describe Gitlab::UsageDataCounters::CycleAnalyticsCounter do it_behaves_like 'a redis usage counter', 'CycleAnalytics', :views it_behaves_like 'a redis usage counter with totals', :cycle_analytics, views: 3 diff --git a/spec/lib/gitlab/usage_data_counters/designs_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/designs_counter_spec.rb index deaf7ebc7f3..10a09e737f9 100644 --- a/spec/lib/gitlab/usage_data_counters/designs_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/designs_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::DesignsCounter do +RSpec.describe Gitlab::UsageDataCounters::DesignsCounter do it_behaves_like 'a redis usage counter', 'Designs', :create it_behaves_like 'a redis usage counter', 'Designs', :update it_behaves_like 'a redis usage counter', 'Designs', :delete diff --git a/spec/lib/gitlab/usage_data_counters/merge_request_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/merge_request_counter_spec.rb index 4be4a661260..d16c73e9312 100644 --- a/spec/lib/gitlab/usage_data_counters/merge_request_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/merge_request_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::MergeRequestCounter do +RSpec.describe Gitlab::UsageDataCounters::MergeRequestCounter do it_behaves_like 'a redis usage counter', 'Merge Request', :create it_behaves_like 'a redis usage counter with totals', :merge_request, create: 5 diff --git a/spec/lib/gitlab/usage_data_counters/note_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/note_counter_spec.rb index b385d1b07c7..7e8f0172e06 100644 --- a/spec/lib/gitlab/usage_data_counters/note_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/note_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::NoteCounter, :clean_gitlab_redis_shared_state do +RSpec.describe Gitlab::UsageDataCounters::NoteCounter, :clean_gitlab_redis_shared_state do shared_examples 'a note usage counter' do |event, noteable_type| describe ".count(#{event})" do it "increments the Note #{event} counter by 1" do diff --git a/spec/lib/gitlab/usage_data_counters/productivity_analytics_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/productivity_analytics_counter_spec.rb index f4e92791728..34b2cfcf1de 100644 --- a/spec/lib/gitlab/usage_data_counters/productivity_analytics_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/productivity_analytics_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::ProductivityAnalyticsCounter do +RSpec.describe Gitlab::UsageDataCounters::ProductivityAnalyticsCounter do it_behaves_like 'a redis usage counter', 'ProductivityAnalytics', :views it_behaves_like 'a redis usage counter with totals', :productivity_analytics, views: 3 diff --git a/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb index c34ac7867ab..be528b081c5 100644 --- a/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/redis_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::RedisCounter, :clean_gitlab_redis_shared_state do +RSpec.describe Gitlab::UsageDataCounters::RedisCounter, :clean_gitlab_redis_shared_state do let(:redis_key) { 'foobar' } subject { Class.new.extend(described_class) } diff --git a/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb index 35b0f9a67f4..b55e20ba555 100644 --- a/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::SearchCounter, :clean_gitlab_redis_shared_state do +RSpec.describe Gitlab::UsageDataCounters::SearchCounter, :clean_gitlab_redis_shared_state do shared_examples_for 'usage counter with totals' do |counter| it 'increments counter and returns total count' do expect(described_class.read(counter)).to eq(0) diff --git a/spec/lib/gitlab/usage_data_counters/snippet_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/snippet_counter_spec.rb index 65381ed36d1..6109437da77 100644 --- a/spec/lib/gitlab/usage_data_counters/snippet_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/snippet_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::SnippetCounter do +RSpec.describe Gitlab::UsageDataCounters::SnippetCounter do it_behaves_like 'a redis usage counter', 'Snippet', :create it_behaves_like 'a redis usage counter', 'Snippet', :update diff --git a/spec/lib/gitlab/usage_data_counters/source_code_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/source_code_counter_spec.rb index 47077345e0c..73d5b4038f8 100644 --- a/spec/lib/gitlab/usage_data_counters/source_code_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/source_code_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::SourceCodeCounter do +RSpec.describe Gitlab::UsageDataCounters::SourceCodeCounter do it_behaves_like 'a redis usage counter', 'Source Code', :pushes it_behaves_like 'a redis usage counter with totals', :source_code, pushes: 5 diff --git a/spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb b/spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb new file mode 100644 index 00000000000..584d8407e79 --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redis_shared_state do + subject(:track_unique_events) { described_class } + + let(:time) { Time.zone.now } + + def track_action(params) + track_unique_events.track_action(params) + end + + def count_unique_events(params) + track_unique_events.count_unique_events(params) + end + + context 'tracking an event' do + context 'when tracking successfully' do + context 'when the feature flag and the application setting is enabled' do + context 'when the target and the action is valid' do + before do + stub_feature_flags(described_class::FEATURE_FLAG => true) + stub_application_setting(usage_ping_enabled: true) + end + + it 'tracks and counts the events as expected' do + project = Event::TARGET_TYPES[:project] + design = Event::TARGET_TYPES[:design] + wiki = Event::TARGET_TYPES[:wiki] + + expect(track_action(event_action: :pushed, event_target: project, author_id: 1)).to be_truthy + expect(track_action(event_action: :pushed, event_target: project, author_id: 1)).to be_truthy + expect(track_action(event_action: :pushed, event_target: project, author_id: 2)).to be_truthy + expect(track_action(event_action: :pushed, event_target: project, author_id: 3)).to be_truthy + expect(track_action(event_action: :pushed, event_target: project, author_id: 4, time: time - 3.days)).to be_truthy + expect(track_action(event_action: :created, event_target: project, author_id: 5, time: time - 3.days)).to be_truthy + + expect(track_action(event_action: :destroyed, event_target: design, author_id: 3)).to be_truthy + expect(track_action(event_action: :created, event_target: design, author_id: 4)).to be_truthy + expect(track_action(event_action: :updated, event_target: design, author_id: 5)).to be_truthy + expect(track_action(event_action: :pushed, event_target: design, author_id: 6)).to be_truthy + + expect(track_action(event_action: :destroyed, event_target: wiki, author_id: 5)).to be_truthy + expect(track_action(event_action: :created, event_target: wiki, author_id: 3)).to be_truthy + expect(track_action(event_action: :updated, event_target: wiki, author_id: 4)).to be_truthy + expect(track_action(event_action: :pushed, event_target: wiki, author_id: 6)).to be_truthy + + expect(count_unique_events(event_action: described_class::PUSH_ACTION, date_from: time, date_to: Date.today)).to eq(3) + expect(count_unique_events(event_action: described_class::PUSH_ACTION, date_from: time - 5.days, date_to: Date.tomorrow)).to eq(4) + expect(count_unique_events(event_action: described_class::DESIGN_ACTION, date_from: time - 5.days, date_to: Date.today)).to eq(3) + expect(count_unique_events(event_action: described_class::WIKI_ACTION, date_from: time - 5.days, date_to: Date.today)).to eq(3) + expect(count_unique_events(event_action: described_class::PUSH_ACTION, date_from: time - 5.days, date_to: time - 2.days)).to eq(1) + end + end + end + end + + context 'when tracking unsuccessfully' do + using RSpec::Parameterized::TableSyntax + + where(:feature_flag, :application_setting, :target, :action) do + true | true | Project | :invalid_action + false | true | Project | :pushed + true | false | Project | :pushed + true | true | :invalid_target | :pushed + end + + with_them do + before do + stub_application_setting(usage_ping_enabled: application_setting) + stub_feature_flags(described_class::FEATURE_FLAG => feature_flag) + end + + it 'returns the expected values' do + expect(track_action(event_action: action, event_target: target, author_id: 2)).to be_nil + expect(count_unique_events(event_action: described_class::PUSH_ACTION, date_from: time, date_to: Date.today)).to eq(0) + end + end + end + end +end 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 42abbecead0..b0e5bd18b66 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 @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_state do +RSpec.describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_state do shared_examples 'counter examples' do |event| it 'increments counter and return the total count' do expect(described_class.public_send(:total_count, event)).to eq(0) 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 index 4e8ae35187e..685f6ea0a85 100644 --- a/spec/lib/gitlab/usage_data_counters/wiki_page_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/wiki_page_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::UsageDataCounters::WikiPageCounter do +RSpec.describe Gitlab::UsageDataCounters::WikiPageCounter do it_behaves_like 'a redis usage counter', 'Wiki Page', :create it_behaves_like 'a redis usage counter', 'Wiki Page', :update it_behaves_like 'a redis usage counter', 'Wiki Page', :delete |