Skip to content

Commit

Permalink
upgrade to Rails 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Adeynack committed Mar 3, 2025
1 parent e35abd5 commit 1dae90c
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
130 changes: 62 additions & 68 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -315,31 +308,31 @@ 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
nokogiri (>= 1.6)
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion app/models/reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/reminder_split.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/split.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 9 additions & 3 deletions spec/models/register_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1dae90c

Please sign in to comment.