Files
sure/test/controllers/goal_pledges_controller_test.rb
Guillem Arias e16d9c4a6a Merge origin/feat/goals-v2-architecture; reconcile beta→preview rename
Remote branch added a beta_gated_nav_item helper + 'Gating the main nav'
docs section. Main concurrently renamed the beta-features gate to
preview-features (concern, predicate, JSONB key, locale flash). Rename
the new helper / partial local / pill marker to match preview naming and
port the nav-gating docs into gating-a-preview-feature.md so the
improvement survives the rename.

Resolved conflicts:
- db/schema.rb: take the later schema version (2026_05_19_100000).
- docs/llm-guides/gating-a-beta-feature.md: accept main's deletion;
  port the 'Gating the main nav' section into the preview guide.

Renames carried through to keep the gate wired end-to-end:
- application_helper.rb: beta_gated_nav_item → preview_gated_nav_item;
  beta_features_enabled? → preview_features_enabled?; beta: → preview:.
- _nav_item.html.erb: beta: local → preview: local; shared.beta i18n
  key → shared.preview.
- application.html.erb: caller renamed to preview_gated_nav_item.
- goals/index.html.erb: pill label uses shared.preview.
- shared/en.yml: 'beta: Beta' → 'preview: Preview'.
- goals_controller, goal_pledges_controller: require_beta_features! →
  require_preview_features!.
- goals_controller_test, goal_pledges_controller_test: flip the
  preference key, flash matcher, and test names to 'preview'.
2026-05-20 21:47:27 +02:00

95 lines
3.1 KiB
Ruby

require "test_helper"
class GoalPledgesControllerTest < ActionDispatch::IntegrationTest
setup do
@user = users(:family_admin)
@user.update!(preferences: (@user.preferences || {}).merge("preview_features_enabled" => true))
sign_in @user
@goal = goals(:vacation_italy)
@account = accounts(:depository)
@pledge = goal_pledges(:open_transfer)
ensure_tailwind_build
end
test "redirects users without preview access" do
@user.update!(preferences: (@user.preferences || {}).merge("preview_features_enabled" => false))
get new_goal_pledge_url(@goal), headers: { "Turbo-Frame" => "modal" }
assert_redirected_to root_path
assert_match(/preview/i, flash[:alert])
end
test "new renders the pledge form inside a turbo frame" do
get new_goal_pledge_url(@goal), headers: { "Turbo-Frame" => "modal" }
assert_response :success
end
test "new redirects to the goal show page on a non-frame GET" do
get new_goal_pledge_url(@goal)
assert_redirected_to goal_path(@goal)
end
test "create opens a pledge with default kind" do
assert_difference -> { GoalPledge.count } => 1 do
post goal_pledges_url(@goal), params: {
goal_pledge: {
amount: "150",
account_id: @account.id
}
}
end
pledge = GoalPledge.order(created_at: :desc).first
assert_equal "open", pledge.status
assert_equal @goal.id, pledge.goal_id
assert_redirected_to goal_path(@goal)
end
test "create rejects amount <= 0" do
assert_no_difference "GoalPledge.count" do
post goal_pledges_url(@goal), params: {
goal_pledge: { amount: "0", account_id: @account.id }
}
end
assert_response :unprocessable_entity
end
test "extend pushes expires_at forward" do
before = @pledge.expires_at
patch renew_goal_pledge_url(@goal, @pledge)
assert_redirected_to goal_path(@goal)
assert @pledge.reload.expires_at > before
end
test "extend on non-open pledge flashes alert" do
pledge = goal_pledges(:matched_transfer)
patch renew_goal_pledge_url(@goal, pledge)
assert_redirected_to goal_path(@goal)
assert flash[:alert].present?
end
test "destroy cancels an open pledge" do
delete goal_pledge_url(@goal, @pledge)
assert_redirected_to goal_path(@goal)
assert @pledge.reload.status_cancelled?
end
test "destroy on non-open pledge flashes alert" do
pledge = goal_pledges(:matched_transfer)
delete goal_pledge_url(@goal, pledge)
assert_redirected_to goal_path(@goal)
assert flash[:alert].present?
end
test "another family's goal returns redirect" 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.goals.new(name: "Foreign goal", target_amount: 100, currency: "USD")
other_goal.goal_accounts.build(account: other_account)
other_goal.save!
get new_goal_pledge_url(other_goal)
assert_redirected_to goals_path
end
end