mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-21 14:19:39 +02:00
* feat: add validation to require consistent category color * feat: reflect color requirement in new category form * refactor: move logic inline over shared component * rubocop * tests: fix breaking and add case for new validation * feat: hide color selector when parent category selected * feat: override color with parent color in model * tests: remove case for unnecessary validation --------- Signed-off-by: Julien Bertazzo Lambert <42924425+JLambertazzo@users.noreply.github.com>
33 lines
1,018 B
Ruby
33 lines
1,018 B
Ruby
require "test_helper"
|
|
|
|
class CategoryTest < ActiveSupport::TestCase
|
|
def setup
|
|
@family = families(:dylan_family)
|
|
end
|
|
|
|
test "replacing and destroying" do
|
|
transactions = categories(:food_and_drink).transactions.to_a
|
|
|
|
categories(:food_and_drink).replace_and_destroy!(categories(:income))
|
|
|
|
assert_equal categories(:income), transactions.map { |t| t.reload.category }.uniq.first
|
|
end
|
|
|
|
test "replacing with nil should nullify the category" do
|
|
transactions = categories(:food_and_drink).transactions.to_a
|
|
|
|
categories(:food_and_drink).replace_and_destroy!(nil)
|
|
|
|
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", family: @family)
|
|
end
|
|
|
|
assert_equal "Validation failed: Parent can't have more than 2 levels of subcategories", error.message
|
|
end
|
|
end
|