diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/support/shared_examples/controllers | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/support/shared_examples/controllers')
6 files changed, 133 insertions, 47 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 index c1ec515f1fe..acce7642cfe 100644 --- a/spec/support/shared_examples/controllers/binary_blob_shared_examples.rb +++ b/spec/support/shared_examples/controllers/binary_blob_shared_examples.rb @@ -1,6 +1,8 @@ # 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) @@ -8,6 +10,8 @@ RSpec.shared_examples 'editing snippet checks blob is binary' do allow(blob).to receive(:binary?).and_return(binary) end + stub_feature_flags(snippets_binary_blob: snippets_binary_blob_value) + subject end @@ -23,13 +27,24 @@ RSpec.shared_examples 'editing snippet checks blob is binary' do context 'when blob is binary' do let(:binary) { true } - it 'redirects away' do - expect(response).to redirect_to(gitlab_snippet_path(snippet)) + 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) @@ -37,6 +52,8 @@ RSpec.shared_examples 'updating snippet checks blob is binary' do allow(blob).to receive(:binary?).and_return(binary) end + stub_feature_flags(snippets_binary_blob: snippets_binary_blob_value) + subject end @@ -52,9 +69,18 @@ RSpec.shared_examples 'updating snippet checks blob is binary' do context 'when blob is binary' do let(:binary) { true } - it 'redirects away without updating' do + it 'updates successfully' do + expect(snippet.reload.title).to eq title expect(response).to redirect_to(gitlab_snippet_path(snippet)) - expect(snippet.reload.title).not_to eq title + 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/concerns/graceful_timeout_handling_shared_examples.rb b/spec/support/shared_examples/controllers/concerns/graceful_timeout_handling_shared_examples.rb new file mode 100644 index 00000000000..ea002776eeb --- /dev/null +++ b/spec/support/shared_examples/controllers/concerns/graceful_timeout_handling_shared_examples.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +RSpec.shared_examples GracefulTimeoutHandling do + it 'includes GracefulTimeoutHandling' do + expect(controller).to be_a(GracefulTimeoutHandling) + 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 a01fa49d701..8bc91f72b8c 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 @@ -72,7 +72,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: GET status' do project = create(:project, import_type: provider, namespace: user.namespace, import_status: :finished, import_source: 'example/repo') group = create(:group) group.add_owner(user) - stub_client(repos: [repo, org_repo], orgs: [org], org_repos: [org_repo]) + stub_client(repos: [repo, org_repo], orgs: [org], org_repos: [org_repo], each_page: [OpenStruct.new(objects: [repo, org_repo])].to_enum) get :status, format: :json @@ -85,7 +85,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: GET status' do 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: []) + stub_client(repos: [repo], orgs: [], each_page: [OpenStruct.new(objects: [repo])].to_enum) get :status, format: :json @@ -94,7 +94,8 @@ RSpec.shared_examples 'a GitHub-ish import controller: GET status' do end it "touches the etag cache store" do - expect(stub_client(repos: [], orgs: [])).to receive(:repos) + stub_client(repos: [], orgs: [], each_page: []) + expect_next_instance_of(Gitlab::EtagCaching::Store) do |store| expect(store).to receive(:touch) { "realtime_changes_import_#{provider}_path" } end @@ -102,17 +103,11 @@ RSpec.shared_examples 'a GitHub-ish import controller: GET status' do get :status, format: :json end - it "requests provider repos list" do - expect(stub_client(repos: [], orgs: [])).to receive(:repos) - - get :status - - expect(response).to have_gitlab_http_status(:ok) - end - it "handles an invalid access token" do - allow_any_instance_of(Gitlab::LegacyGithubImport::Client) - .to receive(:repos).and_raise(Octokit::Unauthorized) + client = stub_client(repos: [], orgs: [], each_page: []) + + allow(client).to receive(:repos).and_raise(Octokit::Unauthorized) + allow(client).to receive(:each_page).and_raise(Octokit::Unauthorized) get :status @@ -122,7 +117,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: GET status' do end it "does not produce N+1 database queries" do - stub_client(repos: [repo], orgs: []) + stub_client(repos: [repo], orgs: [], each_page: [].to_enum) group_a = create(:group) group_a.add_owner(user) create(:project, :import_started, import_type: provider, namespace: user.namespace) @@ -144,10 +139,12 @@ RSpec.shared_examples 'a GitHub-ish import controller: GET status' do let(:repo_2) { OpenStruct.new(login: 'emacs', full_name: 'asd/emacs', name: 'emacs', owner: { login: 'owner' }) } let(:project) { create(:project, import_type: provider, namespace: user.namespace, import_status: :finished, import_source: 'example/repo') } let(:group) { create(:group) } + let(:repos) { [repo, repo_2, org_repo] } before do group.add_owner(user) - stub_client(repos: [repo, repo_2, org_repo], orgs: [org], org_repos: [org_repo]) + client = stub_client(repos: repos, orgs: [org], org_repos: [org_repo]) + allow(client).to receive(:each_page).and_return([OpenStruct.new(objects: repos)].to_enum) end it 'filters list of repositories by name' do @@ -187,14 +184,14 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do end before do - stub_client(user: provider_user, repo: provider_repo) + stub_client(user: provider_user, repo: provider_repo, repository: provider_repo) assign_session_token(provider) end it 'returns 200 response when the project is imported successfully' do allow(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, format: :json @@ -208,7 +205,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do allow(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, format: :json @@ -219,7 +216,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it "touches the etag cache store" do allow(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) expect_next_instance_of(Gitlab::EtagCaching::Store) do |store| expect(store).to receive(:touch) { "realtime_changes_import_#{provider}_path" } end @@ -232,7 +229,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it "takes the current user's namespace" do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, format: :json end @@ -244,7 +241,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it "takes the current user's namespace" do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, format: :json end @@ -271,7 +268,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it "takes the existing namespace" do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, existing_namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, format: :json end @@ -283,7 +280,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, format: :json end @@ -302,7 +299,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it "takes the new namespace" do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, an_instance_of(Group), user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, params: { target_namespace: provider_repo.name }, format: :json end @@ -323,7 +320,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it "takes the current user's namespace" do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, format: :json end @@ -341,7 +338,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it 'takes the selected namespace and name' do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, test_name, test_namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, params: { target_namespace: test_namespace.name, new_name: test_name }, format: :json end @@ -349,7 +346,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it 'takes the selected name and default namespace' do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, test_name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, params: { new_name: test_name }, format: :json end @@ -368,7 +365,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it 'takes the selected namespace and name' do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, test_name, nested_namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, params: { target_namespace: nested_namespace.full_path, new_name: test_name }, format: :json end @@ -380,7 +377,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it 'takes the selected namespace and name' do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, params: { target_namespace: 'foo/bar', new_name: test_name }, format: :json end @@ -388,7 +385,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it 'creates the namespaces' do allow(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) expect { post :create, params: { target_namespace: 'foo/bar', new_name: test_name }, format: :json } .to change { Namespace.count }.by(2) @@ -397,7 +394,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it 'new namespace has the right parent' do allow(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, params: { target_namespace: 'foo/bar', new_name: test_name }, format: :json @@ -416,7 +413,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it 'takes the selected namespace and name' do expect(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) post :create, params: { target_namespace: 'foo/foobar/bar', new_name: test_name }, format: :json end @@ -424,7 +421,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it 'creates the namespaces' do allow(Gitlab::LegacyGithubImport::ProjectCreator) .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) - .and_return(double(execute: project)) + .and_return(double(execute: project)) expect { post :create, params: { target_namespace: 'foo/foobar/bar', new_name: test_name }, format: :json } .to change { Namespace.count }.by(2) @@ -432,11 +429,11 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it 'does not create a new namespace under the user namespace' do expect(Gitlab::LegacyGithubImport::ProjectCreator) - .to receive(:new).with(provider_repo, test_name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .to receive(:new).with(provider_repo, test_name, user.namespace, user, access_params, type: provider) + .and_return(double(execute: project)) expect { post :create, params: { target_namespace: "#{user.namespace_path}/test_group", new_name: test_name }, format: :js } - .not_to change { Namespace.count } + .not_to change { Namespace.count } end end @@ -446,19 +443,19 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do it 'does not take the selected namespace and name' do expect(Gitlab::LegacyGithubImport::ProjectCreator) - .to receive(:new).with(provider_repo, test_name, user.namespace, user, access_params, type: provider) - .and_return(double(execute: project)) + .to receive(:new).with(provider_repo, test_name, user.namespace, user, access_params, type: provider) + .and_return(double(execute: project)) post :create, params: { target_namespace: 'foo/foobar/bar', new_name: test_name }, format: :js end it 'does not create the namespaces' do allow(Gitlab::LegacyGithubImport::ProjectCreator) - .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) - .and_return(double(execute: project)) + .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, access_params, type: provider) + .and_return(double(execute: project)) expect { post :create, params: { target_namespace: 'foo/foobar/bar', new_name: test_name }, format: :js } - .not_to change { Namespace.count } + .not_to change { Namespace.count } end end @@ -471,8 +468,8 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do user.update!(can_create_group: false) expect(Gitlab::LegacyGithubImport::ProjectCreator) - .to receive(:new).with(provider_repo, test_name, group, user, access_params, type: provider) - .and_return(double(execute: project)) + .to receive(:new).with(provider_repo, test_name, group, user, access_params, type: provider) + .and_return(double(execute: project)) post :create, params: { target_namespace: 'foo', new_name: test_name }, format: :js end diff --git a/spec/support/shared_examples/controllers/metrics/dashboard/prometheus_api_proxy_shared_examples.rb b/spec/support/shared_examples/controllers/metrics/dashboard/prometheus_api_proxy_shared_examples.rb index 94cd6971f7c..19b1cee44ee 100644 --- a/spec/support/shared_examples/controllers/metrics/dashboard/prometheus_api_proxy_shared_examples.rb +++ b/spec/support/shared_examples/controllers/metrics/dashboard/prometheus_api_proxy_shared_examples.rb @@ -9,6 +9,7 @@ RSpec.shared_examples_for 'metrics dashboard prometheus api proxy' do id: proxyable.id.to_s } end + let(:expected_params) do ActionController::Parameters.new( prometheus_proxy_params( diff --git a/spec/support/shared_examples/controllers/variables_shared_examples.rb b/spec/support/shared_examples/controllers/variables_shared_examples.rb index 9ff0bc3d217..34632993cf0 100644 --- a/spec/support/shared_examples/controllers/variables_shared_examples.rb +++ b/spec/support/shared_examples/controllers/variables_shared_examples.rb @@ -21,6 +21,7 @@ RSpec.shared_examples 'PATCH #update updates variables' do secret_value: variable.value, protected: variable.protected?.to_s } end + let(:new_variable_attributes) do { key: 'new_key', secret_value: 'dummy_value', 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 4df3139d56e..c89ee0d25ae 100644 --- a/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb +++ b/spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb @@ -61,6 +61,14 @@ RSpec.shared_examples 'wiki controller actions' do expect(assigns(:sidebar_wiki_entries)).to be_nil expect(assigns(:sidebar_limited)).to be_nil end + + context 'when the request is of non-html format' do + it 'returns a 404 error' do + get :pages, params: routing_params.merge(format: 'json') + + expect(response).to have_gitlab_http_status(:not_found) + end + end end describe 'GET #history' do @@ -153,6 +161,14 @@ RSpec.shared_examples 'wiki controller actions' do expect(assigns(:sidebar_limited)).to be(false) end + it 'increases the page view counter' do + expect do + subject + + expect(response).to have_gitlab_http_status(:ok) + end.to change { Gitlab::UsageDataCounters::WikiPageCounter.read(:view) }.by(1) + end + context 'when page content encoding is invalid' do it 'sets flash error' do allow(controller).to receive(:valid_encoding?).and_return(false) @@ -339,6 +355,44 @@ RSpec.shared_examples 'wiki controller actions' do end end + describe 'POST #create' do + let(:new_title) { 'New title' } + let(:new_content) { 'New content' } + + subject do + post(:create, + params: routing_params.merge( + wiki: { title: new_title, content: new_content } + )) + end + + context 'when page is valid' do + it 'creates the page' do + expect do + subject + end.to change { wiki.list_pages.size }.by 1 + + wiki_page = wiki.find_page(new_title) + + expect(wiki_page.title).to eq new_title + expect(wiki_page.content).to eq new_content + end + end + + context 'when page is not valid' do + let(:new_title) { '' } + + 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(flash[:alert]).to eq('Could not create wiki page') + end + end + end + def redirect_to_wiki(wiki, page) redirect_to(controller.wiki_page_path(wiki, page)) end |