diff options
Diffstat (limited to 'spec/support/shared_examples/controllers')
6 files changed, 97 insertions, 142 deletions
diff --git a/spec/support/shared_examples/controllers/binary_blob_shared_examples.rb b/spec/support/shared_examples/controllers/binary_blob_shared_examples.rb deleted file mode 100644 index acce7642cfe..00000000000 --- a/spec/support/shared_examples/controllers/binary_blob_shared_examples.rb +++ /dev/null @@ -1,86 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'editing snippet checks blob is binary' do - let(:snippets_binary_blob_value) { true } - - before do - sign_in(user) - - allow_next_instance_of(Blob) do |blob| - allow(blob).to receive(:binary?).and_return(binary) - end - - stub_feature_flags(snippets_binary_blob: snippets_binary_blob_value) - - subject - end - - context 'when blob is text' do - let(:binary) { false } - - it 'responds with status 200' do - expect(response).to have_gitlab_http_status(:ok) - expect(response).to render_template(:edit) - end - end - - context 'when blob is binary' do - let(:binary) { true } - - it 'responds with status 200' do - expect(response).to have_gitlab_http_status(:ok) - expect(response).to render_template(:edit) - end - - context 'when feature flag :snippets_binary_blob is disabled' do - let(:snippets_binary_blob_value) { false } - - it 'redirects away' do - expect(response).to redirect_to(gitlab_snippet_path(snippet)) - end - end - end -end - -RSpec.shared_examples 'updating snippet checks blob is binary' do - let(:snippets_binary_blob_value) { true } - - before do - sign_in(user) - - allow_next_instance_of(Blob) do |blob| - allow(blob).to receive(:binary?).and_return(binary) - end - - stub_feature_flags(snippets_binary_blob: snippets_binary_blob_value) - - subject - end - - context 'when blob is text' do - let(:binary) { false } - - it 'updates successfully' do - expect(snippet.reload.title).to eq title - expect(response).to redirect_to(gitlab_snippet_path(snippet)) - end - end - - context 'when blob is binary' do - let(:binary) { true } - - it 'updates successfully' do - expect(snippet.reload.title).to eq title - expect(response).to redirect_to(gitlab_snippet_path(snippet)) - end - - context 'when feature flag :snippets_binary_blob is disabled' do - let(:snippets_binary_blob_value) { false } - - it 'redirects away without updating' do - expect(response).to redirect_to(gitlab_snippet_path(snippet)) - expect(snippet.reload.title).not_to eq title - end - end - end -end diff --git a/spec/support/shared_examples/controllers/instance_statistics_controllers_shared_examples.rb b/spec/support/shared_examples/controllers/instance_statistics_controllers_shared_examples.rb deleted file mode 100644 index 17087456720..00000000000 --- a/spec/support/shared_examples/controllers/instance_statistics_controllers_shared_examples.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples 'instance statistics availability' do - let(:user) { create(:user) } - - before do - sign_in(user) - - stub_application_setting(usage_ping_enabled: true) - end - - describe 'GET #index' do - it 'is available when the feature is available publicly' do - get :index - - expect(response).to have_gitlab_http_status(:success) - end - - it 'renders a 404 when the feature is not available publicly' do - stub_application_setting(instance_statistics_visibility_private: true) - - get :index - - expect(response).to have_gitlab_http_status(:not_found) - end - - context 'for admins' do - let(:user) { create(:admin) } - - context 'when admin mode disabled' do - it 'forbids access when the feature is not available publicly' do - stub_application_setting(instance_statistics_visibility_private: true) - - get :index - - expect(response).to have_gitlab_http_status(:not_found) - end - end - - context 'when admin mode enabled', :enable_admin_mode do - it 'allows access when the feature is not available publicly' do - stub_application_setting(instance_statistics_visibility_private: true) - - get :index - - expect(response).to have_gitlab_http_status(:success) - end - end - end - end -end diff --git a/spec/support/shared_examples/controllers/issuables_list_metadata_shared_examples.rb b/spec/support/shared_examples/controllers/issuables_list_metadata_shared_examples.rb index 62a1a07b6c1..02915206cc5 100644 --- a/spec/support/shared_examples/controllers/issuables_list_metadata_shared_examples.rb +++ b/spec/support/shared_examples/controllers/issuables_list_metadata_shared_examples.rb @@ -42,10 +42,6 @@ RSpec.shared_examples 'issuables list meta-data' do |issuable_type, action = nil let(:result_issuable) { issuables.first } let(:search) { result_issuable.title } - before do - stub_feature_flags(attempt_project_search_optimizations: true) - end - # .simple_sorts is the same across all Sortable classes sorts = ::Issue.simple_sorts.keys + %w[popularity priority label_priority] sorts.each do |sort| diff --git a/spec/support/shared_examples/controllers/unique_hll_events_examples.rb b/spec/support/shared_examples/controllers/unique_hll_events_examples.rb new file mode 100644 index 00000000000..7e5a225f020 --- /dev/null +++ b/spec/support/shared_examples/controllers/unique_hll_events_examples.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'tracking unique hll events' do |feature_flag| + context 'when format is HTML' do + let(:format) { :html } + + it 'tracks unique event' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(expected_type, target_id) + + subject + end + + it 'tracks unique event if DNT is not enabled' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(expected_type, target_id) + request.headers['DNT'] = '0' + + subject + end + + it 'does not track unique event if DNT is enabled' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(expected_type, target_id) + request.headers['DNT'] = '1' + + subject + end + + context 'when feature flag is disabled' do + it 'does not track unique event' do + stub_feature_flags(feature_flag => false) + + expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(expected_type, target_id) + + subject + end + end + end + + context 'when format is JSON' do + let(:format) { :json } + + it 'does not track unique event if the format is JSON' do + expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(expected_type, target_id) + + subject + 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 90588756eb0..428389a9a01 100644 --- a/spec/support/shared_examples/controllers/unique_visits_shared_examples.rb +++ b/spec/support/shared_examples/controllers/unique_visits_shared_examples.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true 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) diff --git a/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb b/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb index c89ee0d25ae..4ca400dd87b 100644 --- a/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb +++ b/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb @@ -388,7 +388,54 @@ RSpec.shared_examples 'wiki controller actions' do end.not_to change { wiki.list_pages.size } expect(response).to render_template('shared/wikis/edit') - expect(flash[:alert]).to eq('Could not create wiki page') + end + end + end + + describe 'DELETE #destroy' do + let(:id_param) { wiki_title } + + subject do + delete(:destroy, + params: routing_params.merge( + id: id_param + )) + end + + context 'when page exists' do + it 'deletes the page' do + expect do + subject + end.to change { wiki.list_pages.size }.by(-1) + end + + context 'but page cannot be deleted' do + before do + allow_next_instance_of(WikiPage) do |page| + allow(page).to receive(:delete).and_return(false) + end + end + + it 'renders the edit state' do + expect do + subject + end.not_to change { wiki.list_pages.size } + + expect(response).to render_template('shared/wikis/edit') + expect(assigns(:error).message).to eq('Could not delete wiki page') + end + end + end + + context 'when page does not exist' do + let(:id_param) { 'nil' } + + it 'renders 404' do + expect do + subject + end.not_to change { wiki.list_pages.size } + + expect(response).to have_gitlab_http_status(:not_found) end end end |