Commit 9f310a26 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'tc-cleanup-application-settings-spec-ee' into 'master'

CE -> EE port: cleanup application settings spec ee

See merge request !1498
parents 3233b76a 501a338b
...@@ -52,16 +52,6 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -52,16 +52,6 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
end end
def application_setting_params def application_setting_params
restricted_levels = params[:application_setting][:restricted_visibility_levels]
if restricted_levels.nil?
params[:application_setting][:restricted_visibility_levels] = []
else
restricted_levels.map! do |level|
level.to_i
end
end
import_sources = params[:application_setting][:import_sources] import_sources = params[:application_setting][:import_sources]
if import_sources.nil? if import_sources.nil?
......
...@@ -262,7 +262,8 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -262,7 +262,8 @@ class ApplicationSetting < ActiveRecord::Base
elasticsearch_aws: false, elasticsearch_aws: false,
elasticsearch_aws_region: ENV['ELASTIC_REGION'] || 'us-east-1', elasticsearch_aws_region: ENV['ELASTIC_REGION'] || 'us-east-1',
usage_ping_enabled: true, usage_ping_enabled: true,
minimum_mirror_sync_time: Gitlab::Mirror::FIFTEEN minimum_mirror_sync_time: Gitlab::Mirror::FIFTEEN,
repository_size_limit: 0
} }
end end
......
...@@ -3,7 +3,7 @@ module ApplicationSettings ...@@ -3,7 +3,7 @@ module ApplicationSettings
def execute def execute
# Repository size limit comes as MB from the view # Repository size limit comes as MB from the view
limit = @params.delete(:repository_size_limit) limit = @params.delete(:repository_size_limit)
@application_setting.repository_size_limit = (limit.to_i.megabytes if limit.present?) @application_setting.repository_size_limit = Gitlab::Utils.try_megabytes_to_bytes(limit) if limit
@application_setting.update(@params) @application_setting.update(@params)
end end
......
...@@ -15,7 +15,7 @@ module Groups ...@@ -15,7 +15,7 @@ module Groups
# Repository size limit comes as MB from the view # Repository size limit comes as MB from the view
limit = params.delete(:repository_size_limit) limit = params.delete(:repository_size_limit)
@group.repository_size_limit = (limit.to_i.megabytes if limit.present?) @group.repository_size_limit = Gitlab::Utils.try_megabytes_to_bytes(limit) if limit
if @group.parent && !can?(current_user, :admin_group, @group.parent) if @group.parent && !can?(current_user, :admin_group, @group.parent)
@group.parent = nil @group.parent = nil
......
...@@ -14,7 +14,7 @@ module Groups ...@@ -14,7 +14,7 @@ module Groups
# Repository size limit comes as MB from the view # Repository size limit comes as MB from the view
limit = @params.delete(:repository_size_limit) limit = @params.delete(:repository_size_limit)
group.repository_size_limit = (limit.to_i.megabytes if limit.present?) group.repository_size_limit = Gitlab::Utils.try_megabytes_to_bytes(limit) if limit
group.assign_attributes(params) group.assign_attributes(params)
......
...@@ -147,7 +147,7 @@ module Projects ...@@ -147,7 +147,7 @@ module Projects
def set_repository_size_limit_as_bytes def set_repository_size_limit_as_bytes
limit = params.delete(:repository_size_limit) limit = params.delete(:repository_size_limit)
@project.repository_size_limit = (limit.to_i.megabytes if limit.present?) @project.repository_size_limit = Gitlab::Utils.try_megabytes_to_bytes(limit) if limit
end end
def set_project_name_from_path def set_project_name_from_path
......
...@@ -15,7 +15,7 @@ module Projects ...@@ -15,7 +15,7 @@ module Projects
# Repository size limit comes as MB from the view # Repository size limit comes as MB from the view
limit = params.delete(:repository_size_limit) limit = params.delete(:repository_size_limit)
project.repository_size_limit = (limit.to_i.megabytes if limit.present?) project.repository_size_limit = Gitlab::Utils.try_megabytes_to_bytes(limit) if limit
new_branch = params.delete(:default_branch) new_branch = params.delete(:default_branch)
new_repository_storage = params.delete(:repository_storage) new_repository_storage = params.delete(:repository_storage)
......
...@@ -21,5 +21,11 @@ module Gitlab ...@@ -21,5 +21,11 @@ module Gitlab
nil nil
end end
def try_megabytes_to_bytes(size)
Integer(size).megabytes
rescue ArgumentError
size
end
end end
end end
...@@ -3,8 +3,6 @@ require 'spec_helper' ...@@ -3,8 +3,6 @@ require 'spec_helper'
describe Admin::ApplicationSettingsController do describe Admin::ApplicationSettingsController do
include StubENV include StubENV
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
let(:user) { create(:user)} let(:user) { create(:user)}
...@@ -17,28 +15,54 @@ describe Admin::ApplicationSettingsController do ...@@ -17,28 +15,54 @@ describe Admin::ApplicationSettingsController do
sign_in(admin) sign_in(admin)
end end
context 'with valid params' do it 'updates the default_project_visibility for string value' do
subject { put :update, application_setting: { repository_size_limit: '100' } } put :update, application_setting: { default_project_visibility: "20" }
it 'redirect to application settings page' do expect(response).to redirect_to(admin_application_settings_path)
is_expected.to redirect_to(admin_application_settings_path) expect(ApplicationSetting.current.default_project_visibility).to eq(Gitlab::VisibilityLevel::PUBLIC)
end end
it 'set flash notice' do it 'update the restricted levels for string values' do
is_expected.to set_flash[:notice].to('Application settings saved successfully') 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 end
it 'falls back to defaults when settings are omitted' do
put :update, application_setting: {}
expect(response).to redirect_to(admin_application_settings_path)
expect(ApplicationSetting.current.default_project_visibility).to eq(Gitlab::VisibilityLevel::PRIVATE)
expect(ApplicationSetting.current.restricted_visibility_levels).to be_empty
end end
context 'with invalid params' do it 'updates repository_size_limit' do
subject! { put :update, application_setting: { repository_size_limit: '-100' } } put :update, application_setting: { repository_size_limit: '100' }
it 'render show template' do expect(response).to redirect_to(admin_application_settings_path)
is_expected.to render_template(:show) expect(response).to set_flash[:notice].to('Application settings saved successfully')
end end
it 'assigned @application_settings has errors' do it 'does not accept negative repository_size_limit' do
put :update, application_setting: { repository_size_limit: '-100' }
expect(response).to render_template(:show)
expect(assigns(:application_setting).errors[:repository_size_limit]).to be_present expect(assigns(:application_setting).errors[:repository_size_limit]).to be_present
end end
it 'does not accept invalid repository_size_limit' do
put :update, application_setting: { repository_size_limit: 'one thousand' }
expect(response).to render_template(:show)
expect(assigns(:application_setting).errors[:repository_size_limit]).to be_present
end
it 'does not accept empty repository_size_limit' do
put :update, application_setting: { repository_size_limit: '' }
expect(response).to render_template(:show)
expect(assigns(:application_setting).errors[:repository_size_limit]).to be_present
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment