From 4762c1a299b390f42bfeca0d220dcfab3c8395e8 Mon Sep 17 00:00:00 2001 From: Sparsha Lamichhane Date: Fri, 31 May 2024 03:33:31 +0545 Subject: [PATCH] =?UTF-8?q?Refactor:=20Use=20'full=5Fname'=20attribute=20f?= =?UTF-8?q?or=20user=20full=20names=20instead=20of=20st=E2=80=A6=20(#761)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refactor: Use 'full_name' attribute for user full names instead of string concatenation * Fix broken tests & linters --- app/helpers/avatar_helper.rb | 2 +- app/models/adopter_application.rb | 2 +- app/models/user.rb | 4 ++++ app/views/layouts/adopter_foster_dashboard.html.erb | 2 +- app/views/layouts/dashboard.html.erb | 2 +- .../staff/adoption_application_reviews/edit.html.erb | 3 +-- app/views/organizations/staff/fosterers/index.html.erb | 4 ++-- app/views/organizations/staff/profile_reviews/show.html.erb | 2 +- app/views/organizations/staff/staff/index.html.erb | 4 ++-- .../sign_up_mailer/admin_notification_new_staff.html.erb | 3 +-- .../sign_up_mailer/admin_notification_new_staff.text.erb | 2 +- .../staff/adoption_application_reviews_controller_test.rb | 2 +- test/integration/adoption_application_reviews_test.rb | 2 +- 13 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/helpers/avatar_helper.rb b/app/helpers/avatar_helper.rb index 49da551fc..644fb2ade 100644 --- a/app/helpers/avatar_helper.rb +++ b/app/helpers/avatar_helper.rb @@ -4,7 +4,7 @@ def render_avatar_partial(xl = false) render partial_name do |partial| partial.alt "#{current_user.first_name.first.upcase} Avatar" - partial.initials "#{current_user.first_name.first}#{current_user.last_name.first}".upcase + partial.initials current_user.name_initials.to_s if current_user.avatar.attached? partial.avatar do diff --git a/app/models/adopter_application.rb b/app/models/adopter_application.rb index f5dd052ee..06a2c5a62 100644 --- a/app/models/adopter_application.rb +++ b/app/models/adopter_application.rb @@ -71,7 +71,7 @@ def self.retire_applications(pet_id:) end def applicant_name - "#{adopter_foster_account.user.last_name}, #{adopter_foster_account.user.first_name}" + adopter_foster_account.user.full_name.to_s end def withdraw diff --git a/app/models/user.rb b/app/models/user.rb index 9de130e69..264070d08 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -100,4 +100,8 @@ def full_name(format = :default) raise ArgumentError, "Unsupported format: #{format}" end end + + def name_initials + full_name.split.map { |part| part[0] }.join.upcase + end end diff --git a/app/views/layouts/adopter_foster_dashboard.html.erb b/app/views/layouts/adopter_foster_dashboard.html.erb index 23aac11b2..b714cf635 100644 --- a/app/views/layouts/adopter_foster_dashboard.html.erb +++ b/app/views/layouts/adopter_foster_dashboard.html.erb @@ -21,7 +21,7 @@ <%= render_avatar_partial(xl: true) %>
-

<%= "#{current_user.first_name} #{current_user.last_name}" %>

+

<%= "#{current_user.full_name}" %>

diff --git a/app/views/layouts/dashboard.html.erb b/app/views/layouts/dashboard.html.erb index f99520253..d56a49cee 100644 --- a/app/views/layouts/dashboard.html.erb +++ b/app/views/layouts/dashboard.html.erb @@ -29,7 +29,7 @@
<%= render_avatar_partial %>
-
<%= "#{current_user.first_name} #{current_user.last_name}" %>
+
<%= "#{current_user.full_name}" %>

<%= current_user.email %>

diff --git a/app/views/organizations/staff/adoption_application_reviews/edit.html.erb b/app/views/organizations/staff/adoption_application_reviews/edit.html.erb index f195b4d55..b5c568aa8 100644 --- a/app/views/organizations/staff/adoption_application_reviews/edit.html.erb +++ b/app/views/organizations/staff/adoption_application_reviews/edit.html.erb @@ -1,7 +1,6 @@ <%= render "components/dashboard/page" do |p| %> <% p.header_title do %> - <%= @application.adopter_foster_account.user.first_name %> - <%= @application.adopter_foster_account.user.last_name %>'s application for + <%= @application.adopter_foster_account.user.full_name %>'s application for <%= @application.pet.name %> <% end %> diff --git a/app/views/organizations/staff/fosterers/index.html.erb b/app/views/organizations/staff/fosterers/index.html.erb index 2d64e62ab..61ff4a71d 100644 --- a/app/views/organizations/staff/fosterers/index.html.erb +++ b/app/views/organizations/staff/fosterers/index.html.erb @@ -44,7 +44,7 @@
-

<%= "#{fosterer.user.first_name} #{fosterer.user.last_name}" %>

+

<%= "#{fosterer.user.full_name}" %>

Joined @@ -84,7 +84,7 @@
-
<%= "#{fosterer.user.first_name} #{fosterer.user.last_name}" %>
+
<%= "#{fosterer.user.full_name}" %>
diff --git a/app/views/organizations/staff/profile_reviews/show.html.erb b/app/views/organizations/staff/profile_reviews/show.html.erb index 3eea533a2..a22f596df 100644 --- a/app/views/organizations/staff/profile_reviews/show.html.erb +++ b/app/views/organizations/staff/profile_reviews/show.html.erb @@ -5,7 +5,7 @@

- <%= @adopter_foster_profile.adopter_foster_account.user.first_name %> <%= @adopter_foster_profile.adopter_foster_account.user.last_name %>'s Profile + <%= @adopter_foster_profile.adopter_foster_account.user.full_name %>'s Profile

diff --git a/app/views/organizations/staff/staff/index.html.erb b/app/views/organizations/staff/staff/index.html.erb index 500ef7224..d5c409e57 100644 --- a/app/views/organizations/staff/staff/index.html.erb +++ b/app/views/organizations/staff/staff/index.html.erb @@ -44,7 +44,7 @@ -

<%= "#{staff.user.first_name} #{staff.user.last_name}" %>

+

<%= "#{staff.user.full_name}" %>

Role @@ -94,7 +94,7 @@
-
<%= "#{staff.user.first_name} #{staff.user.last_name}" %>
+
<%= "#{staff.user.full_name}" %>
diff --git a/app/views/sign_up_mailer/admin_notification_new_staff.html.erb b/app/views/sign_up_mailer/admin_notification_new_staff.html.erb index 49082c23b..1cfb2a3ea 100644 --- a/app/views/sign_up_mailer/admin_notification_new_staff.html.erb +++ b/app/views/sign_up_mailer/admin_notification_new_staff.html.erb @@ -8,8 +8,7 @@

Name: - <%= @user.first_name %> - <%= @user.last_name %> + <%= @user.full_name %>

diff --git a/app/views/sign_up_mailer/admin_notification_new_staff.text.erb b/app/views/sign_up_mailer/admin_notification_new_staff.text.erb index 0f03123e7..d86ba9f1e 100644 --- a/app/views/sign_up_mailer/admin_notification_new_staff.text.erb +++ b/app/views/sign_up_mailer/admin_notification_new_staff.text.erb @@ -1,7 +1,7 @@ New Staff Sign Up =============================================== -Name: <%= "#{@user.first_name} #{@user.last_name}" %> +Name: <%= "#{@user.full_name}" %> Email: <%= @user.email %> user_id: <%= @user.id %> diff --git a/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb b/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb index be0696fe8..0624fba1b 100644 --- a/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb +++ b/test/controllers/organizations/staff/adoption_application_reviews_controller_test.rb @@ -114,7 +114,7 @@ class Organizations::Staff::AdoptionApplicationReviewsControllerTest < ActionDis should "return applications for a specific applicant name" do get staff_adoption_application_reviews_url, params: {q: {adopter_applications_applicant_name_i_cont: "Attenborough"}} assert_response :success - assert_select "a.link-underline.link-underline-opacity-0", text: "Attenborough, David" + assert_select "a.link-underline.link-underline-opacity-0", text: "David Attenborough" refute_match "Goodall, Jane", @response.body end end diff --git a/test/integration/adoption_application_reviews_test.rb b/test/integration/adoption_application_reviews_test.rb index de55982b8..3a6368393 100644 --- a/test/integration/adoption_application_reviews_test.rb +++ b/test/integration/adoption_application_reviews_test.rb @@ -78,7 +78,7 @@ class AdoptionApplicationReviewsTest < ActionDispatch::IntegrationTest def verify_application_elements(application) assert_select "tr[id='adopter_application_#{application.id}']" do adopter = application.adopter_foster_account.user - assert_select "a", text: "#{adopter.last_name}, #{adopter.first_name}" + assert_select "a", text: "#{adopter.first_name} #{adopter.last_name}" assert_select "button", text: application.status.titleize end end