gitlab-org--gitlab-foss/spec/controllers/admin/application_settings_controller_spec.rb
Tomasz Maczukin 42af229510
Simplify runner registration token resetting
This icommit adds several changes related to the same topic
- resetting a Runner registration token:

1. On Project settings page it adds a button for resetting the
   registration token and it removes the Runner token field
   that was confusing all GitLab users.

2. On Group settings page it adds the same button for resetting
   the registration token.

3. On Admin Runners settings page it moves the button to the same
   place as in Project and Group settings and it changes slightly
   the page layout to make it more similar to Group and Project
   setting pages.

4. It refactorizes a little the partial that prints runner
   registration description. Thanks to this Project, Group
   and Admin settings of the Runner are re-using the same
   code to generate the button.

5. Updates the translations of changed text.
2018-10-04 08:37:01 +02:00

107 lines
3 KiB
Ruby

require 'spec_helper'
describe Admin::ApplicationSettingsController do
include StubENV
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
let(:admin) { create(:admin) }
let(:user) { create(:user)}
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
end
describe 'GET #usage_data with no access' do
before do
sign_in(user)
end
it 'returns 404' do
get :usage_data, format: :html
expect(response.status).to eq(404)
end
end
describe 'GET #usage_data' do
before do
sign_in(admin)
end
it 'returns HTML data' do
get :usage_data, format: :html
expect(response.body).to start_with('<span')
expect(response.status).to eq(200)
end
it 'returns JSON data' do
get :usage_data, format: :json
body = JSON.parse(response.body)
expect(body["version"]).to eq(Gitlab::VERSION)
expect(body).to include('counts')
expect(response.status).to eq(200)
end
end
describe 'PUT #update' do
before do
sign_in(admin)
end
it 'updates the password_authentication_enabled_for_git setting' do
put :update, application_setting: { password_authentication_enabled_for_git: "0" }
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.password_authentication_enabled_for_git).to eq(false)
end
it 'updates the default_project_visibility for string value' do
put :update, application_setting: { default_project_visibility: "20" }
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.default_project_visibility).to eq(Gitlab::VisibilityLevel::PUBLIC)
end
it 'update the restricted levels for string values' do
put :update, application_setting: { restricted_visibility_levels: %w[10 20] }
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.restricted_visibility_levels).to eq([10, 20])
end
it 'updates the restricted_visibility_levels when empty array is passed' do
put :update, application_setting: { restricted_visibility_levels: [""] }
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.restricted_visibility_levels).to be_empty
end
it 'updates the receive_max_input_size setting' do
put :update, application_setting: { receive_max_input_size: "1024" }
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.receive_max_input_size).to eq(1024)
end
end
describe 'PUT #reset_registration_token' do
before do
sign_in(admin)
end
subject { put :reset_registration_token }
it 'resets runner registration token' do
expect { subject }.to change { ApplicationSetting.current.runners_registration_token }
end
it 'redirects the user to admin runners page' do
subject
expect(response).to redirect_to(admin_runners_path)
end
end
end