1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-26 00:29:40 +02:00

Nested Categories (#1561)
Some checks failed
Publish Docker image / ci (push) Has been cancelled
Publish Docker image / Build docker image (push) Has been cancelled

* Prepare entry search for nested categories

* Subcategory implementation

* Remove caching for test stability
This commit is contained in:
Zach Gollwitzer 2024-12-20 11:37:26 -05:00 committed by GitHub
parent a4d10097d5
commit 77def1db40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 297 additions and 234 deletions

View file

@ -5,34 +5,6 @@ class CategoryTest < ActiveSupport::TestCase
@family = families(:dylan_family)
end
test "create_default_categories should generate categories if none exist" do
@family.accounts.destroy_all
@family.categories.destroy_all
assert_difference "Category.count", Category::DEFAULT_CATEGORIES.size do
Category.create_default_categories(@family)
end
end
test "create_default_categories should raise when there are existing categories" do
assert_raises(ArgumentError) do
Category.create_default_categories(@family)
end
end
test "updating name should clear the internal_category field" do
category = categories(:income)
assert_changes "category.reload.internal_category", to: nil do
category.update_attribute(:name, "new name")
end
end
test "updating other field than name should not clear the internal_category field" do
category = Category.take
assert_no_changes "category.reload.internal_category" do
category.update_attribute(:color, "#000")
end
end
test "replacing and destroying" do
transactions = categories(:food_and_drink).transactions.to_a
@ -48,4 +20,14 @@ class CategoryTest < ActiveSupport::TestCase
assert_nil transactions.map { |t| t.reload.category }.uniq.first
end
test "subcategory can only be one level deep" do
category = categories(:subcategory)
error = assert_raises(ActiveRecord::RecordInvalid) do
category.subcategories.create!(name: "Invalid category", color: "#000", family: @family)
end
assert_equal "Validation failed: Parent can't have more than 2 levels of subcategories", error.message
end
end