require "test_helper" class DepositoriesControllerTest < ActionDispatch::IntegrationTest include AccountableResourceInterfaceTest setup do sign_in @user = users(:family_admin) @account = accounts(:depository) end test "create falls back to the stored return_to when no form param is present" do get new_account_path(return_to: transactions_path) # StoreLocation captures it into the session assert_difference -> { Account.count } => 1 do post depositories_path, params: { account: { name: "Return To Checking", currency: "USD", balance: 100, accountable_type: "Depository" } } end assert_redirected_to transactions_path end test "create prefers the form return_to over the session value" do get new_account_path(return_to: transactions_path) # session return_to post depositories_path, params: { account: { name: "Form RT Checking", currency: "USD", balance: 100, accountable_type: "Depository", return_to: budgets_path } } assert_redirected_to budgets_path end test "create ignores an external return_to (open-redirect guard)" do post depositories_path, params: { account: { name: "Evil RT Checking", currency: "USD", balance: 100, accountable_type: "Depository", return_to: "https://evil.example/phish" } } created = Account.order(:created_at).last assert_redirected_to account_path(created) # not the external URL end end