From 4d1ede353142f15f5b3c54775793397127c28214 Mon Sep 17 00:00:00 2001 From: niyas301 Date: Thu, 6 Nov 2025 12:28:29 +0530 Subject: [PATCH] Move legacy asset to avoid application.js logical path conflict --- Gemfile.lock | 222 +++++++++++------- app/assets/config/manifest.js | 3 + .../{application.js => legacy_flash.js} | 0 app/assets/stylesheets/application.css.scss | 2 + app/controllers/categories_controller.rb | 70 ++++++ app/controllers/expenses_controller.rb | 25 +- app/helpers/categories_helper.rb | 2 + app/javascript/legacy_flash.js | 11 + app/models/category.rb | 4 + app/views/categories/_category.html.erb | 17 ++ app/views/categories/_category.json.jbuilder | 4 + app/views/categories/_form.html.erb | 32 +++ app/views/categories/edit.html.erb | 12 + app/views/categories/index.html.erb | 16 ++ app/views/categories/index.json.jbuilder | 1 + app/views/categories/new.html.erb | 11 + app/views/categories/show.html.erb | 10 + app/views/categories/show.json.jbuilder | 1 + app/views/expenses/report.html.erb | 6 +- app/views/layouts/application.html.erb | 11 +- config/application.rb | 2 + config/environment.rb | 4 + config/environments/production.rb | 7 + config/importmap.rb | 2 +- config/routes.rb | 1 + .../20251106035813_create_categories.rb | 9 + db/schema.rb | 8 +- .../controllers/categories_controller_test.rb | 48 ++++ test/fixtures/categories.yml | 7 + test/models/category_test.rb | 7 + test/system/categories_test.rb | 41 ++++ 31 files changed, 488 insertions(+), 108 deletions(-) rename app/assets/javascripts/{application.js => legacy_flash.js} (100%) create mode 100644 app/controllers/categories_controller.rb create mode 100644 app/helpers/categories_helper.rb create mode 100644 app/javascript/legacy_flash.js create mode 100644 app/models/category.rb create mode 100644 app/views/categories/_category.html.erb create mode 100644 app/views/categories/_category.json.jbuilder create mode 100644 app/views/categories/_form.html.erb create mode 100644 app/views/categories/edit.html.erb create mode 100644 app/views/categories/index.html.erb create mode 100644 app/views/categories/index.json.jbuilder create mode 100644 app/views/categories/new.html.erb create mode 100644 app/views/categories/show.html.erb create mode 100644 app/views/categories/show.json.jbuilder create mode 100644 db/migrate/20251106035813_create_categories.rb create mode 100644 test/controllers/categories_controller_test.rb create mode 100644 test/fixtures/categories.yml create mode 100644 test/models/category_test.rb create mode 100644 test/system/categories_test.rb diff --git a/Gemfile.lock b/Gemfile.lock index 883215e..4d41e8b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,29 +1,29 @@ GEM remote: https://rubygems.org/ specs: - actioncable (8.0.3) - actionpack (= 8.0.3) - activesupport (= 8.0.3) + actioncable (8.0.4) + actionpack (= 8.0.4) + activesupport (= 8.0.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (8.0.3) - actionpack (= 8.0.3) - activejob (= 8.0.3) - activerecord (= 8.0.3) - activestorage (= 8.0.3) - activesupport (= 8.0.3) + actionmailbox (8.0.4) + actionpack (= 8.0.4) + activejob (= 8.0.4) + activerecord (= 8.0.4) + activestorage (= 8.0.4) + activesupport (= 8.0.4) mail (>= 2.8.0) - actionmailer (8.0.3) - actionpack (= 8.0.3) - actionview (= 8.0.3) - activejob (= 8.0.3) - activesupport (= 8.0.3) + actionmailer (8.0.4) + actionpack (= 8.0.4) + actionview (= 8.0.4) + activejob (= 8.0.4) + activesupport (= 8.0.4) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (8.0.3) - actionview (= 8.0.3) - activesupport (= 8.0.3) + actionpack (8.0.4) + actionview (= 8.0.4) + activesupport (= 8.0.4) nokogiri (>= 1.8.5) rack (>= 2.2.4) rack-session (>= 1.0.1) @@ -31,35 +31,35 @@ GEM rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (8.0.3) - actionpack (= 8.0.3) - activerecord (= 8.0.3) - activestorage (= 8.0.3) - activesupport (= 8.0.3) + actiontext (8.0.4) + actionpack (= 8.0.4) + activerecord (= 8.0.4) + activestorage (= 8.0.4) + activesupport (= 8.0.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (8.0.3) - activesupport (= 8.0.3) + actionview (8.0.4) + activesupport (= 8.0.4) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (8.0.3) - activesupport (= 8.0.3) + activejob (8.0.4) + activesupport (= 8.0.4) globalid (>= 0.3.6) - activemodel (8.0.3) - activesupport (= 8.0.3) - activerecord (8.0.3) - activemodel (= 8.0.3) - activesupport (= 8.0.3) + activemodel (8.0.4) + activesupport (= 8.0.4) + activerecord (8.0.4) + activemodel (= 8.0.4) + activesupport (= 8.0.4) timeout (>= 0.4.0) - activestorage (8.0.3) - actionpack (= 8.0.3) - activejob (= 8.0.3) - activerecord (= 8.0.3) - activesupport (= 8.0.3) + activestorage (8.0.4) + actionpack (= 8.0.4) + activejob (= 8.0.4) + activerecord (= 8.0.4) + activesupport (= 8.0.4) marcel (~> 1.0) - activesupport (8.0.3) + activesupport (8.0.4) base64 benchmark (>= 0.3) bigdecimal @@ -78,12 +78,14 @@ GEM base64 (0.3.0) bcrypt (3.1.20) bcrypt_pbkdf (1.1.1) - benchmark (0.4.1) - bigdecimal (3.2.3) + bcrypt_pbkdf (1.1.1-arm64-darwin) + bcrypt_pbkdf (1.1.1-x86_64-darwin) + benchmark (0.5.0) + bigdecimal (3.3.1) bindex (0.8.1) bootsnap (1.18.6) msgpack (~> 1.2) - brakeman (7.1.0) + brakeman (7.1.1) racc builder (3.3.0) capybara (3.40.0) @@ -98,7 +100,7 @@ GEM concurrent-ruby (1.3.5) connection_pool (2.5.4) crass (1.0.6) - date (3.4.1) + date (3.5.0) debug (1.11.0) irb (~> 1.10) reline (>= 0.3.8) @@ -111,15 +113,22 @@ GEM dotenv (3.1.8) drb (2.2.3) ed25519 (1.4.0) - erb (5.0.2) + erb (5.1.3) erubi (1.13.1) et-orbi (1.4.0) tzinfo + ffi (1.17.2-aarch64-linux-gnu) + ffi (1.17.2-aarch64-linux-musl) + ffi (1.17.2-arm-linux-gnu) + ffi (1.17.2-arm-linux-musl) + ffi (1.17.2-arm64-darwin) + ffi (1.17.2-x86_64-darwin) ffi (1.17.2-x86_64-linux-gnu) + ffi (1.17.2-x86_64-linux-musl) font-awesome-sass (5.15.1) sassc (>= 1.11) - fugit (1.11.2) - et-orbi (~> 1, >= 1.2.11) + fugit (1.12.1) + et-orbi (~> 1.4) raabro (~> 1.4) globalid (1.3.0) activesupport (>= 6.1) @@ -133,15 +142,15 @@ GEM activesupport (>= 6.0.0) railties (>= 6.0.0) io-console (0.8.1) - irb (1.15.2) + irb (1.15.3) pp (>= 0.6.0) rdoc (>= 4.0.0) reline (>= 0.4.2) jbuilder (2.14.1) actionview (>= 7.0.0) activesupport (>= 7.0.0) - json (2.15.0) - kamal (2.7.0) + json (2.15.2) + kamal (2.8.2) activesupport (>= 7.0) base64 (~> 0.2) bcrypt_pbkdf (~> 1.0) @@ -158,7 +167,8 @@ GEM loofah (2.24.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) - mail (2.8.1) + mail (2.9.0) + logger mini_mime (>= 0.1.1) net-imap net-pop @@ -168,9 +178,9 @@ GEM mini_magick (5.3.1) logger mini_mime (1.1.5) - minitest (5.25.5) + minitest (5.26.0) msgpack (1.8.0) - net-imap (0.5.10) + net-imap (0.5.12) date net-protocol net-pop (0.1.2) @@ -184,19 +194,33 @@ GEM net-smtp (0.5.1) net-protocol net-ssh (7.3.0) - nio4r (2.7.4) + nio4r (2.7.5) + nokogiri (1.18.10-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.10-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.18.10-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.10-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.18.10-arm64-darwin) + racc (~> 1.4) + nokogiri (1.18.10-x86_64-darwin) + racc (~> 1.4) nokogiri (1.18.10-x86_64-linux-gnu) racc (~> 1.4) + nokogiri (1.18.10-x86_64-linux-musl) + racc (~> 1.4) orm_adapter (0.5.0) ostruct (0.6.3) parallel (1.27.0) - parser (3.3.9.0) + parser (3.3.10.0) ast (~> 2.4.1) racc - pp (0.6.2) + pp (0.6.3) prettyprint prettyprint (0.2.0) - prism (1.5.1) + prism (1.6.0) propshaft (1.3.1) actionpack (>= 7.0.0) activesupport (>= 7.0.0) @@ -205,11 +229,11 @@ GEM date stringio public_suffix (6.0.2) - puma (7.0.4) + puma (7.1.0) nio4r (~> 2.0) raabro (1.4.0) racc (1.8.1) - rack (3.2.1) + rack (3.2.4) rack-session (2.1.1) base64 (>= 0.1.0) rack (>= 3.0.0) @@ -217,20 +241,20 @@ GEM rack (>= 1.3) rackup (2.2.1) rack (>= 3) - rails (8.0.3) - actioncable (= 8.0.3) - actionmailbox (= 8.0.3) - actionmailer (= 8.0.3) - actionpack (= 8.0.3) - actiontext (= 8.0.3) - actionview (= 8.0.3) - activejob (= 8.0.3) - activemodel (= 8.0.3) - activerecord (= 8.0.3) - activestorage (= 8.0.3) - activesupport (= 8.0.3) + rails (8.0.4) + actioncable (= 8.0.4) + actionmailbox (= 8.0.4) + actionmailer (= 8.0.4) + actionpack (= 8.0.4) + actiontext (= 8.0.4) + actionview (= 8.0.4) + activejob (= 8.0.4) + activemodel (= 8.0.4) + activerecord (= 8.0.4) + activestorage (= 8.0.4) + activesupport (= 8.0.4) bundler (>= 1.15.0) - railties (= 8.0.3) + railties (= 8.0.4) rails-dom-testing (2.3.0) activesupport (>= 5.0.0) minitest @@ -238,9 +262,9 @@ GEM rails-html-sanitizer (1.6.2) loofah (~> 2.21) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) - railties (8.0.3) - actionpack (= 8.0.3) - activesupport (= 8.0.3) + railties (8.0.4) + actionpack (= 8.0.4) + activesupport (= 8.0.4) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) @@ -248,10 +272,11 @@ GEM tsort (>= 0.2) zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.3.0) - rdoc (6.14.2) + rake (13.3.1) + rdoc (6.15.1) erb psych (>= 4.0.0) + tsort regexp_parser (2.11.3) reline (0.6.2) io-console (~> 0.5) @@ -259,7 +284,7 @@ GEM actionpack (>= 7.0) railties (>= 7.0) rexml (3.4.4) - rubocop (1.81.1) + rubocop (1.81.7) json (~> 2.3) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.1.0) @@ -273,10 +298,10 @@ GEM rubocop-ast (1.47.1) parser (>= 3.3.7.2) prism (~> 1.4) - rubocop-performance (1.26.0) + rubocop-performance (1.26.1) lint_roller (~> 1.1) rubocop (>= 1.75.0, < 2.0) - rubocop-ast (>= 1.44.0, < 2.0) + rubocop-ast (>= 1.47.1, < 2.0) rubocop-rails (2.33.4) activesupport (>= 4.2.0) lint_roller (~> 1.1) @@ -291,7 +316,7 @@ GEM ruby-vips (2.2.5) ffi (~> 1.12) logger - rubyzip (3.1.1) + rubyzip (3.2.2) sassc (2.4.0) ffi (~> 1.9) sassc-rails (2.1.2) @@ -301,7 +326,7 @@ GEM sprockets-rails tilt securerandom (0.4.1) - selenium-webdriver (4.35.0) + selenium-webdriver (4.38.0) base64 (~> 0.2) logger (~> 1.4) rexml (~> 3.2, >= 3.2.5) @@ -312,15 +337,15 @@ GEM activejob (>= 7.2) activerecord (>= 7.2) railties (>= 7.2) - solid_cache (1.0.7) + solid_cache (1.0.8) activejob (>= 7.2) activerecord (>= 7.2) railties (>= 7.2) - solid_queue (1.2.1) + solid_queue (1.2.4) activejob (>= 7.1) activerecord (>= 7.1) concurrent-ruby (>= 1.3.1) - fugit (~> 1.11.0) + fugit (~> 1.11) railties (>= 7.1) thor (>= 1.3.1) sprockets (4.2.2) @@ -331,7 +356,14 @@ GEM actionpack (>= 6.1) activesupport (>= 6.1) sprockets (>= 3.0.0) - sqlite3 (2.7.4-x86_64-linux-gnu) + sqlite3 (2.8.0-aarch64-linux-gnu) + sqlite3 (2.8.0-aarch64-linux-musl) + sqlite3 (2.8.0-arm-linux-gnu) + sqlite3 (2.8.0-arm-linux-musl) + sqlite3 (2.8.0-arm64-darwin) + sqlite3 (2.8.0-x86_64-darwin) + sqlite3 (2.8.0-x86_64-linux-gnu) + sqlite3 (2.8.0-x86_64-linux-musl) sshkit (1.24.0) base64 logger @@ -343,11 +375,15 @@ GEM railties (>= 6.0.0) stringio (3.1.7) thor (1.4.0) - thruster (0.1.15-x86_64-linux) + thruster (0.1.16) + thruster (0.1.16-aarch64-linux) + thruster (0.1.16-arm64-darwin) + thruster (0.1.16-x86_64-darwin) + thruster (0.1.16-x86_64-linux) tilt (2.6.1) - timeout (0.4.3) + timeout (0.4.4) tsort (0.2.0) - turbo-rails (2.0.17) + turbo-rails (2.0.20) actionpack (>= 7.1.0) railties (>= 7.1.0) tzinfo (2.0.6) @@ -355,7 +391,7 @@ GEM unicode-display_width (3.2.0) unicode-emoji (~> 4.1) unicode-emoji (4.1.0) - uri (1.1.0) + uri (1.1.1) useragent (0.16.11) warden (1.2.9) rack (>= 2.0.9) @@ -374,7 +410,15 @@ GEM zeitwerk (2.7.3) PLATFORMS - x86_64-linux + aarch64-linux + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux-gnu + x86_64-linux-musl DEPENDENCIES bootsnap @@ -405,4 +449,4 @@ DEPENDENCIES web-console BUNDLED WITH - 2.4.20 + 2.5.7 diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index 3f31662..8024967 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -2,3 +2,6 @@ //= link_directory ../stylesheets .css //= link_tree ../video .mp4 //= link just.mp4 +// Include all JavaScript files from app/javascript so importmap-pinned modules +// (e.g. dropdown.js, flash_messages.js) are available to the asset pipeline. +//= link_tree ../../javascript .js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/legacy_flash.js similarity index 100% rename from app/assets/javascripts/application.js rename to app/assets/javascripts/legacy_flash.js diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index d23eb91..b0aa92c 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -9,6 +9,8 @@ * Consider organizing styles into separate files for maintainability. */ @import "font-awesome"; +@import "trix/dist/trix.css"; + #flash-message { position: fixed; diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb new file mode 100644 index 0000000..4ba4bcc --- /dev/null +++ b/app/controllers/categories_controller.rb @@ -0,0 +1,70 @@ +class CategoriesController < ApplicationController + before_action :set_category, only: %i[ show edit update destroy ] + + # GET /categories or /categories.json + def index + @categories = Category.all + end + + # GET /categories/1 or /categories/1.json + def show + end + + # GET /categories/new + def new + @category = Category.new + end + + # GET /categories/1/edit + def edit + end + + # POST /categories or /categories.json + def create + @category = Category.new(category_params) + + respond_to do |format| + if @category.save + format.html { redirect_to @category, notice: "Category was successfully created." } + format.json { render :show, status: :created, location: @category } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @category.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /categories/1 or /categories/1.json + def update + respond_to do |format| + if @category.update(category_params) + format.html { redirect_to @category, notice: "Category was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @category } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @category.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /categories/1 or /categories/1.json + def destroy + @category.destroy! + + respond_to do |format| + format.html { redirect_to categories_path, notice: "Category was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_category + @category = Category.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def category_params + params.require(:category).permit(:name, :description, :image) + end +end diff --git a/app/controllers/expenses_controller.rb b/app/controllers/expenses_controller.rb index 97a9aa6..4bed929 100644 --- a/app/controllers/expenses_controller.rb +++ b/app/controllers/expenses_controller.rb @@ -33,19 +33,24 @@ class ExpensesController < ApplicationController # GET /expenses/report def report - set_summary - render :report - @daily_expense_items = Expense.where(date: Date.today.all_day) + # Daily expenses + @daily_expense_items = Expense.where(date: Date.today) + @daily_expense = @daily_expense_items.sum(:amount) + + # Weekly expenses @weekly_expense_items = Expense.where(date: Date.today.beginning_of_week..Date.today.end_of_week) + @weekly_expense = @weekly_expense_items.sum(:amount) + + # Monthly expenses @monthly_expense_items = Expense.where(date: Date.today.beginning_of_month..Date.today.end_of_month) + @monthly_expense = @monthly_expense_items.sum(:amount) - @daily_expenses = @daily_expense_items.sum(:amount) - @weekly_expenses = @weekly_expense_items.sum(:amount) - @monthly_expenses = @monthly_expense_items.sum(:amount) - - # For chart - @chart_labels = @monthly_expense_items.pluck(:date).map { |d| d.strftime("%d %b") } - @chart_data = @monthly_expense_items.pluck(:amount) + # For chart - last 7 days + @chart_labels = (0..6).map { |i| (Date.today - i).strftime("%d %b") }.reverse + @chart_data = @chart_labels.map { |date_str| + date = Date.parse(date_str) + Expense.where(date: date).sum(:amount) + } end # GET /expenses/new diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 0000000..e06f315 --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,2 @@ +module CategoriesHelper +end diff --git a/app/javascript/legacy_flash.js b/app/javascript/legacy_flash.js new file mode 100644 index 0000000..54b181c --- /dev/null +++ b/app/javascript/legacy_flash.js @@ -0,0 +1,11 @@ +// migrated from app/assets/javascripts/application.js +document.addEventListener("DOMContentLoaded", () => { + const flash = document.getElementById("flash-message"); + if (flash) { + setTimeout(() => { + flash.style.transition = "opacity 0.5s ease"; + flash.style.opacity = "0"; + setTimeout(() => flash.remove(), 500); + }, 3000); + } +}); diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000..d58b9f4 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,4 @@ +class Category < ApplicationRecord + has_rich_text :description + has_one_attached :image +end diff --git a/app/views/categories/_category.html.erb b/app/views/categories/_category.html.erb new file mode 100644 index 0000000..17b84da --- /dev/null +++ b/app/views/categories/_category.html.erb @@ -0,0 +1,17 @@ +
+

