diff options
Diffstat (limited to 'spec/support/shared_examples/controllers')
4 files changed, 114 insertions, 20 deletions
diff --git a/spec/support/shared_examples/controllers/concerns/integrations_actions_shared_examples.rb b/spec/support/shared_examples/controllers/concerns/integrations_actions_shared_examples.rb new file mode 100644 index 00000000000..748a3acf17b --- /dev/null +++ b/spec/support/shared_examples/controllers/concerns/integrations_actions_shared_examples.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +RSpec.shared_examples IntegrationsActions do + let(:integration) do + create(:datadog_integration, + integration_attributes.merge( + api_url: 'http://example.com', + api_key: 'secret' + ) + ) + end + + describe 'GET #edit' do + before do + get :edit, params: routing_params + end + + it 'assigns the integration' do + expect(response).to have_gitlab_http_status(:ok) + expect(assigns(:integration)).to eq(integration) + end + end + + describe 'PUT #update' do + let(:params) do + { + datadog_env: 'env', + datadog_service: 'service' + } + end + + before do + put :update, params: routing_params.merge(integration: params) + end + + it 'updates the integration with the provided params and redirects to the form' do + expect(response).to redirect_to(routing_params.merge(action: :edit)) + expect(integration.reload).to have_attributes(params) + end + + context 'when sending a password field' do + let(:params) { super().merge(api_key: 'new') } + + it 'updates the integration with the password and other params' do + expect(response).to be_redirect + expect(integration.reload).to have_attributes(params) + end + end + + context 'when sending a blank password field' do + let(:params) { super().merge(api_key: '') } + + it 'ignores the password field and saves the other params' do + expect(response).to be_redirect + expect(integration.reload).to have_attributes(params.merge(api_key: 'secret')) + end + end + end +end diff --git a/spec/support/shared_examples/controllers/githubish_import_controller_shared_examples.rb b/spec/support/shared_examples/controllers/githubish_import_controller_shared_examples.rb index a9c6da7bc2b..0ffa32dec9e 100644 --- a/spec/support/shared_examples/controllers/githubish_import_controller_shared_examples.rb +++ b/spec/support/shared_examples/controllers/githubish_import_controller_shared_examples.rb @@ -82,16 +82,6 @@ RSpec.shared_examples 'a GitHub-ish import controller: GET status' do expect(json_response.dig("provider_repos", 1, "id")).to eq(org_repo.id) end - it "does not show already added project" do - project = create(:project, import_type: provider, namespace: user.namespace, import_status: :finished, import_source: 'asd/vim') - stub_client(repos: [repo], orgs: [], each_page: [OpenStruct.new(objects: [repo])].to_enum) - - get :status, format: :json - - expect(json_response.dig("imported_projects", 0, "id")).to eq(project.id) - expect(json_response.dig("provider_repos")).to eq([]) - end - it "touches the etag cache store" do stub_client(repos: [], orgs: [], each_page: []) diff --git a/spec/support/shared_examples/controllers/import_controller_status_shared_examples.rb b/spec/support/shared_examples/controllers/import_controller_status_shared_examples.rb index b9ae0e23e26..44baadaaade 100644 --- a/spec/support/shared_examples/controllers/import_controller_status_shared_examples.rb +++ b/spec/support/shared_examples/controllers/import_controller_status_shared_examples.rb @@ -19,14 +19,4 @@ RSpec.shared_examples 'import controller status' do expect(json_response.dig("imported_projects", 0, "id")).to eq(project.id) expect(json_response.dig("provider_repos", 0, "id")).to eq(repo_id) end - - it "does not show already added project" do - project = create(:project, import_type: provider_name, namespace: user.namespace, import_status: :finished, import_source: import_source) - stub_client(client_repos_field => [repo]) - - get :status, format: :json - - expect(json_response.dig("imported_projects", 0, "id")).to eq(project.id) - expect(json_response.dig("provider_repos")).to eq([]) - end end diff --git a/spec/support/shared_examples/controllers/issuable_anonymous_search_disabled_examples.rb b/spec/support/shared_examples/controllers/issuable_anonymous_search_disabled_examples.rb new file mode 100644 index 00000000000..e77acb93798 --- /dev/null +++ b/spec/support/shared_examples/controllers/issuable_anonymous_search_disabled_examples.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'issuable list with anonymous search disabled' do |action| + let(:controller_action) { :index } + let(:params_with_search) { params.merge(search: 'some search term') } + + context 'when disable_anonymous_search is enabled' do + before do + stub_feature_flags(disable_anonymous_search: true) + end + + it 'shows a flash message' do + get controller_action, params: params_with_search + + expect(flash.now[:notice]).to eq('You must sign in to search for specific terms.') + end + + context 'when search param is not given' do + it 'does not show a flash message' do + get controller_action, params: params + + expect(flash.now[:notice]).to be_nil + end + end + + context 'when user is signed-in' do + it 'does not show a flash message' do + sign_in(create(:user)) + get controller_action, params: params_with_search + + expect(flash.now[:notice]).to be_nil + end + end + + context 'when format is not HTML' do + it 'does not show a flash message' do + get controller_action, params: params_with_search.merge(format: :atom) + + expect(flash.now[:notice]).to be_nil + end + end + end + + context 'when disable_anonymous_search is disabled' do + before do + stub_feature_flags(disable_anonymous_search: false) + end + + it 'does not show a flash message' do + get controller_action, params: params_with_search + + expect(flash.now[:notice]).to be_nil + end + end +end |