Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb')
-rw-r--r--spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb63
1 files changed, 30 insertions, 33 deletions
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
index 584d8407e79..bd348666729 100644
--- a/spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb
+++ b/spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb
@@ -7,20 +7,19 @@ RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redi
let(:time) { Time.zone.now }
- def track_action(params)
- track_unique_events.track_action(params)
+ def track_event(params)
+ track_unique_events.track_event(params)
end
- def count_unique_events(params)
- track_unique_events.count_unique_events(params)
+ def count_unique(params)
+ track_unique_events.count_unique(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 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
@@ -29,28 +28,28 @@ RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redi
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_event(event_action: :pushed, event_target: project, author_id: 1)).to be_truthy
+ expect(track_event(event_action: :pushed, event_target: project, author_id: 1)).to be_truthy
+ expect(track_event(event_action: :pushed, event_target: project, author_id: 2)).to be_truthy
+ expect(track_event(event_action: :pushed, event_target: project, author_id: 3)).to be_truthy
+ expect(track_event(event_action: :pushed, event_target: project, author_id: 4, time: time - 3.days)).to be_truthy
+ expect(track_event(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_event(event_action: :destroyed, event_target: design, author_id: 3)).to be_truthy
+ expect(track_event(event_action: :created, event_target: design, author_id: 4)).to be_truthy
+ expect(track_event(event_action: :updated, event_target: design, author_id: 5)).to be_truthy
+ expect(track_event(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(track_event(event_action: :destroyed, event_target: wiki, author_id: 5)).to be_truthy
+ expect(track_event(event_action: :created, event_target: wiki, author_id: 3)).to be_truthy
+ expect(track_event(event_action: :updated, event_target: wiki, author_id: 4)).to be_truthy
+ expect(track_event(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)
+ expect(count_unique(event_action: described_class::PUSH_ACTION, date_from: time, date_to: Date.today)).to eq(3)
+ expect(count_unique(event_action: described_class::PUSH_ACTION, date_from: time - 5.days, date_to: Date.tomorrow)).to eq(4)
+ expect(count_unique(event_action: described_class::DESIGN_ACTION, date_from: time - 5.days, date_to: Date.today)).to eq(3)
+ expect(count_unique(event_action: described_class::WIKI_ACTION, date_from: time - 5.days, date_to: Date.today)).to eq(3)
+ expect(count_unique(event_action: described_class::PUSH_ACTION, date_from: time - 5.days, date_to: time - 2.days)).to eq(1)
end
end
end
@@ -59,22 +58,20 @@ RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redi
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
+ where(:application_setting, :target, :action) do
+ true | Project | :invalid_action
+ false | Project | :pushed
+ 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)
+ expect(track_event(event_action: action, event_target: target, author_id: 2)).to be_nil
+ expect(count_unique(event_action: described_class::PUSH_ACTION, date_from: time, date_to: Date.today)).to eq(0)
end
end
end