mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 07:39:39 +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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue