From 498d38eb737ac991f5e86950aa90dcfbb1182493 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 17 Nov 2024 19:07:00 +0300 Subject: [PATCH] Don't change color scheme preference if the value wasn't provided --- app/controllers/preferences_controller.rb | 2 +- test/controllers/preferences_controller_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/preferences_controller.rb b/app/controllers/preferences_controller.rb index 722e4599a6..fcc64aa8f3 100644 --- a/app/controllers/preferences_controller.rb +++ b/app/controllers/preferences_controller.rb @@ -23,7 +23,7 @@ def update end site_color_scheme_preference = current_user.preferences.find_or_create_by(:k => "site.color_scheme") - site_color_scheme_preference.v = params[:site_color_scheme] + site_color_scheme_preference.v = params[:site_color_scheme] if params[:site_color_scheme] if current_user.save && site_color_scheme_preference.save # Use a partial so that it is rendered during the next page load in the correct language. diff --git a/test/controllers/preferences_controller_test.rb b/test/controllers/preferences_controller_test.rb index dec483d454..d442e2cd2b 100644 --- a/test/controllers/preferences_controller_test.rb +++ b/test/controllers/preferences_controller_test.rb @@ -22,6 +22,7 @@ def test_routes def test_update_preferred_editor user = create(:user, :languages => []) + user.preferences.create(:k => "site.color_scheme", :v => "light") session_for(user) # Changing to a invalid editor should fail @@ -32,6 +33,7 @@ def test_update_preferred_editor assert_select ".alert-success", false assert_select ".alert-danger", true assert_select "form > div > select#user_preferred_editor > option[selected]", false + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v # Changing to a valid editor should work user.preferred_editor = "id" @@ -41,6 +43,7 @@ def test_update_preferred_editor assert_template :show assert_select ".alert-success", /^Preferences updated/ assert_select "dd", "iD (in-browser editor)" + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v # Changing to the default editor should work user.preferred_editor = "default" @@ -50,6 +53,7 @@ def test_update_preferred_editor assert_template :show assert_select ".alert-success", /^Preferences updated/ assert_select "dd", "Default (currently iD)" + assert_equal "light", user.preferences.find_by(:k => "site.color_scheme")&.v end def test_update_preferred_site_color_scheme