+ Name: + <%= category.name %> +

+ +

+ Description: + <%= category.description %> +

+ +

+ Image: + <%= link_to category.image.filename, category.image if category.image.attached? %> +

+ +
diff --git a/app/views/categories/_category.json.jbuilder b/app/views/categories/_category.json.jbuilder new file mode 100644 index 0000000..7e3e997 --- /dev/null +++ b/app/views/categories/_category.json.jbuilder @@ -0,0 +1,4 @@ +json.extract! category, :id, :name, :description, :image, :created_at, :updated_at +json.url category_url(category, format: :json) +json.description category.description.to_s +json.image url_for(category.image) diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb new file mode 100644 index 0000000..b02af69 --- /dev/null +++ b/app/views/categories/_form.html.erb @@ -0,0 +1,32 @@ +<%= form_with(model: category) do |form| %> + <% if category.errors.any? %> +
+

<%= pluralize(category.errors.count, "error") %> prohibited this category from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :name, style: "display: block" %> + <%= form.text_field :name %> +
+ +
+ <%= form.label :description, style: "display: block" %> + <%= form.rich_textarea :description %> +
+ +
+ <%= form.label :image, style: "display: block" %> + <%= form.file_field :image %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/categories/edit.html.erb b/app/views/categories/edit.html.erb new file mode 100644 index 0000000..87cbced --- /dev/null +++ b/app/views/categories/edit.html.erb @@ -0,0 +1,12 @@ +<% content_for :title, "Editing category" %> + +

