mirror of
https://github.com/we-promise/sure.git
synced 2026-08-03 23:52:13 +00:00
fix(insights): keep rolling period labels on month boundaries (#2880)
* fix(ci): skip scheduled preview cleanup on forks Only run the hourly Cloudflare preview cleanup on we-promise/sure, where the required secrets exist. * fix(insights): pin meta-line forward-window test mid-month Date.current..Date.current+30 is a full calendar month on the 1st of 31-day months (e.g. Aug 1..31), so insight_period_label prefers the month name over "Next 30 days" and flakes CI. Co-authored-by: Cursor <cursoragent@cursor.com> * Fix rolling insight period labels on month boundaries --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: sure-admin <sure-admin@splashblot.com>
This commit is contained in:
@@ -141,13 +141,15 @@ module InsightsHelper
|
||||
return facts["account"] || facts["name"]
|
||||
end
|
||||
|
||||
if start_date == start_date.beginning_of_month && end_date == start_date.end_of_month
|
||||
format = start_date.year == Date.current.year ? "%B" : "%B %Y"
|
||||
return I18n.l(start_date, format: format)
|
||||
end
|
||||
|
||||
days = (end_date - start_date).to_i
|
||||
if start_date >= Date.current - 1
|
||||
if rolling_period_insight?(insight) && start_date >= Date.current - 1
|
||||
t("insights.meta.next_n_days", count: days)
|
||||
elsif rolling_period_insight?(insight) && end_date >= Date.current - 1
|
||||
t("insights.meta.last_n_days", count: days)
|
||||
elsif start_date == start_date.beginning_of_month && end_date == start_date.end_of_month
|
||||
format = start_date.year == Date.current.year ? "%B" : "%B %Y"
|
||||
I18n.l(start_date, format: format)
|
||||
elsif start_date >= Date.current - 1
|
||||
t("insights.meta.next_n_days", count: days)
|
||||
elsif end_date >= Date.current - 1
|
||||
t("insights.meta.last_n_days", count: days)
|
||||
@@ -155,4 +157,8 @@ module InsightsHelper
|
||||
t("insights.meta.date_range", from: I18n.l(start_date, format: :short), to: I18n.l(end_date, format: :short))
|
||||
end
|
||||
end
|
||||
|
||||
def rolling_period_insight?(insight)
|
||||
insight.insight_type.in?(%w[cash_flow_warning net_worth_milestone])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,13 +70,39 @@ class InsightsHelperTest < ActionView::TestCase
|
||||
end
|
||||
|
||||
test "meta line labels a forward-looking window as next N days" do
|
||||
insight = build_insight(
|
||||
"cash_flow_warning",
|
||||
period_start: Date.current,
|
||||
period_end: Date.current + 30
|
||||
)
|
||||
travel_to Date.new(2026, 8, 1) do
|
||||
insight = build_insight(
|
||||
"cash_flow_warning",
|
||||
period_start: Date.current,
|
||||
period_end: Date.current + 30
|
||||
)
|
||||
|
||||
assert_equal "Cash flow · Next 30 days", insight_meta_line(insight)
|
||||
assert_equal "Cash flow · Next 30 days", insight_meta_line(insight)
|
||||
end
|
||||
end
|
||||
|
||||
test "meta line labels a backward-looking rolling window as last N days" do
|
||||
travel_to Date.new(2026, 8, 31) do
|
||||
insight = build_insight(
|
||||
"net_worth_milestone",
|
||||
period_start: Date.current - 30,
|
||||
period_end: Date.current
|
||||
)
|
||||
|
||||
assert_equal "Net worth · Last 30 days", insight_meta_line(insight)
|
||||
end
|
||||
end
|
||||
|
||||
test "meta line keeps monthly insight periods labeled as the month on boundaries" do
|
||||
travel_to Date.new(2026, 8, 1) do
|
||||
insight = build_insight(
|
||||
"budget_at_risk",
|
||||
period_start: Date.current.beginning_of_month,
|
||||
period_end: Date.current.end_of_month
|
||||
)
|
||||
|
||||
assert_equal "Budget · August", insight_meta_line(insight)
|
||||
end
|
||||
end
|
||||
|
||||
test "meta line falls back to the subject when there is no period" do
|
||||
|
||||
Reference in New Issue
Block a user