The personal finance app for everyone (by everyone)
Ruby
fix(goals): stop the days-left phrase splitting across lines (#2970)
Guillem Arias Fauste214a139a7e75
diff --git a/app/models/goal.rb b/app/models/goal.rbindex a2578b78b9..e0a2598ed2 100644--- a/app/models/goal.rb+++ b/app/models/goal.rb@@ -507,7 +507,11 @@ class Goal < ApplicationRecord# Header copy under the goal title on show. Used to live as a multi-line# if/elsif block in show.html.erb. Keeps the view template free of date# math + i18n key picking.- def header_summary+ # The dot-separated segments of the header line, kept as separate strings so+ # the view can stop a short one breaking mid-phrase. Joined into a single+ # string, "184 days left" could wrap after "days" and orphan "left" on the+ # next line — which is what a phone did.+ def header_summary_partsparts = []if target_datedays = (target_date - Date.current).to_i@@ -528,7 +532,7 @@ class Goal < ApplicationRecordparts << I18n.t("goals.show.header.target",amount: target_amount_money.format(precision: 0))end- parts.join(" · ")+ partsend# Single source of truth for the projection-chart subtitle / chart-ariadiff --git a/app/views/goals/show.html.erb b/app/views/goals/show.html.erbindex 7fef996100..5a79115a2f 100644--- a/app/views/goals/show.html.erb+++ b/app/views/goals/show.html.erb@@ -5,7 +5,18 @@</div><div class="min-w-0 flex-1"><h1 class="text-2xl font-semibold text-primary break-words"><%= @goal.name %></h1>- <p class="text-sm text-secondary mt-1 privacy-sensitive"><%= @goal.header_summary %></p>+ <%# Each segment is its own nowrap span so a short trailing one — "184 days+ left" — moves to the next line whole instead of breaking after "days".+ The first segment carries the target and a long-format date, so it is+ left free to wrap; pinning it would overflow a narrow screen. %>+ <p class="text-sm text-secondary mt-1 privacy-sensitive">+ <%= safe_join(+ @goal.header_summary_parts.map.with_index { |part, i|+ tag.span(part, class: ("whitespace-nowrap" unless i.zero?))+ },+ " · "+ ) %>+ </p><% last_days = @goal.last_matched_pledge_days_ago %><% unless last_days.nil? %><p class="text-xs text-subdued mt-0.5">diff --git a/test/models/goal_test.rb b/test/models/goal_test.rbindex 8427a208bd..e6af35e840 100644--- a/test/models/goal_test.rb+++ b/test/models/goal_test.rb@@ -14,6 +14,38 @@ class GoalTest < ActiveSupport::TestCaseassert @goal.valid?end+ # The days-left segment is returned separately so the view can keep it+ # unbroken; joined into one string it wrapped after "days" on a phone.+ test "header_summary_parts keeps the days-left phrase in its own segment" do+ # Pinned: the count is `target_date - Date.current`, so a suite that crossed+ # midnight between setting the date and reading it would report 183.+ travel_to Date.new(2026, 6, 1) do+ # Target well above the linked account's balance, or the goal reads as+ # :reached and drops the days-left segment on purpose.+ @goal.target_amount = 1_000_000+ @goal.target_date = Date.current + 184++ parts = @goal.header_summary_parts++ assert_equal 2, parts.size+ assert_match(/184 days left/, parts.last)+ assert_no_match(/days left/, parts.first)+ end+ end++ test "header_summary_parts omits days left once the target is reached" do+ @goal.target_date = 184.days.from_now.to_date+ @goal.complete!++ assert_equal 1, @goal.header_summary_parts.size+ end++ test "header_summary_parts is a single segment without a target date" do+ @goal.target_date = nil++ assert_equal 1, @goal.header_summary_parts.size+ end+test "name is required" do@goal.name = ""assert_not @goal.valid?