Skip to content

Commit

Permalink
Refactor: Use 'full_name' attribute for user full names instead of st… (
Browse files Browse the repository at this point in the history
rubyforgood#761)

* Refactor: Use 'full_name' attribute for user full names instead of string concatenation

* Fix broken tests & linters
  • Loading branch information
sparshalc authored May 30, 2024
1 parent 5eb4869 commit 4762c1a
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/helpers/avatar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/adopter_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/views/layouts/adopter_foster_dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<%= render_avatar_partial(xl: true) %>
</div>
<div class="lh-1">
<h2 class="mb-0"><%= "#{current_user.first_name} #{current_user.last_name}" %></h2>
<h2 class="mb-0"><%= "#{current_user.full_name}" %></h2>
</div>
</div>
<div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="d-flex">
<%= render_avatar_partial %>
<div class="ms-3 lh-1">
<h5 class="mb-1"><%= "#{current_user.first_name} #{current_user.last_name}" %></h5>
<h5 class="mb-1"><%= "#{current_user.full_name}" %></h5>
<p class="mb-0 text-muted"><%= current_user.email %></p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/organizations/staff/fosterers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<span class="status bg-success"></span>
</a>
</div>
<h4 class="mb-0"><%= "#{fosterer.user.first_name} #{fosterer.user.last_name}" %></h4>
<h4 class="mb-0"><%= "#{fosterer.user.full_name}" %></h4>
</div>
<div class="d-flex justify-content-between border-bottom py-2">
<span>Joined</span>
Expand Down Expand Up @@ -84,7 +84,7 @@
<span class="status bg-success"></span>
</a>
</div>
<h5 class="mb-0"><%= "#{fosterer.user.first_name} #{fosterer.user.last_name}" %></h5>
<h5 class="mb-0"><%= "#{fosterer.user.full_name}" %></h5>
</div>
</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!--page heading-->
<div class="text-center mb-5">
<h1 class="section-heading text-uppercase underline">
<%= @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
</h1>
</div>

Expand Down
4 changes: 2 additions & 2 deletions app/views/organizations/staff/staff/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<span class="status bg-success"></span>
</a>
</div>
<h4 class="mb-0"><%= "#{staff.user.first_name} #{staff.user.last_name}" %></h4>
<h4 class="mb-0"><%= "#{staff.user.full_name}" %></h4>
</div>
<div class="d-flex justify-content-between border-bottom py-2 mt-4">
<span>Role</span>
Expand Down Expand Up @@ -94,7 +94,7 @@
<span class="status bg-success"></span>
</a>
</div>
<h5 class="mb-0"><%= "#{staff.user.first_name} #{staff.user.last_name}" %></h5>
<h5 class="mb-0"><%= "#{staff.user.full_name}" %></h5>
</div>
</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

<p>
Name:
<%= @user.first_name %>
<%= @user.last_name %>
<%= @user.full_name %>
</p>

<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/integration/adoption_application_reviews_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4762c1a

Please sign in to comment.