mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 23:59:40 +02:00
Move categories to top-level namespace (#894)
This commit is contained in:
parent
a947db92b2
commit
2681dd96b1
48 changed files with 229 additions and 223 deletions
|
@ -1,24 +1,24 @@
|
|||
require "test_helper"
|
||||
|
||||
class Transactions::Categories::DeletionsControllerTest < ActionDispatch::IntegrationTest
|
||||
class Categories::DeletionsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
@category = transaction_categories(:food_and_drink)
|
||||
@category = categories(:food_and_drink)
|
||||
end
|
||||
|
||||
test "new" do
|
||||
get new_transaction_category_deletion_url(@category)
|
||||
get new_category_deletion_url(@category)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "create with replacement" do
|
||||
replacement_category = transaction_categories(:income)
|
||||
replacement_category = categories(:income)
|
||||
|
||||
assert_not_empty @category.transactions
|
||||
|
||||
assert_difference "Transaction::Category.count", -1 do
|
||||
assert_difference "Category.count", -1 do
|
||||
assert_difference "replacement_category.transactions.count", @category.transactions.count do
|
||||
post transaction_category_deletions_url(@category),
|
||||
post category_deletions_url(@category),
|
||||
params: { replacement_category_id: replacement_category.id }
|
||||
end
|
||||
end
|
||||
|
@ -29,9 +29,9 @@ class Transactions::Categories::DeletionsControllerTest < ActionDispatch::Integr
|
|||
test "create without replacement" do
|
||||
assert_not_empty @category.transactions
|
||||
|
||||
assert_difference "Transaction::Category.count", -1 do
|
||||
assert_difference "Category.count", -1 do
|
||||
assert_difference "Transaction.where(category: nil).count", @category.transactions.count do
|
||||
post transaction_category_deletions_url(@category)
|
||||
post category_deletions_url(@category)
|
||||
end
|
||||
end
|
||||
|
73
test/controllers/categories_controller_test.rb
Normal file
73
test/controllers/categories_controller_test.rb
Normal file
|
@ -0,0 +1,73 @@
|
|||
require "test_helper"
|
||||
|
||||
class CategoriesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
end
|
||||
|
||||
test "index" do
|
||||
get categories_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "new" do
|
||||
get new_category_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "create" do
|
||||
color = Category::COLORS.sample
|
||||
|
||||
assert_difference "Category.count", +1 do
|
||||
post categories_url, params: {
|
||||
category: {
|
||||
name: "New Category",
|
||||
color: color } }
|
||||
end
|
||||
|
||||
new_category = Category.order(:created_at).last
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert_equal "New Category", new_category.name
|
||||
assert_equal color, new_category.color
|
||||
end
|
||||
|
||||
test "create and assign to transaction" do
|
||||
color = Category::COLORS.sample
|
||||
|
||||
assert_difference "Category.count", +1 do
|
||||
post categories_url, params: {
|
||||
transaction_id: transactions(:checking_one).id,
|
||||
category: {
|
||||
name: "New Category",
|
||||
color: color } }
|
||||
end
|
||||
|
||||
new_category = Category.order(:created_at).last
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert_equal "New Category", new_category.name
|
||||
assert_equal color, new_category.color
|
||||
assert_equal transactions(:checking_one).reload.category, new_category
|
||||
end
|
||||
|
||||
test "edit" do
|
||||
get edit_category_url(categories(:food_and_drink))
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "update" do
|
||||
new_color = Category::COLORS.without(categories(:income).color).sample
|
||||
|
||||
assert_changes -> { categories(:income).name }, to: "New Name" do
|
||||
assert_changes -> { categories(:income).reload.color }, to: new_color do
|
||||
patch category_url(categories(:income)), params: {
|
||||
category: {
|
||||
name: "New Name",
|
||||
color: new_color } }
|
||||
end
|
||||
end
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
end
|
||||
end
|
|
@ -16,7 +16,7 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test "create seeds default transaction categories" do
|
||||
assert_difference "Transaction::Category.count", Transaction::Category::DEFAULT_CATEGORIES.size do
|
||||
assert_difference "Category.count", Category::DEFAULT_CATEGORIES.size do
|
||||
post registration_url, params: { user: {
|
||||
email: "john@example.com",
|
||||
password: "password",
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
require "test_helper"
|
||||
|
||||
class Transactions::CategoriesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
end
|
||||
|
||||
test "index" do
|
||||
get transaction_categories_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "new" do
|
||||
get new_transaction_category_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "create" do
|
||||
color = Transaction::Category::COLORS.sample
|
||||
|
||||
assert_difference "Transaction::Category.count", +1 do
|
||||
post transaction_categories_url, params: {
|
||||
transaction_category: {
|
||||
name: "New Category",
|
||||
color: color } }
|
||||
end
|
||||
|
||||
new_category = Transaction::Category.order(:created_at).last
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert_equal "New Category", new_category.name
|
||||
assert_equal color, new_category.color
|
||||
end
|
||||
|
||||
test "create and assign to transaction" do
|
||||
color = Transaction::Category::COLORS.sample
|
||||
|
||||
assert_difference "Transaction::Category.count", +1 do
|
||||
post transaction_categories_url, params: {
|
||||
transaction_id: transactions(:checking_one).id,
|
||||
transaction_category: {
|
||||
name: "New Category",
|
||||
color: color } }
|
||||
end
|
||||
|
||||
new_category = Transaction::Category.order(:created_at).last
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert_equal "New Category", new_category.name
|
||||
assert_equal color, new_category.color
|
||||
assert_equal transactions(:checking_one).reload.category, new_category
|
||||
end
|
||||
|
||||
test "edit" do
|
||||
get edit_transaction_category_url(transaction_categories(:food_and_drink))
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "update" do
|
||||
new_color = Transaction::Category::COLORS.without(transaction_categories(:income).color).sample
|
||||
|
||||
assert_changes -> { transaction_categories(:income).name }, to: "New Name" do
|
||||
assert_changes -> { transaction_categories(:income).reload.color }, to: new_color do
|
||||
patch transaction_category_url(transaction_categories(:income)), params: {
|
||||
transaction_category: {
|
||||
name: "New Name",
|
||||
color: new_color } }
|
||||
end
|
||||
end
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
end
|
||||
end
|
|
@ -159,7 +159,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
|||
transactions.each do |transaction|
|
||||
transaction.update! \
|
||||
excluded: false,
|
||||
category_id: Transaction::Category.first.id,
|
||||
category_id: Category.first.id,
|
||||
merchant_id: Transaction::Merchant.first.id,
|
||||
notes: "Starting note"
|
||||
end
|
||||
|
@ -169,7 +169,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
|||
date: Date.current,
|
||||
transaction_ids: transactions.map(&:id),
|
||||
excluded: true,
|
||||
category_id: Transaction::Category.second.id,
|
||||
category_id: Category.second.id,
|
||||
merchant_id: Transaction::Merchant.second.id,
|
||||
notes: "Updated note"
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
|||
transactions.reload.each do |transaction|
|
||||
assert_equal Date.current, transaction.date
|
||||
assert transaction.excluded
|
||||
assert_equal Transaction::Category.second, transaction.category
|
||||
assert_equal Category.second, transaction.category
|
||||
assert_equal Transaction::Merchant.second, transaction.merchant
|
||||
assert_equal "Updated note", transaction.notes
|
||||
end
|
||||
|
|
|
@ -1,50 +1,50 @@
|
|||
require "test_helper"
|
||||
|
||||
class Transaction::CategoryTest < ActiveSupport::TestCase
|
||||
class CategoryTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@family = families(:dylan_family)
|
||||
end
|
||||
|
||||
test "create_default_categories should generate categories if none exist" do
|
||||
@family.accounts.destroy_all
|
||||
@family.transaction_categories.destroy_all
|
||||
assert_difference "Transaction::Category.count", Transaction::Category::DEFAULT_CATEGORIES.size do
|
||||
Transaction::Category.create_default_categories(@family)
|
||||
@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
|
||||
Transaction::Category.create_default_categories(@family)
|
||||
Category.create_default_categories(@family)
|
||||
end
|
||||
end
|
||||
|
||||
test "updating name should clear the internal_category field" do
|
||||
category = Transaction::Category.take
|
||||
category = Category.take
|
||||
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 = Transaction::Category.take
|
||||
category = Category.take
|
||||
assert_no_changes "category.reload.internal_category" do
|
||||
category.update_attribute(:color, "#000")
|
||||
end
|
||||
end
|
||||
|
||||
test "replacing and destroying" do
|
||||
transctions = transaction_categories(:food_and_drink).transactions.to_a
|
||||
transctions = categories(:food_and_drink).transactions.to_a
|
||||
|
||||
transaction_categories(:food_and_drink).replace_and_destroy!(transaction_categories(:income))
|
||||
categories(:food_and_drink).replace_and_destroy!(categories(:income))
|
||||
|
||||
assert_equal transaction_categories(:income), transactions.map { |t| t.reload.category }.uniq.first
|
||||
assert_equal categories(:income), transactions.map { |t| t.reload.category }.uniq.first
|
||||
end
|
||||
|
||||
test "replacing with nil should nullify the category" do
|
||||
transactions = transaction_categories(:food_and_drink).transactions.to_a
|
||||
transactions = categories(:food_and_drink).transactions.to_a
|
||||
|
||||
transaction_categories(:food_and_drink).replace_and_destroy!(nil)
|
||||
categories(:food_and_drink).replace_and_destroy!(nil)
|
||||
|
||||
assert_nil transactions.map { |t| t.reload.category }.uniq.first
|
||||
end
|
|
@ -33,7 +33,7 @@ class FamilyTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test "should destroy dependent transaction categories" do
|
||||
assert_difference("Transaction::Category.count", -@family.transaction_categories.count) do
|
||||
assert_difference("Category.count", -@family.categories.count) do
|
||||
@family.destroy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,7 +46,7 @@ class ImportTest < ActiveSupport::TestCase
|
|||
# "Shopping" is a new category, but should only be created 1x during import
|
||||
assert_difference \
|
||||
-> { Transaction.count } => 4,
|
||||
-> { Transaction::Category.count } => 1,
|
||||
-> { Category.count } => 1,
|
||||
-> { Tagging.count } => 4,
|
||||
-> { Tag.count } => 2 do
|
||||
@loaded_import.publish
|
||||
|
@ -59,7 +59,7 @@ class ImportTest < ActiveSupport::TestCase
|
|||
|
||||
test "publishes a valid import with missing data" do
|
||||
@empty_import.update! raw_csv_str: valid_csv_with_missing_data
|
||||
assert_difference -> { Transaction::Category.count } => 1, -> { Transaction.count } => 2 do
|
||||
assert_difference -> { Category.count } => 1, -> { Transaction.count } => 2 do
|
||||
@empty_import.publish
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class SettingsTest < ApplicationSystemTestCase
|
|||
[ "Billing", "Billing", settings_billing_path ],
|
||||
[ "Accounts", "Accounts", accounts_path ],
|
||||
[ "Tags", "Tags", tags_path ],
|
||||
[ "Categories", "Categories", transaction_categories_path ],
|
||||
[ "Categories", "Categories", categories_path ],
|
||||
[ "Merchants", "Merchants", transaction_merchants_path ],
|
||||
[ "Rules", "Rules", transaction_rules_path ],
|
||||
[ "Imports", "Imports", imports_path ],
|
||||
|
|
|
@ -5,7 +5,7 @@ class TransactionsTest < ApplicationSystemTestCase
|
|||
sign_in @user = users(:family_admin)
|
||||
|
||||
@latest_transactions = @user.family.transactions.ordered.limit(20).to_a
|
||||
@test_category = @user.family.transaction_categories.create! name: "System Test Category"
|
||||
@test_category = @user.family.categories.create! name: "System Test Category"
|
||||
@test_merchant = @user.family.transaction_merchants.create! name: "System Test Merchant"
|
||||
@target_txn = @user.family.accounts.first.transactions.create! \
|
||||
name: "Oldest transaction",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue