2017-03-20 17:54:34 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Admin::ApplicationSettingsController do
|
|
|
|
include StubENV
|
|
|
|
|
2017-04-05 08:29:48 -04:00
|
|
|
let(:group) { create(:group) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, namespace: group) }
|
2017-03-20 17:54:34 -04:00
|
|
|
let(:admin) { create(:admin) }
|
2017-04-05 08:29:48 -04:00
|
|
|
let(:user) { create(:user)}
|
2017-03-20 17:54:34 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
|
|
|
end
|
|
|
|
|
2017-04-05 08:29:48 -04:00
|
|
|
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
|
|
|
|
|
2017-03-23 06:13:11 -04:00
|
|
|
describe 'PUT #update' do
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
2017-03-20 17:54:34 -04:00
|
|
|
it 'updates the default_project_visibility for string value' do
|
2017-03-23 06:13:11 -04:00
|
|
|
put :update, application_setting: { default_project_visibility: "20" }
|
2017-03-20 17:54:34 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(admin_application_settings_path)
|
2017-03-23 10:25:42 -04:00
|
|
|
expect(ApplicationSetting.current.default_project_visibility).to eq(Gitlab::VisibilityLevel::PUBLIC)
|
2017-03-20 17:54:34 -04:00
|
|
|
end
|
|
|
|
|
2017-03-23 10:25:42 -04:00
|
|
|
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 'falls back to defaults when settings are omitted' do
|
2017-03-23 06:13:11 -04:00
|
|
|
put :update, application_setting: {}
|
2017-03-20 17:54:34 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(admin_application_settings_path)
|
2017-03-23 10:25:42 -04:00
|
|
|
expect(ApplicationSetting.current.default_project_visibility).to eq(Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
expect(ApplicationSetting.current.restricted_visibility_levels).to be_empty
|
2017-03-20 17:54:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|