Skip to content

Commit

Permalink
Don't change color scheme preference if the value wasn't provided
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Nov 17, 2024
1 parent 354f41b commit 6f06d69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/preferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def update
end

pref = current_user.preferences.find_or_create_by(:k => "site.color_scheme")
pref.v = params[:color_scheme]
pref.v = params[:color_scheme] if params[:color_scheme]

if current_user.save && pref.save
# Use a partial so that it is rendered during the next page load in the correct language.
Expand Down
4 changes: 4 additions & 0 deletions test/controllers/preferences_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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_color_scheme
Expand Down

0 comments on commit 6f06d69

Please sign in to comment.