mirror of
https://github.com/we-promise/sure.git
synced 2026-05-30 07:49:01 +00:00
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.
This commit is contained in:
58
test/controllers/goal_contributions_controller_test.rb
Normal file
58
test/controllers/goal_contributions_controller_test.rb
Normal file
@@ -0,0 +1,58 @@
|
||||
require "test_helper"
|
||||
|
||||
class GoalContributionsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
@goal = goals(:vacation_italy)
|
||||
@depository = accounts(:depository)
|
||||
ensure_tailwind_build
|
||||
end
|
||||
|
||||
test "new renders the modal form" do
|
||||
get new_goal_contribution_url(@goal)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "create saves a manual contribution" do
|
||||
assert_difference -> { @goal.goal_contributions.count } => 1 do
|
||||
post goal_contributions_url(@goal), params: {
|
||||
goal_contribution: {
|
||||
amount: "100",
|
||||
contributed_at: Date.current.iso8601,
|
||||
notes: ""
|
||||
},
|
||||
goal_contribution_account_id: @depository.id
|
||||
}.merge(goal_contribution: { account_id: @depository.id, amount: "100", contributed_at: Date.current.iso8601 })
|
||||
end
|
||||
|
||||
assert_redirected_to goal_path(@goal)
|
||||
contribution = @goal.goal_contributions.order(created_at: :desc).first
|
||||
assert_equal "manual", contribution.source
|
||||
assert_equal @depository, contribution.account
|
||||
end
|
||||
|
||||
test "create rejects contribution from non-linked account" do
|
||||
unlinked = Account.create!(family: @goal.family, accountable: Depository.new, name: "Unlinked", currency: "USD", balance: 100)
|
||||
assert_no_difference "@goal.goal_contributions.count" do
|
||||
post goal_contributions_url(@goal), params: {
|
||||
goal_contribution: { amount: "10", contributed_at: Date.current.iso8601, account_id: unlinked.id }
|
||||
}
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "destroy manual contribution removes it" do
|
||||
manual = goal_contributions(:vacation_italy_manual)
|
||||
assert_difference "GoalContribution.count", -1 do
|
||||
delete goal_contribution_url(@goal, manual)
|
||||
end
|
||||
end
|
||||
|
||||
test "destroy initial contribution is blocked" do
|
||||
initial = goal_contributions(:vacation_italy_initial)
|
||||
assert_no_difference "GoalContribution.count" do
|
||||
delete goal_contribution_url(@goal, initial)
|
||||
end
|
||||
assert_redirected_to goal_path(@goal)
|
||||
end
|
||||
end
|
||||
@@ -1,41 +1,41 @@
|
||||
require "test_helper"
|
||||
|
||||
class SavingsGoalsControllerTest < ActionDispatch::IntegrationTest
|
||||
class GoalsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
@goal = savings_goals(:vacation_italy)
|
||||
@goal = goals(:vacation_italy)
|
||||
@depository = accounts(:depository)
|
||||
@connected = accounts(:connected)
|
||||
ensure_tailwind_build
|
||||
end
|
||||
|
||||
test "index renders with active filter by default" do
|
||||
get savings_goals_url
|
||||
get goals_url
|
||||
assert_response :success
|
||||
assert_match(/Savings/i, response.body)
|
||||
assert_match(/Goals/i, response.body)
|
||||
end
|
||||
|
||||
test "index honors state filter" do
|
||||
get savings_goals_url(state: "paused")
|
||||
get goals_url(state: "paused")
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "show renders the goal" do
|
||||
get savings_goal_url(@goal)
|
||||
get goal_url(@goal)
|
||||
assert_response :success
|
||||
assert_match(@goal.name, response.body)
|
||||
end
|
||||
|
||||
test "new renders the modal form" do
|
||||
get new_savings_goal_url
|
||||
get new_goal_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "create persists a goal with linked accounts" do
|
||||
assert_difference -> { SavingsGoal.count } => 1,
|
||||
-> { SavingsGoalAccount.count } => 2 do
|
||||
post savings_goals_url, params: {
|
||||
savings_goal: {
|
||||
assert_difference -> { Goal.count } => 1,
|
||||
-> { GoalAccount.count } => 2 do
|
||||
post goals_url, params: {
|
||||
goal: {
|
||||
name: "New goal",
|
||||
target_amount: "1000",
|
||||
target_date: 3.months.from_now.to_date.iso8601,
|
||||
@@ -45,14 +45,14 @@ class SavingsGoalsControllerTest < ActionDispatch::IntegrationTest
|
||||
}
|
||||
end
|
||||
|
||||
goal = SavingsGoal.order(created_at: :desc).first
|
||||
assert_redirected_to savings_goal_path(goal)
|
||||
goal = Goal.order(created_at: :desc).first
|
||||
assert_redirected_to goal_path(goal)
|
||||
end
|
||||
|
||||
test "create with initial contribution writes the contribution" do
|
||||
assert_difference -> { SavingsContribution.count } => 1 do
|
||||
post savings_goals_url, params: {
|
||||
savings_goal: {
|
||||
assert_difference -> { GoalContribution.count } => 1 do
|
||||
post goals_url, params: {
|
||||
goal: {
|
||||
name: "Goal with initial",
|
||||
target_amount: "1000",
|
||||
color: "#4da568",
|
||||
@@ -63,15 +63,15 @@ class SavingsGoalsControllerTest < ActionDispatch::IntegrationTest
|
||||
}
|
||||
end
|
||||
|
||||
contribution = SavingsContribution.order(created_at: :desc).first
|
||||
contribution = GoalContribution.order(created_at: :desc).first
|
||||
assert_equal "initial", contribution.source
|
||||
assert_equal 50, contribution.amount.to_i
|
||||
end
|
||||
|
||||
test "create rejects missing account_ids" do
|
||||
assert_no_difference "SavingsGoal.count" do
|
||||
post savings_goals_url, params: {
|
||||
savings_goal: {
|
||||
assert_no_difference "Goal.count" do
|
||||
post goals_url, params: {
|
||||
goal: {
|
||||
name: "Bad goal",
|
||||
target_amount: "1000",
|
||||
color: "#4da568"
|
||||
@@ -85,9 +85,9 @@ class SavingsGoalsControllerTest < ActionDispatch::IntegrationTest
|
||||
other_family = Family.create!(name: "Other", currency: "USD", locale: "en", country: "US", timezone: "UTC")
|
||||
foreign = Account.create!(family: other_family, accountable: Depository.new, name: "Foreign", currency: "USD", balance: 100)
|
||||
|
||||
assert_no_difference "SavingsGoal.count" do
|
||||
post savings_goals_url, params: {
|
||||
savings_goal: {
|
||||
assert_no_difference "Goal.count" do
|
||||
post goals_url, params: {
|
||||
goal: {
|
||||
name: "Foreign goal",
|
||||
target_amount: "1000",
|
||||
color: "#4da568",
|
||||
@@ -99,48 +99,48 @@ class SavingsGoalsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "update modifies identity fields" do
|
||||
patch savings_goal_url(@goal), params: { savings_goal: { name: "Renamed" } }
|
||||
assert_redirected_to savings_goal_path(@goal)
|
||||
patch goal_url(@goal), params: { goal: { name: "Renamed" } }
|
||||
assert_redirected_to goal_path(@goal)
|
||||
assert_equal "Renamed", @goal.reload.name
|
||||
end
|
||||
|
||||
test "pause/resume/complete/archive/unarchive flow" do
|
||||
fresh = savings_goals(:emergency_fund)
|
||||
patch pause_savings_goal_url(fresh)
|
||||
fresh = goals(:emergency_fund)
|
||||
patch pause_goal_url(fresh)
|
||||
assert fresh.reload.paused?
|
||||
patch resume_savings_goal_url(fresh)
|
||||
patch resume_goal_url(fresh)
|
||||
assert fresh.reload.active?
|
||||
patch complete_savings_goal_url(fresh)
|
||||
patch complete_goal_url(fresh)
|
||||
assert fresh.reload.completed?
|
||||
patch archive_savings_goal_url(fresh)
|
||||
patch archive_goal_url(fresh)
|
||||
assert fresh.reload.archived?
|
||||
patch unarchive_savings_goal_url(fresh)
|
||||
patch unarchive_goal_url(fresh)
|
||||
assert fresh.reload.active?
|
||||
end
|
||||
|
||||
test "destroy on non-archived is rejected" do
|
||||
assert_no_difference "SavingsGoal.count" do
|
||||
delete savings_goal_url(@goal)
|
||||
assert_no_difference "Goal.count" do
|
||||
delete goal_url(@goal)
|
||||
end
|
||||
assert_redirected_to savings_goal_path(@goal)
|
||||
assert_redirected_to goal_path(@goal)
|
||||
end
|
||||
|
||||
test "destroy on archived deletes" do
|
||||
@goal.archive!
|
||||
assert_difference "SavingsGoal.count", -1 do
|
||||
delete savings_goal_url(@goal)
|
||||
assert_difference "Goal.count", -1 do
|
||||
delete goal_url(@goal)
|
||||
end
|
||||
assert_redirected_to savings_goals_path
|
||||
assert_redirected_to goals_path
|
||||
end
|
||||
|
||||
test "another family's goal returns 404" do
|
||||
other_family = Family.create!(name: "Other", currency: "USD", locale: "en", country: "US", timezone: "UTC")
|
||||
other_account = Account.create!(family: other_family, accountable: Depository.new, name: "Foreign", currency: "USD", balance: 100)
|
||||
other_goal = other_family.savings_goals.new(name: "Foreign goal", target_amount: 100, currency: "USD")
|
||||
other_goal.savings_goal_accounts.build(account: other_account)
|
||||
other_goal = other_family.goals.new(name: "Foreign goal", target_amount: 100, currency: "USD")
|
||||
other_goal.goal_accounts.build(account: other_account)
|
||||
other_goal.save!
|
||||
|
||||
get savings_goal_url(other_goal)
|
||||
get goal_url(other_goal)
|
||||
assert_response :not_found
|
||||
end
|
||||
end
|
||||
@@ -1,58 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class SavingsContributionsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
@goal = savings_goals(:vacation_italy)
|
||||
@depository = accounts(:depository)
|
||||
ensure_tailwind_build
|
||||
end
|
||||
|
||||
test "new renders the modal form" do
|
||||
get new_savings_goal_contribution_url(@goal)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "create saves a manual contribution" do
|
||||
assert_difference -> { @goal.savings_contributions.count } => 1 do
|
||||
post savings_goal_contributions_url(@goal), params: {
|
||||
savings_contribution: {
|
||||
amount: "100",
|
||||
contributed_at: Date.current.iso8601,
|
||||
notes: ""
|
||||
},
|
||||
savings_contribution_account_id: @depository.id
|
||||
}.merge(savings_contribution: { account_id: @depository.id, amount: "100", contributed_at: Date.current.iso8601 })
|
||||
end
|
||||
|
||||
assert_redirected_to savings_goal_path(@goal)
|
||||
contribution = @goal.savings_contributions.order(created_at: :desc).first
|
||||
assert_equal "manual", contribution.source
|
||||
assert_equal @depository, contribution.account
|
||||
end
|
||||
|
||||
test "create rejects contribution from non-linked account" do
|
||||
unlinked = Account.create!(family: @goal.family, accountable: Depository.new, name: "Unlinked", currency: "USD", balance: 100)
|
||||
assert_no_difference "@goal.savings_contributions.count" do
|
||||
post savings_goal_contributions_url(@goal), params: {
|
||||
savings_contribution: { amount: "10", contributed_at: Date.current.iso8601, account_id: unlinked.id }
|
||||
}
|
||||
end
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "destroy manual contribution removes it" do
|
||||
manual = savings_contributions(:vacation_italy_manual)
|
||||
assert_difference "SavingsContribution.count", -1 do
|
||||
delete savings_goal_contribution_url(@goal, manual)
|
||||
end
|
||||
end
|
||||
|
||||
test "destroy initial contribution is blocked" do
|
||||
initial = savings_contributions(:vacation_italy_initial)
|
||||
assert_no_difference "SavingsContribution.count" do
|
||||
delete savings_goal_contribution_url(@goal, initial)
|
||||
end
|
||||
assert_redirected_to savings_goal_path(@goal)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user