The personal finance app for everyone (by everyone)
Ruby
Let a split row's category and merchant be changed in its drawer (#4467)
GFR577821db5928
diff --git a/app/views/transactions/show.html.erb b/app/views/transactions/show.html.erbindex 0c9b235fb4..676f0a0b7c 100644--- a/app/views/transactions/show.html.erb+++ b/app/views/transactions/show.html.erb@@ -106,7 +106,7 @@form: ef,categories: Current.family.categories.alphabetically_by_hierarchy,selected_id: ef.object.category_id,- disabled: @entry.split_child? || annotate_locked,+ disabled: annotate_locked,auto_submit: true,blank_label: t(".uncategorized"),locked: Current.family.categories_locked?@@ -155,7 +155,7 @@selected_id: ef.object.merchant_id,include_blank: t(".none"),label: t(".merchant_label"),- disabled: @entry.split_child? || !can_annotate_entry?,+ disabled: !can_annotate_entry?,auto_submit: true) %><% end %>diff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rbindex 1438712b4a..4e1eb2dc44 100644--- a/test/controllers/transactions_controller_test.rb+++ b/test/controllers/transactions_controller_test.rb@@ -761,6 +761,39 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTestassert_equal [ tag.id ], child.reload.entryable.tag_idsend+ test "split child drawer lets the user change category and merchant but not the name" do+ parent = create_transaction(account: accounts(:depository), amount: 100)+ parent.split!([ { name: "Part 1", amount: 60, category_id: nil }, { name: "Part 2", amount: 40, category_id: nil } ])+ child = parent.child_entries.first++ get transaction_url(child), headers: { "Turbo-Frame" => "drawer" }++ assert_response :success+ assert_select "[data-category-select-disabled-value='false']", count: 1+ assert_select "[data-merchant-select-disabled-value='false']", count: 1+ assert_select "input[name='entry[name]'][disabled]", count: 1+ end++ test "category and merchant changed on a split child are kept and locked" do+ parent = create_transaction(account: accounts(:depository), amount: 100, merchant: merchants(:amazon))+ parent.split!([ { name: "Part 1", amount: 60, category_id: nil }, { name: "Part 2", amount: 40, category_id: nil } ])+ child = parent.child_entries.find_by(name: "Part 1")+ sibling = parent.child_entries.find_by(name: "Part 2")++ patch transaction_url(child), params: {+ entry: { entryable_attributes: { id: child.entryable_id, category_id: categories(:food_and_drink).id, merchant_id: merchants(:netflix).id } }+ }++ assert_response :redirect+ transaction = child.reload.entryable+ assert_equal categories(:food_and_drink), transaction.category+ assert_equal merchants(:netflix), transaction.merchant+ assert transaction.locked?(:category_id)+ assert transaction.locked?(:merchant_id)+ assert_equal merchants(:amazon), parent.reload.entryable.merchant+ assert_equal merchants(:amazon), sibling.reload.entryable.merchant+ end+test "can update tags through tag-only endpoint" dopatch tags_transaction_url(@entry, format: :json), params: {tag_ids: [ tags(:one).id, tags(:two).id ]