From b3b69a6726e6435c9a6b5ad16367701c5c234b67 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 1 Jul 2025 19:59:53 +0300 Subject: [PATCH] Turn own profile image into an edit link --- app/views/users/show.html.erb | 6 +++- test/system/profile_image_change_test.rb | 45 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index efca2852d..926ac2ff2 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -4,7 +4,11 @@ <% content_for :heading do %>
- <%= user_image @user %> + <% if current_user and @user == current_user %> + <%= link_to user_image(@user), profile_image_path, :class => "d-block", :title => t(".change_image") %> + <% else %> + <%= user_image @user %> + <% end %>

<%= @user.display_name %> <%= role_icons(@user) %>

diff --git a/test/system/profile_image_change_test.rb b/test/system/profile_image_change_test.rb index 51b71fd59..d9272674b 100644 --- a/test/system/profile_image_change_test.rb +++ b/test/system/profile_image_change_test.rb @@ -6,6 +6,10 @@ class ProfileImageChangeTest < ApplicationSystemTestCase visit user_path(user) + within_content_heading do + assert_no_link "Change Image" + end + within_content_body do assert_no_button "Edit Profile Details" assert_no_link "Change Image" @@ -19,6 +23,10 @@ class ProfileImageChangeTest < ApplicationSystemTestCase sign_in_as(user) visit user_path(another_user) + within_content_heading do + assert_no_link "Change Image" + end + within_content_body do assert_no_button "Edit Profile Details" assert_no_link "Change Image" @@ -71,4 +79,41 @@ class ProfileImageChangeTest < ApplicationSystemTestCase assert_no_field "Replace the current image" end end + + test "can add image by clicking the placeholder image" do + user = create(:user) + + sign_in_as(user) + visit user_path(user) + + within_content_heading do + click_on "Change Image" + end + + within_content_body do + assert_unchecked_field "Add an image" + assert_no_field "Keep the current image" + assert_no_field "Remove the current image" + assert_no_field "Replace the current image" + + attach_file "Avatar", "test/gpx/fixtures/a.gif" + + assert_checked_field "Add an image" + + click_on "Update Profile" + end + + assert_text "Profile image updated." + + within_content_heading do + click_on "Change Image" + end + + within_content_body do + assert_no_field "Add an image" + assert_checked_field "Keep the current image" + assert_unchecked_field "Remove the current image" + assert_unchecked_field "Replace the current image" + end + end end -- 2.39.5