Editing category

+ +<%= render "form", category: @category %> + +
+ +
+ <%= link_to "Show this category", @category %> | + <%= link_to "Back to categories", categories_path %> +
diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb new file mode 100644 index 0000000..4f7b00d --- /dev/null +++ b/app/views/categories/index.html.erb @@ -0,0 +1,16 @@ +

<%= notice %>

+ +<% content_for :title, "Categories" %> + +

Categories

+ +
+ <% @categories.each do |category| %> + <%= render category %> +

+ <%= link_to "Show this category", category %> +

+ <% end %> +
+ +<%= link_to "New category", new_category_path %> diff --git a/app/views/categories/index.json.jbuilder b/app/views/categories/index.json.jbuilder new file mode 100644 index 0000000..aa5baad --- /dev/null +++ b/app/views/categories/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @categories, partial: "categories/category", as: :category diff --git a/app/views/categories/new.html.erb b/app/views/categories/new.html.erb new file mode 100644 index 0000000..d550c84 --- /dev/null +++ b/app/views/categories/new.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "New category" %> + +

New category

+ +<%= render "form", category: @category %> + +
+ +
+ <%= link_to "Back to categories", categories_path %> +
diff --git a/app/views/categories/show.html.erb b/app/views/categories/show.html.erb new file mode 100644 index 0000000..dd28ade --- /dev/null +++ b/app/views/categories/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +<%= render @category %> + +
+ <%= link_to "Edit this category", edit_category_path(@category) %> | + <%= link_to "Back to categories", categories_path %> + + <%= button_to "Destroy this category", @category, method: :delete %> +
diff --git a/app/views/categories/show.json.jbuilder b/app/views/categories/show.json.jbuilder new file mode 100644 index 0000000..30e6b47 --- /dev/null +++ b/app/views/categories/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "categories/category", category: @category diff --git a/app/views/expenses/report.html.erb b/app/views/expenses/report.html.erb index 95ff3e6..8adee59 100644 --- a/app/views/expenses/report.html.erb +++ b/app/views/expenses/report.html.erb @@ -202,7 +202,7 @@ <%= expense.title %> <%= number_to_currency(expense.amount, unit: "₹") %> - <%= expense.created_at.strftime("%d %b %Y") %> + <%= expense.date.strftime("%d %b %Y") %> <%= expense.description %> <% end %> @@ -233,7 +233,7 @@ <%= expense.title %> <%= number_to_currency(expense.amount, unit: "₹") %> - <%= expense.created_at.strftime("%d %b %Y") %> + <%= expense.date.strftime("%d %b %Y") %> <%= expense.description %> <% end %> @@ -264,7 +264,7 @@ <%= expense.title %> <%= number_to_currency(expense.amount, unit: "₹") %> - <%= expense.created_at.strftime("%d %b %Y") %> + <%= expense.date.strftime("%d %b %Y") %> <%= expense.description %> <% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8ee1db8..72c72f2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,13 +5,16 @@ - <%= csrf_meta_tags %> - <%= csp_meta_tag %> + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + + <%= javascript_importmap_tags %> - - <%= yield :head %> + <%= yield :head %> <%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %> <%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %> diff --git a/config/application.rb b/config/application.rb index 1fd893e..82f78b7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -24,6 +24,8 @@ module BadarMadeena # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") config.assets.enabled = true + config.assets.paths << Rails.root.join("app/assets") + # Set the URL options for ActiveStorage config.active_storage.service_urls_expire_in = 5.minutes # Optional: You can set the expiration time for URLs here if you need diff --git a/config/environment.rb b/config/environment.rb index cac5315..ef4be1e 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,9 @@ # Load the Rails application. require_relative "application" +# If you're using Propshaft, ensure it's correctly initialized +require "propshaft" + + # Initialize the Rails application. Rails.application.initialize! diff --git a/config/environments/production.rb b/config/environments/production.rb index bdcd01d..11cc153 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -87,4 +87,11 @@ Rails.application.configure do # # Skip DNS rebinding protection for the default health check endpoint. # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } + + config.assets.compile = false # Do not compile assets on the fly in production + config.assets.digest = true # Generate digests for asset URLs + config.assets.js_compressor = :uglifier # Optional for JavaScript minification + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? || ENV['RAILS_ENV'] == 'production' + + end diff --git a/config/importmap.rb b/config/importmap.rb index 43e49e8..447f002 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -9,5 +9,5 @@ pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/core@2.11.8/lib/inde pin_all_from "app/javascript/controllers", under: "controllers" pin "dropdown", to: "dropdown.js" pin "flash_messages", to: "flash_messages.js" -pin "trix" +pin "trix", to: "trix.js" pin "@rails/actiontext", to: "actiontext.esm.js" diff --git a/config/routes.rb b/config/routes.rb index d6d26bc..3ffe792 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :categories resources :products devise_for :users diff --git a/db/migrate/20251106035813_create_categories.rb b/db/migrate/20251106035813_create_categories.rb new file mode 100644 index 0000000..c47bd02 --- /dev/null +++ b/db/migrate/20251106035813_create_categories.rb @@ -0,0 +1,9 @@ +class CreateCategories < ActiveRecord::Migration[8.0] + def change + create_table :categories do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 537d380..c0788dc 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[8.0].define(version: 2025_11_05_180728) do +ActiveRecord::Schema[8.0].define(version: 2025_11_06_035813) do create_table "action_mailbox_inbound_emails", force: :cascade do |t| t.integer "status", default: 0, null: false t.string "message_id", null: false @@ -58,6 +58,12 @@ ActiveRecord::Schema[8.0].define(version: 2025_11_05_180728) do t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true end + create_table "categories", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "exclusive_traditional_records", force: :cascade do |t| t.string "name" t.string "author" diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb new file mode 100644 index 0000000..d27b7ed --- /dev/null +++ b/test/controllers/categories_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class CategoriesControllerTest < ActionDispatch::IntegrationTest + setup do + @category = categories(:one) + end + + test "should get index" do + get categories_url + assert_response :success + end + + test "should get new" do + get new_category_url + assert_response :success + end + + test "should create category" do + assert_difference("Category.count") do + post categories_url, params: { category: { name: @category.name } } + end + + assert_redirected_to category_url(Category.last) + end + + test "should show category" do + get category_url(@category) + assert_response :success + end + + test "should get edit" do + get edit_category_url(@category) + assert_response :success + end + + test "should update category" do + patch category_url(@category), params: { category: { name: @category.name } } + assert_redirected_to category_url(@category) + end + + test "should destroy category" do + assert_difference("Category.count", -1) do + delete category_url(@category) + end + + assert_redirected_to categories_url + end +end diff --git a/test/fixtures/categories.yml b/test/fixtures/categories.yml new file mode 100644 index 0000000..7d41224 --- /dev/null +++ b/test/fixtures/categories.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/category_test.rb b/test/models/category_test.rb new file mode 100644 index 0000000..869357c --- /dev/null +++ b/test/models/category_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class CategoryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/categories_test.rb b/test/system/categories_test.rb new file mode 100644 index 0000000..f9cb583 --- /dev/null +++ b/test/system/categories_test.rb @@ -0,0 +1,41 @@ +require "application_system_test_case" + +class CategoriesTest < ApplicationSystemTestCase + setup do + @category = categories(:one) + end + + test "visiting the index" do + visit categories_url + assert_selector "h1", text: "Categories" + end + + test "should create category" do + visit categories_url + click_on "New category" + + fill_in "Name", with: @category.name + click_on "Create Category" + + assert_text "Category was successfully created" + click_on "Back" + end + + test "should update Category" do + visit category_url(@category) + click_on "Edit this category", match: :first + + fill_in "Name", with: @category.name + click_on "Update Category" + + assert_text "Category was successfully updated" + click_on "Back" + end + + test "should destroy Category" do + visit category_url(@category) + click_on "Destroy this category", match: :first + + assert_text "Category was successfully destroyed" + end +end