Browse Source

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

Thorsten Eckel 6 years ago
parent
commit
1e512f6cd0

+ 13 - 0
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

+ 1 - 1
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
 )

+ 24 - 0
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