From a7f4f8ddd3ea9dfac7b615d9bbd4871f8c69426a Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 10 Sep 2026 18:16:37 +0100 Subject: [PATCH] Make profiles/links#update handle being given no links --- app/controllers/profiles/links_controller.rb | 3 +-- test/controllers/profiles/links_controller_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/profiles/links_controller.rb b/app/controllers/profiles/links_controller.rb index be0874839..5e4ead981 100644 --- a/app/controllers/profiles/links_controller.rb +++ b/app/controllers/profiles/links_controller.rb @@ -6,8 +6,7 @@ module Profiles def update_profile social_links_params = params.permit(:user => [{ :social_links_attributes => [:id, :url, :_destroy] }]) - current_user.assign_attributes(social_links_params[:user]) - + current_user.assign_attributes(social_links_params.fetch(:user, {})) current_user.save end end diff --git a/test/controllers/profiles/links_controller_test.rb b/test/controllers/profiles/links_controller_test.rb index 28739dc3a..f0a87952f 100644 --- a/test/controllers/profiles/links_controller_test.rb +++ b/test/controllers/profiles/links_controller_test.rb @@ -47,6 +47,19 @@ module Profiles assert_dom "a[href*='test.com/test'] span", "test.com/test" end + def test_update_no_links + user = create(:user) + session_for(user) + + put profile_links_path + + assert_redirected_to user_path(user) + follow_redirect! + assert_response :success + assert_template :show + assert_dom ".alert-success", :text => "Profile links updated." + end + def test_update_empty_social_link user = create(:user) session_for(user) -- 2.47.3