mirror of
https://github.com/we-promise/sure.git
synced 2026-05-30 07:49:01 +00:00
fix(goals): drop no-target-date goals from the on-track denominator
The KPI tile reads 'X of Y on track'. Y was every active goal minus reached + paused, which included open-ended goals (no target_date). But an open-ended goal has no required monthly pace to compare against — by definition it can be neither on track nor behind. Counting it in the denominator dragged the ratio down and never improved as the user kept saving (the fraction stays stuck because the open-ended goal is never a hit). Exclude :no_target_date from tracked_total. Numerator unchanged. The subline still surfaces 'N without a deadline' as informational so the user knows those goals exist.
This commit is contained in:
@@ -176,6 +176,23 @@ class GoalsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_match(/1\s*reached/i, response.body)
|
||||
end
|
||||
|
||||
test "index KPI 'on track' denominator excludes no-target-date goals" do
|
||||
family = users(:family_admin).family
|
||||
family.goals.destroy_all
|
||||
# One trackable goal (has target_date) + one open-ended (no target_date).
|
||||
# The trackable one should be the only thing in the denominator;
|
||||
# open-ended goals can't be off pace because they have no required pace.
|
||||
build_goal(family, "House", target_amount: 1_000_000, target_date: 1.year.from_now)
|
||||
build_goal(family, "Emergency", target_amount: 1_000_000, target_date: nil)
|
||||
|
||||
get goals_url
|
||||
assert_response :success
|
||||
# Expect "0 of 1" — the open-ended goal stays out of the fraction
|
||||
# even though it's active.
|
||||
assert_match(/0\s*of\s*1/i, response.body)
|
||||
assert_match(/without a deadline/i, response.body)
|
||||
end
|
||||
|
||||
private
|
||||
def build_goal(family, name, target_amount: 1_000_000, target_date: nil)
|
||||
g = family.goals.new(name: name, target_amount: target_amount, target_date: target_date, currency: "USD")
|
||||
|
||||
Reference in New Issue
Block a user