Commit d8d1a9aa authored by Nicolas Dular's avatar Nicolas Dular Committed by Dmytro Zaporozhets (DZ)

Replace all snowplow mocks with the spec helper

This removes all existing offenses, where we mocked `Gitlab::Tracking`
instead of using the Snowplow spec helper.
parent ab333de7
...@@ -183,19 +183,6 @@ RSpec/ContextWording: ...@@ -183,19 +183,6 @@ RSpec/ContextWording:
RSpec/ExpectChange: RSpec/ExpectChange:
Enabled: false Enabled: false
# Offense count: 47
RSpec/ExpectGitlabTracking:
Exclude:
- 'spec/controllers/projects/registry/repositories_controller_spec.rb'
- 'spec/controllers/projects/registry/tags_controller_spec.rb'
- 'spec/controllers/projects/settings/operations_controller_spec.rb'
- 'spec/lib/api/helpers_spec.rb'
- 'spec/requests/api/project_container_repositories_spec.rb'
- 'spec/support/shared_examples/controllers/trackable_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/discussions_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/packages_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/tracking_shared_examples.rb'
# Offense count: 751 # Offense count: 751
RSpec/ExpectInHook: RSpec/ExpectInHook:
Enabled: false Enabled: false
......
...@@ -50,18 +50,17 @@ RSpec.describe Projects::Registry::RepositoriesController do ...@@ -50,18 +50,17 @@ RSpec.describe Projects::Registry::RepositoriesController do
tags: %w[rc1 latest]) tags: %w[rc1 latest])
end end
it 'successfully renders container repositories' do it 'successfully renders container repositories', :snowplow do
expect(Gitlab::Tracking).not_to receive(:event)
go_to_index go_to_index
expect_no_snowplow_event
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
it 'tracks the event' do it 'tracks the event', :snowplow do
expect(Gitlab::Tracking).to receive(:event).with(anything, 'list_repositories')
go_to_index(format: :json) go_to_index(format: :json)
expect_snowplow_event(category: anything, action: 'list_repositories')
end end
it 'creates a root container repository' do it 'creates a root container repository' do
...@@ -132,11 +131,12 @@ RSpec.describe Projects::Registry::RepositoriesController do ...@@ -132,11 +131,12 @@ RSpec.describe Projects::Registry::RepositoriesController do
expect(response).to have_gitlab_http_status(:no_content) expect(response).to have_gitlab_http_status(:no_content)
end end
it 'tracks the event' do it 'tracks the event', :snowplow do
expect(Gitlab::Tracking).to receive(:event).with(anything, 'delete_repository')
allow(DeleteContainerRepositoryWorker).to receive(:perform_async).with(user.id, repository.id) allow(DeleteContainerRepositoryWorker).to receive(:perform_async).with(user.id, repository.id)
delete_repository(repository) delete_repository(repository)
expect_snowplow_event(category: anything, action: 'delete_repository')
end end
end end
end end
......
...@@ -39,10 +39,10 @@ RSpec.describe Projects::Registry::TagsController do ...@@ -39,10 +39,10 @@ RSpec.describe Projects::Registry::TagsController do
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
end end
it 'tracks the event' do it 'tracks the event', :snowplow do
expect(Gitlab::Tracking).to receive(:event).with(anything, 'list_tags')
get_tags get_tags
expect_snowplow_event(category: anything, action: 'list_tags')
end end
end end
...@@ -148,11 +148,11 @@ RSpec.describe Projects::Registry::TagsController do ...@@ -148,11 +148,11 @@ RSpec.describe Projects::Registry::TagsController do
bulk_destroy_tags(tags) bulk_destroy_tags(tags)
end end
it 'tracks the event' do it 'tracks the event', :snowplow do
expect_delete_tags(tags) expect_delete_tags(tags)
expect(Gitlab::Tracking).to receive(:event).with(anything, 'delete_tag_bulk')
bulk_destroy_tags(tags) bulk_destroy_tags(tags)
expect_snowplow_event(category: anything, action: 'delete_tag_bulk')
end end
end end
end end
......
...@@ -166,23 +166,22 @@ RSpec.describe Projects::Settings::OperationsController do ...@@ -166,23 +166,22 @@ RSpec.describe Projects::Settings::OperationsController do
context 'updating each incident management setting' do context 'updating each incident management setting' do
let(:new_incident_management_settings) { {} } let(:new_incident_management_settings) { {} }
shared_examples 'a gitlab tracking event' do |params, event_key| shared_examples 'a gitlab tracking event' do |params, event_key, **args|
it "creates a gitlab tracking event #{event_key}" do it "creates a gitlab tracking event #{event_key}", :snowplow do
new_incident_management_settings = params new_incident_management_settings = params
expect(Gitlab::Tracking).to receive(:event)
.with('IncidentManagement::Settings', event_key, any_args)
patch :update, params: project_params(project, incident_management_setting_attributes: new_incident_management_settings) patch :update, params: project_params(project, incident_management_setting_attributes: new_incident_management_settings)
project.reload project.reload
expect_snowplow_event(category: 'IncidentManagement::Settings', action: event_key, **args)
end end
end end
it_behaves_like 'a gitlab tracking event', { create_issue: '1' }, 'enabled_issue_auto_creation_on_alerts' it_behaves_like 'a gitlab tracking event', { create_issue: '1' }, 'enabled_issue_auto_creation_on_alerts'
it_behaves_like 'a gitlab tracking event', { create_issue: '0' }, 'disabled_issue_auto_creation_on_alerts' it_behaves_like 'a gitlab tracking event', { create_issue: '0' }, 'disabled_issue_auto_creation_on_alerts'
it_behaves_like 'a gitlab tracking event', { issue_template_key: 'template' }, 'enabled_issue_template_on_alerts' it_behaves_like 'a gitlab tracking event', { issue_template_key: 'template' }, 'enabled_issue_template_on_alerts', label: "Template name", property: "template"
it_behaves_like 'a gitlab tracking event', { issue_template_key: nil }, 'disabled_issue_template_on_alerts' it_behaves_like 'a gitlab tracking event', { issue_template_key: nil }, 'disabled_issue_template_on_alerts', label: "Template name", property: ""
it_behaves_like 'a gitlab tracking event', { send_email: '1' }, 'enabled_sending_emails' it_behaves_like 'a gitlab tracking event', { send_email: '1' }, 'enabled_sending_emails'
it_behaves_like 'a gitlab tracking event', { send_email: '0' }, 'disabled_sending_emails' it_behaves_like 'a gitlab tracking event', { send_email: '0' }, 'disabled_sending_emails'
it_behaves_like 'a gitlab tracking event', { pagerduty_active: '1' }, 'enabled_pagerduty_webhook' it_behaves_like 'a gitlab tracking event', { pagerduty_active: '1' }, 'enabled_pagerduty_webhook'
......
...@@ -176,10 +176,10 @@ RSpec.describe API::Helpers do ...@@ -176,10 +176,10 @@ RSpec.describe API::Helpers do
end end
describe '#track_event' do describe '#track_event' do
it "creates a gitlab tracking event" do it "creates a gitlab tracking event", :snowplow do
expect(Gitlab::Tracking).to receive(:event).with('foo', 'my_event')
subject.track_event('my_event', category: 'foo') subject.track_event('my_event', category: 'foo')
expect_snowplow_event(category: 'foo', action: 'my_event')
end end
it "logs an exception" do it "logs an exception" do
......
...@@ -299,7 +299,7 @@ RSpec.describe API::ProjectContainerRepositories do ...@@ -299,7 +299,7 @@ RSpec.describe API::ProjectContainerRepositories do
it_behaves_like 'rejected container repository access', :reporter, :forbidden it_behaves_like 'rejected container repository access', :reporter, :forbidden
it_behaves_like 'rejected container repository access', :anonymous, :not_found it_behaves_like 'rejected container repository access', :anonymous, :not_found
context 'for developer' do context 'for developer', :snowplow do
let(:api_user) { developer } let(:api_user) { developer }
context 'when there are multiple tags' do context 'when there are multiple tags' do
...@@ -310,11 +310,11 @@ RSpec.describe API::ProjectContainerRepositories do ...@@ -310,11 +310,11 @@ RSpec.describe API::ProjectContainerRepositories do
it 'properly removes tag' do it 'properly removes tag' do
expect(service).to receive(:execute).with(root_repository) { { status: :success } } expect(service).to receive(:execute).with(root_repository) { { status: :success } }
expect(Projects::ContainerRepository::DeleteTagsService).to receive(:new).with(root_repository.project, api_user, tags: %w[rootA]) { service } expect(Projects::ContainerRepository::DeleteTagsService).to receive(:new).with(root_repository.project, api_user, tags: %w[rootA]) { service }
expect(Gitlab::Tracking).to receive(:event).with(described_class.name, 'delete_tag')
subject subject
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect_snowplow_event(category: described_class.name, action: 'delete_tag')
end end
end end
...@@ -326,11 +326,11 @@ RSpec.describe API::ProjectContainerRepositories do ...@@ -326,11 +326,11 @@ RSpec.describe API::ProjectContainerRepositories do
it 'properly removes tag' do it 'properly removes tag' do
expect(service).to receive(:execute).with(root_repository) { { status: :success } } expect(service).to receive(:execute).with(root_repository) { { status: :success } }
expect(Projects::ContainerRepository::DeleteTagsService).to receive(:new).with(root_repository.project, api_user, tags: %w[rootA]) { service } expect(Projects::ContainerRepository::DeleteTagsService).to receive(:new).with(root_repository.project, api_user, tags: %w[rootA]) { service }
expect(Gitlab::Tracking).to receive(:event).with(described_class.name, 'delete_tag')
subject subject
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect_snowplow_event(category: described_class.name, action: 'delete_tag')
end end
end end
end end
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'a Trackable Controller' do RSpec.shared_examples 'a Trackable Controller' do
describe '#track_event' do describe '#track_event', :snowplow do
before do before do
sign_in user sign_in user
end end
...@@ -14,9 +14,10 @@ RSpec.shared_examples 'a Trackable Controller' do ...@@ -14,9 +14,10 @@ RSpec.shared_examples 'a Trackable Controller' do
end end
end end
it 'tracks the action name' do it 'tracks the action name', :snowplow do
expect(Gitlab::Tracking).to receive(:event).with('AnonymousController', 'index')
get :index get :index
expect_snowplow_event(category: 'AnonymousController', action: 'index')
end end
end end
...@@ -29,8 +30,9 @@ RSpec.shared_examples 'a Trackable Controller' do ...@@ -29,8 +30,9 @@ RSpec.shared_examples 'a Trackable Controller' do
end end
it 'tracks with the specified param' do it 'tracks with the specified param' do
expect(Gitlab::Tracking).to receive(:event).with('SomeCategory', 'some_event', label: 'errorlabel')
get :index get :index
expect_snowplow_event(category: 'SomeCategory', action: 'some_event', label: 'errorlabel')
end end
end end
end end
......
...@@ -128,10 +128,10 @@ RSpec.shared_examples 'discussions API' do |parent_type, noteable_type, id_name, ...@@ -128,10 +128,10 @@ RSpec.shared_examples 'discussions API' do |parent_type, noteable_type, id_name,
stub_feature_flags(notes_create_service_tracking: false) stub_feature_flags(notes_create_service_tracking: false)
end end
it 'does not track any events' do it 'does not track any events', :snowplow do
expect(Gitlab::Tracking).not_to receive(:event)
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions"), params: { body: 'hi!' } post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions"), params: { body: 'hi!' }
expect_no_snowplow_event
end end
end end
......
...@@ -132,9 +132,9 @@ RSpec.shared_examples 'a package tracking event' do |category, action| ...@@ -132,9 +132,9 @@ RSpec.shared_examples 'a package tracking event' do |category, action|
stub_feature_flags(collect_package_events: true) stub_feature_flags(collect_package_events: true)
end end
it "creates a gitlab tracking event #{action}" do it "creates a gitlab tracking event #{action}", :snowplow do
expect(Gitlab::Tracking).to receive(:event).with(category, action)
expect { subject }.to change { Packages::Event.count }.by(1) expect { subject }.to change { Packages::Event.count }.by(1)
expect_snowplow_event(category: category, action: action)
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'a gitlab tracking event' do |category, action| RSpec.shared_examples 'a gitlab tracking event' do |category, action|
it "creates a gitlab tracking event #{action}" do it "creates a gitlab tracking event #{action}", :snowplow do
expect(Gitlab::Tracking).to receive(:event).with(category, action)
subject subject
expect_snowplow_event(category: category, action: action)
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment