From 436d2aea385748bd0d91d7ba742ce716f74dba67 Mon Sep 17 00:00:00 2001 From: Kira Date: Wed, 11 Nov 2020 21:06:12 -0800 Subject: [PATCH] [Ruby 3] Fix up some deprecations involving ruby 3 Still pending are gems that make poor choices and need to be removed, replaced, or fixed up. Memoist ActiveModelSerializers --- app/controllers/application_controller.rb | 2 +- app/logical/related_tag_query.rb | 2 +- app/models/application_record.rb | 6 +++--- app/models/ban.rb | 4 ++-- app/models/post.rb | 2 +- app/presenters/post_presenter.rb | 2 +- config/environments/test.rb | 5 +---- db/structure.sql | 3 ++- test/factories/post.rb | 1 + test/factories/user.rb | 1 + test/test_helper.rb | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4dfb5e605..514881536 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -115,7 +115,7 @@ class ApplicationController < ActionController::Base def render_error_page(status, exception, message: exception.message, format: request.format.symbol) @exception = exception @expected = status < 500 - @message = message.encode("utf-8", { invalid: :replace, undef: :replace }) + @message = message.encode("utf-8", invalid: :replace, undef: :replace ) @backtrace = Rails.backtrace_cleaner.clean(@exception.backtrace) format = :html unless format.in?(%i[html json atom]) diff --git a/app/logical/related_tag_query.rb b/app/logical/related_tag_query.rb index 48a18dae6..3ffaad3c8 100644 --- a/app/logical/related_tag_query.rb +++ b/app/logical/related_tag_query.rb @@ -62,7 +62,7 @@ class RelatedTagQuery tags_with_categories(tags) end - def serializable_hash(**options) + def serializable_hash(options) { query: query, category: category, diff --git a/app/models/application_record.rb b/app/models/application_record.rb index c795b117b..6faf20a07 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -267,13 +267,13 @@ class ApplicationRecord < ActiveRecord::Base class_methods do def user_status_counter(counter_name, options = {}) class_eval do - belongs_to :user_status, {foreign_key: :creator_id, primary_key: :user_id, counter_cache: counter_name}.merge(options) + belongs_to :user_status, **{foreign_key: :creator_id, primary_key: :user_id, counter_cache: counter_name}.merge(options) end end def belongs_to_creator(options = {}) class_eval do - belongs_to :creator, options.merge(class_name: "User") + belongs_to :creator, **options.merge(class_name: "User") before_validation(on: :create) do |rec| if rec.creator_id.nil? rec.creator_id = CurrentUser.id @@ -289,7 +289,7 @@ class ApplicationRecord < ActiveRecord::Base def belongs_to_updater(options = {}) class_eval do - belongs_to :updater, options.merge(class_name: "User") + belongs_to :updater, **options.merge(class_name: "User") before_validation do |rec| rec.updater_id = CurrentUser.id rec.updater_ip_addr = CurrentUser.ip_addr if rec.respond_to?(:updater_ip_addr=) diff --git a/app/models/ban.rb b/app/models/ban.rb index d9fa15ac5..2c5a76b13 100644 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -97,11 +97,11 @@ class Ban < ApplicationRecord end def update_user_on_create - user.update_attributes(is_banned: true, level: 10) + user.update(is_banned: true, level: 10) end def update_user_on_destroy - user.update_attributes(is_banned: false, level: 20) + user.update(is_banned: false, level: 20) end def user_name diff --git a/app/models/post.rb b/app/models/post.rb index 186aa1598..efecd94cb 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1901,7 +1901,7 @@ class Post < ApplicationRecord def raw_tag_match(tag) tags = {related: tag.split(' '), include: [], exclude: []} - ElasticPostQueryBuilder.new(tag_count: tags[:related].size, tags: tags).build + ElasticPostQueryBuilder.new({tag_count: tags[:related].size, tags: tags}).build end def tag_match(query) diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 9d9700ee9..dd660d85d 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -26,7 +26,7 @@ class PostPresenter < Presenter locals[:article_attrs] = { "id" => "post_#{post.id}", - "class" => preview_class(post, options).join(" ") + "class" => preview_class(post, **options).join(" ") }.merge(data_attributes(post)) locals[:link_target] = options[:link_target] || post diff --git a/config/environments/test.rb b/config/environments/test.rb index 4e9d6d55d..2f62f93cb 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -5,7 +5,7 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - + config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application @@ -30,9 +30,6 @@ Rails.application.configure do # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - # Store uploaded files on the local file system in a temporary directory. - config.active_storage.service = :test - config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. diff --git a/db/structure.sql b/db/structure.sql index 4dd83edbc..e98af2e6f 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1890,7 +1890,8 @@ CREATE TABLE public.posts ( change_seq bigint NOT NULL, tag_count_lore integer DEFAULT 0 NOT NULL, bg_color character varying, - generated_samples character varying[] + generated_samples character varying[], + duration numeric ); diff --git a/test/factories/post.rb b/test/factories/post.rb index 3906cd734..4f091d794 100644 --- a/test/factories/post.rb +++ b/test/factories/post.rb @@ -13,6 +13,7 @@ FactoryBot.define do image_height { 1000 } file_size { 2000 } rating { "q" } + duration { 0.0 } source { FFaker::Internet.http_url } end end diff --git a/test/factories/user.rb b/test/factories/user.rb index 1ee6639d0..38d30b29a 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -4,6 +4,7 @@ FactoryBot.define do "user#{n}" end password { "password" } + password_confirmation { "password" } password_hash {"password"} email {FFaker::Internet.email} default_image_size { "large" } diff --git a/test/test_helper.rb b/test/test_helper.rb index f75c28213..ea0635d9e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -101,7 +101,7 @@ class ActionDispatch::IntegrationTest def method_authenticated(method_name, url, user, options) post session_path, params: { name: user.name, password: user.password } - self.send(method_name, url, options) + self.send(method_name, url, **options) end def get_auth(url, user, options = {})