Files
sure/test/models/goal_contribution_test.rb
Guillem Arias 9b61e4a41b refactor: rename Savings Goals feature to Goals
User-facing rename + structural rename. Feature is now called just
"Goals" everywhere — page title, sidebar nav, modal headings, flash
messages, AI assistant tool. Code identifiers follow:

- Models: SavingsGoal → Goal, SavingsContribution → GoalContribution,
  SavingsGoalAccount → GoalAccount.
- Tables: savings_goals → goals, savings_contributions → goal_contributions,
  savings_goal_accounts → goal_accounts. FK columns savings_goal_id →
  goal_id. New migration db/migrate/20260511100003_rename_savings_to_goals.rb
  uses rename_table + rename_column; PG handles index renaming and FK
  redirection automatically.
- Controllers: SavingsGoalsController → GoalsController,
  SavingsContributionsController → GoalContributionsController.
- Routes: /savings_goals → /goals, nested /goals/:id/contributions
  (resource name shifts; old route name aliases dropped).
- ViewComponent namespace: Savings::* → Goals::*. Component class
  names drop their redundant "Goal" prefix where the namespace already
  carries it: Savings::GoalCardComponent → Goals::CardComponent,
  Savings::GoalAvatarComponent → Goals::AvatarComponent. Others keep
  their names (Goals::ProgressRingComponent, Goals::StatusPillComponent,
  Goals::AccountStackComponent, Goals::FundingAccountsBreakdownComponent).
- Stimulus controllers: savings_goal_* → goal_*, savings_goals_filter
  → goals_filter. Stimulus identifiers in data-controller / data-*
  attributes follow.
- Locale keys: savings_goals: → goals: (top level), savings_contributions:
  → goal_contributions: (top level). All t() callers updated.
- AI assistant tool: Assistant::Function::CreateSavingsGoal →
  Assistant::Function::CreateGoal, tool name "create_savings_goal" →
  "create_goal", description / response text updated.
- Sidebar nav label "Savings" → "Goals". Goals/show + index page title
  "Savings" → "Goals". Empty goals_section heading/subtitle dropped
  (duplicated the page title post-rename).

Original migrations create_savings_goals / create_savings_goal_accounts /
create_savings_contributions remain untouched so historical replay
still works; the rename migration runs on top.
2026-05-11 20:08:32 +02:00

47 lines
1.6 KiB
Ruby

require "test_helper"
class GoalContributionTest < ActiveSupport::TestCase
setup do
@goal = goals(:vacation_italy)
@depository = accounts(:depository)
end
test "valid fixture contribution saves" do
assert goal_contributions(:vacation_italy_initial).valid?
end
test "amount must be positive" do
c = @goal.goal_contributions.new(account: @depository, amount: 0, currency: "USD", source: "manual", contributed_at: Date.current)
assert_not c.valid?
end
test "source must be manual or initial" do
c = @goal.goal_contributions.new(account: @depository, amount: 10, currency: "USD", source: "auto", contributed_at: Date.current)
assert_not c.valid?
end
test "currency syncs from goal when blank" do
c = @goal.goal_contributions.new(account: @depository, amount: 10, source: "manual", contributed_at: Date.current)
c.valid?
assert_equal @goal.currency, c.currency
end
test "account must be linked to goal" do
other_depository = Account.create!(
family: @goal.family,
accountable: Depository.new,
name: "Unlinked Depository",
currency: "USD",
balance: 100
)
c = @goal.goal_contributions.new(account: other_depository, amount: 10, currency: "USD", source: "manual", contributed_at: Date.current)
assert_not c.valid?
assert_includes c.errors[:account], "Account must be one of the goal's linked accounts."
end
test "manual? and initial? predicates" do
assert goal_contributions(:vacation_italy_initial).initial?
assert goal_contributions(:vacation_italy_manual).manual?
end
end