mirror of
https://github.com/we-promise/sure.git
synced 2026-05-30 07:49:01 +00:00
feat(goals/edit): funding-accounts editor in the edit modal
Previously a user who linked the wrong account at creation had to delete + recreate the goal. Now the edit modal carries the same funding-accounts checkbox group as Step 1 of the stepper, pre-checked with the goal's current links. - GoalsController#edit loads @linkable_accounts + @currently_linked_account_ids. - #update accepts account_ids; when supplied, runs the create / update inside a Goal.transaction and syncs linked accounts via sync_linked_accounts! (set-diff: destroy_all unselected goal_accounts, create the new ones). Validates at least one account before touching goal_accounts so the user gets a clean re-render. - Removing an account preserves the goal's existing contributions — GoalContribution#account_must_be_linked_to_goal only fires on save, so historical rows stay valid. - _form_edit partial accepts new locals; edit.html.erb threads them through. - 3 new controller tests: identity-only patch leaves links intact; account_ids patch replaces the link set; empty account_ids re-renders with error.
This commit is contained in:
@@ -104,6 +104,25 @@ class GoalsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal "Renamed", @goal.reload.name
|
||||
end
|
||||
|
||||
test "update without account_ids leaves linked accounts intact" do
|
||||
before = @goal.goal_accounts.pluck(:account_id).sort
|
||||
patch goal_url(@goal), params: { goal: { name: "Still here" } }
|
||||
assert_redirected_to goal_path(@goal)
|
||||
assert_equal before, @goal.reload.goal_accounts.pluck(:account_id).sort
|
||||
end
|
||||
|
||||
test "update with account_ids syncs linked accounts (add + remove)" do
|
||||
patch goal_url(@goal), params: { goal: { account_ids: [ @connected.id ] } }
|
||||
assert_redirected_to goal_path(@goal)
|
||||
assert_equal [ @connected.id ], @goal.reload.goal_accounts.pluck(:account_id)
|
||||
end
|
||||
|
||||
test "update with empty account_ids re-renders with error" do
|
||||
patch goal_url(@goal), params: { goal: { account_ids: [ "" ] } }
|
||||
assert_response :unprocessable_entity
|
||||
assert_not_empty @goal.reload.goal_accounts
|
||||
end
|
||||
|
||||
test "pause/resume/complete/archive/unarchive flow" do
|
||||
fresh = goals(:emergency_fund)
|
||||
patch pause_goal_url(fresh)
|
||||
|
||||
Reference in New Issue
Block a user