The personal finance app for everyone (by everyone)
Ruby
Fix category ordering in the merge dialog (#3471)
Shibu Medf65e2ed7f5
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rbindex a035bcd439..53895c6414 100644--- a/app/controllers/categories_controller.rb+++ b/app/controllers/categories_controller.rb@@ -20,7 +20,7 @@ class CategoriesController < ApplicationControllerenddef merge- @categories = Current.family.categories.alphabetically+ @categories = Current.family.categories.alphabetically_by_hierarchyrender layout: turbo_frame_request? ? false : "settings"enddiff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rbindex a12bef6d09..17f4af0230 100644--- a/test/controllers/categories_controller_test.rb+++ b/test/controllers/categories_controller_test.rb@@ -184,6 +184,37 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTestassert_select "dialog"end+ test "merge orders subcategories immediately after their parent" do+ parent = @family.categories.create!(+ name: "Zoo",+ color: "#000000",+ lucide_icon: "folder"+ )+ child = @family.categories.create!(+ name: "Apple",+ color: "#111111",+ lucide_icon: "folder",+ parent: parent+ )++ get merge_categories_path++ assert_response :success++ form = Nokogiri::HTML(response.body).at_css("form[action='#{perform_merge_categories_path}']")+ assert_not_nil form++ category_ids = form.css("[data-select-target='option']").map { |option| option["data-value"] }+ source_ids = form.css("input[name='source_ids[]']").map { |input| input["value"] }+ parent_index = category_ids.index(parent.id)+ child_index = category_ids.index(child.id)++ assert_not_nil parent_index+ assert_not_nil child_index+ assert_equal parent_index + 1, child_index+ assert_equal category_ids, source_ids+ end+test "merge selected categories into an existing category" dotarget = @family.categories.create!(name: "Dining",