mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +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
|
@ -28,7 +28,7 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest
|
|||
|
||||
new_category = Category.order(:created_at).last
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert_redirected_to categories_url
|
||||
assert_equal "New Category", new_category.name
|
||||
assert_equal color, new_category.color
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest
|
|||
|
||||
new_category = Category.order(:created_at).last
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert_redirected_to categories_url
|
||||
assert_equal "New Category", new_category.name
|
||||
assert_equal color, new_category.color
|
||||
assert_equal @transaction.reload.category, new_category
|
||||
|
@ -69,6 +69,14 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert_redirected_to categories_url
|
||||
end
|
||||
|
||||
test "bootstrap" do
|
||||
assert_difference "Category.count", 16 do
|
||||
post bootstrap_categories_url
|
||||
end
|
||||
|
||||
assert_redirected_to categories_url
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,15 +15,6 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_redirected_to root_url
|
||||
end
|
||||
|
||||
test "create seeds default transaction categories" do
|
||||
assert_difference "Category.count", Category::DEFAULT_CATEGORIES.size do
|
||||
post registration_url, params: { user: {
|
||||
email: "john@example.com",
|
||||
password: "password",
|
||||
password_confirmation: "password" } }
|
||||
end
|
||||
end
|
||||
|
||||
test "create when hosted requires an invite code" do
|
||||
with_env_overrides REQUIRE_INVITE_CODE: "true" do
|
||||
assert_no_difference "User.count" do
|
||||
|
|
7
test/fixtures/categories.yml
vendored
7
test/fixtures/categories.yml
vendored
|
@ -4,11 +4,14 @@ one:
|
|||
|
||||
income:
|
||||
name: Income
|
||||
internal_category: income
|
||||
color: "#fd7f6f"
|
||||
family: dylan_family
|
||||
|
||||
food_and_drink:
|
||||
name: Food & Drink
|
||||
internal_category: food_and_drink
|
||||
family: dylan_family
|
||||
|
||||
subcategory:
|
||||
name: Restaurants
|
||||
parent: food_and_drink
|
||||
family: dylan_family
|
||||
|
|
|
@ -63,10 +63,6 @@ class Account::EntryTest < ActiveSupport::TestCase
|
|||
|
||||
assert_equal 2, family.entries.search(params).size
|
||||
|
||||
params = params.merge(categories: [ category.name ], merchants: [ merchant.name ]) # transaction specific search param
|
||||
|
||||
assert_equal 1, family.entries.search(params).size
|
||||
|
||||
params = { search: "%" }
|
||||
assert_equal 0, family.entries.search(params).size
|
||||
end
|
||||
|
|
|
@ -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