Commit 9544e9bb authored by James Fargher's avatar James Fargher

Merge branch '295264-stub-do-not-track-helper' into 'master'

Implement stub_do_not_track helper

See merge request gitlab-org/gitlab!67400
parents 63c8ab25 2175002e
......@@ -3,6 +3,8 @@
require "spec_helper"
RSpec.describe RedisTracking do
include TrackingHelpers
let(:user) { create(:user) }
controller(ApplicationController) do
......@@ -60,7 +62,7 @@ RSpec.describe RedisTracking do
end
it 'tracks the event if DNT is not enabled' do
request.headers['DNT'] = '0'
stub_do_not_track('0')
expect_tracking
......@@ -68,7 +70,7 @@ RSpec.describe RedisTracking do
end
it 'does not track the event if DNT is enabled' do
request.headers['DNT'] = '1'
stub_do_not_track('1')
expect_no_tracking
......
......@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Projects::MergeRequests::DiffsController do
include ProjectForksHelper
include TrackingHelpers
shared_examples '404 for unexistent diffable' do
context 'when diffable does not exists' do
......@@ -447,7 +448,7 @@ RSpec.describe Projects::MergeRequests::DiffsController do
context 'when DNT is enabled' do
before do
request.headers['DNT'] = '1'
stub_do_not_track('1')
end
it 'does not track any mr_diffs event' do
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
include TrackingHelpers
before do
stub_const('Gitlab::Experimentation::EXPERIMENTS', {
backwards_compatible_test_experiment: {
......@@ -43,7 +45,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
let(:cookie_value) { nil }
before do
request.headers['DNT'] = do_not_track if do_not_track.present?
stub_do_not_track(do_not_track) if do_not_track.present?
request.cookies[:experimentation_subject_id] = cookie_value if cookie_value
get :index
......@@ -242,7 +244,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
context 'do not track is disabled' do
before do
request.headers['DNT'] = '0'
stub_do_not_track('0')
end
it 'does track the event' do
......@@ -260,7 +262,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
context 'do not track enabled' do
before do
request.headers['DNT'] = '1'
stub_do_not_track('1')
end
it 'does not track the event' do
......@@ -396,7 +398,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
context 'do not track disabled' do
before do
request.headers['DNT'] = '0'
stub_do_not_track('0')
end
it 'pushes the right parameters to gon' do
......@@ -414,7 +416,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
context 'do not track enabled' do
before do
request.headers['DNT'] = '1'
stub_do_not_track('1')
end
it 'does not push data to gon' do
......@@ -525,7 +527,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
context 'is disabled' do
before do
request.headers['DNT'] = '0'
stub_do_not_track('0')
stub_experiment_for_subject(test_experiment: false)
end
......@@ -538,7 +540,7 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
context 'is enabled' do
before do
request.headers['DNT'] = '1'
stub_do_not_track('1')
end
it 'does not call add_user on the Experiment model' do
......
# frozen_string_literal: true
module TrackingHelpers
def stub_do_not_track(value)
request.headers['DNT'] = value
end
end
# frozen_string_literal: true
RSpec.shared_examples 'tracking unique visits' do |method|
include TrackingHelpers
let(:request_params) { {} }
it 'tracks unique visit if the format is HTML' do
......@@ -14,14 +16,15 @@ RSpec.shared_examples 'tracking unique visits' do |method|
expect(Gitlab::UsageDataCounters::HLLRedisCounter)
.to receive(:track_event).with(target_id, values: kind_of(String))
request.headers['DNT'] = '0'
stub_do_not_track('0')
get method, params: request_params, format: :html
end
it 'does not track unique visit if DNT is enabled' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event)
request.headers['DNT'] = '1'
stub_do_not_track('1')
get method, params: request_params, format: :html
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