Follow up #2345: Default value for Setting 'es_attachment_max_size_in_mb' is not in sync and to high.

This commit is contained in:
Thorsten Eckel 2018-11-23 12:50:46 +01:00
parent 6be530bb1c
commit 1e512f6cd0
3 changed files with 38 additions and 1 deletions

View file

@ -0,0 +1,13 @@
class Issue2345EsAttachmentMaxSizeInMbSettingLowerDefault < ActiveRecord::Migration[5.1]
def change
# return if it's a new setup to avoid running the migration
return if !Setting.find_by(name: 'system_init_done')
# don't change non default/custom value
return if Setting.get('es_attachment_max_size_in_mb') != 50
# set new default value
Setting.set('es_attachment_max_size_in_mb', 10)
end
end

View file

@ -2761,7 +2761,7 @@ Setting.create_if_not_exists(
name: 'es_attachment_max_size_in_mb',
area: 'SearchIndex::Elasticsearch',
description: 'Define max. attachment size for Elasticsearch.',
state: 50,
state: 10,
preferences: { online_service_disable: true },
frontend: false
)

View file

@ -0,0 +1,24 @@
require 'rails_helper'
RSpec.describe Issue2345EsAttachmentMaxSizeInMbSettingLowerDefault, type: :db_migration do
context 'Issue2345EsAttachmentMaxSizeInMbSettingLowerDefault migration' do
it 'decreases the default value' do
allow(Setting).to receive(:get).with('es_attachment_max_size_in_mb').and_return(50)
migrate
# reset/remove mocks
RSpec::Mocks.space.proxy_for(Setting).reset
expect(Setting.get('es_attachment_max_size_in_mb')).not_to be(50)
end
it 'preserves custom Setting value' do
allow(Setting).to receive(:get).with('es_attachment_max_size_in_mb').and_return(5)
expect { migrate }.not_to change { Setting.get('es_attachment_max_size_in_mb') }
end
it 'performs no action for new systems', system_init_done: false do
expect { migrate }.not_to change { Setting.get('es_attachment_max_size_in_mb') }
end
end
end