The personal finance app for everyone
Move categories to top-level namespace (#894)
Zach Gollwitzer2681dd96b12d
diff --git a/app/controllers/transactions/categories/deletions_controller.rb b/app/controllers/categories/deletions_controller.rbsimilarity index 60%rename from app/controllers/transactions/categories/deletions_controller.rbrename to app/controllers/categories/deletions_controller.rbindex 3e67a762..678823f2 100644--- a/app/controllers/transactions/categories/deletions_controller.rb+++ b/app/controllers/categories/deletions_controller.rb@@ -1,4 +1,4 @@-class Transactions::Categories::DeletionsController < ApplicationController+class Categories::DeletionsController < ApplicationControllerlayout "with_sidebar"before_action :set_category@@ -15,12 +15,12 @@ class Transactions::Categories::DeletionsController < ApplicationControllerprivatedef set_category- @category = Current.family.transaction_categories.find(params[:category_id])+ @category = Current.family.categories.find(params[:category_id])enddef set_replacement_categoryif params[:replacement_category_id].present?- @replacement_category = Current.family.transaction_categories.find(params[:replacement_category_id])+ @replacement_category = Current.family.categories.find(params[:replacement_category_id])endendenddiff --git a/app/controllers/transactions/categories/dropdowns_controller.rb b/app/controllers/categories/dropdowns_controller.rbsimilarity index 77%rename from app/controllers/transactions/categories/dropdowns_controller.rbrename to app/controllers/categories/dropdowns_controller.rbindex 80654467..3da1bfe6 100644--- a/app/controllers/transactions/categories/dropdowns_controller.rb+++ b/app/controllers/categories/dropdowns_controller.rb@@ -1,4 +1,4 @@-class Transactions::Categories::DropdownsController < ApplicationController+class Categories::DropdownsController < ApplicationControllerbefore_action :set_from_paramsdef show@@ -17,6 +17,6 @@ class Transactions::Categories::DropdownsController < ApplicationControllerenddef categories_scope- Current.family.transaction_categories.alphabetically+ Current.family.categories.alphabeticallyendenddiff --git a/app/controllers/transactions/categories_controller.rb b/app/controllers/categories_controller.rbsimilarity index 58%rename from app/controllers/transactions/categories_controller.rbrename to app/controllers/categories_controller.rbindex 99bcf6fc..dfbe63e4 100644--- a/app/controllers/transactions/categories_controller.rb+++ b/app/controllers/categories_controller.rb@@ -1,20 +1,20 @@-class Transactions::CategoriesController < ApplicationController+class CategoriesController < ApplicationControllerlayout "with_sidebar"before_action :set_category, only: %i[ edit update ]before_action :set_transaction, only: :createdef index- @categories = Current.family.transaction_categories.alphabetically+ @categories = Current.family.categories.alphabeticallyenddef new- @category = Current.family.transaction_categories.new color: Transaction::Category::COLORS.sample+ @category = Current.family.categories.new color: Category::COLORS.sampleenddef create- Transaction::Category.transaction do- category = Current.family.transaction_categories.create!(category_params)+ Category.transaction do+ category = Current.family.categories.create!(category_params)@transaction.update!(category_id: category.id) if @transactionend@@ -32,7 +32,7 @@ class Transactions::CategoriesController < ApplicationControllerprivatedef set_category- @category = Current.family.transaction_categories.find(params[:id])+ @category = Current.family.categories.find(params[:id])enddef set_transaction@@ -42,6 +42,6 @@ class Transactions::CategoriesController < ApplicationControllerenddef category_params- params.require(:transaction_category).permit(:name, :color)+ params.require(:category).permit(:name, :color)endenddiff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rbindex 714fbb5e..3a18477d 100644--- a/app/controllers/registrations_controller.rb+++ b/app/controllers/registrations_controller.rb@@ -16,7 +16,7 @@ class RegistrationsController < ApplicationController@user.role = :adminif @user.save- Transaction::Category.create_default_categories(@user.family)+ Category.create_default_categories(@user.family)login @userflash[:notice] = t(".success")redirect_to root_pathdiff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rbnew file mode 100644index 00000000..83bddbf3--- /dev/null+++ b/app/helpers/categories_helper.rb@@ -0,0 +1,7 @@+module CategoriesHelper+ def null_category+ Category.new \+ name: "Uncategorized",+ color: Category::UNCATEGORIZED_COLOR+ end+enddiff --git a/app/helpers/transactions/categories_helper.rb b/app/helpers/transactions/categories_helper.rbdeleted file mode 100644index 19d77a23..00000000--- a/app/helpers/transactions/categories_helper.rb+++ /dev/null@@ -1,7 +0,0 @@-module Transactions::CategoriesHelper- def null_category- Transaction::Category.new \- name: "Uncategorized",- color: Transaction::Category::UNCATEGORIZED_COLOR- end-enddiff --git a/app/models/transaction/category.rb b/app/models/category.rbsimilarity index 94%rename from app/models/transaction/category.rbrename to app/models/category.rbindex 58955720..b846ca51 100644--- a/app/models/transaction/category.rb+++ b/app/models/category.rb@@ -1,4 +1,4 @@-class Transaction::Category < ApplicationRecord+class Category < ApplicationRecordhas_many :transactions, dependent: :nullifybelongs_to :family@@ -24,7 +24,7 @@ class Transaction::Category < ApplicationRecord]def self.create_default_categories(family)- if family.transaction_categories.size > 0+ if family.categories.size > 0raise ArgumentError, "Family already has some categories"enddiff --git a/app/models/family.rb b/app/models/family.rbindex d7ccafd9..a86980ff 100644--- a/app/models/family.rb+++ b/app/models/family.rb@@ -5,7 +5,7 @@ class Family < ApplicationRecordhas_many :institutions, dependent: :destroyhas_many :transactions, through: :accountshas_many :imports, through: :accounts- has_many :transaction_categories, dependent: :destroy, class_name: "Transaction::Category"+ has_many :categories, dependent: :destroyhas_many :transaction_merchants, dependent: :destroy, class_name: "Transaction::Merchant"def snapshot(period = Period.all)diff --git a/app/models/import.rb b/app/models/import.rbindex cbe93697..49fc4f96 100644--- a/app/models/import.rb+++ b/app/models/import.rb@@ -124,7 +124,7 @@ class Import < ApplicationRecordtags << tag_cache[tag_string] ||= account.family.tags.find_or_initialize_by(name: tag_string)end- category = category_cache[category_name] ||= account.family.transaction_categories.find_or_initialize_by(name: category_name) if category_name.present?+ category = category_cache[category_name] ||= account.family.categories.find_or_initialize_by(name: category_name) if category_name.present?txn = account.transactions.build \name: row["name"].presence || FALLBACK_TRANSACTION_NAME,diff --git a/app/models/transaction.rb b/app/models/transaction.rbindex 1d6b304e..7f534839 100644--- a/app/models/transaction.rb+++ b/app/models/transaction.rb@@ -18,7 +18,7 @@ class Transaction < ApplicationRecordscope :inflows, -> { where("amount <= 0") }scope :outflows, -> { where("amount > 0") }scope :by_name, ->(name) { where("transactions.name ILIKE ?", "%#{name}%") }- scope :with_categories, ->(categories) { joins(:category).where(transaction_categories: { name: categories }) }+ scope :with_categories, ->(categories) { joins(:category).where(categories: { name: categories }) }scope :with_accounts, ->(accounts) { joins(:account).where(accounts: { name: accounts }) }scope :with_account_ids, ->(account_ids) { joins(:account).where(accounts: { id: account_ids }) }scope :with_merchants, ->(merchants) { joins(:merchant).where(transaction_merchants: { name: merchants }) }diff --git a/app/views/accounts/transactions/_transaction.html.erb b/app/views/accounts/transactions/_transaction.html.erbindex 5adc5817..e725c818 100644--- a/app/views/accounts/transactions/_transaction.html.erb+++ b/app/views/accounts/transactions/_transaction.html.erb@@ -10,7 +10,7 @@<p>Transfer</p></div><% else %>- <%= render "transactions/categories/badge", category: transaction.category %>+ <%= render "categories/badge", category: transaction.category %><% end %></div>diff --git a/app/views/transactions/categories/_badge.html.erb b/app/views/categories/_badge.html.erbsimilarity index 100%rename from app/views/transactions/categories/_badge.html.erbrename to app/views/categories/_badge.html.erbdiff --git a/app/views/transactions/categories/_form.html.erb b/app/views/categories/_form.html.erbsimilarity index 96%rename from app/views/transactions/categories/_form.html.erbrename to app/views/categories/_form.html.erbindex 0e12b4e7..b5fba349 100644--- a/app/views/transactions/categories/_form.html.erb+++ b/app/views/categories/_form.html.erb@@ -14,7 +14,7 @@<%= form.hidden_field :color, data: { color_select_target: "input" } %><ul role="radiogroup" class="flex justify-between items-center py-2">- <% Transaction::Category::COLORS.each do |color| %>+ <% Category::COLORS.each do |color| %><li tabindex="0"role="radio"data-action="click->color-select#select keydown.enter->color-select#select keydown.space->color-select#select"diff --git a/app/views/transactions/categories/_menu.html.erb b/app/views/categories/_menu.html.erbsimilarity index 67%rename from app/views/transactions/categories/_menu.html.erbrename to app/views/categories/_menu.html.erbindex a4c6d724..6c632596 100644--- a/app/views/transactions/categories/_menu.html.erb+++ b/app/views/categories/_menu.html.erb@@ -1,11 +1,11 @@<%# locals: (transaction:) %><div class="relative" data-controller="menu"><button data-menu-target="button" class="flex cursor-pointer">- <%= render partial: "transactions/categories/badge", locals: { category: transaction.category } %>+ <%= render partial: "categories/badge", locals: { category: transaction.category } %></button><div data-menu-target="content" class="absolute z-10 hidden w-screen mt-2 max-w-min cursor-default"><div class="w-64 text-sm font-semibold leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">- <%= turbo_frame_tag "category_dropdown", src: transaction_category_dropdown_path(category_id: transaction.category_id, transaction_id: transaction.id), loading: :lazy do %>+ <%= turbo_frame_tag "category_dropdown", src: category_dropdown_path(category_id: transaction.category_id, transaction_id: transaction.id), loading: :lazy do %><div class="p-6 flex items-center justify-center"><p class="text-sm text-gray-500 animate-pulse"><%= t(".loading") %></p></div>diff --git a/app/views/transactions/categories/_row.html.erb b/app/views/categories/_row.html.erbsimilarity index 80%rename from app/views/transactions/categories/_row.html.erbrename to app/views/categories/_row.html.erbindex b724f746..ba2aea0b 100644--- a/app/views/transactions/categories/_row.html.erb+++ b/app/views/categories/_row.html.erb@@ -1,9 +1,9 @@<div class="flex justify-between mx-4 py-5 border-b last:border-b-0 border-alpha-black-50">- <%= render partial: "transactions/categories/badge", locals: { category: row } %>+ <%= render partial: "categories/badge", locals: { category: row } %><%= contextual_menu do %><div class="w-48 p-1 text-sm leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">- <%= link_to edit_transaction_category_path(row),+ <%= link_to edit_category_path(row),class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg",data: { turbo_frame: :modal } do %><%= lucide_icon "pencil-line", class: "w-5 h-5 text-gray-500" %>@@ -11,7 +11,7 @@<span><%= t(".edit") %></span><% end %>- <%= link_to new_transaction_category_deletion_path(row),+ <%= link_to new_category_deletion_path(row),class: "block w-full py-2 px-3 space-x-2 text-red-600 hover:bg-red-50 flex items-center rounded-lg",data: { turbo_frame: :modal } do %><%= lucide_icon "trash-2", class: "w-5 h-5" %>diff --git a/app/views/transactions/categories/deletions/new.html.erb b/app/views/categories/deletions/new.html.erbsimilarity index 90%rename from app/views/transactions/categories/deletions/new.html.erbrename to app/views/categories/deletions/new.html.erbindex 9a86ed1c..53981162 100644--- a/app/views/transactions/categories/deletions/new.html.erb+++ b/app/views/categories/deletions/new.html.erb@@ -11,7 +11,7 @@</p></div>- <%= form_with url: transaction_category_deletions_path(@category),+ <%= form_with url: category_deletions_path(@category),data: {turbo: false,controller: "deletion",@@ -20,7 +20,7 @@deletion_submit_text_when_not_replacing_value: t(".delete_and_leave_uncategorized", category_name: @category.name),deletion_submit_text_when_replacing_value: t(".delete_and_recategorize", category_name: @category.name) } do |f| %><%= f.collection_select :replacement_category_id,- Current.family.transaction_categories.alphabetically.without(@category),+ Current.family.categories.alphabetically.without(@category),:id, :name,{ prompt: t(".replacement_category_prompt"), label: t(".category") },{ data: { deletion_target: "replacementField", action: "deletion#updateSubmitButton" } } %>diff --git a/app/views/transactions/categories/dropdowns/_row.html.erb b/app/views/categories/dropdowns/_row.html.erbsimilarity index 86%rename from app/views/transactions/categories/dropdowns/_row.html.erbrename to app/views/categories/dropdowns/_row.html.erbindex 8092ce39..44d47fef 100644--- a/app/views/transactions/categories/dropdowns/_row.html.erb+++ b/app/views/categories/dropdowns/_row.html.erb@@ -6,12 +6,12 @@<span class="w-5 h-5"><%= lucide_icon("check", class: "w-5 h-5 text-gray-500") if is_selected %></span>- <%= render partial: "transactions/categories/badge", locals: { category: category } %>+ <%= render partial: "categories/badge", locals: { category: category } %><% end %><%= contextual_menu do %><div class="w-48 p-1 text-sm leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">- <%= link_to edit_transaction_category_path(category),+ <%= link_to edit_category_path(category),class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg",data: { turbo_frame: :modal } do %><%= lucide_icon "pencil-line", class: "w-5 h-5 text-gray-500" %>@@ -19,7 +19,7 @@<span><%= t(".edit") %></span><% end %>- <%= link_to new_transaction_category_deletion_path(category),+ <%= link_to new_category_deletion_path(category),class: "block w-full py-2 px-3 space-x-2 text-red-600 hover:bg-red-50 flex items-center rounded-lg",data: { turbo_frame: :modal } do %><%= lucide_icon "trash-2", class: "w-5 h-5" %>diff --git a/app/views/transactions/categories/dropdowns/show.html.erb b/app/views/categories/dropdowns/show.html.erbsimilarity index 91%rename from app/views/transactions/categories/dropdowns/show.html.erbrename to app/views/categories/dropdowns/show.html.erbindex b36926d6..098e00e8 100644--- a/app/views/transactions/categories/dropdowns/show.html.erb+++ b/app/views/categories/dropdowns/show.html.erb@@ -11,12 +11,12 @@<%= t(".no_categories") %></div><% @categories.each do |category| %>- <%= render partial: "transactions/categories/dropdowns/row", locals: { category: } %>+ <%= render partial: "categories/dropdowns/row", locals: { category: } %><% end %></div><hr><div class="relative p-1.5 w-full">- <%= link_to new_transaction_category_path(transaction_id: @transaction),+ <%= link_to new_category_path(transaction_id: @transaction),class: "flex text-sm font-medium items-center gap-2 text-gray-500 w-full rounded-lg p-2 hover:bg-gray-100",data: { turbo_frame: "modal" } do %><%= lucide_icon "plus", class: "w-5 h-5" %>diff --git a/app/views/transactions/categories/edit.html.erb b/app/views/categories/edit.html.erbsimilarity index 100%rename from app/views/transactions/categories/edit.html.erbrename to app/views/categories/edit.html.erbdiff --git a/app/views/transactions/categories/index.html.erb b/app/views/categories/index.html.erbsimilarity index 75%rename from app/views/transactions/categories/index.html.erbrename to app/views/categories/index.html.erbindex 10c8674a..29a2a12c 100644--- a/app/views/transactions/categories/index.html.erb+++ b/app/views/categories/index.html.erb@@ -5,7 +5,7 @@<header class="flex items-center justify-between"><h1 class="text-gray-900 text-xl font-medium"><%= t(".categories") %></h1>- <%= link_to new_transaction_category_path, class: "rounded-lg bg-gray-900 text-white flex items-center gap-1 justify-center hover:bg-gray-700 px-3 py-2", data: { turbo_frame: :modal } do %>+ <%= link_to new_category_path, class: "rounded-lg bg-gray-900 text-white flex items-center gap-1 justify-center hover:bg-gray-700 px-3 py-2", data: { turbo_frame: :modal } do %><%= lucide_icon "plus", class: "w-5 h-5" %><p><%= t(".new") %></p><% end %>@@ -16,7 +16,7 @@<h2 class="uppercase px-4 py-2 text-gray-500 text-xs"><%= t(".categories") %> · <%= @categories.size %></h2><div class="border border-alpha-gray-100 rounded-lg bg-white shadow-xs">- <%= render collection: @categories, partial: "transactions/categories/row" %>+ <%= render collection: @categories, partial: "categories/row" %></div></div></div>diff --git a/app/views/transactions/categories/new.html.erb b/app/views/categories/new.html.erbsimilarity index 100%rename from app/views/transactions/categories/new.html.erbrename to app/views/categories/new.html.erbdiff --git a/app/views/imports/transactions/_transaction.html.erb b/app/views/imports/transactions/_transaction.html.erbindex a467c3c3..d3594222 100644--- a/app/views/imports/transactions/_transaction.html.erb+++ b/app/views/imports/transactions/_transaction.html.erb@@ -5,7 +5,7 @@</div><div class="col-span-2">- <%= render partial: "transactions/categories/badge", locals: { category: transaction.category } %>+ <%= render partial: "categories/badge", locals: { category: transaction.category } %></div><div class="col-span-2 flex items-center gap-1">diff --git a/app/views/settings/_nav.html.erb b/app/views/settings/_nav.html.erbindex 9c93f1e2..355ff63c 100644--- a/app/views/settings/_nav.html.erb+++ b/app/views/settings/_nav.html.erb@@ -50,7 +50,7 @@<%= sidebar_link_to t(".tags_label"), tags_path, icon: "tags" %></li><li>- <%= sidebar_link_to t(".categories_label"), transaction_categories_path, icon: "tags" %>+ <%= sidebar_link_to t(".categories_label"), categories_path, icon: "tags" %></li><li><%= sidebar_link_to t(".merchants_label"), transaction_merchants_path, icon: "store" %>diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erbindex 0b43104c..6f28d6f5 100644--- a/app/views/tags/index.html.erb+++ b/app/views/tags/index.html.erb@@ -44,6 +44,6 @@<footer class="flex justify-between gap-4"><%= previous_setting("Accounts", accounts_path) %>- <%= next_setting("Categories", transaction_categories_path) %>+ <%= next_setting("Categories", categories_path) %></footer></section>diff --git a/app/views/transactions/_form.html.erb b/app/views/transactions/_form.html.erbindex 2cd52e18..4839772e 100644--- a/app/views/transactions/_form.html.erb+++ b/app/views/transactions/_form.html.erb@@ -14,7 +14,7 @@<%= f.text_field :name, label: t(".description"), placeholder: t(".description_placeholder"), required: true %><%= f.collection_select :account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".account_prompt"), label: t(".account") }, required: true %><%= f.money_field :amount_money, label: t(".amount"), required: true %>- <%= f.collection_select :category_id, Current.family.transaction_categories.alphabetically, :id, :name, { prompt: t(".category_prompt"), label: t(".category") } %>+ <%= f.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_prompt"), label: t(".category") } %><%= f.date_field :date, label: t(".date"), required: true, max: Date.today %></section>diff --git a/app/views/transactions/_header.html.erb b/app/views/transactions/_header.html.erbindex f34690b8..737c83cd 100644--- a/app/views/transactions/_header.html.erb+++ b/app/views/transactions/_header.html.erb@@ -4,7 +4,7 @@<div class="flex items-center gap-2"><%= contextual_menu do %><div class="w-48 p-1 text-sm leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">- <%= link_to transaction_categories_path,+ <%= link_to categories_path,class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg font-normal" do %><%= lucide_icon "tags", class: "w-5 h-5 text-gray-500" %><span class="text-black"><%= t(".edit_categories") %></span>diff --git a/app/views/transactions/_transaction.html.erb b/app/views/transactions/_transaction.html.erbindex c824cee0..98f49c81 100644--- a/app/views/transactions/_transaction.html.erb+++ b/app/views/transactions/_transaction.html.erb@@ -28,7 +28,7 @@<% unless unconfirmed_transfer?(transaction) %><div class="col-span-3">- <%= render "transactions/categories/menu", transaction: transaction %>+ <%= render "categories/menu", transaction: transaction %></div><%= link_to transaction.account.name,diff --git a/app/views/transactions/bulk_edit.html.erb b/app/views/transactions/bulk_edit.html.erbindex d3b383f1..1c10cd8a 100644--- a/app/views/transactions/bulk_edit.html.erb+++ b/app/views/transactions/bulk_edit.html.erb@@ -28,7 +28,7 @@<div class="pb-6 space-y-2"><%= form.date_field :date, label: t(".date_label"), max: Date.current %>- <%= form.collection_select :category_id, Current.family.transaction_categories.alphabetically, :id, :name, { prompt: t(".category_placeholder"), label: t(".category_label"), class: "text-gray-400" } %>+ <%= form.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_placeholder"), label: t(".category_label"), class: "text-gray-400" } %><%= form.collection_select :merchant_id, Current.family.transaction_merchants.alphabetically, :id, :name, { prompt: t(".merchant_placeholder"), label: t(".merchant_label"), class: "text-gray-400" } %></div></details>diff --git a/app/views/transactions/merchants/index.html.erb b/app/views/transactions/merchants/index.html.erbindex f26bdfc2..1dd8162d 100644--- a/app/views/transactions/merchants/index.html.erb+++ b/app/views/transactions/merchants/index.html.erb@@ -32,7 +32,7 @@<% end %></div><div class="flex justify-between gap-4">- <%= previous_setting("Categories", transaction_categories_path) %>+ <%= previous_setting("Categories", categories_path) %><%= next_setting("Rules", transaction_rules_path) %></div></div>diff --git a/app/views/transactions/searches/filters/_category_filter.html.erb b/app/views/transactions/searches/filters/_category_filter.html.erbindex a2f691ba..60e3a05c 100644--- a/app/views/transactions/searches/filters/_category_filter.html.erb+++ b/app/views/transactions/searches/filters/_category_filter.html.erb@@ -5,18 +5,18 @@<%= lucide_icon("search", class: "w-5 h-5 text-gray-500 absolute inset-y-0 left-2 top-1/2 transform -translate-y-1/2") %></div><div class="my-2" id="list" data-list-filter-target="list">- <% Current.family.transaction_categories.alphabetically.each do |transaction_category| %>- <div class="filterable-item flex items-center gap-2 p-2" data-filter-name="<%= transaction_category.name %>">+ <% Current.family.categories.alphabetically.each do |category| %>+ <div class="filterable-item flex items-center gap-2 p-2" data-filter-name="<%= category.name %>"><%= form.check_box :categories,{multiple: true,- checked: @q[:categories]&.include?(transaction_category.name),+ checked: @q[:categories]&.include?(category.name),class: "rounded-sm border-gray-300 text-indigo-600 shadow-xs focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"},- transaction_category.name,+ category.name,nil %>- <%= form.label :categories, transaction_category.name, value: transaction_category.name, class: "text-sm text-gray-900 cursor-pointer" do %>- <%= render partial: "transactions/categories/badge", locals: { category: transaction_category } %>+ <%= form.label :categories, category.name, value: category.name, class: "text-sm text-gray-900 cursor-pointer" do %>+ <%= render partial: "categories/badge", locals: { category: category } %><% end %></div><% end %>diff --git a/app/views/transactions/show.html.erb b/app/views/transactions/show.html.erbindex 6fc355d1..fe49b650 100644--- a/app/views/transactions/show.html.erb+++ b/app/views/transactions/show.html.erb@@ -29,7 +29,7 @@<%= f.date_field :date, label: t(".date_label"), max: Date.today, "data-auto-submit-form-target": "auto" %><% unless @transaction.marked_as_transfer %>- <%= f.collection_select :category_id, Current.family.transaction_categories.alphabetically, :id, :name, { prompt: t(".category_placeholder"), label: t(".category_label"), class: "text-gray-400" }, "data-auto-submit-form-target": "auto" %>+ <%= f.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_placeholder"), label: t(".category_label"), class: "text-gray-400" }, "data-auto-submit-form-target": "auto" %><%= f.collection_select :merchant_id, Current.family.transaction_merchants.alphabetically, :id, :name, { prompt: t(".merchant_placeholder"), label: t(".merchant_label"), class: "text-gray-400" }, "data-auto-submit-form-target": "auto" %><% end %>diff --git a/config/locales/views/categories/en.yml b/config/locales/views/categories/en.ymlnew file mode 100644index 00000000..9451094a--- /dev/null+++ b/config/locales/views/categories/en.yml@@ -0,0 +1,43 @@+---+en:+ categories:+ create:+ success: New transaction category created successfully+ deletions:+ create:+ success: Transaction category deleted successfully+ new:+ category: Category+ delete_and_leave_uncategorized: Delete "%{category_name}" and leave uncategorized+ delete_and_recategorize: Delete "%{category_name}" and assign new category+ delete_category: Delete category?+ explanation: By deleting this category, every transaction that has the "%{category_name}"+ category will be uncategorized. Instead of leaving them uncategorized, you+ can also assign a new category below.+ replacement_category_prompt: Select category+ dropdowns:+ row:+ delete: Delete category+ edit: Edit category+ show:+ add_new: Add new+ clear: Clear+ no_categories: No categories found+ search_placeholder: Search+ edit:+ edit: Edit category+ form:+ create: Create category+ update: Update+ index:+ categories: Categories+ new: New+ menu:+ loading: Loading...+ new:+ new_category: New category+ row:+ delete: Delete category+ edit: Edit category+ update:+ success: Transaction category updated successfullydiff --git a/config/locales/views/transactions/en.yml b/config/locales/views/transactions/en.ymlindex 8b5e7e53..b74298d4 100644--- a/config/locales/views/transactions/en.yml+++ b/config/locales/views/transactions/en.yml@@ -22,47 +22,6 @@ en:bulk_update:failure: Could not update transactionssuccess: "%{count} transactions updated"- categories:- create:- success: New transaction category created successfully- deletions:- create:- success: Transaction category deleted successfully- new:- category: Category- delete_and_leave_uncategorized: Delete "%{category_name}" and leave uncategorized- delete_and_recategorize: Delete "%{category_name}" and assign new category- delete_category: Delete category?- explanation: By deleting this category, every transaction that has the "%{category_name}"- category will be uncategorized. Instead of leaving them uncategorized,- you can also assign a new category below.- replacement_category_prompt: Select category- dropdowns:- row:- delete: Delete category- edit: Edit category- show:- add_new: Add new- clear: Clear- no_categories: No categories found- search_placeholder: Search- edit:- edit: Edit category- form:- create: Create category- update: Update- index:- categories: Categories- new: New- menu:- loading: Loading...- new:- new_category: New category- row:- delete: Delete category- edit: Edit category- update:- success: Transaction category updated successfullycreate:success: New transaction created successfullydestroy:diff --git a/config/routes.rb b/config/routes.rbindex 66ca561e..a1f98f7e 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -41,6 +41,13 @@ Rails.application.routes.draw doresources :deletions, only: %i[ new create ], module: :tagsend+ resources :categories do+ resources :deletions, only: %i[ new create ], module: :categories+ collection do+ resource :dropdown, only: :show, module: :categories, as: :category_dropdown+ end+ end+resources :transactions docollection dopost "bulk_delete"@@ -51,14 +58,6 @@ Rails.application.routes.draw doscope module: :transactions, as: :transaction doresources :rows, only: %i[ show update ]-- resources :categories do- resources :deletions, only: %i[ new create ], module: :categories- collection do- resource :dropdown, only: :show, module: :categories, as: :category_dropdown- end- end-resources :rules, only: %i[ index ]resources :merchants, only: %i[ index new create edit update destroy ]enddiff --git a/db/migrate/20240620114307_rename_categories_table.rb b/db/migrate/20240620114307_rename_categories_table.rbnew file mode 100644index 00000000..0a6231bd--- /dev/null+++ b/db/migrate/20240620114307_rename_categories_table.rb@@ -0,0 +1,5 @@+class RenameCategoriesTable < ActiveRecord::Migration[7.2]+ def change+ rename_table :transaction_categories, :categories+ end+enddiff --git a/db/schema.rb b/db/schema.rbindex 0f06cf85..1a40956f 100644--- a/db/schema.rb+++ b/db/schema.rb@@ -10,7 +10,7 @@## It's strongly recommended that you check this file into your version control system.-ActiveRecord::Schema[7.2].define(version: 2024_06_19_125949) do+ActiveRecord::Schema[7.2].define(version: 2024_06_20_114307) do# These are extensions that must be enabled in order to support this databaseenable_extension "pgcrypto"enable_extension "plpgsql"@@ -48,7 +48,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_19_125949) dot.jsonb "sync_errors", default: [], null: falset.date "last_sync_date"t.uuid "institution_id"- t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY ((ARRAY['Loan'::character varying, 'CreditCard'::character varying, 'OtherLiability'::character varying])::text[])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true+ t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY (ARRAY[('Loan'::character varying)::text, ('CreditCard'::character varying)::text, ('OtherLiability'::character varying)::text])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: truet.index ["accountable_type"], name: "index_accounts_on_accountable_type"t.index ["family_id"], name: "index_accounts_on_family_id"t.index ["institution_id"], name: "index_accounts_on_institution_id"@@ -82,6 +82,16 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_19_125949) dot.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: trueend+ create_table "categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|+ t.string "name", null: false+ t.string "color", default: "#6172F3", null: false+ t.string "internal_category"+ t.uuid "family_id", null: false+ t.datetime "created_at", null: false+ t.datetime "updated_at", null: false+ t.index ["family_id"], name: "index_categories_on_family_id"+ end+create_table "credit_cards", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|t.datetime "created_at", null: falset.datetime "updated_at", null: false@@ -274,16 +284,6 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_19_125949) dot.index ["family_id"], name: "index_tags_on_family_id"end- create_table "transaction_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|- t.string "name", null: false- t.string "color", default: "#6172F3", null: false- t.string "internal_category"- t.uuid "family_id", null: false- t.datetime "created_at", null: false- t.datetime "updated_at", null: false- t.index ["family_id"], name: "index_transaction_categories_on_family_id"- end-create_table "transaction_merchants", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|t.string "name", null: falset.string "color", default: "#e99537", null: false@@ -356,14 +356,14 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_19_125949) doadd_foreign_key "accounts", "institutions"add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"+ add_foreign_key "categories", "families"add_foreign_key "imports", "accounts"add_foreign_key "institutions", "families"add_foreign_key "taggings", "tags"add_foreign_key "tags", "families"- add_foreign_key "transaction_categories", "families"add_foreign_key "transaction_merchants", "families"add_foreign_key "transactions", "accounts", on_delete: :cascade- add_foreign_key "transactions", "transaction_categories", column: "category_id", on_delete: :nullify+ add_foreign_key "transactions", "categories", on_delete: :nullifyadd_foreign_key "transactions", "transaction_merchants", column: "merchant_id"add_foreign_key "transactions", "transfers"add_foreign_key "users", "families"diff --git a/lib/tasks/demo_data.rake b/lib/tasks/demo_data.rakeindex 9893df87..8d7d6e32 100644--- a/lib/tasks/demo_data.rake+++ b/lib/tasks/demo_data.rake@@ -5,10 +5,10 @@ namespace :demo_data dofamily.accounts.delete_allExchangeRate.delete_all- family.transaction_categories.delete_all+ family.categories.delete_allTagging.delete_allfamily.tags.delete_all- Transaction::Category.create_default_categories(family)+ Category.create_default_categories(family)user = User.find_or_create_by(email: "[email protected]") do |u|u.password = "password"diff --git a/test/controllers/transactions/categories/deletions_controller_test.rb b/test/controllers/categories/deletions_controller_test.rbsimilarity index 58%rename from test/controllers/transactions/categories/deletions_controller_test.rbrename to test/controllers/categories/deletions_controller_test.rbindex 7145ef5f..a9b0caa8 100644--- a/test/controllers/transactions/categories/deletions_controller_test.rb+++ b/test/controllers/categories/deletions_controller_test.rb@@ -1,24 +1,24 @@require "test_helper"-class Transactions::Categories::DeletionsControllerTest < ActionDispatch::IntegrationTest+class Categories::DeletionsControllerTest < ActionDispatch::IntegrationTestsetup dosign_in users(:family_admin)- @category = transaction_categories(:food_and_drink)+ @category = categories(:food_and_drink)endtest "new" do- get new_transaction_category_deletion_url(@category)+ get new_category_deletion_url(@category)assert_response :successendtest "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 doassert_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 }endend@@ -29,9 +29,9 @@ class Transactions::Categories::DeletionsControllerTest < ActionDispatch::Integrtest "create without replacement" doassert_not_empty @category.transactions- assert_difference "Transaction::Category.count", -1 do+ assert_difference "Category.count", -1 doassert_difference "Transaction.where(category: nil).count", @category.transactions.count do- post transaction_category_deletions_url(@category)+ post category_deletions_url(@category)endenddiff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rbnew file mode 100644index 00000000..b38fff9f--- /dev/null+++ b/test/controllers/categories_controller_test.rb@@ -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+enddiff --git a/test/controllers/registrations_controller_test.rb b/test/controllers/registrations_controller_test.rbindex db11757d..1c3169f6 100644--- a/test/controllers/registrations_controller_test.rb+++ b/test/controllers/registrations_controller_test.rb@@ -16,7 +16,7 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTestendtest "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 dopost registration_url, params: { user: {email: "[email protected]",password: "password",diff --git a/test/controllers/transactions/categories_controller_test.rb b/test/controllers/transactions/categories_controller_test.rbdeleted file mode 100644index 17a52e4c..00000000--- a/test/controllers/transactions/categories_controller_test.rb+++ /dev/null@@ -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-enddiff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rbindex 57feedcc..b31fe159 100644--- a/test/controllers/transactions_controller_test.rb+++ b/test/controllers/transactions_controller_test.rb@@ -159,7 +159,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTesttransactions.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::IntegrationTestdate: 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::IntegrationTesttransactions.reload.each do |transaction|assert_equal Date.current, transaction.dateassert transaction.excluded- assert_equal Transaction::Category.second, transaction.category+ assert_equal Category.second, transaction.categoryassert_equal Transaction::Merchant.second, transaction.merchantassert_equal "Updated note", transaction.notesenddiff --git a/test/fixtures/transaction/categories.yml b/test/fixtures/categories.ymlsimilarity index 100%rename from test/fixtures/transaction/categories.ymlrename to test/fixtures/categories.ymldiff --git a/test/models/transaction/category_test.rb b/test/models/category_test.rbsimilarity index 52%rename from test/models/transaction/category_test.rbrename to test/models/category_test.rbindex 4850063b..a0f920f6 100644--- a/test/models/transaction/category_test.rb+++ b/test/models/category_test.rb@@ -1,50 +1,50 @@require "test_helper"-class Transaction::CategoryTest < ActiveSupport::TestCase+class CategoryTest < ActiveSupport::TestCasedef setup@family = families(:dylan_family)endtest "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)endendtest "create_default_categories should raise when there are existing categories" doassert_raises(ArgumentError) do- Transaction::Category.create_default_categories(@family)+ Category.create_default_categories(@family)endendtest "updating name should clear the internal_category field" do- category = Transaction::Category.take+ category = Category.takeassert_changes "category.reload.internal_category", to: nil docategory.update_attribute(:name, "new name")endendtest "updating other field than name should not clear the internal_category field" do- category = Transaction::Category.take+ category = Category.takeassert_no_changes "category.reload.internal_category" docategory.update_attribute(:color, "#000")endendtest "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.firstendtest "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.firstenddiff --git a/test/models/family_test.rb b/test/models/family_test.rbindex fc9ff284..55218957 100644--- a/test/models/family_test.rb+++ b/test/models/family_test.rb@@ -33,7 +33,7 @@ class FamilyTest < ActiveSupport::TestCaseendtest "should destroy dependent transaction categories" do- assert_difference("Transaction::Category.count", [email protected]_categories.count) do+ assert_difference("Category.count", [email protected]) do@family.destroyendenddiff --git a/test/models/import_test.rb b/test/models/import_test.rbindex 4945b48d..02c4d127 100644--- a/test/models/import_test.rb+++ b/test/models/import_test.rb@@ -46,7 +46,7 @@ class ImportTest < ActiveSupport::TestCase# "Shopping" is a new category, but should only be created 1x during importassert_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::TestCasetest "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.publishenddiff --git a/test/system/settings_test.rb b/test/system/settings_test.rbindex 576eb889..e9be8a86 100644--- a/test/system/settings_test.rb+++ b/test/system/settings_test.rb@@ -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 ],diff --git a/test/system/transactions_test.rb b/test/system/transactions_test.rbindex 3dd2d585..f75edd76 100644--- a/test/system/transactions_test.rb+++ b/test/system/transactions_test.rb@@ -5,7 +5,7 @@ class TransactionsTest < ApplicationSystemTestCasesign_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",