From 1e512f6cd0f12f0b60b179486b6503ec654b60af Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 23 Nov 2018 12:50:46 +0100 Subject: [PATCH] Follow up #2345: Default value for Setting 'es_attachment_max_size_in_mb' is not in sync and to high. --- ...nt_max_size_in_mb_setting_lower_default.rb | 13 ++++++++++ db/seeds/settings.rb | 2 +- ...x_size_in_mb_setting_lower_default_spec.rb | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20181120150357_issue_2345_es_attachment_max_size_in_mb_setting_lower_default.rb create mode 100644 spec/db/migrate/issue_2345_es_attachment_max_size_in_mb_setting_lower_default_spec.rb diff --git a/db/migrate/20181120150357_issue_2345_es_attachment_max_size_in_mb_setting_lower_default.rb b/db/migrate/20181120150357_issue_2345_es_attachment_max_size_in_mb_setting_lower_default.rb new file mode 100644 index 000000000..dd7e4e91c --- /dev/null +++ b/db/migrate/20181120150357_issue_2345_es_attachment_max_size_in_mb_setting_lower_default.rb @@ -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 diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 9645459bf..3ae0d3450 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -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 ) diff --git a/spec/db/migrate/issue_2345_es_attachment_max_size_in_mb_setting_lower_default_spec.rb b/spec/db/migrate/issue_2345_es_attachment_max_size_in_mb_setting_lower_default_spec.rb new file mode 100644 index 000000000..3665eb714 --- /dev/null +++ b/spec/db/migrate/issue_2345_es_attachment_max_size_in_mb_setting_lower_default_spec.rb @@ -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