diff options
Diffstat (limited to 'spec/support/shared_examples/controllers')
4 files changed, 35 insertions, 53 deletions
diff --git a/spec/support/shared_examples/controllers/snippet_blob_shared_examples.rb b/spec/support/shared_examples/controllers/snippet_blob_shared_examples.rb index 62aaec85162..c939c306d93 100644 --- a/spec/support/shared_examples/controllers/snippet_blob_shared_examples.rb +++ b/spec/support/shared_examples/controllers/snippet_blob_shared_examples.rb @@ -36,16 +36,6 @@ RSpec.shared_examples 'raw snippet blob' do expect(response.header['Content-Disposition']).to match "attachment; filename=\"#{filepath}\"" end - - context 'when the feature flag attachment_with_filename is disabled' do - it 'returns just attachment in the disposition header' do - stub_feature_flags(attachment_with_filename: false) - - subject - - expect(response.header['Content-Disposition']).to eq 'attachment' - end - end end end diff --git a/spec/support/shared_examples/controllers/snippet_shared_examples.rb b/spec/support/shared_examples/controllers/snippet_shared_examples.rb new file mode 100644 index 00000000000..f49cc979368 --- /dev/null +++ b/spec/support/shared_examples/controllers/snippet_shared_examples.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'snippets views' do + let(:params) { {} } + + before do + sign_in(user) + end + + context 'when rendered' do + render_views + + it 'avoids N+1 database queries' do + # Warming call to load everything non snippet related + get(:index, params: params) + + project = create(:project, namespace: user.namespace) + create(:project_snippet, project: project, author: user) + + control_count = ActiveRecord::QueryRecorder.new { get(:index, params: params) }.count + + project = create(:project, namespace: user.namespace) + create(:project_snippet, project: project, author: user) + + expect { get(:index, params: params) }.not_to exceed_query_limit(control_count) + end + end +end diff --git a/spec/support/shared_examples/controllers/trackable_shared_examples.rb b/spec/support/shared_examples/controllers/trackable_shared_examples.rb deleted file mode 100644 index dac7d8c94ff..00000000000 --- a/spec/support/shared_examples/controllers/trackable_shared_examples.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'a Trackable Controller' do - describe '#track_event', :snowplow do - before do - sign_in user - end - - context 'with no params' do - controller(described_class) do - def index - track_event - head :ok - end - end - - it 'tracks the action name', :snowplow do - get :index - - expect_snowplow_event(category: 'AnonymousController', action: 'index') - end - end - - context 'with params' do - controller(described_class) do - def index - track_event('some_event', category: 'SomeCategory', label: 'errorlabel') - head :ok - end - end - - it 'tracks with the specified param' do - get :index - - expect_snowplow_event(category: 'SomeCategory', action: 'some_event', label: 'errorlabel') - end - end - end -end diff --git a/spec/support/shared_examples/controllers/unique_visits_shared_examples.rb b/spec/support/shared_examples/controllers/unique_visits_shared_examples.rb index 428389a9a01..3f97c031e27 100644 --- a/spec/support/shared_examples/controllers/unique_visits_shared_examples.rb +++ b/spec/support/shared_examples/controllers/unique_visits_shared_examples.rb @@ -4,27 +4,30 @@ RSpec.shared_examples 'tracking unique visits' do |method| let(:request_params) { {} } it 'tracks unique visit if the format is HTML' do - expect_any_instance_of(Gitlab::Analytics::UniqueVisits).to receive(:track_visit).with(instance_of(String), target_id) + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .to receive(:track_event).with(target_id, values: kind_of(String)) get method, params: request_params, format: :html end it 'tracks unique visit if DNT is not enabled' do - expect_any_instance_of(Gitlab::Analytics::UniqueVisits).to receive(:track_visit).with(instance_of(String), target_id) + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .to receive(:track_event).with(target_id, values: kind_of(String)) + request.headers['DNT'] = '0' get method, params: request_params, format: :html end it 'does not track unique visit if DNT is enabled' do - expect_any_instance_of(Gitlab::Analytics::UniqueVisits).not_to receive(:track_visit) + expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event) request.headers['DNT'] = '1' get method, params: request_params, format: :html end it 'does not track unique visit if the format is JSON' do - expect_any_instance_of(Gitlab::Analytics::UniqueVisits).not_to receive(:track_visit) + expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event) get method, params: request_params, format: :json end |