diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-16 17:46:18 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-20 22:26:58 +0300 |
commit | 2d38a24a8688b3db5e8cba90e81a0eccd8086474 (patch) | |
tree | 1b199c45668a8afee84a02ee36c6f9dcd2547cba | |
parent | 2f30b42d93821aa1fe0c52229433b3d6176c29c9 (diff) |
Upgrade to rails 6.0
-rw-r--r-- | .rubocop.yml | 6 | ||||
-rw-r--r-- | Gemfile | 4 | ||||
-rw-r--r-- | Gemfile.lock | 110 | ||||
-rw-r--r-- | app/mailers/notifier.rb | 2 | ||||
-rwxr-xr-x | bin/setup | 33 | ||||
-rw-r--r-- | config/application.rb | 36 | ||||
-rw-r--r-- | config/boot.rb | 2 | ||||
-rw-r--r-- | config/environments/development.rb | 17 | ||||
-rw-r--r-- | config/environments/production.rb | 43 | ||||
-rw-r--r-- | config/environments/test.rb | 18 | ||||
-rw-r--r-- | config/initializers/application_controller_renderer.rb | 10 | ||||
-rw-r--r-- | config/initializers/filter_parameter_logging.rb | 3 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | spec/controllers/node_info_controller_spec.rb | 2 |
14 files changed, 188 insertions, 100 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index e1a7219a2..fa0c9d76c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -57,6 +57,12 @@ Layout/SpaceAroundEqualsInParameterDefault: # are needed. Style/StringLiterals: EnforcedStyle: double_quotes + Exclude: + # These files are generated by rails, so it's best to keep them close to the original for smaller diffs + - "config/application.rb" + - "config/boot.rb" + - "config/environment.rb" + - "config/environments/*.rb" # We do not need to support Ruby 1.9, so this is good to use. Style/SymbolArray: @@ -2,7 +2,7 @@ source "https://rubygems.org" -gem "rails", "5.2.8" +gem "rails", "6.0.5.1" # Legacy Rails features, remove me! # responders (class level) @@ -128,7 +128,7 @@ gem "markdown-it-html5-embed", "1.0.0" gem "http_accept_language", "2.1.1" gem "i18n-inflector-rails", "1.0.7" -gem "rails-i18n", "5.1.3" +gem "rails-i18n", "6.0.0" # Map gem "leaflet-rails", "1.7.0" diff --git a/Gemfile.lock b/Gemfile.lock index 3a6990d88..fe1f5cc44 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,52 +2,66 @@ GEM remote: https://rubygems.org/ remote: https://gems.diasporafoundation.org/ specs: - actioncable (5.2.8) - actionpack (= 5.2.8) + actioncable (6.0.5.1) + actionpack (= 6.0.5.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.8) - actionpack (= 5.2.8) - actionview (= 5.2.8) - activejob (= 5.2.8) + actionmailbox (6.0.5.1) + actionpack (= 6.0.5.1) + activejob (= 6.0.5.1) + activerecord (= 6.0.5.1) + activestorage (= 6.0.5.1) + activesupport (= 6.0.5.1) + mail (>= 2.7.1) + actionmailer (6.0.5.1) + actionpack (= 6.0.5.1) + actionview (= 6.0.5.1) + activejob (= 6.0.5.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.8) - actionview (= 5.2.8) - activesupport (= 5.2.8) + actionpack (6.0.5.1) + actionview (= 6.0.5.1) + activesupport (= 6.0.5.1) rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.8) - activesupport (= 5.2.8) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.5.1) + actionpack (= 6.0.5.1) + activerecord (= 6.0.5.1) + activestorage (= 6.0.5.1) + activesupport (= 6.0.5.1) + nokogiri (>= 1.8.5) + actionview (6.0.5.1) + activesupport (= 6.0.5.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) + rails-html-sanitizer (~> 1.1, >= 1.2.0) active_model_serializers (0.9.8) activemodel (>= 3.2) concurrent-ruby (~> 1.0) - activejob (5.2.8) - activesupport (= 5.2.8) + activejob (6.0.5.1) + activesupport (= 6.0.5.1) globalid (>= 0.3.6) - activemodel (5.2.8) - activesupport (= 5.2.8) - activerecord (5.2.8) - activemodel (= 5.2.8) - activesupport (= 5.2.8) - arel (>= 9.0) + activemodel (6.0.5.1) + activesupport (= 6.0.5.1) + activerecord (6.0.5.1) + activemodel (= 6.0.5.1) + activesupport (= 6.0.5.1) activerecord-import (1.4.0) activerecord (>= 4.2) - activestorage (5.2.8) - actionpack (= 5.2.8) - activerecord (= 5.2.8) - marcel (~> 1.0.0) - activesupport (5.2.8) + activestorage (6.0.5.1) + actionpack (= 6.0.5.1) + activejob (= 6.0.5.1) + activerecord (= 6.0.5.1) + marcel (~> 1.0) + activesupport (6.0.5.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + zeitwerk (~> 2.2, >= 2.2.2) acts-as-taggable-on (8.1.0) activerecord (>= 5.0, < 6.2) acts_as_api (1.0.1) @@ -60,7 +74,6 @@ GEM apparition (0.6.0) capybara (~> 3.13, < 4) websocket-driver (>= 0.6.5) - arel (9.0.0) asset_sync (2.15.2) activemodel (>= 4.1.0) fog-core @@ -317,7 +330,7 @@ GEM mime-types (~> 3.0) multi_xml (>= 0.5.2) httpclient (2.8.3) - i18n (1.10.0) + i18n (1.12.0) concurrent-ruby (~> 1.0) i18n-inflector (2.6.7) i18n (>= 0.4.1) @@ -502,18 +515,20 @@ GEM rack rack-test (2.0.2) rack (>= 1.3) - rails (5.2.8) - actioncable (= 5.2.8) - actionmailer (= 5.2.8) - actionpack (= 5.2.8) - actionview (= 5.2.8) - activejob (= 5.2.8) - activemodel (= 5.2.8) - activerecord (= 5.2.8) - activestorage (= 5.2.8) - activesupport (= 5.2.8) + rails (6.0.5.1) + actioncable (= 6.0.5.1) + actionmailbox (= 6.0.5.1) + actionmailer (= 6.0.5.1) + actionpack (= 6.0.5.1) + actiontext (= 6.0.5.1) + actionview (= 6.0.5.1) + activejob (= 6.0.5.1) + activemodel (= 6.0.5.1) + activerecord (= 6.0.5.1) + activestorage (= 6.0.5.1) + activesupport (= 6.0.5.1) bundler (>= 1.3.0) - railties (= 5.2.8) + railties (= 6.0.5.1) sprockets-rails (>= 2.0.0) rails-assets-autosize (4.0.2) rails-assets-backbone (1.3.3) @@ -571,18 +586,18 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.4.3) loofah (~> 2.3) - rails-i18n (5.1.3) + rails-i18n (6.0.0) i18n (>= 0.7, < 2) - railties (>= 5.0, < 6) + railties (>= 6.0.0, < 7) rails-timeago (2.20.0) actionpack (>= 5.2) activesupport (>= 5.2) - railties (5.2.8) - actionpack (= 5.2.8) - activesupport (= 5.2.8) + railties (6.0.5.1) + actionpack (= 6.0.5.1) + activesupport (= 6.0.5.1) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + thor (>= 0.20.3, < 2.0) rainbow (3.1.1) raindrops (0.20.0) rake (12.3.3) @@ -770,6 +785,7 @@ GEM nokogiri (~> 1.8) yard (0.9.28) webrick (~> 1.7.0) + zeitwerk (2.6.0) PLATFORMS ruby @@ -849,7 +865,7 @@ DEPENDENCIES rack-piwik (= 0.3.0) rack-rewrite (= 1.5.1) rack-ssl (= 1.4.1) - rails (= 5.2.8) + rails (= 6.0.5.1) rails-assets-autosize (= 4.0.2)! rails-assets-backbone (= 1.3.3)! rails-assets-blueimp-gallery (= 2.33.0)! @@ -875,7 +891,7 @@ DEPENDENCIES rails-assets-markdown-it-sup (= 1.0.0)! rails-assets-utatti-perfect-scrollbar (= 1.4.0)! rails-controller-testing (= 1.0.5) - rails-i18n (= 5.1.3) + rails-i18n (= 6.0.0) rails-timeago (= 2.20.0) redcarpet (= 3.5.1) redis (= 4.7.0) diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 977883985..35b3f9f69 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -54,8 +54,8 @@ class Notifier < ApplicationMailer @notification = NotificationMailers.const_get(type.to_s.camelize).new(*args) with_recipient_locale do + self.action_name = type mail(@notification.headers) do |format| - self.action_name = type format.text format.html end diff --git a/bin/setup b/bin/setup new file mode 100755 index 000000000..0e39e8cb1 --- /dev/null +++ b/bin/setup @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require 'fileutils' + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime 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 "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:prepare' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/config/application.rb b/config/application.rb index 83c82284d..36b801b9d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -32,42 +32,26 @@ require_relative 'asset_sync' module Diaspora class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.1 + config.load_defaults 6.0 # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. + + # Use classic autoloader for now + config.autoloader = :classic # Custom directories with classes and modules you want to be autoloadable. config.autoload_paths += %W[#{config.root}/app] config.autoload_once_paths += %W[#{config.root}/lib] - # Only load the plugins named here, in the order given (default is alphabetical). - # :all can be used as a placeholder for all plugins not explicitly named. - # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - - # Activate observers that should always be running. - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - - # Configure the default encoding used in templates for Ruby 1.9. - config.encoding = "utf-8" + # Allow to decode Time from serialized columns + config.active_record.yaml_column_permitted_classes = [Time] # Enable escaping HTML in JSON. config.active_support.escape_html_entities_in_json = true - # Use SQL instead of Active Record's schema dumper when creating the database. - # This is necessary if your schema can't be completely dumped by the schema dumper, - # like if you have constraints or database-specific column types - # config.active_record.schema_format = :sql - # Enable the asset pipeline config.assets.enabled = true @@ -75,7 +59,7 @@ module Diaspora config.assets.initialize_on_precompile = false # See lib/tasks/assets.rake: non_digest_assets - config.assets.non_digest_assets = %w(branding/logos/asterisk.png) + config.assets.non_digest_assets = %w[branding/logos/asterisk.png] # Configure generators values. Many other options are available, be sure to check the documentation. config.generators do |g| diff --git a/config/boot.rb b/config/boot.rb index dcd2d28d5..4fe16d4e8 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/config/environments/development.rb b/config/environments/development.rb index ea9b17981..8358d6b51 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -15,12 +15,14 @@ Rails.application.configure do config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. - if Rails.root.join("tmp", "caching-dev.txt").exist? + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true + 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.seconds.to_i}" + 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -28,6 +30,9 @@ Rails.application.configure do config.cache_store = :null_store end + # Store uploaded files on the local file system (see config/storage.yml for options). + # config.active_storage.service = :local + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false @@ -39,6 +44,9 @@ Rails.application.configure do # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. @@ -53,13 +61,16 @@ Rails.application.configure do # Show the logging configuration on STDOUT config.show_log_configuration = true - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = 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 + # Allow the host configured in the diaspora.toml to access the development server + config.hosts << AppConfig.pod_uri.host + # Speed up asset serving config.middleware.insert 0, TurboDevAssets end diff --git a/config/environments/production.rb b/config/environments/production.rb index 13a91a017..60b0ba0f3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -17,14 +17,13 @@ Rails.application.configure do config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Attempt to read encrypted secrets from `config/secrets.yml.enc`. - # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or - # `config/secrets.yml.key`. - config.read_encrypted_secrets = true + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :terser @@ -45,7 +44,10 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX - # Mount Action Cable outside main process or domain + # Store uploaded files on the local file system (see config/storage.yml for options). + # config.active_storage.service = :local + + # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] @@ -68,12 +70,20 @@ Rails.application.configure do # Use a different cache store in production. # config.cache_store = :mem_cache_store + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "diaspora_production" + config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # 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 @@ -92,4 +102,25 @@ Rails.application.configure do # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + + # 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/config/environments/test.rb b/config/environments/test.rb index 4f56e4017..0762db9fd 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application @@ -17,7 +18,7 @@ Rails.application.configure do # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{1.hour.seconds.to_i}" + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Suppress logger output for asset requests. @@ -38,12 +39,17 @@ Rails.application.configure do # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false + config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false # 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. @@ -57,7 +63,7 @@ Rails.application.configure do # Set the logging destination(s) config.log_to = %w[file] - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true # for fixture_builder diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 315ac48a9..f4556db39 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true # Be sure to restart your server when you modify this file. -# ApplicationController.renderer.defaults.merge!( -# http_host: 'example.org', -# https: false -# ) +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 791647716..dde581019 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -3,5 +3,4 @@ # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += %i[password message text bio] -Rails.application.config.filter_parameters += [:otp_attempt] +Rails.application.config.filter_parameters += %i[password otp_attempt message text bio] diff --git a/config/routes.rb b/config/routes.rb index 88c1d5fde..5c0d4f19c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,7 @@ require "sidekiq/web" require "sidekiq/cron/web" Rails.application.routes.draw do - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html resources :report, except: %i(edit new show) diff --git a/spec/controllers/node_info_controller_spec.rb b/spec/controllers/node_info_controller_spec.rb index ba3c10738..fcad4bc31 100644 --- a/spec/controllers/node_info_controller_spec.rb +++ b/spec/controllers/node_info_controller_spec.rb @@ -52,7 +52,7 @@ describe NodeInfoController do get :document, params: {version: version}, format: :json expect(response.content_type) - .to eq("application/json; profile=http://nodeinfo.diaspora.software/ns/schema/#{version}#") + .to eq("application/json; profile=http://nodeinfo.diaspora.software/ns/schema/#{version}#; charset=utf-8") end end end |