]> source.dussan.org Git - redmine.git/commitdiff
Don't error when posting empty plugin settings (#26393).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 10 Jul 2017 21:05:35 +0000 (21:05 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 10 Jul 2017 21:05:35 +0000 (21:05 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16812 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/settings_controller.rb
test/functional/settings_controller_test.rb

index 51ab871ca6ae14b64187a7e851e43074f395cad8..7b2dceb3147553ddba12a8e5d577a688eb06a70b 100644 (file)
@@ -67,7 +67,8 @@ class SettingsController < ApplicationController
     end
 
     if request.post?
-      Setting.send "plugin_#{@plugin.id}=", params[:settings].permit!.to_h
+      setting = params[:settings] ? params[:settings].permit!.to_h : {}
+      Setting.send "plugin_#{@plugin.id}=", setting
       flash[:notice] = l(:notice_successful_update)
       redirect_to plugin_settings_path(@plugin)
     else
index c506978c0c9e8c7770adeb1ec2a1c87fd8fd2f3c..4c10191915a5e42ede763d20a664241e42a47f72 100644 (file)
@@ -242,6 +242,20 @@ class SettingsControllerTest < Redmine::ControllerTest
     assert_equal({'sample_setting' => 'Value'}, Setting.plugin_foo)
   end
 
+  def test_post_empty_plugin_settings
+    Redmine::Plugin.register(:foo) do
+      settings :partial => 'not blank', # so that configurable? is true
+        :default => {'sample_setting' => 'Plugin setting value'}
+    end
+
+    post :plugin, :params => {
+      :id => 'foo'
+    }
+    assert_redirected_to '/settings/plugin/foo'
+
+    assert_equal({}, Setting.plugin_foo)
+  end
+
   def test_post_non_configurable_plugin_settings
     Redmine::Plugin.register(:foo) {}