1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00

Move categories to top-level namespace (#894)

This commit is contained in:
Zach Gollwitzer 2024-06-20 08:15:09 -04:00 committed by GitHub
parent a947db92b2
commit 2681dd96b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 229 additions and 223 deletions

View 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