mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-26 00:29:40 +02:00
Nested Categories (#1561)
* Prepare entry search for nested categories * Subcategory implementation * Remove caching for test stability
This commit is contained in:
parent
a4d10097d5
commit
77def1db40
31 changed files with 297 additions and 234 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue