From 15a9bff336d09bf563c6f8cb88d47240cac358b3 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 3 Jun 2025 19:02:45 +0300 Subject: [PATCH] Move profile links editing to links page --- .../profiles/descriptions_controller.rb | 3 -- app/controllers/profiles/links_controller.rb | 3 ++ app/views/profiles/descriptions/show.html.erb | 28 ------------------ app/views/profiles/links/show.html.erb | 27 +++++++++++++++++ config/locales/en.yml | 8 ++--- .../profiles/descriptions_controller_test.rb | 24 ++------------- .../profiles/links_controller_test.rb | 25 ++++++++++++++++ test/system/user_social_links_test.rb | 29 ++++++++++++++----- 8 files changed, 82 insertions(+), 65 deletions(-) diff --git a/app/controllers/profiles/descriptions_controller.rb b/app/controllers/profiles/descriptions_controller.rb index 15a3e8129..02ee17cc2 100644 --- a/app/controllers/profiles/descriptions_controller.rb +++ b/app/controllers/profiles/descriptions_controller.rb @@ -3,9 +3,6 @@ module Profiles private def update_profile - social_links_params = params.permit(:user => [:social_links_attributes => [:id, :url, :_destroy]]) - current_user.assign_attributes(social_links_params[:user]) - if params[:user][:description] != current_user.description current_user.description = params[:user][:description] current_user.description_format = "markdown" diff --git a/app/controllers/profiles/links_controller.rb b/app/controllers/profiles/links_controller.rb index b82a254fb..d5d03196e 100644 --- a/app/controllers/profiles/links_controller.rb +++ b/app/controllers/profiles/links_controller.rb @@ -3,6 +3,9 @@ module Profiles private 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.save end end diff --git a/app/views/profiles/descriptions/show.html.erb b/app/views/profiles/descriptions/show.html.erb index e1fa7be75..17582284a 100644 --- a/app/views/profiles/descriptions/show.html.erb +++ b/app/views/profiles/descriptions/show.html.erb @@ -1,7 +1,3 @@ -<% content_for :head do %> - <%= javascript_include_tag "user" %> -<% end %> - <% content_for :heading_class, "pb-0" %> <% content_for :heading do %> @@ -12,30 +8,6 @@ <%= bootstrap_form_for current_user, :url => { :action => :update }, :html => { :multipart => true, :autocomplete => :off } do |f| %> <%= f.richtext_field :description, :cols => 80, :rows => 20 %> -
- - <%= f.label t(".social_links.title"), :class => "form-label" %> - - - -
- <%= f.primary t(".save") %> <%= link_to t(".cancel"), current_user, :class => "btn btn-link" %> <% end %> diff --git a/app/views/profiles/links/show.html.erb b/app/views/profiles/links/show.html.erb index a63e38f56..894eef868 100644 --- a/app/views/profiles/links/show.html.erb +++ b/app/views/profiles/links/show.html.erb @@ -1,3 +1,7 @@ +<% content_for :head do %> + <%= javascript_include_tag "user" %> +<% end %> + <% content_for :heading_class, "pb-0" %> <% content_for :heading do %> @@ -6,6 +10,29 @@ <% end %> <%= bootstrap_form_for current_user, :url => { :action => :update } do |f| %> +
+ <%= f.label t(".social_links.title"), :class => "form-label" %> + + + +
+ <%= f.primary t(".save") %> <%= link_to t(".cancel"), current_user, :class => "btn btn-link" %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index d1f75a693..492d242d5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2006,10 +2006,6 @@ en: title: Edit Profile save: Update Profile cancel: Cancel - social_links: - title: Social Profile Links - remove: Remove - add: Add Social Link update: success: Profile updated. failure: Couldn't update profile. @@ -2018,6 +2014,10 @@ en: title: Edit Profile save: Update Profile cancel: Cancel + social_links: + title: Social Profile Links + remove: Remove + add: Add Social Link update: success: Profile updated. failure: Couldn't update profile. diff --git a/test/controllers/profiles/descriptions_controller_test.rb b/test/controllers/profiles/descriptions_controller_test.rb index 8dbbf483c..d90aa8af7 100644 --- a/test/controllers/profiles/descriptions_controller_test.rb +++ b/test/controllers/profiles/descriptions_controller_test.rb @@ -41,34 +41,14 @@ module Profiles user = create(:user) session_for(user) - # Updating the description should work put profile_description_path, :params => { :user => { :description => "new description" } } - assert_redirected_to user_path(user) - follow_redirect! - assert_response :success - assert_template :show - assert_select ".alert-success", /^Profile updated./ - assert_select "div", "new description" - # Updating social links should work - put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "https://test.com/test" }] } } assert_redirected_to user_path(user) follow_redirect! assert_response :success assert_template :show - assert_select ".alert-success", /^Profile updated./ - assert_select "a", "test.com/test" - end - - def test_update_empty_social_link - user = create(:user) - session_for(user) - - put profile_description_path, :params => { :user => { :description => user.description, :social_links_attributes => [{ :url => "" }] } } - - assert_response :success - assert_template :show - assert_dom ".alert-danger", :text => "Couldn't update profile." + assert_dom ".alert-success", :text => "Profile updated." + assert_dom "div", "new description" end end end diff --git a/test/controllers/profiles/links_controller_test.rb b/test/controllers/profiles/links_controller_test.rb index dfd23db65..6ed745911 100644 --- a/test/controllers/profiles/links_controller_test.rb +++ b/test/controllers/profiles/links_controller_test.rb @@ -30,5 +30,30 @@ module Profiles assert_redirected_to login_path(:referer => profile_links_path) end + + def test_update + user = create(:user) + session_for(user) + + put profile_links_path, :params => { :user => { :social_links_attributes => [{ :url => "https://test.com/test" }] } } + + assert_redirected_to user_path(user) + follow_redirect! + assert_response :success + assert_template :show + assert_dom ".alert-success", :text => "Profile updated." + assert_dom "a", "test.com/test" + end + + def test_update_empty_social_link + user = create(:user) + session_for(user) + + put profile_links_path, :params => { :user => { :social_links_attributes => [{ :url => "" }] } } + + assert_response :success + assert_template :show + assert_dom ".alert-danger", :text => "Couldn't update profile." + end end end diff --git a/test/system/user_social_links_test.rb b/test/system/user_social_links_test.rb index 5609987f8..a448e9ee3 100644 --- a/test/system/user_social_links_test.rb +++ b/test/system/user_social_links_test.rb @@ -6,13 +6,11 @@ class UserSocialLinksTest < ApplicationSystemTestCase @user = create(:user) sign_in_as(@user) - visit user_path(@user) + visit profile_links_path end test "can add and remove social link without submitting" do within_content_body do - click_on "Edit Profile" - assert_no_field "Social Profile Link 1" click_on "Add Social Link" @@ -27,8 +25,6 @@ class UserSocialLinksTest < ApplicationSystemTestCase test "can add and remove social links" do within_content_body do - click_on "Edit Profile" - assert_no_field "Social Profile Link 1" click_on "Add Social Link" @@ -38,6 +34,13 @@ class UserSocialLinksTest < ApplicationSystemTestCase assert_link "example.com/user/fred" click_on "Edit Profile" + end + + within_content_heading do + click_on "Links" + end + + within_content_body do click_on "Remove Social Profile Link 1" assert_no_field "Social Profile Link 1" @@ -50,7 +53,6 @@ class UserSocialLinksTest < ApplicationSystemTestCase test "can control social links using keyboard without submitting" do within_content_body do - click_on "Edit Profile" click_on "Add Social Link" assert_field "Social Profile Link 1" @@ -63,7 +65,6 @@ class UserSocialLinksTest < ApplicationSystemTestCase test "can control social links using keyboard" do within_content_body do - click_on "Edit Profile" click_on "Add Social Link" send_keys "https://example.com/user/typed" click_on "Update Profile" @@ -71,6 +72,13 @@ class UserSocialLinksTest < ApplicationSystemTestCase assert_link "example.com/user/typed" click_on "Edit Profile" + end + + within_content_heading do + click_on "Links" + end + + within_content_body do find_field("Social Profile Link 1").click send_keys :tab, :enter @@ -84,7 +92,6 @@ class UserSocialLinksTest < ApplicationSystemTestCase test "can add and remove multiple links" do within_content_body do - click_on "Edit Profile" click_on "Add Social Link" fill_in "Social Profile Link 1", :with => "https://example.com/a" click_on "Add Social Link" @@ -98,7 +105,13 @@ class UserSocialLinksTest < ApplicationSystemTestCase assert_link "example.com/c" click_on "Edit Profile" + end + within_content_heading do + click_on "Links" + end + + within_content_body do assert_field "Social Profile Link 1", :with => "https://example.com/a" assert_field "Social Profile Link 2", :with => "https://example.com/b" assert_field "Social Profile Link 3", :with => "https://example.com/c" -- 2.39.5