From 1dae90c821b51935d38eccd142854740d7081e77 Mon Sep 17 00:00:00 2001 From: Adeynack Date: Mon, 3 Mar 2025 21:17:51 +0000 Subject: [PATCH] upgrade to Rails 8 --- Gemfile | 2 +- Gemfile.lock | 130 +++++++++++++++++------------------ app/models/exchange.rb | 2 +- app/models/register.rb | 2 + app/models/reminder.rb | 4 +- app/models/reminder_split.rb | 2 +- app/models/split.rb | 2 + config/application.rb | 3 + spec/models/register_spec.rb | 12 +++- 9 files changed, 84 insertions(+), 75 deletions(-) diff --git a/Gemfile b/Gemfile index 6c595693..c1120037 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source "https://rubygems.org" ruby File.read(".ruby-version").strip -gem "rails", "~> 7.1.3", ">= 7.1.3.4" +gem "rails", "~> 8.0.1" gem "rack-cors" gem "sprockets-rails" gem "pg", "~> 1.1" diff --git a/Gemfile.lock b/Gemfile.lock index 3984dd28..7e61e6da 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,83 +17,77 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (7.1.5.1) - actionpack (= 7.1.5.1) - activesupport (= 7.1.5.1) + actioncable (8.0.1) + actionpack (= 8.0.1) + activesupport (= 8.0.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.5.1) - actionpack (= 7.1.5.1) - activejob (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.5.1) - actionpack (= 7.1.5.1) - actionview (= 7.1.5.1) - activejob (= 7.1.5.1) - activesupport (= 7.1.5.1) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (8.0.1) + actionpack (= 8.0.1) + activejob (= 8.0.1) + activerecord (= 8.0.1) + activestorage (= 8.0.1) + activesupport (= 8.0.1) + mail (>= 2.8.0) + actionmailer (8.0.1) + actionpack (= 8.0.1) + actionview (= 8.0.1) + activejob (= 8.0.1) + activesupport (= 8.0.1) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.5.1) - actionview (= 7.1.5.1) - activesupport (= 7.1.5.1) + actionpack (8.0.1) + actionview (= 8.0.1) + activesupport (= 8.0.1) nokogiri (>= 1.8.5) - racc rack (>= 2.2.4) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.5.1) - actionpack (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) + useragent (~> 0.16) + actiontext (8.0.1) + actionpack (= 8.0.1) + activerecord (= 8.0.1) + activestorage (= 8.0.1) + activesupport (= 8.0.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.5.1) - activesupport (= 7.1.5.1) + actionview (8.0.1) + activesupport (= 8.0.1) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.5.1) - activesupport (= 7.1.5.1) + activejob (8.0.1) + activesupport (= 8.0.1) globalid (>= 0.3.6) - activemodel (7.1.5.1) - activesupport (= 7.1.5.1) - activerecord (7.1.5.1) - activemodel (= 7.1.5.1) - activesupport (= 7.1.5.1) + activemodel (8.0.1) + activesupport (= 8.0.1) + activerecord (8.0.1) + activemodel (= 8.0.1) + activesupport (= 8.0.1) timeout (>= 0.4.0) - activestorage (7.1.5.1) - actionpack (= 7.1.5.1) - activejob (= 7.1.5.1) - activerecord (= 7.1.5.1) - activesupport (= 7.1.5.1) + activestorage (8.0.1) + actionpack (= 8.0.1) + activejob (= 8.0.1) + activerecord (= 8.0.1) + activesupport (= 8.0.1) marcel (~> 1.0) - activesupport (7.1.5.1) + activesupport (8.0.1) base64 benchmark (>= 0.3) bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) logger (>= 1.4.2) minitest (>= 5.1) - mutex_m securerandom (>= 0.3) - tzinfo (~> 2.0) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) acts_as_list (1.2.4) activerecord (>= 6.1) activesupport (>= 6.1) @@ -235,7 +229,6 @@ GEM montrose (0.18.0) activesupport (>= 5.2, < 9) msgpack (1.8.0) - mutex_m (0.3.0) nenv (0.3.0) net-http (0.6.0) uri @@ -315,20 +308,20 @@ GEM rack (>= 1.0.0) rackup (2.2.1) rack (>= 3) - rails (7.1.5.1) - actioncable (= 7.1.5.1) - actionmailbox (= 7.1.5.1) - actionmailer (= 7.1.5.1) - actionpack (= 7.1.5.1) - actiontext (= 7.1.5.1) - actionview (= 7.1.5.1) - activejob (= 7.1.5.1) - activemodel (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) + rails (8.0.1) + actioncable (= 8.0.1) + actionmailbox (= 8.0.1) + actionmailer (= 8.0.1) + actionpack (= 8.0.1) + actiontext (= 8.0.1) + actionview (= 8.0.1) + activejob (= 8.0.1) + activemodel (= 8.0.1) + activerecord (= 8.0.1) + activestorage (= 8.0.1) + activesupport (= 8.0.1) bundler (>= 1.15.0) - railties (= 7.1.5.1) + railties (= 8.0.1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -336,10 +329,10 @@ 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 (7.1.5.1) - actionpack (= 7.1.5.1) - activesupport (= 7.1.5.1) - irb + railties (8.0.1) + actionpack (= 8.0.1) + activesupport (= 8.0.1) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) @@ -482,6 +475,7 @@ GEM unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) uri (1.0.3) + useragent (0.16.11) web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -543,7 +537,7 @@ DEPENDENCIES pundit rack-cors rack_session_access - rails (~> 7.1.3, >= 7.1.3.4) + rails (~> 8.0.1) rspec-rails rubocop rubocop-graphql diff --git a/app/models/exchange.rb b/app/models/exchange.rb index 842eb0d5..1ec8816a 100644 --- a/app/models/exchange.rb +++ b/app/models/exchange.rb @@ -23,7 +23,7 @@ class Exchange < ApplicationRecord has_many :splits, dependent: :destroy - enum status: [:uncleared, :reconciling, :cleared].index_with(&:to_s) + enum :status, [:uncleared, :reconciling, :cleared].index_with(&:to_s), validate: true validates :description, presence: true validates :date, presence: true diff --git a/app/models/register.rb b/app/models/register.rb index 0b5b6b5a..bd47fe55 100644 --- a/app/models/register.rb +++ b/app/models/register.rb @@ -37,6 +37,8 @@ class Register < ApplicationRecord CATEGORY_TYPES = ["Expense", "Income"].freeze KNOWN_TYPES = (ACCOUNT_TYPES + CATEGORY_TYPES).freeze + enum :type, KNOWN_TYPES.index_with(&:itself), validate: true + belongs_to :book, optional: false has_closure_tree order: :name, dependent: :destroy diff --git a/app/models/reminder.rb b/app/models/reminder.rb index 5977fb7d..a0aa88da 100644 --- a/app/models/reminder.rb +++ b/app/models/reminder.rb @@ -30,7 +30,9 @@ class Reminder < ApplicationRecord has_many :reminder_splits, dependent: :destroy - enum mode: [:manual, :auto_commit, :auto_cancel].index_with(&:to_s) + enum :mode, [:manual, :auto_commit, :auto_cancel].index_with(&:to_s), validate: true + enum :exchange_status, Exchange.statuses, validate: true + serialize :recurrence, coder: MontroseJSONSerializer validates :title, presence: true diff --git a/app/models/reminder_split.rb b/app/models/reminder_split.rb index 2f1d77d0..7193dc38 100644 --- a/app/models/reminder_split.rb +++ b/app/models/reminder_split.rb @@ -25,7 +25,7 @@ class ReminderSplit < ApplicationRecord acts_as_list scope: :reminder - enum status: Exchange.statuses + enum :status, Exchange.statuses, validate: true def book super || reminder.book diff --git a/app/models/split.rb b/app/models/split.rb index 0d95969f..d4518cc3 100644 --- a/app/models/split.rb +++ b/app/models/split.rb @@ -19,6 +19,8 @@ class Split < ApplicationRecord include Taggable include Importable + enum :status, Exchange.statuses, validate: true + belongs_to :exchange has_one :book, through: :exchange belongs_to :register # destination of the exchange's split diff --git a/config/application.rb b/config/application.rb index 5b823a01..962975b5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -47,5 +47,8 @@ class Application < Rails::Application config.generators.system_tests = nil config.action_mailer.default_url_options = {host: ENV["HOST"]} if ENV["HOST"].present? + + # DEPRECATION WARNING: `to_time` will always preserve the full timezone rather than offset of the receiver in Rails 8.1. + config.active_support.to_time_preserves_timezone = :zone end end diff --git a/spec/models/register_spec.rb b/spec/models/register_spec.rb index 5355c663..c02845e1 100644 --- a/spec/models/register_spec.rb +++ b/spec/models/register_spec.rb @@ -66,17 +66,23 @@ end describe "IBAN" do + let(:r) do + Register.new type: "Card", starts_at: Time.zone.now, name: "Visa", book: books(:joe), currency_iso_code: "EUR" + end + it "cannot create a card when IBAN is not valid" do - r = Register.new name: "Visa", book: books(:joe), iban: "foo" + r.iban = "foo" expect(r.validate).to be_falsy expect(r.errors.details[:iban]).to eq [{error: :invalid}] end it "can create a card when IBAN is valid" do - r = Register.new name: "Visa", book: books(:joe), iban: "SE35 5000 0000 0549 1000 0003", currency_iso_code: "EUR" - expect(r.valid?).to be_truthy + r.iban = "SE35 5000 0000 0549 1000 0003" + expect { r.validate! }.not_to raise_error end + end + describe "currency_iso_code" do it "cannot create any register with an invalid ISO currency code" do r = Register.new name: "Visa", book: books(:joe), currency_iso_code: "FOO" expect(r.validate).to be_falsy