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/services/event_create_service_spec.rb')
-rw-r--r--spec/services/event_create_service_spec.rb77
1 files changed, 40 insertions, 37 deletions
diff --git a/spec/services/event_create_service_spec.rb b/spec/services/event_create_service_spec.rb
index d10ed7d6640..a91519a710f 100644
--- a/spec/services/event_create_service_spec.rb
+++ b/spec/services/event_create_service_spec.rb
@@ -171,45 +171,52 @@ RSpec.describe EventCreateService do
let_it_be(:wiki_page) { create(:wiki_page) }
let_it_be(:meta) { create(:wiki_page_meta, :for_wiki_page, wiki_page: wiki_page) }
- Event::WIKI_ACTIONS.each do |action|
- context "The action is #{action}" do
- let(:event) { service.wiki_event(meta, user, action) }
-
- it 'creates the event', :aggregate_failures do
- expect(event).to have_attributes(
- wiki_page?: true,
- valid?: true,
- persisted?: true,
- action: action.to_s,
- wiki_page: wiki_page,
- author: user
- )
- end
+ let(:fingerprint) { generate(:sha) }
- it 'records the event in the event counter' do
- stub_feature_flags(Gitlab::UsageDataCounters::TrackUniqueActions::FEATURE_FLAG => true)
- counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
- tracking_params = { event_action: counter_class::WIKI_ACTION, date_from: Date.yesterday, date_to: Date.today }
+ def create_event
+ service.wiki_event(meta, user, action, fingerprint)
+ end
- expect { event }
- .to change { counter_class.count_unique_events(tracking_params) }
- .from(0).to(1)
- end
+ where(:action) { Event::WIKI_ACTIONS.map { |action| [action] } }
+
+ with_them do
+ it 'creates the event' do
+ expect(create_event).to have_attributes(
+ wiki_page?: true,
+ valid?: true,
+ persisted?: true,
+ action: action.to_s,
+ wiki_page: wiki_page,
+ author: user,
+ fingerprint: fingerprint
+ )
+ end
- it 'is idempotent', :aggregate_failures do
- expect { event }.to change(Event, :count).by(1)
- duplicate = nil
- expect { duplicate = service.wiki_event(meta, user, action) }.not_to change(Event, :count)
+ it 'is idempotent', :aggregate_failures do
+ event = nil
+ expect { event = create_event }.to change(Event, :count).by(1)
+ duplicate = nil
+ expect { duplicate = create_event }.not_to change(Event, :count)
- expect(duplicate).to eq(event)
- end
+ expect(duplicate).to eq(event)
+ end
+
+ it 'records the event in the event counter' do
+ counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
+ tracking_params = { event_action: counter_class::WIKI_ACTION, date_from: Date.yesterday, date_to: Date.today }
+
+ expect { create_event }
+ .to change { counter_class.count_unique(tracking_params) }
+ .by(1)
end
end
(Event.actions.keys - Event::WIKI_ACTIONS).each do |bad_action|
context "The action is #{bad_action}" do
+ let(:action) { bad_action }
+
it 'raises an error' do
- expect { service.wiki_event(meta, user, bad_action) }.to raise_error(described_class::IllegalActionError)
+ expect { create_event }.to raise_error(described_class::IllegalActionError)
end
end
end
@@ -236,12 +243,11 @@ RSpec.describe EventCreateService do
it_behaves_like 'service for creating a push event', PushEventPayloadService
it 'records the event in the event counter' do
- stub_feature_flags(Gitlab::UsageDataCounters::TrackUniqueActions::FEATURE_FLAG => true)
counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
tracking_params = { event_action: counter_class::PUSH_ACTION, date_from: Date.yesterday, date_to: Date.today }
expect { subject }
- .to change { counter_class.count_unique_events(tracking_params) }
+ .to change { counter_class.count_unique(tracking_params) }
.from(0).to(1)
end
end
@@ -260,12 +266,11 @@ RSpec.describe EventCreateService do
it_behaves_like 'service for creating a push event', BulkPushEventPayloadService
it 'records the event in the event counter' do
- stub_feature_flags(Gitlab::UsageDataCounters::TrackUniqueActions::FEATURE_FLAG => true)
counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
tracking_params = { event_action: counter_class::PUSH_ACTION, date_from: Date.yesterday, date_to: Date.today }
expect { subject }
- .to change { counter_class.count_unique_events(tracking_params) }
+ .to change { counter_class.count_unique(tracking_params) }
.from(0).to(1)
end
end
@@ -315,12 +320,11 @@ RSpec.describe EventCreateService do
end
it 'records the event in the event counter' do
- stub_feature_flags(Gitlab::UsageDataCounters::TrackUniqueActions::FEATURE_FLAG => true)
counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
tracking_params = { event_action: counter_class::DESIGN_ACTION, date_from: Date.yesterday, date_to: Date.today }
expect { result }
- .to change { counter_class.count_unique_events(tracking_params) }
+ .to change { counter_class.count_unique(tracking_params) }
.from(0).to(1)
end
end
@@ -343,12 +347,11 @@ RSpec.describe EventCreateService do
end
it 'records the event in the event counter' do
- stub_feature_flags(Gitlab::UsageDataCounters::TrackUniqueActions::FEATURE_FLAG => true)
counter_class = Gitlab::UsageDataCounters::TrackUniqueActions
tracking_params = { event_action: counter_class::DESIGN_ACTION, date_from: Date.yesterday, date_to: Date.today }
expect { result }
- .to change { counter_class.count_unique_events(tracking_params) }
+ .to change { counter_class.count_unique(tracking_params) }
.from(0).to(1)
end
end