mirror of
https://github.com/we-promise/sure.git
synced 2026-05-10 14:15:01 +00:00
feat(splits): add exclusion support for splits and improve rendering (#1661)
* feat(splits): add excluded attribute support for split children and improve rendering of split transactions * address coderabbitai suggestions to improve code quality * Fix split excluded coercion, DRY helpers, and clean up view partials Fix boolean coercion bug where string "false" from form params was truthy in Ruby, causing all split children to be marked excluded. Use ActiveModel::Type::Boolean for explicit casting in Entry#split!. Additional changes addressing code review feedback: - Extract duplicated in_split_group logic from TransactionsController and TransactionCategoriesController into TransactionsHelper - Remove redundant local_assigns.fetch calls in partials that already declare defaults via the Rails 7.1 locals: magic comment - Simplify ternary in _transaction.html.erb to pass grouped directly - Guard hidden_field_tag :grouped to only emit when value is "true" - Add model tests for excluded on split children (boolean and string) - Add controller test for excluded param through full HTTP stack - Add test confirming excluded children are dropped from balance queries * fix(splits): simplify excluded attribute boolean check * refactor(splits): extract truthy values constant for excluded check Extract the array of truthy values used for excluded attribute check into a private constant to improve code maintainability and avoid duplication of the magic array. * refactor: simplify split grouping link generation and add test coverage for excluded split parameters
This commit is contained in:
@@ -120,6 +120,26 @@ class SplitsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "create with excluded parameter sets child as excluded" do
|
||||
assert_difference "Entry.count", 2 do
|
||||
post transaction_split_path(@entry), params: {
|
||||
split: {
|
||||
splits: [
|
||||
{ name: "Groceries", amount: "-70", category_id: categories(:food_and_drink).id, excluded: "true" },
|
||||
{ name: "Household", amount: "-30", category_id: "", excluded: "false" }
|
||||
]
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
children = @entry.child_entries.order(:amount)
|
||||
# Household has amount 30 (smaller), Groceries has amount 70 (larger)
|
||||
# Household is NOT excluded, Groceries IS excluded
|
||||
refute children.first.excluded?
|
||||
assert children.last.excluded?
|
||||
end
|
||||
|
||||
# Edit action tests
|
||||
test "edit renders with existing children pre-filled" do
|
||||
@entry.split!([
|
||||
@@ -193,6 +213,27 @@ class SplitsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal 2, @entry.reload.child_entries.count
|
||||
end
|
||||
|
||||
test "update with excluded parameter sets child as excluded" do
|
||||
@entry.split!([
|
||||
{ name: "Groceries", amount: 70, category_id: nil },
|
||||
{ name: "Household", amount: 30, category_id: nil }
|
||||
])
|
||||
|
||||
patch transaction_split_path(@entry), params: {
|
||||
split: {
|
||||
splits: [
|
||||
{ name: "Groceries", amount: "-70", category_id: "", excluded: "true" },
|
||||
{ name: "Household", amount: "-30", category_id: "", excluded: "false" }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
children = @entry.child_entries.order(:amount)
|
||||
refute children.first.excluded?
|
||||
assert children.last.excluded?
|
||||
end
|
||||
|
||||
# Destroy from child tests
|
||||
test "destroy from child resolves to parent and unsplits" do
|
||||
@entry.split!([
|
||||
|
||||
Reference in New Issue
Block a user