diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/controllers/admin | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/controllers/admin')
4 files changed, 96 insertions, 7 deletions
diff --git a/spec/controllers/admin/ci/variables_controller_spec.rb b/spec/controllers/admin/ci/variables_controller_spec.rb new file mode 100644 index 00000000000..57f2dd21f39 --- /dev/null +++ b/spec/controllers/admin/ci/variables_controller_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Admin::Ci::VariablesController do + let_it_be(:variable) { create(:ci_instance_variable) } + + before do + sign_in(user) + end + + describe 'GET #show' do + subject do + get :show, params: {}, format: :json + end + + context 'when signed in as admin' do + let(:user) { create(:admin) } + + include_examples 'GET #show lists all variables' + end + + context 'when signed in as regular user' do + let(:user) { create(:user) } + + it 'returns 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + describe 'PATCH #update' do + subject do + patch :update, + params: { + variables_attributes: variables_attributes + }, + format: :json + end + + context 'when signed in as admin' do + let(:user) { create(:admin) } + + include_examples 'PATCH #update updates variables' do + let(:variables_scope) { Ci::InstanceVariable.all } + let(:file_variables_scope) { variables_scope.file } + end + end + + context 'when signed in as regular user' do + let(:user) { create(:user) } + + let(:variables_attributes) do + [{ + id: variable.id, + key: variable.key, + secret_value: 'new value' + }] + end + + it 'returns 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end +end diff --git a/spec/controllers/admin/clusters_controller_spec.rb b/spec/controllers/admin/clusters_controller_spec.rb index bd6d5614ccd..d4a12e0dc52 100644 --- a/spec/controllers/admin/clusters_controller_spec.rb +++ b/spec/controllers/admin/clusters_controller_spec.rb @@ -27,7 +27,7 @@ describe Admin::ClustersController do create(:cluster, :disabled, :provided_by_gcp, :production_environment, :instance) end - it 'lists available clusters' do + it 'lists available clusters and displays html' do get_index expect(response).to have_gitlab_http_status(:ok) @@ -35,20 +35,39 @@ describe Admin::ClustersController do expect(assigns(:clusters)).to match_array([enabled_cluster, disabled_cluster]) end + it 'lists available clusters and renders json serializer' do + get_index(format: :json) + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('cluster_list') + end + context 'when page is specified' do let(:last_page) { Clusters::Cluster.instance_type.page.total_pages } + let(:total_count) { Clusters::Cluster.instance_type.page.total_count } before do - allow(Clusters::Cluster).to receive(:paginates_per).and_return(1) - create_list(:cluster, 2, :provided_by_gcp, :production_environment, :instance) + create_list(:cluster, 30, :provided_by_gcp, :production_environment, :instance) end it 'redirects to the page' do + expect(last_page).to be > 1 + get_index(page: last_page) expect(response).to have_gitlab_http_status(:ok) expect(assigns(:clusters).current_page).to eq(last_page) end + + it 'displays cluster list for associated page' do + expect(last_page).to be > 1 + + get_index(page: last_page, format: :json) + + expect(response).to have_gitlab_http_status(:ok) + expect(response.headers['X-Page'].to_i).to eq(last_page) + expect(response.headers['X-Total'].to_i).to eq(total_count) + end end end diff --git a/spec/controllers/admin/requests_profiles_controller_spec.rb b/spec/controllers/admin/requests_profiles_controller_spec.rb index 13123c8e486..629233b04e7 100644 --- a/spec/controllers/admin/requests_profiles_controller_spec.rb +++ b/spec/controllers/admin/requests_profiles_controller_spec.rb @@ -27,7 +27,7 @@ describe Admin::RequestsProfilesController do end context 'when loading HTML profile' do - let(:basename) { "profile_#{Time.now.to_i}_execution.html" } + let(:basename) { "profile_#{Time.current.to_i}_execution.html" } let(:sample_data) do '<html> <body> <h1>Heading</h1> <p>paragraph.</p> </body> </html>' @@ -42,7 +42,7 @@ describe Admin::RequestsProfilesController do end context 'when loading TXT profile' do - let(:basename) { "profile_#{Time.now.to_i}_memory.txt" } + let(:basename) { "profile_#{Time.current.to_i}_memory.txt" } let(:sample_data) do <<~TXT @@ -60,7 +60,7 @@ describe Admin::RequestsProfilesController do end context 'when loading PDF profile' do - let(:basename) { "profile_#{Time.now.to_i}_anything.pdf" } + let(:basename) { "profile_#{Time.current.to_i}_anything.pdf" } let(:sample_data) { 'mocked pdf content' } diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 387fc0407b6..7a7201a6454 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -296,7 +296,7 @@ describe Admin::UsersController do it 'sets the new password to expire immediately' do expect { update_password(user, 'AValidPassword1') } - .to change { user.reload.password_expires_at }.to be_within(2.seconds).of(Time.now) + .to change { user.reload.password_expires_at }.to be_within(2.seconds).of(Time.current) end end |