Commit c6afe660 authored by John Cai's avatar John Cai

Add ApplicationSetting ui changes for repository_storages_weighted

parent 3793df51
......@@ -18,9 +18,9 @@
= _('Select the configured storage available for new repositories to be placed on.')
= link_to icon('question-circle'), help_page_path('administration/repository_storage_paths')
.form-check
= f.collection_check_boxes :repository_storages, Gitlab.config.repositories.storages, :first, :first, include_hidden: false do |b|
= b.check_box class: 'form-check-input'
= b.label class: 'label-bold form-check-label'
- @application_setting.repository_storages_weighted.each_key do |storage|
= f.text_field "repository_storages_weighted_#{storage}".to_sym, class: 'form-text-input'
= f.label storage, storage, class: 'label-bold form-check-label'
%br
= f.submit _('Save changes'), class: "btn btn-success qa-save-changes-button"
---
title: Add ApplicationSetting ui changes for repository_storages_weighted
merge_request: 33096
author:
type: added
# frozen_string_literal: true
class SeedRepositoryStoragesWeighted < ActiveRecord::Migration[6.0]
class ApplicationSetting < ActiveRecord::Base
serialize :repository_storages
self.table_name = 'application_settings'
end
def up
ApplicationSetting.all.each do |settings|
storages = Gitlab.config.repositories.storages.keys.collect do |storage|
weight = settings.repository_storages.include?(storage) ? 100 : 0
[storage, weight]
end
settings.repository_storages_weighted = Hash[storages]
settings.save!
end
end
def down
end
end
......@@ -13955,6 +13955,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200521022725
20200525114553
20200525121014
20200526000407
20200526120714
20200526164946
20200526164947
......
......@@ -277,6 +277,19 @@ describe 'Admin updates settings', :clean_gitlab_redis_shared_state, :do_not_moc
end
end
context 'Repository page' do
it 'Change Repository storage settings' do
visit repository_admin_application_settings_path
page.within('.as-repository-storage') do
fill_in 'application_setting_repository_storages_weighted_default', with: 50
click_button 'Save changes'
end
expect(current_settings.repository_storages_weighted_default).to be 50
end
end
context 'Reporting page' do
it 'Change Spam settings' do
visit reporting_admin_application_settings_path
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200526000407_seed_repository_storages_weighted.rb')
describe SeedRepositoryStoragesWeighted do
let(:storages) { { "foo" => {}, "baz" => {} } }
let(:application_settings) do
table(:application_settings).tap do |klass|
klass.class_eval do
serialize :repository_storages
end
end
end
before do
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
end
let(:application_setting) { application_settings.create }
let(:repository_storages) { ["foo"] }
it 'correctly schedules background migrations' do
application_setting.repository_storages = repository_storages
application_setting.save!
migrate!
expect(application_settings.find(application_setting.id).repository_storages_weighted).to eq({ "foo" => 100, "baz" => 0 })
end
end
......@@ -3,24 +3,26 @@
require 'spec_helper'
describe 'admin/application_settings/_repository_storage.html.haml' do
let(:app_settings) { build(:application_setting) }
let(:storages) do
let(:app_settings) { create(:application_setting) }
let(:repository_storages_weighted) do
{
"mepmep" => { "path" => "/tmp" },
"foobar" => { "path" => "/tmp" }
"mepmep" => 100,
"foobar" => 50
}
end
before do
allow(app_settings).to receive(:repository_storages_weighted).and_return(repository_storages_weighted)
allow(app_settings).to receive(:repository_storages_weighted_mepmep).and_return(100)
allow(app_settings).to receive(:repository_storages_weighted_foobar).and_return(50)
assign(:application_setting, app_settings)
stub_storage_settings(storages)
end
context 'when multiple storages are available' do
it 'lists them all' do
render
storages.keys.each do |storage_name|
repository_storages_weighted.each do |storage_name, storage_weight|
expect(rendered).to have_content(storage_name)
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