From a0e1cac95f72f2c9edac68d0f8a51e9ac8868852 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 3 Jul 2022 03:39:44 +0200 Subject: [PATCH] Add rails 7 support --- Gemfile.lock | 48 +++++++++---------- .../diaspora_federation/fetch_controller.rb | 5 +- bin/rails | 8 ++-- diaspora_federation-rails.gemspec | 2 +- test/dummy/bin/rails | 2 +- test/dummy/bin/setup | 12 ++--- test/dummy/config/application.rb | 3 +- test/dummy/config/boot.rb | 1 - test/dummy/config/environments/development.rb | 13 ++--- test/dummy/config/environments/production.rb | 39 +++------------ test/dummy/config/environments/test.rb | 9 ++-- .../initializers/backtrace_silencers.rb | 10 ++++ .../initializers/filter_parameter_logging.rb | 4 +- test/dummy/config/routes.rb | 2 + 14 files changed, 69 insertions(+), 89 deletions(-) create mode 100644 test/dummy/config/initializers/backtrace_silencers.rb diff --git a/Gemfile.lock b/Gemfile.lock index 93b86b5..ba45006 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,7 +9,7 @@ PATH valid (~> 1.0) diaspora_federation-json_schema (0.3.0) diaspora_federation-rails (0.3.0) - actionpack (>= 5.2, < 7) + actionpack (>= 5.2, < 8) diaspora_federation (= 0.3.0) diaspora_federation-test (0.3.0) diaspora_federation (= 0.3.0) @@ -19,32 +19,31 @@ PATH GEM remote: https://rubygems.org/ specs: - actionpack (6.1.4.1) - actionview (= 6.1.4.1) - activesupport (= 6.1.4.1) - rack (~> 2.0, >= 2.0.9) + actionpack (7.0.3.1) + actionview (= 7.0.3.1) + activesupport (= 7.0.3.1) + rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (6.1.4.1) - activesupport (= 6.1.4.1) + actionview (7.0.3.1) + activesupport (= 7.0.3.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activesupport (6.1.4.1) + activesupport (7.0.3.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) ast (2.4.2) builder (3.2.4) byebug (11.1.3) coderay (1.1.3) - concurrent-ruby (1.1.9) + concurrent-ruby (1.1.10) crack (0.4.5) rexml crass (1.0.6) @@ -86,7 +85,7 @@ GEM httparty (0.20.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (1.8.11) + i18n (1.12.0) concurrent-ruby (~> 1.0) json-schema (2.8.1) addressable (>= 2.4) @@ -96,7 +95,7 @@ GEM listen (3.7.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.12.0) + loofah (2.18.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) macaddr (1.7.2) @@ -106,10 +105,10 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2021.1115) mini_portile2 (2.8.0) - minitest (5.14.4) + minitest (5.16.2) multi_xml (0.6.0) multipart-post (2.1.1) - nokogiri (1.13.3) + nokogiri (1.13.7) mini_portile2 (~> 2.8.0) racc (~> 1.4) nyan-cat-formatter (0.12.0) @@ -139,20 +138,21 @@ GEM pry (~> 0.10) public_suffix (4.0.6) racc (1.6.0) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) + rack (2.2.4) + rack-test (2.0.2) + rack (>= 1.3) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) + rails-html-sanitizer (1.4.3) loofah (~> 2.3) - railties (6.1.4.1) - actionpack (= 6.1.4.1) - activesupport (= 6.1.4.1) + railties (7.0.3.1) + actionpack (= 7.0.3.1) + activesupport (= 7.0.3.1) method_source - rake (>= 0.13) + rake (>= 12.2) thor (~> 1.0) + zeitwerk (~> 2.5) rainbow (3.0.0) rake (13.0.6) rb-fsevent (0.11.0) @@ -217,7 +217,7 @@ GEM simplecov_json_formatter (0.1.3) systemu (2.6.5) terminal-table (1.6.0) - thor (1.1.0) + thor (1.2.1) typhoeus (1.4.0) ethon (>= 0.9.0) tzinfo (2.0.4) @@ -231,7 +231,7 @@ GEM crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) yard (0.9.26) - zeitwerk (2.5.1) + zeitwerk (2.6.0) PLATFORMS ruby diff --git a/app/controllers/diaspora_federation/fetch_controller.rb b/app/controllers/diaspora_federation/fetch_controller.rb index 24ec5fd..8fe8b07 100644 --- a/app/controllers/diaspora_federation/fetch_controller.rb +++ b/app/controllers/diaspora_federation/fetch_controller.rb @@ -15,8 +15,9 @@ module DiasporaFederation if magic_env render xml: magic_env, content_type: "application/magic-envelope+xml" else - redirect_to DiasporaFederation.callbacks.trigger(:fetch_person_url_to, - entity.author, "/fetch/#{params[:type]}/#{params[:guid]}") + redirect_url = DiasporaFederation.callbacks.trigger(:fetch_person_url_to, + entity.author, "/fetch/#{params[:type]}/#{params[:guid]}") + redirect_to redirect_url, allow_other_host: true end else head :not_found diff --git a/bin/rails b/bin/rails index 6b5ee87..79d888a 100755 --- a/bin/rails +++ b/bin/rails @@ -2,12 +2,12 @@ # This command will automatically be run when you run "rails" with Rails gems # installed from the root of your application. -ENGINE_ROOT = File.expand_path('..', __dir__) -ENGINE_PATH = File.expand_path('../lib/diaspora_federation/engine', __dir__) -APP_PATH = File.expand_path('../test/dummy/config/application', __dir__) +ENGINE_ROOT = File.expand_path("..", __dir__) +ENGINE_PATH = File.expand_path("../lib/diaspora_federation/engine", __dir__) +APP_PATH = File.expand_path("../test/dummy/config/application", __dir__) # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) require "rails/all" diff --git a/diaspora_federation-rails.gemspec b/diaspora_federation-rails.gemspec index 5908d29..71d4fd7 100644 --- a/diaspora_federation-rails.gemspec +++ b/diaspora_federation-rails.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 2.7" - s.add_dependency "actionpack", ">= 5.2", "< 7" + s.add_dependency "actionpack", ">= 5.2", "< 8" s.add_dependency "diaspora_federation", DiasporaFederation::VERSION end diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails index 6fb4e40..efc0377 100755 --- a/test/dummy/bin/rails +++ b/test/dummy/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../config/application', __dir__) +APP_PATH = File.expand_path("../config/application", __dir__) require_relative "../config/boot" require "rails/commands" diff --git a/test/dummy/bin/setup b/test/dummy/bin/setup index bf08171..57b65c8 100755 --- a/test/dummy/bin/setup +++ b/test/dummy/bin/setup @@ -2,7 +2,7 @@ require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -13,13 +13,13 @@ FileUtils.chdir APP_ROOT do # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index f7d2554..1f3ea4c 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -14,7 +14,6 @@ require "action_controller/railtie" # require "action_text/engine" require "action_view/railtie" # require "action_cable/engine" -# require "sprockets/railtie" require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems @@ -25,7 +24,7 @@ require "diaspora_federation/rails" module Dummy class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.0 + config.load_defaults 7.0 # Configuration for the application, engines, and railties goes here. # diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index 593ee1f..7aedefb 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -# Set up gems listed in the Gemfile. ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 70df74b..ae14d32 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -16,6 +16,9 @@ Rails.application.configure do # Show full error reports. config.consider_all_requests_local = true + # Enable server timing + config.server_timing = true + # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join("tmp/caching-dev.txt").exist? @@ -47,16 +50,6 @@ Rails.application.configure do # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true - # Use an evented file watcher to asynchronously detect changes in source code, - # routes, locales, etc. This feature depends on the listen gem. - config.file_watcher = ActiveSupport::EventedFileUpdateChecker - - # Set the logging destination(s) - config.log_to = %w[stdout file] - - # Show the logging configuration on STDOUT - config.show_log_configuration = true - # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true end diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index 35b3954..602df3e 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -27,11 +27,11 @@ Rails.application.configure do config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.asset_host = 'http://assets.example.com' + # config.asset_host = "http://assets.example.com" # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache + # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -54,46 +54,19 @@ Rails.application.configure do # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Log disallowed deprecations. - config.active_support.disallowed_deprecation = :log - - # Tell Active Support which deprecation messages to disallow. - config.active_support.disallowed_deprecation_warnings = [] + # Don't log any deprecations. + config.active_support.report_deprecations = false # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require "syslog/logger" - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end - - # Inserts middleware to perform automatic connection switching. - # The `database_selector` hash is used to pass options to the DatabaseSelector - # middleware. The `delay` is used to determine how long to wait after a write - # to send a subsequent read to the primary. - # - # The `database_resolver` class is used by the middleware to determine which - # database is appropriate to use based on the time delay. - # - # The `database_resolver_context` class is used by the middleware to set - # timestamps for the last write to the primary. The resolver uses the context - # class timestamps to determine how long to wait before reading from the - # replica. - # - # By default Rails will store a last write timestamp in the session. The - # DatabaseSelector middleware is designed as such you can define your own - # strategy for connection switching and pass that into the middleware through - # these configuration options. - # config.active_record.database_selector = { delay: 2.seconds } - # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver - # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 18e193d..d344e7c 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -10,12 +10,13 @@ require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. + # Turn false under Spring and add config.action_view.cache_template_loading = true. config.cache_classes = true - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. + config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true diff --git a/test/dummy/config/initializers/backtrace_silencers.rb b/test/dummy/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..74f30e8 --- /dev/null +++ b/test/dummy/config/initializers/backtrace_silencers.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code +# by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". +Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb index 3babc73..3df77c5 100644 --- a/test/dummy/config/initializers/filter_parameter_logging.rb +++ b/test/dummy/config/initializers/filter_parameter_logging.rb @@ -2,7 +2,9 @@ # Be sure to restart your server when you modify this file. -# Configure sensitive parameters which will be filtered from the log file. +# Configure parameters to be filtered from the log file. Use this to limit dissemination of +# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported +# notations and behaviors. Rails.application.config.filter_parameters += %i[ passw secret token _key crypt salt certificate otp ssn ] diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index cabecec..e9d6ce4 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true Rails.application.routes.draw do + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + mount DiasporaFederation::Engine => "/" get "discovery" => "discovery#discovery"