From 6007a8996f3a0d8b62eda2a1a18a1a8a92a893ba Mon Sep 17 00:00:00 2001 From: Adrien POLY Date: Sun, 12 May 2024 10:07:44 +0200 Subject: [PATCH] upgrade to rails 7.2 alpha --- Gemfile | 4 +- Gemfile.lock | 10 ++- app/content/helpers/page_helper.rb | 4 +- app/markdown/application_markdown.rb | 3 +- config/environments/development.rb | 5 +- config/environments/production.rb | 6 +- config/environments/test.rb | 4 +- .../new_framework_defaults_7_2.rb | 68 +++++++++++++++++++ ..._storage_variant_records.active_storage.rb | 21 +++--- db/schema.rb | 55 --------------- lib/authenticator.rb | 4 +- lib/ui_form_helpers.rb | 16 ++--- test/components/back_to_component_test.rb | 12 ++-- 13 files changed, 111 insertions(+), 101 deletions(-) create mode 100644 config/initializers/new_framework_defaults_7_2.rb diff --git a/Gemfile b/Gemfile index ad9cb97..f3a0ec5 100644 --- a/Gemfile +++ b/Gemfile @@ -51,7 +51,7 @@ group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "byebug" gem "debug", platforms: %i[mri windows] - gem "standardrb", "~> 1.0" + gem "standard", ">= 1.35.1" gem "erb_lint" gem "kamal" @@ -98,7 +98,7 @@ gem "dry-types", "~> 1.7" gem "avo", ">= 3.2" gem "ransack", "~> 4.1" -gem 'activerecord-enhancedsqlite3-adapter' +gem "activerecord-enhancedsqlite3-adapter" # sitepress gem "sitepress-rails", "~> 4.0" diff --git a/Gemfile.lock b/Gemfile.lock index 33d1ab3..ca39c61 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -408,7 +408,7 @@ GEM io-console (~> 0.5) rexml (3.2.6) rouge (4.2.1) - rubocop (1.63.5) + rubocop (1.62.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -476,10 +476,10 @@ GEM net-scp (>= 1.1.2) net-sftp (>= 2.1.2) net-ssh (>= 2.8.0) - standard (1.35.0.1) + standard (1.35.1) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) - rubocop (~> 1.62) + rubocop (~> 1.62.0) standard-custom (~> 1.0.0) standard-performance (~> 1.3) standard-custom (1.0.2) @@ -488,8 +488,6 @@ GEM standard-performance (1.3.1) lint_roller (~> 1.1) rubocop-performance (~> 1.20.2) - standardrb (1.0.1) - standard stimulus-rails (1.3.3) railties (>= 6.0.0) stringio (3.1.0) @@ -573,7 +571,7 @@ DEPENDENCIES solid_errors solid_queue (~> 0.2.2) sqlite3 (~> 1.4) - standardrb (~> 1.0) + standard (>= 1.35.1) stimulus-rails turbo-rails (>= 2.0.0.pre.beta.2) tzinfo-data diff --git a/app/content/helpers/page_helper.rb b/app/content/helpers/page_helper.rb index adfd944..26d81e4 100644 --- a/app/content/helpers/page_helper.rb +++ b/app/content/helpers/page_helper.rb @@ -23,7 +23,7 @@ def with(*args, &block) # Render a block within a layout. This is a useful, and prefered way, to handle # nesting layouts, within Sitepress. - def render_layout(layout, **, &block) - render(html: capture(&block), layout: "layouts/#{layout}", **) + def render_layout(layout, **, &) + render(html: capture(&), layout: "layouts/#{layout}", **) end end diff --git a/app/markdown/application_markdown.rb b/app/markdown/application_markdown.rb index 25e5e3e..409a761 100644 --- a/app/markdown/application_markdown.rb +++ b/app/markdown/application_markdown.rb @@ -49,8 +49,7 @@ def youtube_tag(url, alt) width: 560, height: 325, allow: "encrypted-media; picture-in-picture", - allowfullscreen: true \ - do + allowfullscreen: true do alt end end diff --git a/config/environments/development.rb b/config/environments/development.rb index a09b2d8..c126173 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -24,7 +24,7 @@ config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store - config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } + config.public_file_server.headers = {"Cache-Control" => "public, max-age=#{2.days.to_i}"} else config.action_controller.perform_caching = false @@ -41,7 +41,7 @@ config.action_mailer.perform_caching = false - config.action_mailer.default_url_options = { host: "localhost", port: 3000 } + config.action_mailer.default_url_options = {host: "localhost", port: 3000} # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -61,7 +61,6 @@ # Highlight code that enqueued background job in logs. config.active_job.verbose_enqueue_logs = true - # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 860a816..c773ac7 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -48,12 +48,12 @@ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } # Log to STDOUT by default - config.logger = ActiveSupport::Logger.new(STDOUT) - .tap { |logger| logger.formatter = ::Logger::Formatter.new } + config.logger = ActiveSupport::Logger.new($stdout) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } .then { |logger| ActiveSupport::TaggedLogging.new(logger) } # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # "info" includes generic and useful information about system operation, but avoids logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). If you diff --git a/config/environments/test.rb b/config/environments/test.rb index 8781777..06b5e2f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -18,7 +18,7 @@ config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. - config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{1.hour.to_i}" } + config.public_file_server.headers = {"Cache-Control" => "public, max-age=#{1.hour.to_i}"} # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -43,7 +43,7 @@ # Unlike controllers, the mailer instance doesn't have any context about the # incoming request so you'll need to provide the :host parameter yourself. - config.action_mailer.default_url_options = { host: "www.example.com" } + config.action_mailer.default_url_options = {host: "www.example.com"} # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/new_framework_defaults_7_2.rb b/config/initializers/new_framework_defaults_7_2.rb new file mode 100644 index 0000000..4855249 --- /dev/null +++ b/config/initializers/new_framework_defaults_7_2.rb @@ -0,0 +1,68 @@ +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 7.2 framework defaults upgrade. +# +# Uncomment each configuration one by one to switch to the new default. +# Once your application is ready to run with all new defaults, you can remove +# this file and set the `config.load_defaults` to `7.2`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +### +# Controls whether Active Job's `#perform_later` and similar methods automatically defer +# the job queuing to after the current Active Record transaction is committed. +# +# Example: +# Topic.transaction do +# topic = Topic.create(...) +# NewTopicNotificationJob.perform_later(topic) +# end +# +# In this example, if the configuration is set to `:never`, the job will +# be enqueued immediately, even though the `Topic` hasn't been committed yet. +# Because of this, if the job is picked up almost immediately, or if the +# transaction doesn't succeed for some reason, the job will fail to find this +# topic in the database. +# +# If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter +# will define the behaviour. +# +# Note: Active Job backends can disable this feature. This is generally done by +# backends that use the same database as Active Record as a queue, hence they +# don't need this feature. +#++ +# Rails.application.config.active_job.enqueue_after_transaction_commit = :default + +### +# Adds image/webp to the list of content types Active Storage considers as an image +# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png. +# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support +# WebP. Requires imagemagick/libvips built with WebP support. +#++ +# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp] + +### +# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError +# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp +# associated with the current time. This is done to prevent forward-dating of migration files, which can +# impact migration generation and other migration commands. +# +# Applications with existing timestamped migrations that do not adhere to the +# expected format can disable validation by setting this config to `false`. +#++ +# Rails.application.config.active_record.validate_migration_timestamps = true + +### +# Controls whether Active Record will automatically look for inverse relations +# with a pluralized name. +# +# Example: +# class Comment < ActiveRecord::Base +# belongs_to :post +# end +# +# In this example, Active Record will try to infer a `:comment` (singular) association +# on `Post`. With this option enabled, it will also look for a `:comments` association. +#++ +# Rails.application.config.active_record.automatically_invert_plural_associations = true diff --git a/db/migrate/20240512061714_create_active_storage_variant_records.active_storage.rb b/db/migrate/20240512061714_create_active_storage_variant_records.active_storage.rb index 94ac83a..95fd27f 100644 --- a/db/migrate/20240512061714_create_active_storage_variant_records.active_storage.rb +++ b/db/migrate/20240512061714_create_active_storage_variant_records.active_storage.rb @@ -8,20 +8,21 @@ def change t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type t.string :variation_digest, null: false - t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true + t.index %i[blob_id variation_digest], name: "index_active_storage_variant_records_uniqueness", unique: true t.foreign_key :active_storage_blobs, column: :blob_id end end private - def primary_key_type - config = Rails.configuration.generators - config.options[config.orm][:primary_key_type] || :primary_key - end - def blobs_primary_key_type - pkey_name = connection.primary_key(:active_storage_blobs) - pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name } - pkey_column.bigint? ? :bigint : pkey_column.type - end + def primary_key_type + config = Rails.configuration.generators + config.options[config.orm][:primary_key_type] || :primary_key + end + + def blobs_primary_key_type + pkey_name = connection.primary_key(:active_storage_blobs) + pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name } + pkey_column.bigint? ? :bigint : pkey_column.type + end end diff --git a/db/schema.rb b/db/schema.rb index 09732e8..e7ab5b3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -109,46 +109,6 @@ t.index ["creator_id"], name: "index_blazer_queries_on_creator_id" end - create_table "mission_control_servers_projects", force: :cascade do |t| - t.string "title" - t.string "token" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["token"], name: "index_mission_control_servers_projects_on_token", unique: true - end - - create_table "mission_control_servers_public_projects", force: :cascade do |t| - t.integer "project_id", null: false - t.string "name" - t.string "token" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["project_id"], name: "index_mission_control_servers_public_projects_on_project_id" - t.index ["token"], name: "index_mission_control_servers_public_projects_on_token", unique: true - end - - create_table "mission_control_servers_service_settings", force: :cascade do |t| - t.integer "project_id", null: false - t.string "hostname" - t.string "label" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["project_id"], name: "index_mission_control_servers_service_settings_on_project_id" - end - - create_table "mission_control_servers_services", force: :cascade do |t| - t.integer "project_id", null: false - t.string "hostname", null: false - t.decimal "cpu", precision: 8, scale: 2 - t.decimal "mem_used", precision: 8, scale: 2 - t.decimal "mem_free", precision: 8, scale: 2 - t.string "disk_free" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["hostname"], name: "index_mission_control_servers_services_on_hostname" - t.index ["project_id"], name: "index_mission_control_servers_services_on_project_id" - end - create_table "sessions", force: :cascade do |t| t.integer "user_id", null: false t.string "user_agent" @@ -158,18 +118,6 @@ t.index ["user_id"], name: "index_sessions_on_user_id" end - create_table "solid_cache_entries", force: :cascade do |t| - t.binary "key", limit: 1024, null: false - t.binary "value", limit: 536870912, null: false - t.datetime "created_at", null: false - t.integer "key_hash", limit: 8, null: false - t.integer "byte_size", limit: 4, null: false - t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size" - t.index ["key"], name: "index_solid_cache_entries_on_key", unique: true - t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" - t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true - end - create_table "solid_errors", force: :cascade do |t| t.string "exception_class", null: false t.string "message", null: false @@ -297,9 +245,6 @@ t.index ["email"], name: "index_users_on_email", unique: true end - add_foreign_key "mission_control_servers_public_projects", "mission_control_servers_projects", column: "project_id" - add_foreign_key "mission_control_servers_service_settings", "mission_control_servers_projects", column: "project_id" - add_foreign_key "mission_control_servers_services", "mission_control_servers_projects", column: "project_id" add_foreign_key "sessions", "users" add_foreign_key "solid_errors_occurrences", "solid_errors", column: "error_id" add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade diff --git a/lib/authenticator.rb b/lib/authenticator.rb index ae50c08..74bafa5 100644 --- a/lib/authenticator.rb +++ b/lib/authenticator.rb @@ -32,8 +32,8 @@ def matches?(request) = false user: UserConstraint } - def authenticate(role, &block) - constraints(constraint_for(role), &block) + def authenticate(role, &) + constraints(constraint_for(role), &) end private diff --git a/lib/ui_form_helpers.rb b/lib/ui_form_helpers.rb index 28d3953..f56a757 100644 --- a/lib/ui_form_helpers.rb +++ b/lib/ui_form_helpers.rb @@ -1,25 +1,25 @@ module UiFormHelpers - def ui_text_field(field_name, attributes = {}, &block) + def ui_text_field(field_name, attributes = {}, &) label = options.delete(:label) { field_name.to_s.humanize } type = options.delete(:type) { :text } - @template.render Ui::Field::TextComponent.new(field_name, form_builder: self, type: type, label: label, **attributes, &block) + @template.render Ui::Field::TextComponent.new(field_name, form_builder: self, type: type, label: label, **attributes, &) end - def ui_email_field(field_name, attributes = {}, &block) + def ui_email_field(field_name, attributes = {}, &) label = options.delete(:label) { field_name.to_s.humanize } type = options.delete(:type) { :email } - @template.render Ui::Field::TextComponent.new(field_name, form_builder: self, type: type, label: label, autocomplete: "email", **attributes, &block) + @template.render Ui::Field::TextComponent.new(field_name, form_builder: self, type: type, label: label, autocomplete: "email", **attributes, &) end - def ui_password_field(field_name, attributes = {}, &block) + def ui_password_field(field_name, attributes = {}, &) label = options.delete(:label) { field_name.to_s.humanize } type = options.delete(:type) { :password } - @template.render Ui::Field::TextComponent.new(field_name, form_builder: self, label: label, type: type, **attributes), &block + @template.render(Ui::Field::TextComponent.new(field_name, form_builder: self, label: label, type: type, **attributes), &) end - def ui_text_area(field_name, attributes = {}, &block) + def ui_text_area(field_name, attributes = {}, &) label = options.delete(:label) { field_name.to_s.humanize } - @template.render Ui::Field::TextAreaComponent.new(field_name, form_builder: self, label: label, **attributes), &block + @template.render(Ui::Field::TextAreaComponent.new(field_name, form_builder: self, label: label, **attributes), &) end def ui_submit(value = nil, attributes = {}) diff --git a/test/components/back_to_component_test.rb b/test/components/back_to_component_test.rb index eac64c7..d4169b2 100644 --- a/test/components/back_to_component_test.rb +++ b/test/components/back_to_component_test.rb @@ -3,10 +3,10 @@ require "test_helper" class BackToComponentTest < ViewComponent::TestCase - def test_component_renders_something_useful - # assert_equal( - # %(Hello, components!), - # render_inline(BackToComponent.new(message: "Hello, components!")).css("span").to_html - # ) - end + # def test_component_renders_something_useful + # # assert_equal( + # # %(Hello, components!), + # # render_inline(BackToComponent.new(message: "Hello, components!")).css("span").to_html + # # ) + # end end