Skip to content

A platform for community discussion. Free, open, simple.

DEV: Upgrade Rails to version 7.1 (#27539)

Loïc Guitaut2301dddcff8c
diff --git a/.licensed.yml b/.licensed.yml
index c5903c31e0c..314a5e82ac4 100644
--- a/.licensed.yml
+++ b/.licensed.yml
@@ -31,6 +31,10 @@ ignored:
- timeout # Ruby (default gem)
- uri # Ruby (default gem)
- mutex_m # BSD-2-Clause
+ - irb # Ruby (default gem)
+ - rdoc # Ruby (default gem)
+ - reline # Ruby (default gem)
+ - stringio # Ruby (default gem)
reviewed:
bundler:
diff --git a/Gemfile b/Gemfile
index b053716bfcd..ad2429502ff 100644
--- a/Gemfile
+++ b/Gemfile
@@ -6,13 +6,13 @@ source "https://rubygems.org"
gem "bootsnap", require: false, platform: :mri
-gem "actionmailer", "< 7.1"
-gem "actionpack", "< 7.1"
-gem "actionview", "< 7.1"
-gem "activemodel", "< 7.1"
-gem "activerecord", "< 7.1"
-gem "activesupport", "< 7.1"
-gem "railties", "< 7.1"
+gem "actionmailer", "~> 7.1.0"
+gem "actionpack", "~> 7.1.0"
+gem "actionview", "~> 7.1.0"
+gem "activemodel", "~> 7.1.0"
+gem "activerecord", "~> 7.1.0"
+gem "activesupport", "~> 7.1.0"
+gem "railties", "~> 7.1.0"
gem "sprockets-rails"
gem "json"
diff --git a/Gemfile.lock b/Gemfile.lock
index f55a203b730..6d3729dd268 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,45 +1,54 @@
GEM
remote: https://rubygems.org/
specs:
- actionmailer (7.0.8.4)
- actionpack (= 7.0.8.4)
- actionview (= 7.0.8.4)
- activejob (= 7.0.8.4)
- activesupport (= 7.0.8.4)
+ actionmailer (7.1.3.4)
+ actionpack (= 7.1.3.4)
+ actionview (= 7.1.3.4)
+ activejob (= 7.1.3.4)
+ activesupport (= 7.1.3.4)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
- rails-dom-testing (~> 2.0)
- actionpack (7.0.8.4)
- actionview (= 7.0.8.4)
- activesupport (= 7.0.8.4)
- rack (~> 2.0, >= 2.2.4)
+ rails-dom-testing (~> 2.2)
+ actionpack (7.1.3.4)
+ actionview (= 7.1.3.4)
+ activesupport (= 7.1.3.4)
+ nokogiri (>= 1.8.5)
+ racc
+ rack (>= 2.2.4)
+ rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
- rails-dom-testing (~> 2.0)
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
- actionview (7.0.8.4)
- activesupport (= 7.0.8.4)
+ rails-dom-testing (~> 2.2)
+ rails-html-sanitizer (~> 1.6)
+ actionview (7.1.3.4)
+ activesupport (= 7.1.3.4)
builder (~> 3.1)
- erubi (~> 1.4)
- rails-dom-testing (~> 2.0)
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
+ erubi (~> 1.11)
+ rails-dom-testing (~> 2.2)
+ rails-html-sanitizer (~> 1.6)
actionview_precompiler (0.4.0)
actionview (>= 6.0.a)
active_model_serializers (0.8.4)
activemodel (>= 3.0)
- activejob (7.0.8.4)
- activesupport (= 7.0.8.4)
+ activejob (7.1.3.4)
+ activesupport (= 7.1.3.4)
globalid (>= 0.3.6)
- activemodel (7.0.8.4)
- activesupport (= 7.0.8.4)
- activerecord (7.0.8.4)
- activemodel (= 7.0.8.4)
- activesupport (= 7.0.8.4)
- activesupport (7.0.8.4)
+ activemodel (7.1.3.4)
+ activesupport (= 7.1.3.4)
+ activerecord (7.1.3.4)
+ activemodel (= 7.1.3.4)
+ activesupport (= 7.1.3.4)
+ timeout (>= 0.4.0)
+ activesupport (7.1.3.4)
+ base64
+ bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
+ connection_pool (>= 2.2.5)
+ drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
+ mutex_m
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
@@ -176,6 +185,10 @@ GEM
progress (~> 3.0, >= 3.0.1)
image_size (3.4.0)
in_threads (1.6.0)
+ io-console (0.7.2)
+ irb (1.13.1)
+ rdoc (>= 4.0.0)
+ reline (>= 0.4.2)
iso8601 (0.13.0)
jmespath (1.6.2)
json (2.7.2)
@@ -321,6 +334,8 @@ GEM
pry-stack_explorer (0.6.1)
binding_of_caller (~> 1.0)
pry (~> 0.13)
+ psych (5.1.2)
+ stringio
public_suffix (5.1.1)
puma (6.4.2)
nio4r (~> 2.0)
@@ -331,8 +346,13 @@ GEM
rack-protection (3.2.0)
base64 (>= 0.1.0)
rack (~> 2.2, >= 2.2.4)
+ rack-session (1.0.2)
+ rack (< 3)
rack-test (2.1.0)
rack (>= 1.3)
+ rackup (1.0.0)
+ rack (< 3)
+ webrick
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
@@ -347,13 +367,14 @@ GEM
rails_multisite (6.0.0)
activerecord (>= 6.0)
railties (>= 6.0)
- railties (7.0.8.4)
- actionpack (= 7.0.8.4)
- activesupport (= 7.0.8.4)
- method_source
+ railties (7.1.3.4)
+ actionpack (= 7.1.3.4)
+ activesupport (= 7.1.3.4)
+ irb
+ rackup (>= 1.0.0)
rake (>= 12.2)
- thor (~> 1.0)
- zeitwerk (~> 2.5)
+ thor (~> 1.0, >= 1.2.2)
+ zeitwerk (~> 2.6)
rainbow (3.1.1)
raindrops (0.20.1)
rake (13.2.1)
@@ -365,11 +386,15 @@ GEM
msgpack (>= 0.4.3)
optimist (>= 3.0.0)
rchardet (1.8.0)
+ rdoc (6.7.0)
+ psych (>= 4.0.0)
redcarpet (3.6.0)
redis (4.8.1)
redis-namespace (1.11.0)
redis (>= 4)
regexp_parser (2.9.2)
+ reline (0.5.8)
+ io-console (~> 0.5)
request_store (1.7.0)
rack (>= 1.4)
rexml (3.3.0)
@@ -508,6 +533,7 @@ GEM
sqlite3 (1.7.3-x86_64-linux)
sshkey (3.0.0)
stackprof (0.2.26)
+ stringio (3.1.0)
strscan (3.1.0)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
@@ -538,6 +564,7 @@ GEM
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
+ webrick (1.8.1)
websocket (1.2.10)
xpath (3.2.0)
nokogiri (~> 1.8)
@@ -559,14 +586,14 @@ PLATFORMS
x86_64-linux
DEPENDENCIES
- actionmailer (< 7.1)
- actionpack (< 7.1)
- actionview (< 7.1)
+ actionmailer (~> 7.1.0)
+ actionpack (~> 7.1.0)
+ actionview (~> 7.1.0)
actionview_precompiler
active_model_serializers (~> 0.8.3)
- activemodel (< 7.1)
- activerecord (< 7.1)
- activesupport (< 7.1)
+ activemodel (~> 7.1.0)
+ activerecord (~> 7.1.0)
+ activesupport (~> 7.1.0)
addressable
annotate
aws-sdk-s3
@@ -654,7 +681,7 @@ DEPENDENCIES
rails-dom-testing
rails_failover
rails_multisite
- railties (< 7.1)
+ railties (~> 7.1.0)
rake
rb-fsevent
rbtrace
diff --git a/app/models/post_revision.rb b/app/models/post_revision.rb
index 7422726fec1..87f8c8d9145 100644
--- a/app/models/post_revision.rb
+++ b/app/models/post_revision.rb
@@ -4,7 +4,7 @@ class PostRevision < ActiveRecord::Base
belongs_to :post
belongs_to :user
- serialize :modifications, Hash
+ serialize :modifications, type: Hash
after_create :create_notification
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index 3c03fae8a11..3a0a228d265 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -33,9 +33,13 @@ class Reviewable < ActiveRecord::Base
has_many :reviewable_scores, -> { order(created_at: :desc) }, dependent: :destroy
enum :status, { pending: 0, approved: 1, rejected: 2, ignored: 3, deleted: 4 }
- enum :priority, { low: 0, medium: 5, high: 10 }, scopes: false, suffix: true
+
+ attribute :sensitivity, :integer
enum :sensitivity, { disabled: 0, low: 9, medium: 6, high: 3 }, scopes: false, suffix: true
+ attribute :priority, :integer
+ enum :priority, { low: 0, medium: 5, high: 10 }, scopes: false, suffix: true
+
validates :reject_reason, length: { maximum: 2000 }
after_create { log_history(:created, created_by) }
diff --git a/app/models/translation_override.rb b/app/models/translation_override.rb
index 0e891f793ff..d37e7301588 100644
--- a/app/models/translation_override.rb
+++ b/app/models/translation_override.rb
@@ -45,6 +45,7 @@ class TranslationOverride < ActiveRecord::Base
validate :check_interpolation_keys
+ attribute :status, :integer
enum status: { up_to_date: 0, outdated: 1, invalid_interpolation_keys: 2, deprecated: 3 }
def self.upsert!(locale, key, value)
diff --git a/app/models/user.rb b/app/models/user.rb
index d3b2d8bd19e..47464ebc707 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -158,7 +158,9 @@ class User < ActiveRecord::Base
unless: :should_skip_user_fields_validation?
validates_associated :primary_email,
- message: ->(_, user_email) { user_email[:value]&.errors&.[](:email)&.first }
+ message: ->(_, user_email) do
+ user_email[:value]&.errors&.[](:email)&.first.to_s
+ end
after_initialize :add_trust_level
diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb
index 7eb767919d8..b52cc2602bc 100644
--- a/app/services/staff_action_logger.rb
+++ b/app/services/staff_action_logger.rb
@@ -549,7 +549,7 @@ class StaffActionLogger
changed_attributes = category.previous_changes.slice(*category_params.keys)
- if !old_permissions.empty? && (old_permissions != category_params[:permissions])
+ if !old_permissions.empty? && (old_permissions != category_params[:permissions].to_h)
changed_attributes.merge!(
permissions: [old_permissions.to_json, category_params[:permissions].to_json],
)
diff --git a/config/application.rb b/config/application.rb
index 2e214e1c5a9..a5f5b728be0 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -90,7 +90,7 @@ module Discourse
# tiny file needed by site settings
require "highlight_js"
- config.load_defaults 6.1
+ config.load_defaults 7.0
config.active_record.cache_versioning = false # our custom cache class doesn’t support this
config.action_controller.forgery_protection_origin_check = false
config.active_record.belongs_to_required_by_default = false
@@ -100,6 +100,9 @@ module Discourse
Time,
Symbol,
]
+ config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA1
+ config.action_dispatch.cookies_serializer = :hybrid
+ config.action_controller.wrap_parameters_by_default = false
# we skip it cause we configure it in the initializer
# the railtie for message_bus would insert it in the
@@ -112,8 +115,9 @@ module Discourse
ENV["DISCOURSE_MULTISITE_CONFIG_PATH"] || GlobalSetting.multisite_config_path
config.multisite_config_path = File.absolute_path(multisite_config_path, Rails.root)
+ config.autoload_lib(ignore: %w[common_passwords emoji generators javascripts tasks])
+ Rails.autoloaders.main.do_not_eager_load(config.root.join("lib"))
# Custom directories with classes and modules you want to be autoloadable.
- config.autoload_paths << "#{root}/lib"
config.autoload_paths << "#{root}/lib/guardian"
config.autoload_paths << "#{root}/lib/i18n"
config.autoload_paths << "#{root}/lib/validators"
@@ -240,6 +244,17 @@ module Discourse
# we got to clear the pool in case plugins connect
ActiveRecord::Base.connection_handler.clear_active_connections!
+
+ # Mailers and controllers may have been patched by plugins and when the
+ # application is eager loaded, the list of public methods is cached.
+ # We need to invalidate the existing caches, otherwise the new actions
+ # won’t be seen by Rails.
+ if Rails.configuration.eager_load
+ AbstractController::Base.descendants.each do |controller|
+ controller.clear_action_methods!
+ controller.action_methods
+ end
+ end
end
require "rbtrace" if ENV["RBTRACE"] == "1"
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 1ea67794833..6609ecf373b 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -99,4 +99,11 @@ Discourse::Application.configure do
end
config.hosts << /\A(([a-z0-9-]+)\.)*localhost(\:\d+)?\Z/
+
+ config.generators.after_generate do |files|
+ parsable_files = files.filter { |file| file.end_with?(".rb") }
+ unless parsable_files.empty?
+ system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
+ end
+ end
end
diff --git a/config/environments/test.rb b/config/environments/test.rb
index 7f6bd425fdf..66f7e3f32b8 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -26,7 +26,7 @@ Discourse::Application.configure do
# production has "show exceptions" on so we better have it
# in test as well
- config.action_dispatch.show_exceptions = true
+ config.action_dispatch.show_exceptions = :all
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
@@ -65,6 +65,7 @@ Discourse::Application.configure do
# Catch missing translations during test runs.
config.i18n.raise_on_missing_translations = true
+ config.i18n.load_path += Dir[Rails.root.join("spec", "support", "locales", "**", "*.yml")]
config.after_initialize do
ActiveRecord::LogSubscriber.backtrace_cleaner.add_silencer do |line|
diff --git a/config/initializers/002-rails_failover.rb b/config/initializers/002-rails_failover.rb
index d5ee5c2da24..d43a24334ac 100644
--- a/config/initializers/002-rails_failover.rb
+++ b/config/initializers/002-rails_failover.rb
@@ -19,7 +19,7 @@ if defined?(RailsFailover::Redis)
SiteSetting.refresh!
end
- RailsFailover::Redis.logger = Rails.logger.chained.first if Rails.logger.respond_to? :chained
+ RailsFailover::Redis.logger = Rails.logger.broadcasts.first
end
if defined?(RailsFailover::ActiveRecord)
diff --git a/config/initializers/100-logster.rb b/config/initializers/100-logster.rb
index 0a33877d3d5..9248e35e326 100644
--- a/config/initializers/100-logster.rb
+++ b/config/initializers/100-logster.rb
@@ -2,7 +2,7 @@
if GlobalSetting.skip_redis?
Rails.application.reloader.to_prepare do
- Rails.logger = Rails.logger.chained.first if Rails.logger.respond_to? :chained
+ Rails.logger.stop_broadcasting_to(Logster.logger) if defined?(Logster::Logger) && Logster.logger
end
return
end
@@ -10,12 +10,12 @@ end
if Rails.env.development? && !Sidekiq.server? && ENV["RAILS_LOGS_STDOUT"] == "1"
Rails.application.config.after_initialize do
console = ActiveSupport::Logger.new(STDOUT)
- original_logger = Rails.logger.chained.first
+ original_logger = Rails.logger.broadcasts.first
console.formatter = original_logger.formatter
console.level = original_logger.level
unless ActiveSupport::Logger.logger_outputs_to?(original_logger, STDOUT)
- original_logger.extend(ActiveSupport::Logger.broadcast(console))
+ Rails.logger.broadcast_to(console)
end
end
end
@@ -118,10 +118,7 @@ RailsMultisite::ConnectionManagement.each_connection do
end
if Rails.configuration.multisite
- if Rails.logger.respond_to? :chained
- chained = Rails.logger.chained
- chained && chained.first.formatter = RailsMultisite::Formatter.new
- end
+ Rails.logger.broadcasts.first.formatter = RailsMultisite::Formatter.new
end
Logster.config.project_directories = [
diff --git a/config/initializers/100-quiet_logger.rb b/config/initializers/100-quiet_logger.rb
index ef156499861..d72387be9e2 100644
--- a/config/initializers/100-quiet_logger.rb
+++ b/config/initializers/100-quiet_logger.rb
@@ -11,13 +11,13 @@ module DiscourseRackQuietAssetsLogger
(env["PATH_INFO"].index("/service-worker") == 0) ||
(env["PATH_INFO"].index("mini-profiler-resources") == 0) ||
(env["PATH_INFO"].index("/srv/status") == 0)
- if ::Logster::Logger === Rails.logger
+ if defined?(::Logster::Logger) && Logster.logger
override = true
- Rails.logger.override_level = Logger::ERROR
+ Logster.logger.override_level = Logger::ERROR
end
end
- super(env).tap { Rails.logger.override_level = nil if override }
+ super(env).tap { Logster.logger.override_level = nil if override }
end
end
diff --git a/config/initializers/100-silence_logger.rb b/config/initializers/100-silence_logger.rb
index e01b29816f7..d74386878bd 100644
--- a/config/initializers/100-silence_logger.rb
+++ b/config/initializers/100-silence_logger.rb
@@ -20,16 +20,21 @@ class SilenceLogger < Rails::Rack::Logger
if env[HTTP_X_SILENCE_LOGGER] || @opts[:silenced].include?(path_info) ||
path_info.start_with?("/logs") || path_info.start_with?("/user_avatar") ||
path_info.start_with?("/letter_avatar")
- if ::Logster::Logger === Rails.logger
+ if defined?(::Logster::Logger) && Logster.logger
override = true
- Rails.logger.override_level = Logger::WARN
+ Logster.logger.override_level = Logger::WARN
end
@app.call(env)
else
- super(env)
+ # TODO: Just call `super` instead when upgrading to Rails 7.2. With Rails
+ # 7.1 there is a bug in `Rails::Rack::Logger` when there is more than one
+ # `ActiveSupport::TaggedLogging` logger in the broadcast logger. It
+ # results in duplicating the response from Rack as many times as there
+ # are tagged loggers, returning an array of arrays.
+ super.tap { break _1.first if _1.any?(Array) }
end
ensure
- Rails.logger.override_level = nil if override
+ Logster.logger.override_level = nil if override
end
end
diff --git a/config/initializers/101-lograge.rb b/config/initializers/101-lograge.rb
index 3baac8b4b46..b17cb7f3c77 100644
--- a/config/initializers/101-lograge.rb
+++ b/config/initializers/101-lograge.rb
@@ -111,8 +111,8 @@ Rails.application.config.to_prepare do
# Remove ActiveSupport::Logger from the chain and replace with Lograge's
# logger
- Rails.logger.chained.pop
- Rails.logger.chain(config.lograge.logger)
+ Rails.logger.stop_broadcasting_to(Rails.logger.broadcasts.last)
+ Rails.logger.broadcast_to(config.lograge.logger)
end
end
end
diff --git a/config/initializers/102-truncate-logs.rb b/config/initializers/102-truncate-logs.rb
index b1276f3d967..29601aa1f4b 100644
--- a/config/initializers/102-truncate-logs.rb
+++ b/config/initializers/102-truncate-logs.rb
@@ -22,10 +22,6 @@ if Rails.env.production? || ENV["ENABLE_LOGS_TRUNCATION"] == "1"
end
Rails.application.config.to_prepare do
- set_or_extend_truncate_logs_formatter(Rails.logger)
-
- if Rails.logger.respond_to? :chained
- Rails.logger.chained.each { |logger| set_or_extend_truncate_logs_formatter(logger) }
- end
+ Rails.logger.broadcasts.each { |logger| set_or_extend_truncate_logs_formatter(logger) }
end
end
diff --git a/config/initializers/new_framework_defaults_7_0.rb b/config/initializers/new_framework_defaults_7_0.rb
deleted file mode 100644
index fdbf91e62fc..00000000000
--- a/config/initializers/new_framework_defaults_7_0.rb
+++ /dev/null
@@ -1,106 +0,0 @@
-# frozen_string_literal: true
-
-# Be sure to restart your server when you modify this file.
-#
-# This file eases your Rails 7.0 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.0`.
-#
-# Read the Guide for Upgrading Ruby on Rails for more info on each option.
-# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
-
-# `button_to` view helper will render `<button>` element, regardless of whether
-# or not the content is passed as the first argument or as a block.
-Rails.application.config.action_view.button_to_generates_button_tag = true
-
-# `stylesheet_link_tag` view helper will not render the media attribute by default.
-Rails.application.config.action_view.apply_stylesheet_media_default = false
-
-# Change the digest class for the key generators to `OpenSSL::Digest::SHA256`.
-# Changing this default means invalidate all encrypted messages generated by
-# your application and, all the encrypted cookies. Only change this after you
-# rotated all the messages using the key rotator.
-#
-# See upgrading guide for more information on how to build a rotator.
-# https://guides.rubyonrails.org/v7.0/upgrading_ruby_on_rails.html
-# Rails.application.config.active_support.key_generator_hash_digest_class = OpenSSL::Digest::SHA256
-
-# Change the digest class for ActiveSupport::Digest.
-# Changing this default means that for example Etags change and
-# various cache keys leading to cache invalidation.
-Rails.application.config.active_support.hash_digest_class = OpenSSL::Digest::SHA256
-
-# Don't override ActiveSupport::TimeWithZone.name and use the default Ruby
-# implementation.
-Rails.application.config.active_support.remove_deprecated_time_with_zone_name = true
-
-# Change the format of the cache entry.
-# Changing this default means that all new cache entries added to the cache
-# will have a different format that is not supported by Rails 6.1 applications.
-# Only change this value after your application is fully deployed to Rails 7.0
-# and you have no plans to rollback.
-Rails.application.config.active_support.cache_format_version = 7.0
-
-# Calls `Rails.application.executor.wrap` around test cases.
-# This makes test cases behave closer to an actual request or job.
-# Several features that are normally disabled in test, such as Active Record query cache
-# and asynchronous queries will then be enabled.
-Rails.application.config.active_support.executor_around_test_case = true
-
-# Define the isolation level of most of Rails internal state.
-# If you use a fiber based server or job processor, you should set it to `:fiber`.
-# Otherwise the default of `:thread` if preferable.
-Rails.application.config.active_support.isolation_level = :thread
-
-# Set both the `:open_timeout` and `:read_timeout` values for `:smtp` delivery method.
-Rails.application.config.action_mailer.smtp_timeout = 5
-
-# Automatically infer `inverse_of` for associations with a scope.
-Rails.application.config.active_record.automatic_scope_inversing = true
-
-# Raise when running tests if fixtures contained foreign key violations
-Rails.application.config.active_record.verify_foreign_keys_for_fixtures = true
-
-# Disable partial inserts.
-# This default means that all columns will be referenced in INSERT queries
-# regardless of whether they have a default or not.
-Rails.application.config.active_record.partial_inserts = false
-#
-# Protect from open redirect attacks in `redirect_back_or_to` and `redirect_to`.
-Rails.application.config.action_controller.raise_on_open_redirects = true
-
-# If you're upgrading and haven't set `cookies_serializer` previously, your cookie serializer
-# was `:marshal`. Convert all cookies to JSON, using the `:hybrid` formatter.
-#
-# If you're confident all your cookies are JSON formatted, you can switch to the `:json` formatter.
-#
-# Continue to use `:marshal` for backward-compatibility with old cookies.
-#
-# If you have configured the serializer elsewhere, you can remove this.
-#
-# See https://guides.rubyonrails.org/action_controller_overview.html#cookies for more information.
-Rails.application.config.action_dispatch.cookies_serializer = :hybrid
-
-# Enable parameter wrapping for JSON.
-# Previously this was set in an initializer. It's fine to keep using that initializer if you've customized it.
-# To disable parameter wrapping entirely, set this config to `false`.
-# Rails.application.config.action_controller.wrap_parameters_by_default = true
-
-# Specifies whether generated namespaced UUIDs follow the RFC 4122 standard for namespace IDs provided as a
-# `String` to `Digest::UUID.uuid_v3` or `Digest::UUID.uuid_v5` method calls.
-#
-# See https://guides.rubyonrails.org/configuring.html#config-active-support-use-rfc4122-namespaced-uuids for
-# more information.
-Rails.application.config.active_support.use_rfc4122_namespaced_uuids = true
-
-# Change the default headers to disable browsers' flawed legacy XSS protection.
-Rails.application.config.action_dispatch.default_headers = {
- "X-Frame-Options" => "SAMEORIGIN",
- "X-XSS-Protection" => "0",
- "X-Content-Type-Options" => "nosniff",
- "X-Download-Options" => "noopen",
- "X-Permitted-Cross-Domain-Policies" => "none",
- "Referrer-Policy" => "strict-origin-when-cross-origin",
-}
diff --git a/config/initializers/new_framework_defaults_7_1.rb b/config/initializers/new_framework_defaults_7_1.rb
new file mode 100644
index 00000000000..974cc2aa3a7
--- /dev/null
+++ b/config/initializers/new_framework_defaults_7_1.rb
@@ -0,0 +1,224 @@
+# frozen_string_literal: true
+# Be sure to restart your server when you modify this file.
+#
+# This file eases your Rails 7.1 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.1`.
+#
+# Read the Guide for Upgrading Ruby on Rails for more info on each option.
+# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
+
+# No longer add autoloaded paths into `$LOAD_PATH`. This means that you won't be able
+# to manually require files that are managed by the autoloader, which you shouldn't do anyway.
+# This will reduce the size of the load path, making `require` faster if you don't use bootsnap, or reduce the size
+# of the bootsnap cache if you use it.
+# Rails.application.config.add_autoload_paths_to_load_path = false
+
+# Remove the default X-Download-Options headers since it is used only by Internet Explorer.
+# If you need to support Internet Explorer, add back `"X-Download-Options" => "noopen"`.
+# Rails.application.config.action_dispatch.default_headers = {
+# "X-Frame-Options" => "SAMEORIGIN",
+# "X-XSS-Protection" => "0",
+# "X-Content-Type-Options" => "nosniff",
+# "X-Permitted-Cross-Domain-Policies" => "none",
+# "Referrer-Policy" => "strict-origin-when-cross-origin"
+# }
+
+# Do not treat an `ActionController::Parameters` instance
+# as equal to an equivalent `Hash` by default.
+# Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality = false
+
+# Active Record Encryption now uses SHA-256 as its hash digest algorithm. Important: If you have
+# data encrypted with previous Rails versions, there are two scenarios to consider:
+#
+# 1. If you have +config.active_support.key_generator_hash_digest_class+ configured as SHA1 (the default
+# before Rails 7.0), you need to configure SHA-1 for Active Record Encryption too:
+# Rails.application.config.active_record.encryption.hash_digest_class = OpenSSL::Digest::SHA1
+# 2. If you have +config.active_support.key_generator_hash_digest_class+ configured as SHA256 (the new default
+# in 7.0), then you need to configure SHA-256 for Active Record Encryption:
+# Rails.application.config.active_record.encryption.hash_digest_class = OpenSSL::Digest::SHA256
+#
+# If you don't currently have data encrypted with Active Record encryption, you can disable this setting to
+# configure the default behavior starting 7.1+:
+# Rails.application.config.active_record.encryption.support_sha1_for_non_deterministic_encryption = false
+
+# No longer run after_commit callbacks on the first of multiple Active Record
+# instances to save changes to the same database row within a transaction.
+# Instead, run these callbacks on the instance most likely to have internal
+# state which matches what was committed to the database, typically the last
+# instance to save.
+# Rails.application.config.active_record.run_commit_callbacks_on_first_saved_instances_in_transaction = false
+
+# Configures SQLite with a strict strings mode, which disables double-quoted string literals.
+#
+# SQLite has some quirks around double-quoted string literals.
+# It first tries to consider double-quoted strings as identifier names, but if they don't exist
+# it then considers them as string literals. Because of this, typos can silently go unnoticed.
+# For example, it is possible to create an index for a non existing column.
+# See https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted for more details.
+# Rails.application.config.active_record.sqlite3_adapter_strict_strings_by_default = true
+
+# Disable deprecated singular associations names
+# Rails.application.config.active_record.allow_deprecated_singular_associations_name = false
+
+# Enable the Active Job `BigDecimal` argument serializer, which guarantees
+# roundtripping. Without this serializer, some queue adapters may serialize
+# `BigDecimal` arguments as simple (non-roundtrippable) strings.
+#
+# When deploying an application with multiple replicas, old (pre-Rails 7.1)
+# replicas will not be able to deserialize `BigDecimal` arguments from this
+# serializer. Therefore, this setting should only be enabled after all replicas
+# have been successfully upgraded to Rails 7.1.
+# Rails.application.config.active_job.use_big_decimal_serializer = true
+
+# Specify if an `ArgumentError` should be raised if `Rails.cache` `fetch` or
+# `write` are given an invalid `expires_at` or `expires_in` time.
+# Options are `true`, and `false`. If `false`, the exception will be reported
+# as `handled` and logged instead.
+# Rails.application.config.active_support.raise_on_invalid_cache_expiration_time = true
+
+# Specify whether Query Logs will format tags using the SQLCommenter format
+# (https://open-telemetry.github.io/opentelemetry-sqlcommenter/), or using the legacy format.
+# Options are `:legacy` and `:sqlcommenter`.
+# Rails.application.config.active_record.query_log_tags_format = :sqlcommenter
+
+# Specify the default serializer used by `MessageEncryptor` and `MessageVerifier`
+# instances.
+#
+# The legacy default is `:marshal`, which is a potential vector for
+# deserialization attacks in cases where a message signing secret has been
+# leaked.
+#
+# In Rails 7.1, the new default is `:json_allow_marshal` which serializes and
+# deserializes with `ActiveSupport::JSON`, but can fall back to deserializing
+# with `Marshal` so that legacy messages can still be read.
+#
+# In Rails 7.2, the default will become `:json` which serializes and
+# deserializes with `ActiveSupport::JSON` only.
+#
+# Alternatively, you can choose `:message_pack` or `:message_pack_allow_marshal`,
+# which serialize with `ActiveSupport::MessagePack`. `ActiveSupport::MessagePack`
+# can roundtrip some Ruby types that are not supported by JSON, and may provide
+# improved performance, but it requires the `msgpack` gem.
+#
+# For more information, see
+# https://guides.rubyonrails.org/v7.1/configuring.html#config-active-support-message-serializer
+#
+# If you are performing a rolling deploy of a Rails 7.1 upgrade, wherein servers
+# that have not yet been upgraded must be able to read messages from upgraded
+# servers, first deploy without changing the serializer, then set the serializer
+# in a subsequent deploy.
+# Rails.application.config.active_support.message_serializer = :json_allow_marshal
+
+# Enable a performance optimization that serializes message data and metadata
+# together. This changes the message format, so messages serialized this way
+# cannot be read by older versions of Rails. However, messages that use the old
+# format can still be read, regardless of whether this optimization is enabled.
+#
+# To perform a rolling deploy of a Rails 7.1 upgrade, wherein servers that have
+# not yet been upgraded must be able to read messages from upgraded servers,
+# leave this optimization off on the first deploy, then enable it on a
+# subsequent deploy.
+# Rails.application.config.active_support.use_message_serializer_for_metadata = true
+
+# Set the maximum size for Rails log files.
+#
+# `config.load_defaults 7.1` does not set this value for environments other than
+# development and test.
+#
+# if Rails.env.local?
+# Rails.application.config.log_file_size = 100 * 1024 * 1024
+# end
+
+# Enable raising on assignment to attr_readonly attributes. The previous
+# behavior would allow assignment but silently not persist changes to the
+# database.
+# Rails.application.config.active_record.raise_on_assign_to_attr_readonly = true
+
+# Enable validating only parent-related columns for presence when the parent is mandatory.
+# The previous behavior was to validate the presence of the parent record, which performed an extra query
+# to get the parent every time the child record was updated, even when parent has not changed.
+# Rails.application.config.active_record.belongs_to_required_validates_foreign_key = false
+
+# Enable precompilation of `config.filter_parameters`. Precompilation can
+# improve filtering performance, depending on the quantity and types of filters.
+# Rails.application.config.precompile_filter_parameters = true
+
+# Enable before_committed! callbacks on all enrolled records in a transaction.
+# The previous behavior was to only run the callbacks on the first copy of a record
+# if there were multiple copies of the same record enrolled in the transaction.
+# Rails.application.config.active_record.before_committed_on_all_records = true
+
+# Disable automatic column serialization into YAML.
+# To keep the historic behavior, you can set it to `YAML`, however it is
+# recommended to explicitly define the serialization method for each column
+# rather than to rely on a global default.
+# Rails.application.config.active_record.default_column_serializer = nil
+
+# Enable a performance optimization that serializes Active Record models
+# in a faster and more compact way.
+#
+# To perform a rolling deploy of a Rails 7.1 upgrade, wherein servers that have
+# not yet been upgraded must be able to read caches from upgraded servers,
+# leave this optimization off on the first deploy, then enable it on a
+# subsequent deploy.
+# Rails.application.config.active_record.marshalling_format_version = 7.1
+
+# Run `after_commit` and `after_*_commit` callbacks in the order they are defined in a model.
+# This matches the behaviour of all other callbacks.
+# In previous versions of Rails, they ran in the inverse order.
+# Rails.application.config.active_record.run_after_transaction_callbacks_in_order_defined = true
+
+# Whether a `transaction` block is committed or rolled back when exited via `return`, `break` or `throw`.
+#
+# Rails.application.config.active_record.commit_transaction_on_non_local_return = true
+
+# Controls when to generate a value for <tt>has_secure_token</tt> declarations.
+#
+# Rails.application.config.active_record.generate_secure_token_on = :initialize
+
+# ** Please read carefully, this must be configured in config/application.rb **
+# Change the format of the cache entry.
+# Changing this default means that all new cache entries added to the cache
+# will have a different format that is not supported by Rails 7.0
+# applications.
+# Only change this value after your application is fully deployed to Rails 7.1
+# and you have no plans to rollback.
+# When you're ready to change format, add this to `config/application.rb` (NOT
+# this file):
+# config.active_support.cache_format_version = 7.1
+
+# Configure Action View to use HTML5 standards-compliant sanitizers when they are supported on your
+# platform.
+#
+# `Rails::HTML::Sanitizer.best_supported_vendor` will cause Action View to use HTML5-compliant
+# sanitizers if they are supported, else fall back to HTML4 sanitizers.
+#
+# In previous versions of Rails, Action View always used `Rails::HTML4::Sanitizer` as its vendor.
+#
+# Rails.application.config.action_view.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor
+
+# Configure Action Text to use an HTML5 standards-compliant sanitizer when it is supported on your
+# platform.
+#
+# `Rails::HTML::Sanitizer.best_supported_vendor` will cause Action Text to use HTML5-compliant
+# sanitizers if they are supported, else fall back to HTML4 sanitizers.
+#
+# In previous versions of Rails, Action Text always used `Rails::HTML4::Sanitizer` as its vendor.
+#
+# Rails.application.config.action_text.sanitizer_vendor = Rails::HTML::Sanitizer.best_supported_vendor
+
+# Configure the log level used by the DebugExceptions middleware when logging
+# uncaught exceptions during requests
+# Rails.application.config.action_dispatch.debug_exception_log_level = :error
+
+# Configure the test helpers in Action View, Action Dispatch, and rails-dom-testing to use HTML5
+# parsers.
+#
+# Nokogiri::HTML5 isn't supported on JRuby, so JRuby applications must set this to :html4.
+#
+# In previous versions of Rails, these test helpers always used an HTML4 parser.
+#
+# Rails.application.config.dom_testing_default_html_version = :html5
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 533e6ef6a5b..5b094278b24 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -323,6 +323,7 @@ en:
other: is the wrong length (should be %{count} characters)
other_than: "must be other than %{count}"
auth_overrides_username: "Username needs to be updated on authentication provider side, since `auth_overrides_username` setting is enabled."
+ required: "must exist"
template:
body: ! "There were problems with the following fields:"
header:
diff --git a/lib/discourse.rb b/lib/discourse.rb
index 2f910cf081a..4957b4c174c 100644
--- a/lib/discourse.rb
+++ b/lib/discourse.rb
@@ -954,14 +954,7 @@ module Discourse
def self.warn(message, env = nil)
append = env ? (+" ") << env.map { |k, v| "#{k}: #{v}" }.join(" ") : ""
- if !(Logster::Logger === Rails.logger)
- Rails.logger.warn("#{message}#{append}")
- return
- end
-
- loggers = [Rails.logger]
- loggers.concat(Rails.logger.chained) if Rails.logger.chained
-
+ loggers = Rails.logger.broadcasts
logster_env = env
if old_env = Thread.current[Logster::Logger::LOGSTER_ENV]
@@ -1116,16 +1109,7 @@ module Discourse
end
end
- schema_cache = ActiveRecord::Base.connection.schema_cache
-
RailsMultisite::ConnectionManagement.safe_each_connection do
- # load up schema cache for all multisite assuming all dbs have
- # an identical schema
- dup_cache = schema_cache.dup
- # this line is not really needed, but just in case the
- # underlying implementation changes lets give it a shot
- dup_cache.connection = nil
- ActiveRecord::Base.connection.schema_cache = dup_cache
I18n.t(:posts)
# this will force Cppjieba to preload if any site has it
diff --git a/lib/hijack.rb b/lib/hijack.rb
index b7a76808440..1e123fd6fc3 100644
--- a/lib/hijack.rb
+++ b/lib/hijack.rb
@@ -53,10 +53,10 @@ module Hijack
# this trick avoids double render, also avoids any litter that the controller hooks
# place on the response
instance = controller_class.new
- response = ActionDispatch::Response.new
- instance.response = response
+ response = ActionDispatch::Response.new.tap { _1.request = request_copy }
+ instance.set_response!(response)
+ instance.set_request!(request_copy)
- instance.request = request_copy
original_headers&.each { |k, v| instance.response.headers[k] = v }
view_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
diff --git a/lib/middleware/discourse_public_exceptions.rb b/lib/middleware/discourse_public_exceptions.rb
index d3666201608..c4ae0d673fb 100644
--- a/lib/middleware/discourse_public_exceptions.rb
+++ b/lib/middleware/discourse_public_exceptions.rb
@@ -34,7 +34,7 @@ module Middleware
if exception
begin
fake_controller = ApplicationController.new
- fake_controller.response = response
+ fake_controller.set_response!(response)
fake_controller.request = request = ActionDispatch::Request.new(env)
# We can not re-dispatch bad mime types
diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb
index d7b97eacf08..b25fb13ee7d 100644
--- a/lib/site_setting_extension.rb
+++ b/lib/site_setting_extension.rb
@@ -274,7 +274,7 @@ module SiteSettingExtension
end
def description(setting)
- I18n.t("site_settings.#{setting}", base_path: Discourse.base_path)
+ I18n.t("site_settings.#{setting}", base_path: Discourse.base_path, default: "")
end
def keywords(setting)
diff --git a/plugins/chat/app/models/chat/category_channel.rb b/plugins/chat/app/models/chat/category_channel.rb
index e23a37f1a7c..c303c191a3c 100644
--- a/plugins/chat/app/models/chat/category_channel.rb
+++ b/plugins/chat/app/models/chat/category_channel.rb
@@ -2,7 +2,7 @@
module Chat
class CategoryChannel < Channel
- alias_attribute :category, :chatable
+ alias_method :category, :chatable
delegate :read_restricted?, to: :category
delegate :url, to: :chatable, prefix: true
diff --git a/plugins/chat/app/models/chat/direct_message_channel.rb b/plugins/chat/app/models/chat/direct_message_channel.rb
index ede478a9713..2e5a1b8e2a9 100644
--- a/plugins/chat/app/models/chat/direct_message_channel.rb
+++ b/plugins/chat/app/models/chat/direct_message_channel.rb
@@ -2,7 +2,7 @@
module Chat
class DirectMessageChannel < Channel
- alias_attribute :direct_message, :chatable
+ alias_method :direct_message, :chatable
def direct_message_channel?
true
diff --git a/plugins/chat/spec/system/visit_channel_spec.rb b/plugins/chat/spec/system/visit_channel_spec.rb
index 506333ebd7e..c268b41640d 100644
--- a/plugins/chat/spec/system/visit_channel_spec.rb
+++ b/plugins/chat/spec/system/visit_channel_spec.rb
@@ -183,7 +183,7 @@ RSpec.describe "Visit channel", type: :system do
context "when visiting a specific channel message ID then navigating to another channel" do
fab!(:early_message) { Fabricate(:chat_message, chat_channel: category_channel_1) }
fab!(:other_channel) do
- Fabricate(:category_channel, category: category_channel_1.chatable)
+ Fabricate(:category_channel, chatable: category_channel_1.chatable)
end
fab!(:other_channel_message) { Fabricate(:chat_message, chat_channel: other_channel) }
diff --git a/spec/integration/invalid_request_spec.rb b/spec/integration/invalid_request_spec.rb
index 6d19bcb9c68..b845c3ef0e6 100644
--- a/spec/integration/invalid_request_spec.rb
+++ b/spec/integration/invalid_request_spec.rb
@@ -1,12 +1,11 @@
# frozen_string_literal: true
RSpec.describe "invalid requests", type: :request do
- before do
- @orig_logger = Rails.logger
- Rails.logger = @fake_logger = FakeLogger.new
- end
+ let(:fake_logger) { FakeLogger.new }
+
+ before { Rails.logger.broadcast_to(fake_logger) }
- after { Rails.logger = @orig_logger }
+ after { Rails.logger.stop_broadcasting_to(fake_logger) }
it "handles NotFound with invalid json body" do
post "/latest.json",
@@ -15,8 +14,8 @@ RSpec.describe "invalid requests", type: :request do
"content-type" => "application/json",
}
expect(response.status).to eq(404)
- expect(@fake_logger.warnings.length).to eq(0)
- expect(@fake_logger.errors.length).to eq(0)
+ expect(fake_logger.warnings.length).to eq(0)
+ expect(fake_logger.errors.length).to eq(0)
end
it "handles EOFError when multipart request is malformed" do
@@ -27,14 +26,14 @@ RSpec.describe "invalid requests", type: :request do
"content-length" => "1",
}
expect(response.status).to eq(400)
- expect(@fake_logger.warnings.length).to eq(0)
- expect(@fake_logger.errors.length).to eq(0)
+ expect(fake_logger.warnings.length).to eq(0)
+ expect(fake_logger.errors.length).to eq(0)
end
it "handles invalid parameters" do
post "/latest.json", params: { "foo" => "\255bar" }
expect(response.status).to eq(404)
- expect(@fake_logger.warnings.length).to eq(0)
- expect(@fake_logger.errors.length).to eq(0)
+ expect(fake_logger.warnings.length).to eq(0)
+ expect(fake_logger.errors.length).to eq(0)
end
end
diff --git a/spec/lib/auth/default_current_user_provider_spec.rb b/spec/lib/auth/default_current_user_provider_spec.rb
index cc0f1983829..e06a711814e 100644
--- a/spec/lib/auth/default_current_user_provider_spec.rb
+++ b/spec/lib/auth/default_current_user_provider_spec.rb
@@ -21,11 +21,11 @@ RSpec.describe Auth::DefaultCurrentUserProvider do
end
def get_cookie_info(cookie_jar, name)
- headers = {}
+ response = ActionDispatch::Response.new
cookie_jar.always_write_cookie = true
- cookie_jar.write(headers)
+ cookie_jar.write(response)
- header = headers["Set-Cookie"]
+ header = response.headers["Set-Cookie"]
return if header.nil?
info = {}
diff --git a/spec/lib/email/message_builder_spec.rb b/spec/lib/email/message_builder_spec.rb
index 3ad1fbd5300..9b27835a2b9 100644
--- a/spec/lib/email/message_builder_spec.rb
+++ b/spec/lib/email/message_builder_spec.rb
@@ -14,9 +14,9 @@ RSpec.describe Email::MessageBuilder do
let(:body_modifier_block) { Proc.new { |subject, opts| "modified body" } }
let(:visit_link_to_respond_modifier_block) do
- Proc.new { |subject, opts| "modified visit_link_to_respond" }
+ Proc.new { |subject, opts| "modified_visit_link_to_respond" }
end
- let(:reply_by_email_modifier_block) { Proc.new { |subject, opts| "modified reply_by_email" } }
+ let(:reply_by_email_modifier_block) { Proc.new { |subject, opts| "modified_reply_by_email" } }
it "has the correct to address" do
expect(build_args[:to]).to eq(to_address)
@@ -69,7 +69,7 @@ RSpec.describe Email::MessageBuilder do
include_respond_instructions: true,
url: "http://localhost",
)
- expect(builder2.reply_by_email_key).to equal("modified reply_by_email")
+ expect(builder2.reply_by_email_key).to equal("modified_reply_by_email")
ensure
DiscoursePluginRegistry.unregister_modifier(
plugin_instance,
@@ -93,7 +93,7 @@ RSpec.describe Email::MessageBuilder do
url: "http://localhost",
)
expect(builder2.template_args[:respond_instructions]).to include(
- "modified visit_link_to_respond",
+ "modified_visit_link_to_respond",
)
ensure
DiscoursePluginRegistry.unregister_modifier(
diff --git a/spec/lib/hijack_spec.rb b/spec/lib/hijack_spec.rb
index 1c30928872a..041cdfd1de6 100644
--- a/spec/lib/hijack_spec.rb
+++ b/spec/lib/hijack_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe Hijack do
self.request = ActionController::TestRequest.new(env, nil, nil)
# we need this for the 418
- self.response = ActionDispatch::Response.new
+ set_response!(ActionDispatch::Response.new)
end
def hijack_test(&blk)
@@ -22,12 +22,10 @@ RSpec.describe Hijack do
end
end
- let :tester do
- Hijack::Tester.new
- end
+ let(:tester) { Hijack::Tester.new }
describe "Request Tracker integration" do
- let :logger do
+ let(:logger) do
lambda do |env, data|
@calls += 1
@status = data[:status]
@@ -181,7 +179,7 @@ RSpec.describe Hijack do
end
result =
- "HTTP/1.1 302 Found\r\nLocation: http://awesome.com\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: 84\r\nConnection: close\r\nX-Runtime: 1.000000\r\n\r\n<html><body>You are being <a href=\"http://awesome.com\">redirected</a>.</body></html>"
+ "HTTP/1.1 302 Found\r\nLocation: http://awesome.com\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: 0\r\nConnection: close\r\nX-Runtime: 1.000000\r\n\r\n"
expect(tester.io.string).to eq(result)
end
diff --git a/spec/lib/migration/safe_migrate_spec.rb b/spec/lib/migration/safe_migrate_spec.rb
index 3ed5413330a..9fe91b84e9f 100644
--- a/spec/lib/migration/safe_migrate_spec.rb
+++ b/spec/lib/migration/safe_migrate_spec.rb
@@ -9,11 +9,12 @@ RSpec.describe Migration::SafeMigrate do
end
def migrate_up(path)
- migrations = ActiveRecord::MigrationContext.new(path, ActiveRecord::SchemaMigration).migrations
+ migrations = ActiveRecord::MigrationContext.new(path).migrations
ActiveRecord::Migrator.new(
:up,
migrations,
- ActiveRecord::SchemaMigration,
+ ActiveRecord::Base.connection.schema_migration,
+ ActiveRecord::Base.connection.internal_metadata,
migrations.first.version,
).run
end
@@ -77,7 +78,7 @@ RSpec.describe Migration::SafeMigrate do
output = capture_stdout { migrate_up(path) }
- expect(output).to include("change_column_null(:users, :username, true)")
+ expect(output).to include("change_column_null(:users, :username, true, nil)")
end
it "supports being disabled" do
diff --git a/spec/lib/site_setting_extension_spec.rb b/spec/lib/site_setting_extension_spec.rb
index 8aaa1fb45ff..cc77db21d2f 100644
--- a/spec/lib/site_setting_extension_spec.rb
+++ b/spec/lib/site_setting_extension_spec.rb
@@ -422,9 +422,7 @@ RSpec.describe SiteSettingExtension do
end
end
- let :test_enum_class do
- TestEnumClass
- end
+ let(:test_enum_class) { TestEnumClass }
before do
settings.setting(:test_enum, "en", enum: test_enum_class)
diff --git a/spec/models/admin_dashboard_data_spec.rb b/spec/models/admin_dashboard_data_spec.rb
index dc660c5b166..e3e1a13607d 100644
--- a/spec/models/admin_dashboard_data_spec.rb
+++ b/spec/models/admin_dashboard_data_spec.rb
@@ -42,7 +42,7 @@ RSpec.describe AdminDashboardData do
end
describe "#problem_message_check" do
- let(:key) { AdminDashboardData.problem_messages.first }
+ let(:key) { "new_key" }
after { described_class.clear_problem_message(key) }
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 7a26329e532..4b06b324de6 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -678,7 +678,7 @@ RSpec.describe User do
quoted_post = create_post(user: user, topic: topic, post_number: 1, raw: "quoted post")
post = create_post(raw: <<~RAW)
Lorem ipsum
-
+
[quote="#{user.username}, post:1, topic:#{quoted_post.topic.id}"]
quoted post
[/quote]
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index c127fa662dc..943732be66e 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -245,7 +245,7 @@ RSpec.configure do |config|
CachedCounting.disable
begin
- ActiveRecord::Migration.check_pending!
+ ActiveRecord::Migration.check_all_pending!
rescue ActiveRecord::PendingMigrationError
raise "There are pending migrations, run RAILS_ENV=test bin/rake db:migrate"
end
@@ -718,7 +718,7 @@ RSpec.configure do |config|
end
config.after(:each, type: :multisite) do
- ActiveRecord::Base.clear_all_connections!
+ ActiveRecord::Base.connection_handler.clear_all_connections!
Rails.configuration.multisite = false # rubocop:disable Discourse/NoDirectMultisiteManipulation
RailsMultisite::ConnectionManagement.clear_settings!
ActiveRecord::Base.establish_connection
diff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rb
index 78a83a574aa..4eaf6b5a1b8 100644
--- a/spec/requests/application_controller_spec.rb
+++ b/spec/requests/application_controller_spec.rb
@@ -287,7 +287,7 @@ RSpec.describe ApplicationController do
expect(log).not_to include("exception app middleware")
- expect(response.parsed_body).to eq("status" => 400, "error" => "Bad Request")
+ expect(response.status).to eq(400)
end
end
diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb
index 1aecd088b26..5d0a23bbf8d 100644
--- a/spec/requests/categories_controller_spec.rb
+++ b/spec/requests/categories_controller_spec.rb
@@ -39,16 +39,16 @@ RSpec.describe CategoriesController do
it "redirects /category paths to /c paths" do
get "/category/uncategorized"
- expect(response.status).to eq(302)
- expect(response.body).to include("c/uncategorized")
+ expect(response).to have_http_status(:found)
+ expect(response).to redirect_to("/c/uncategorized")
end
it "respects permalinks before redirecting /category paths to /c paths" do
_perm = Permalink.create!(url: "category/something", category_id: category.id)
get "/category/something"
- expect(response.status).to eq(301)
- expect(response.body).to include(category.slug)
+ expect(response).to have_http_status(:moved_permanently)
+ expect(response).to redirect_to(%r{/c/#{category.slug}})
end
it "returns the right response for a normal user" do
diff --git a/spec/requests/embed_controller_spec.rb b/spec/requests/embed_controller_spec.rb
index 53284cc46f0..f21a5c92ddb 100644
--- a/spec/requests/embed_controller_spec.rb
+++ b/spec/requests/embed_controller_spec.rb
@@ -190,8 +190,6 @@ RSpec.describe EmbedController do
context "with a host" do
fab!(:embeddable_host)
- before { Jobs.run_immediately! }
-
it "doesn't raise an error with no referer" do
get "/embed/comments", params: { embed_url: embed_url }
@@ -246,6 +244,8 @@ RSpec.describe EmbedController do
end
context "with success" do
+ before { Jobs.run_immediately! }
+
it "tells the topic retriever to work when no previous embed is found" do
TopicRetriever.any_instance.expects(:retrieve)
diff --git a/spec/requests/session_controller_spec.rb b/spec/requests/session_controller_spec.rb
index df8867b276f..25ad4e17853 100644
--- a/spec/requests/session_controller_spec.rb
+++ b/spec/requests/session_controller_spec.rb
@@ -946,7 +946,7 @@ RSpec.describe SessionController do
get "/session/sso_login", params: Rack::Utils.parse_query(sso.payload), headers: headers
expect(response.status).to eq(403)
- expect(response.parsed_body).to include(I18n.t("discourse_connect.account_not_approved"))
+ expect(response.body).to include(I18n.t("discourse_connect.account_not_approved"))
end.to change { User.count }.by(1)
logged_on_user = Discourse.current_user_provider.new(request.env).current_user
@@ -1124,7 +1124,7 @@ RSpec.describe SessionController do
login_with_sso_and_invite
expect(response.status).to eq(403)
- expect(response.parsed_body).to include(I18n.t("discourse_connect.account_not_approved"))
+ expect(response.body).to include(I18n.t("discourse_connect.account_not_approved"))
expect(invite.reload.redeemed?).to eq(true)
user = User.find_by_email("[email protected]")
diff --git a/spec/requests/uploads_controller_multisite_spec.rb b/spec/requests/uploads_controller_multisite_spec.rb
index badb310ef9d..5da91841111 100644
--- a/spec/requests/uploads_controller_multisite_spec.rb
+++ b/spec/requests/uploads_controller_multisite_spec.rb
@@ -8,13 +8,13 @@ RSpec.describe UploadsController, type: %i[multisite request] do
setup_s3
SiteSetting.secure_uploads = true
upload.update(secure: true)
+ sign_in(user)
+ freeze_time
end
it "redirects to the signed_url_for_path with the multisite DB name in the url" do
- sign_in(user)
- freeze_time
get upload.short_path
- expect(response.body).to include(RailsMultisite::ConnectionManagement.current_db)
+ expect(response).to redirect_to(/#{RailsMultisite::ConnectionManagement.current_db}/)
end
end
diff --git a/spec/support/fake_logger.rb b/spec/support/fake_logger.rb
index 15c1a9e5f32..d7c291d9cef 100644
--- a/spec/support/fake_logger.rb
+++ b/spec/support/fake_logger.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class FakeLogger
- attr_reader :debugs, :infos, :warnings, :errors, :fatals
+ attr_reader :debugs, :infos, :warnings, :errors, :fatals, :severities
attr_accessor :level
def initialize
@@ -11,9 +11,10 @@ class FakeLogger
@errors = []
@fatals = []
@level = Logger::DEBUG
+ @severities = { 0 => :debugs, 1 => :infos, 2 => :warnings, 3 => :errors, 4 => :fatals }
end
- def debug(message)
+ def debug(message = nil)
@debugs << message
end
@@ -29,7 +30,7 @@ class FakeLogger
@level <= Logger::INFO
end
- def warn(message)
+ def warn(message = nil)
@warnings << message
end
@@ -37,7 +38,7 @@ class FakeLogger
@level <= Logger::WARN
end
- def error(message)
+ def error(message = nil)
@errors << message
end
@@ -45,7 +46,7 @@ class FakeLogger
@level <= Logger::ERROR
end
- def fatal(message)
+ def fatal(message = nil)
@fatals << message
end
@@ -55,4 +56,12 @@ class FakeLogger
def formatter
end
+
+ def add(severity, message = nil, progname = nil)
+ public_send(severities[severity]) << message
+ end
+
+ def broadcasts
+ [self]
+ end
end
diff --git a/spec/support/i18n_helpers.rb b/spec/support/i18n_helpers.rb
index 4e178d59042..99f2713a947 100644
--- a/spec/support/i18n_helpers.rb
+++ b/spec/support/i18n_helpers.rb
@@ -2,9 +2,12 @@
module I18nHelpers
def allow_missing_translations
+ original_handler = I18n.exception_handler
+ I18n.exception_handler = nil
Rails.application.config.i18n.raise_on_missing_translations = false
yield
ensure
+ I18n.exception_handler = original_handler
Rails.application.config.i18n.raise_on_missing_translations = true
end
end
diff --git a/spec/support/locales/dashboard.en.yml b/spec/support/locales/dashboard.en.yml
new file mode 100644
index 00000000000..9b0bfc1fe5c
--- /dev/null
+++ b/spec/support/locales/dashboard.en.yml
@@ -0,0 +1,6 @@
+en:
+ new_key: new_key
+ dashboard:
+ problem:
+ foo: foo
+ bar: bar
diff --git a/spec/support/locales/message_builder.en.yml b/spec/support/locales/message_builder.en.yml
new file mode 100644
index 00000000000..628f94d8357
--- /dev/null
+++ b/spec/support/locales/message_builder.en.yml
@@ -0,0 +1,2 @@
+en:
+ modified_visit_link_to_respond: modified_visit_link_to_respond
diff --git a/spec/support/locales/problem_check.en.yml b/spec/support/locales/problem_check.en.yml
new file mode 100644
index 00000000000..07898c9a3a8
--- /dev/null
+++ b/spec/support/locales/problem_check.en.yml
@@ -0,0 +1,2 @@
+en:
+ failing_check: failing_check