From bfa7c97fca5b46ffd66c801b6c5f3225269c44e0 Mon Sep 17 00:00:00 2001 From: Dante Soares Date: Tue, 26 Jan 2021 16:46:13 -0600 Subject: [PATCH 01/26] Updated application to Rails 6.0 --- Gemfile | 4 +- Gemfile.lock | 190 ++++++++++-------- bin/setup | 13 +- config/application.rb | 15 +- config/cable.yml | 4 +- config/environment.rb | 4 +- config/environments/development.rb | 38 ++-- config/environments/production.rb | 81 +++++--- config/environments/test.rb | 20 +- config/initializers/assets.rb | 5 +- .../initializers/content_security_policy.rb | 3 + .../new_framework_defaults_6_0.rb | 45 +++++ config/locales/en.yml | 2 +- config/puma.rb | 5 +- config/routes.rb | 4 +- 15 files changed, 266 insertions(+), 167 deletions(-) create mode 100644 config/initializers/new_framework_defaults_6_0.rb diff --git a/Gemfile b/Gemfile index 3d26159e..4d41b844 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,7 @@ git_source(:github) do |repo_name| end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 5.2.3' +gem 'rails', '6.0' # Bootstrap gem 'bootstrap-sass' @@ -124,7 +124,7 @@ gem 'puma_worker_killer' gem 'httparty' # Notify developers of Exceptions in production -gem 'openstax_rescue_from' +gem 'openstax_rescue_from', path: '../rescue_from' # Sentry integration (the require disables automatic Rails integration since we use rescue_from) gem 'sentry-raven', require: 'raven/base' diff --git a/Gemfile.lock b/Gemfile.lock index d39ae1d5..cac7fa70 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,66 +1,86 @@ +PATH + remote: ../rescue_from + specs: + openstax_rescue_from (4.1.0) + rails (>= 3.1, < 7.0) + GEM remote: https://rubygems.org/ specs: - action_interceptor (1.1.2) + action_interceptor (1.2.0) + addressable rails (>= 3.1) - actioncable (5.2.4.4) - actionpack (= 5.2.4.4) + actioncable (6.0.0) + actionpack (= 6.0.0) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.4.4) - actionpack (= 5.2.4.4) - actionview (= 5.2.4.4) - activejob (= 5.2.4.4) + actionmailbox (6.0.0) + actionpack (= 6.0.0) + activejob (= 6.0.0) + activerecord (= 6.0.0) + activestorage (= 6.0.0) + activesupport (= 6.0.0) + mail (>= 2.7.1) + actionmailer (6.0.0) + actionpack (= 6.0.0) + actionview (= 6.0.0) + activejob (= 6.0.0) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.4.4) - actionview (= 5.2.4.4) - activesupport (= 5.2.4.4) - rack (~> 2.0, >= 2.0.8) + actionpack (6.0.0) + actionview (= 6.0.0) + activesupport (= 6.0.0) + rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.4.4) - activesupport (= 5.2.4.4) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.0.0) + actionpack (= 6.0.0) + activerecord (= 6.0.0) + activestorage (= 6.0.0) + activesupport (= 6.0.0) + nokogiri (>= 1.8.5) + actionview (6.0.0) + activesupport (= 6.0.0) 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_attr (0.15.1) actionpack (>= 3.0.2, < 6.2) activemodel (>= 3.0.2, < 6.2) activesupport (>= 3.0.2, < 6.2) - activejob (5.2.4.4) - activesupport (= 5.2.4.4) + activejob (6.0.0) + activesupport (= 6.0.0) globalid (>= 0.3.6) - activemodel (5.2.4.4) - activesupport (= 5.2.4.4) - activerecord (5.2.4.4) - activemodel (= 5.2.4.4) - activesupport (= 5.2.4.4) - arel (>= 9.0) + activemodel (6.0.0) + activesupport (= 6.0.0) + activerecord (6.0.0) + activemodel (= 6.0.0) + activesupport (= 6.0.0) activerecord-import (1.0.2) activerecord (>= 3.2) - activestorage (5.2.4.4) - actionpack (= 5.2.4.4) - activerecord (= 5.2.4.4) + activestorage (6.0.0) + actionpack (= 6.0.0) + activejob (= 6.0.0) + activerecord (= 6.0.0) marcel (~> 0.3.1) - activesupport (5.2.4.4) + activesupport (6.0.0) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + zeitwerk (~> 2.1, >= 2.1.8) acts_as_votable (0.12.0) addressable (2.6.0) public_suffix (>= 2.0.2, < 4.0) apipie-rails (0.5.16) rails (>= 4.1) - arel (9.0.0) ast (2.4.0) autoprefixer-rails (9.6.0) execjs aws-eventstream (1.1.0) - aws-partitions (1.417.0) + aws-partitions (1.419.0) aws-sdk-autoscaling (1.53.0) aws-sdk-core (~> 3, >= 3.109.0) aws-sigv4 (~> 1.1) @@ -133,13 +153,13 @@ GEM crass (1.0.6) daemons (1.3.1) database_cleaner (1.7.0) - declarative (0.0.10) - deep_cloneable (2.4.0) - activerecord (>= 3.1.0, < 6) + declarative (0.0.20) + deep_cloneable (3.0.0) + activerecord (>= 3.1.0, < 7) diff-lcs (1.3) - diffy (3.3.0) + diffy (3.4.0) docile (1.1.5) - doorkeeper (5.1.1) + doorkeeper (5.4.0) railties (>= 5) dotenv (2.7.2) dotenv-rails (2.7.2) @@ -153,9 +173,9 @@ GEM ejs (1.1.1) erubi (1.10.0) eventmachine (1.2.7) - exception_notification (4.3.0) - actionmailer (>= 4.0, < 6) - activesupport (>= 4.0, < 6) + exception_notification (4.4.3) + actionmailer (>= 4.0, < 7) + activesupport (>= 4.0, < 7) excon (0.71.0) execjs (2.7.0) factory_bot (5.0.2) @@ -165,7 +185,7 @@ GEM railties (>= 4.2.0) faker (1.9.3) i18n (>= 0.7) - faraday (0.15.4) + faraday (0.17.3) multipart-post (>= 1.2, < 3) faraday-http-cache (2.2.0) faraday (>= 0.8) @@ -196,7 +216,7 @@ GEM ffi (~> 1.0) globalid (0.4.2) activesupport (>= 4.2.0) - hashie (3.6.0) + hashie (4.1.0) httparty (0.17.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) @@ -212,7 +232,7 @@ GEM jquery-ui-rails (6.0.1) railties (>= 3.2.16) json (2.3.1) - jwt (2.2.1) + jwt (2.2.2) keyword_search (1.5.0) lev (10.1.0) actionpack (>= 4.2) @@ -249,7 +269,7 @@ GEM libv8 (>= 6.9.411) minitest (5.14.3) msgpack (1.2.10) - multi_json (1.13.1) + multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) nifty-generators (0.4.6) @@ -259,20 +279,21 @@ GEM racc (~> 1.4) nokogumbo (2.0.2) nokogiri (~> 1.8, >= 1.8.4) - oauth2 (1.4.1) - faraday (>= 0.8, < 0.16.0) + oauth2 (1.4.4) + faraday (>= 0.8, < 2.0) jwt (>= 1.0, < 3.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) oj (3.7.12) oj_mimic_json (1.0.1) - omniauth (1.9.0) - hashie (>= 3.4.6, < 3.7.0) + omniauth (2.0.1) + hashie (>= 3.4.6) rack (>= 1.6.2, < 3) - omniauth-oauth2 (1.6.0) - oauth2 (~> 1.1) - omniauth (~> 1.9) + rack-protection + omniauth-oauth2 (1.7.1) + oauth2 (~> 1.4) + omniauth (>= 1.9, < 3) openstax_accounts (9.5.1) action_interceptor keyword_search @@ -299,8 +320,6 @@ GEM uber (< 0.1.0) openstax_healthcheck (0.0.3) rails (>= 3.0) - openstax_rescue_from (4.0.0) - rails (>= 3.1, < 6.0) openstax_utilities (4.5.1) aws-sdk-autoscaling faraday @@ -315,7 +334,7 @@ GEM parallel parser (2.6.3.0) ast (~> 2.4.0) - pg (1.1.4) + pg (1.2.3) public_suffix (3.1.0) puma (5.1.0) nio4r (~> 2.0) @@ -324,21 +343,25 @@ GEM puma (>= 2.7) racc (1.5.2) rack (2.2.3) + rack-protection (2.1.0) + rack rack-test (1.1.0) rack (>= 1.0, < 3) railroady (1.5.3) - rails (5.2.4.4) - actioncable (= 5.2.4.4) - actionmailer (= 5.2.4.4) - actionpack (= 5.2.4.4) - actionview (= 5.2.4.4) - activejob (= 5.2.4.4) - activemodel (= 5.2.4.4) - activerecord (= 5.2.4.4) - activestorage (= 5.2.4.4) - activesupport (= 5.2.4.4) + rails (6.0.0) + actioncable (= 6.0.0) + actionmailbox (= 6.0.0) + actionmailer (= 6.0.0) + actionpack (= 6.0.0) + actiontext (= 6.0.0) + actionview (= 6.0.0) + activejob (= 6.0.0) + activemodel (= 6.0.0) + activerecord (= 6.0.0) + activestorage (= 6.0.0) + activesupport (= 6.0.0) bundler (>= 1.3.0) - railties (= 5.2.4.4) + railties (= 6.0.0) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) @@ -350,41 +373,41 @@ GEM ruby-graphviz (~> 1.2) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - railties (5.2.4.4) - actionpack (= 5.2.4.4) - activesupport (= 5.2.4.4) + railties (6.0.0) + actionpack (= 6.0.0) + activesupport (= 6.0.0) method_source rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + thor (>= 0.20.3, < 2.0) rainbow (3.0.0) rake (13.0.3) rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) - redis (4.1.2) - redis-actionpack (5.0.2) - actionpack (>= 4.0, < 6) - redis-rack (>= 1, < 3) + redis (4.2.5) + redis-actionpack (5.2.0) + actionpack (>= 5, < 7) + redis-rack (>= 2.1.0, < 3) redis-store (>= 1.1.0, < 2) - redis-activesupport (5.0.7) - activesupport (>= 3, < 6) + redis-activesupport (5.2.0) + activesupport (>= 3, < 7) redis-store (>= 1.3, < 2) - redis-rack (2.0.5) - rack (>= 1.5, < 3) + redis-rack (2.1.3) + rack (>= 2.0.8, < 3) redis-store (>= 1.2, < 2) redis-rails (5.0.2) redis-actionpack (>= 5.0, < 6) redis-activesupport (>= 5.0, < 6) redis-store (>= 1.2, < 2) - redis-store (1.6.0) - redis (>= 2.2, < 5) + redis-store (1.9.0) + redis (>= 4, < 5) remotipart (1.4.3) representable (3.0.0) declarative (~> 0.0.5) uber (~> 0.0.15) request_store (1.5.0) rack (>= 1.4) - responders (3.0.0) + responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) rinku (2.0.6) @@ -441,8 +464,8 @@ GEM nokogiri (>= 1.8.0) nokogumbo (~> 2.0) sass (3.4.25) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) + sass-rails (5.0.8) + railties (>= 5.2.0) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) @@ -479,7 +502,7 @@ GEM rack (>= 1, < 3) thor (1.1.0) thread_safe (0.3.6) - tilt (2.0.9) + tilt (2.0.10) timecop (0.9.1) transaction_isolation (1.0.5) activerecord (>= 3.0.11) @@ -504,6 +527,7 @@ GEM websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xml-simple (1.1.5) + zeitwerk (2.4.2) PLATFORMS ruby @@ -555,14 +579,14 @@ DEPENDENCIES openstax_accounts (~> 9.5.1) openstax_api openstax_healthcheck - openstax_rescue_from + openstax_rescue_from! openstax_utilities parallel_tests pg puma puma_worker_killer railroady - rails (~> 5.2.3) + rails (= 6.0) rails-erd rails-html-sanitizer redis-rails @@ -588,4 +612,4 @@ DEPENDENCIES web-console BUNDLED WITH - 2.1.4 + 2.2.6 diff --git a/bin/setup b/bin/setup index 94fd4d79..0e39e8cb 100755 --- a/bin/setup +++ b/bin/setup @@ -1,6 +1,5 @@ #!/usr/bin/env ruby require 'fileutils' -include FileUtils # path to your application root. APP_ROOT = File.expand_path('..', __dir__) @@ -9,24 +8,22 @@ def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end -chdir APP_ROOT do - # This script is a starting point to setup your application. +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') - # Install JavaScript dependencies if using Yarn - # system('bin/yarn') - # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" - system! 'bin/rails db:setup' + system! 'bin/rails db:prepare' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/config/application.rb b/config/application.rb index 079ec756..fb7b1213 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,15 +1,17 @@ require_relative 'boot' require "rails" - -# Include each railties manually, excluding `active_storage/engine` +# Pick the frameworks you want: require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" +require "active_storage/engine" require "action_controller/railtie" -require "action_mailer/railtie" +# require "action_mailer/railtie" +# require "action_mailbox/engine" +# require "action_text/engine" require "action_view/railtie" -require "action_cable/engine" +# require "action_cable/engine" require "sprockets/railtie" require "rails/test_unit/railtie" @@ -27,8 +29,9 @@ class Application < Rails::Application config.load_defaults 5.2 # 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/initializer + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. # 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. diff --git a/config/cable.yml b/config/cable.yml index 69d50ecb..54ae5e70 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -2,9 +2,9 @@ development: adapter: async test: - adapter: async + adapter: test production: adapter: redis - url: <%= Rails.application.secrets.redis[:url] %> + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> channel_prefix: exercises_production diff --git a/config/environment.rb b/config/environment.rb index 509fcda4..3fe7a73d 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -29,5 +29,5 @@ SITE_NAME = "OpenStax Exercises" COPYRIGHT_HOLDER = "Rice University" -# Initialize the Rails application -Exercises::Application.initialize! +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index 4f313077..efa151f0 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -9,11 +9,24 @@ # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true - config.cache_store = :null_store + # Enable/disable caching. By default caching is disabled. + # 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.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false @@ -34,18 +47,13 @@ # number of complex assets. config.assets.debug = true - # Asset digests allow you to set far-future HTTP expiration dates on all assets, - # yet still be able to expire them through the digest params. - config.assets.digest = true - - # Adds additional error checking when serving assets at runtime. - # Checks for improperly declared sprockets dependencies. - # Raises helpful error messages. - config.assets.raise_runtime_errors = true + # Suppress logger output for asset requests. + config.assets.quiet = true - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true - # Development site URL for emails - config.action_mailer.default_url_options = { :host => 'localhost:3000' } + # 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 end diff --git a/config/environments/production.rb b/config/environments/production.rb index da4bb8b0..39202d3d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -14,51 +14,54 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. - # config.action_dispatch.rack_cache = 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 Rails's static asset server (Apache or nginx will already do this). - config.serve_static_files = false + # 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? - # Compress JavaScripts and CSS. - config.assets.js_compressor = Uglifier.new(harmony: true) + # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false - # Generate digests for assets URLs. - config.assets.digest = true - - # `config.assets.precompile` has moved to config/initializers/assets.rb + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.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 + + # 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.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # Set to :debug to see everything in the log. + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. config.log_level = :info # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + config.log_tags = [ :request_id, :remote_ip ] # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = "http://assets.example.com" + # 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 = "exercises_production" + + config.action_mailer.perform_caching = false - # Precompile additional assets. - # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - # config.assets.precompile += %w( search.js ) + # 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). @@ -67,20 +70,15 @@ # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify - # Disable automatic flushing of the log to improve performance. - # config.autoflush_log = false - # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Log to STDOUT and let systemd/journald handle the logs - logger = ActiveSupport::Logger.new(STDOUT) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + logger = ActiveSupport::Logger.new(STDOUT) + config.logger = ActiveSupport::TaggedLogging.new(logger) # Lograge configuration (one-line logs in production) config.lograge.enabled = true - config.log_tags = [ :remote_ip ] config.lograge.custom_options = ->(event) do { 'params' => event.payload[:params].reject do |k| @@ -92,4 +90,25 @@ # 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 af95530b..c3cb9714 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,10 +1,11 @@ +# 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 @@ -15,18 +16,20 @@ # 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}" } # 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 + config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. @@ -37,9 +40,6 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true - - # Test site URL for emails - config.action_mailer.default_url_options = { host: 'localhost:3000' } end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index d3ae6cc5..d692fc23 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -5,9 +5,8 @@ # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path -# Add Yarn node_modules folder to the asset load path. -Rails.application.config.assets.paths << Rails.root.join('node_modules') # Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index d3bcaa5e..41c43016 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -19,6 +19,9 @@ # If you are using UJS then enable automatic nonce generation # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } +# Set the nonce only to specific directives +# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) + # Report CSP violations to a specified URI # For further information see the following documentation: # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only diff --git a/config/initializers/new_framework_defaults_6_0.rb b/config/initializers/new_framework_defaults_6_0.rb new file mode 100644 index 00000000..92240ef5 --- /dev/null +++ b/config/initializers/new_framework_defaults_6_0.rb @@ -0,0 +1,45 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 6.0 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Don't force requests from old versions of IE to be UTF-8 encoded. +# Rails.application.config.action_view.default_enforce_utf8 = false + +# Embed purpose and expiry metadata inside signed and encrypted +# cookies for increased security. +# +# This option is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.0. +# Rails.application.config.action_dispatch.use_cookies_with_metadata = true + +# Change the return value of `ActionDispatch::Response#content_type` to Content-Type header without modification. +# Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false + +# Return false instead of self when enqueuing is aborted from a callback. +# Rails.application.config.active_job.return_false_on_aborted_enqueue = true + +# Send Active Storage analysis and purge jobs to dedicated queues. +# Rails.application.config.active_storage.queues.analysis = :active_storage_analysis +# Rails.application.config.active_storage.queues.purge = :active_storage_purge + +# When assigning to a collection of attachments declared via `has_many_attached`, replace existing +# attachments instead of appending. Use #attach to add new attachments without replacing existing ones. +# Rails.application.config.active_storage.replace_on_assign_to_many = true + +# Use ActionMailer::MailDeliveryJob for sending parameterized and normal mail. +# +# The default delivery jobs (ActionMailer::Parameterized::DeliveryJob, ActionMailer::DeliveryJob), +# will be removed in Rails 6.1. This setting is not backwards compatible with earlier Rails versions. +# If you send mail in the background, job workers need to have a copy of +# MailDeliveryJob to ensure all delivery jobs are processed properly. +# Make sure your entire app is migrated and stable on 6.0 before using this setting. +# Rails.application.config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" + +# Enable the same cache key to be reused when the object being cached of type +# `ActiveRecord::Relation` changes by moving the volatile information (max updated at and count) +# of the relation's cache key into the cache version to support recycling cache key. +# Rails.application.config.active_record.collection_cache_versioning = true diff --git a/config/locales/en.yml b/config/locales/en.yml index decc5a85..cf9b342d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -27,7 +27,7 @@ # 'true': 'foo' # # To learn more, please read the Rails Internationalization guide -# available at http://guides.rubyonrails.org/i18n.html. +# available at https://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb index 16e95674..f3162ecf 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -61,11 +61,11 @@ # Specifies the `environment` that Puma will run in. # -environment ENV.fetch('RAILS_ENV', 'development') +environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the `pidfile` that Puma will use. # -pidfile ENV.fetch('PIDFILE', 'tmp/pids/puma.pid') +pidfile ENV.fetch("PIDFILE") { "tmp/pids/puma.pid" } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together @@ -83,5 +83,4 @@ preload_app! if ActiveModel::Type::Boolean.new.cast(ENV.fetch('PRELOAD_APP', false)) # Allow puma to be restarted by `rails restart` command. -# plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb index 2a20f426..cc68727c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ -Exercises::Application.routes.draw do +Rails.application.routes.draw do + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + root controller: :webview, action: :home get :dashboard, controller: :webview, action: :index From 9be09d0d0f09cf75f8d29652cec3ccefab5febd7 Mon Sep 17 00:00:00 2001 From: Dante Soares Date: Tue, 26 Jan 2021 18:41:20 -0600 Subject: [PATCH 02/26] Fix Rails 6.0 specs and warnings --- .gitignore | 30 ++--- Gemfile | 16 +-- Gemfile.lock | 115 +++++++++--------- .../attachment_access_policy.rb | 1 - app/assets/javascripts/utils/ui.js | 88 ++++++++++++++ app/assets/javascripts/utils/ui.js.coffee | 64 ---------- .../admin/delegations_controller.rb | 2 +- .../admin/publications_controller.rb | 2 +- .../oauth/applications_controller.rb | 2 +- config/application.rb | 2 +- config/environments/development.rb | 4 +- config/environments/production.rb | 2 +- config/environments/test.rb | 10 +- config/initializers/models.rb | 2 +- .../new_framework_defaults_6_0.rb | 45 ------- spec/models/publication_group_spec.rb | 2 +- .../api/v1/exercises_controller_spec.rb | 2 +- .../oauth/applications_controller_spec.rb | 2 +- spec/requests/webview_controller_spec.rb | 6 +- spec/routines/attach_file_spec.rb | 15 ++- spec/spec_helper.rb | 2 +- vendor/assets/javascripts/sandbox.js | 62 ++++++++++ vendor/assets/javascripts/sandbox.js.coffee | 40 ------ 23 files changed, 258 insertions(+), 258 deletions(-) create mode 100644 app/assets/javascripts/utils/ui.js delete mode 100644 app/assets/javascripts/utils/ui.js.coffee delete mode 100644 config/initializers/new_framework_defaults_6_0.rb create mode 100644 vendor/assets/javascripts/sandbox.js delete mode 100644 vendor/assets/javascripts/sandbox.js.coffee diff --git a/.gitignore b/.gitignore index b0b2b1be..8bfe1f89 100644 --- a/.gitignore +++ b/.gitignore @@ -50,30 +50,32 @@ bower.json # Ignore Byebug command history file. .byebug_history -# Ignore node_modules -node_modules/ - -# Ignore precompiled javascript packs +# Ignore public precompiled assets, packs, uploaded files, exports and test files +/public/assets +/public/uploads +/public/exports /public/packs /public/packs-test -/public/assets - -# Ignore yarn files -/yarn-error.log -yarn-debug.log* -.yarn-integrity +/public/test # Ignore uploaded files in development /storage/* !/storage/.keep -/public/uploads -# Ignore attached files in development -/public/attachments +# Ignore node_modules +node_modules/ + +# Ignore yarn files +/yarn-error.log +yarn-debug.log* +.yarn-integrity # Ignore Cucumber and RSpec failure information cucumber_rerun.txt -rspec.failures +.rspec_last_failures + +# Ignore brakeman reports +brakeman.html # Ignore webdrivers lock file .webdrivers_update diff --git a/Gemfile b/Gemfile index 4d41b844..4f46c7bb 100644 --- a/Gemfile +++ b/Gemfile @@ -23,9 +23,6 @@ gem 'compass-rails' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' -# Use CoffeeScript for .coffee assets and views -gem 'coffee-rails', '~> 4.2.2' - gem 'mini_racer' # Use jquery as the JavaScript library @@ -66,7 +63,7 @@ gem 'doorkeeper' # API versioning and documentation gem 'representable', '~> 3.0.0' -gem 'openstax_api' +gem 'openstax_api', path: '../openstax_api' gem 'apipie-rails' gem 'maruku' @@ -74,7 +71,7 @@ gem 'maruku' gem 'lev' # Contract management -gem 'fine_print' +gem 'fine_print', path: '../fine_print' # Keyword search gem 'keyword_search' @@ -93,9 +90,6 @@ gem 'roo' # Embedded JavaScript templates gem 'ejs' -# Embedded CoffeeScript templates -gem 'eco' - # Object cloning gem 'deep_cloneable' @@ -184,6 +178,9 @@ group :development, :test do end group :development do + # Listen for file changes in development + gem 'listen' + # Automated security checks gem 'brakeman' @@ -200,9 +197,6 @@ group :development do gem 'rails-erd' gem 'railroady' - # CoffeeScript source maps - gem 'coffee-rails-source-maps' - # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console' end diff --git a/Gemfile.lock b/Gemfile.lock index cac7fa70..07066940 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,27 @@ +PATH + remote: ../fine_print + specs: + fine_print (6.0.0) + action_interceptor + jquery-rails + rails + responders + +PATH + remote: ../openstax_api + specs: + openstax_api (9.4.0) + doorkeeper + exception_notification + lev + openstax_utilities + rails (>= 5.2, < 7) + representable + responders + roar + roar-rails + uber + PATH remote: ../rescue_from specs: @@ -72,8 +96,8 @@ GEM tzinfo (~> 1.1) zeitwerk (~> 2.1, >= 2.1.8) acts_as_votable (0.12.0) - addressable (2.6.0) - public_suffix (>= 2.0.2, < 4.0) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) apipie-rails (0.5.16) rails (>= 4.1) ast (2.4.0) @@ -124,15 +148,6 @@ GEM codecov (0.2.11) json simplecov - coffee-rails (4.2.2) - coffee-script (>= 2.2.0) - railties (>= 4.0.0) - coffee-rails-source-maps (1.4.0) - coffee-script-source (>= 1.6.1) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.12.2) compass (1.0.3) chunky_png (~> 1.2) compass-core (~> 1.0.2) @@ -156,7 +171,7 @@ GEM declarative (0.0.20) deep_cloneable (3.0.0) activerecord (>= 3.1.0, < 7) - diff-lcs (1.3) + diff-lcs (1.4.4) diffy (3.4.0) docile (1.1.5) doorkeeper (5.4.0) @@ -165,11 +180,6 @@ GEM dotenv-rails (2.7.2) dotenv (= 2.7.2) railties (>= 3.2, < 6.1) - eco (1.0.0) - coffee-script - eco-source - execjs - eco-source (1.1.0.rc.1) ejs (1.1.1) erubi (1.10.0) eventmachine (1.2.7) @@ -190,11 +200,6 @@ GEM faraday-http-cache (2.2.0) faraday (>= 0.8) ffi (1.11.1) - fine_print (5.0.0) - action_interceptor - jquery-rails - rails - responders fog-aws (3.5.0) fog-core (~> 2.1) fog-json (~> 1.1) @@ -225,7 +230,7 @@ GEM ipaddress (0.8.3) jaro_winkler (1.5.2) jmespath (1.4.0) - jquery-rails (4.3.3) + jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -244,6 +249,10 @@ GEM transaction_isolation transaction_retry libv8 (7.3.492.27.1) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) lograge (0.11.1) actionpack (>= 4) activesupport (>= 4) @@ -307,17 +316,6 @@ GEM rails (> 5.0) representable roar - openstax_api (9.0.1) - doorkeeper (>= 2.0) - exception_notification (>= 4.0) - lev (>= 1.0.0) - openstax_utilities (>= 4.2.0) - rails (>= 3.1) - representable (>= 2.4, < 4.0) - responders - roar (>= 1.0) - roar-rails (>= 1.0) - uber (< 0.1.0) openstax_healthcheck (0.0.3) rails (>= 3.0) openstax_utilities (4.5.1) @@ -335,7 +333,7 @@ GEM parser (2.6.3.0) ast (~> 2.4.0) pg (1.2.3) - public_suffix (3.1.0) + public_suffix (4.0.6) puma (5.1.0) nio4r (~> 2.0) puma_worker_killer (0.3.1) @@ -423,29 +421,29 @@ GEM roo (2.8.2) nokogiri (~> 1) rubyzip (>= 1.2.1, < 2.0.0) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.3) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) + rspec-support (~> 3.10.0) rspec-instafail (1.0.0) rspec - rspec-mocks (3.8.0) + rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-rails (3.8.2) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) + rspec-support (~> 3.10.0) + rspec-rails (4.0.2) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.10.2) rubocop (0.71.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) @@ -458,6 +456,7 @@ GEM rubocop (>= 0.70.0) ruby-graphviz (1.2.4) ruby-progressbar (1.10.1) + ruby_dep (1.5.0) rubyzip (1.3.0) sanitize (5.2.1) crass (~> 1.0.2) @@ -549,24 +548,22 @@ DEPENDENCIES cheat codeclimate-test-reporter codecov - coffee-rails (~> 4.2.2) - coffee-rails-source-maps compass-rails database_cleaner deep_cloneable doorkeeper dotenv-rails - eco ejs factory_bot_rails faker - fine_print + fine_print! fog-aws httparty jquery-rails jquery-ui-rails keyword_search lev + listen lograge maruku mimemagic @@ -577,7 +574,7 @@ DEPENDENCIES oj_mimic_json omniauth-oauth2 openstax_accounts (~> 9.5.1) - openstax_api + openstax_api! openstax_healthcheck openstax_rescue_from! openstax_utilities diff --git a/app/access_policies/attachment_access_policy.rb b/app/access_policies/attachment_access_policy.rb index 5f58aaf8..d288d013 100644 --- a/app/access_policies/attachment_access_policy.rb +++ b/app/access_policies/attachment_access_policy.rb @@ -14,6 +14,5 @@ def self.action_allowed?(action, requestor, attachment) # all other types of attachments are currently denied false end - end end diff --git a/app/assets/javascripts/utils/ui.js b/app/assets/javascripts/utils/ui.js new file mode 100644 index 00000000..62315411 --- /dev/null +++ b/app/assets/javascripts/utils/ui.js @@ -0,0 +1,88 @@ +/* + * decaffeinate suggestions: + * DS102: Remove unnecessary code created because of implicit returns + * DS104: Avoid inline assignments + * DS207: Consider shorter variations of null checks + * DS208: Avoid top-level this + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +let base, exports; +const Ui = (function() { + + return { + disableButton(selector) { + $(selector).attr('disabled', 'disabled'); + $(selector).addClass('ui-state-disabled ui-button-disabled'); + return $(selector).attr('aria-disabled', true); + }, + + enableButton(selector) { + $(selector).removeAttr('disabled'); + $(selector).removeAttr('aria-disabled'); + $(selector).removeClass('ui-state-disabled ui-button-disabled'); + return $(selector).button(); + }, + + renderAndOpenDialog(html_id, content, modal_options) { + if (modal_options == null) { modal_options = {}; } + if ($('#' + html_id).exists()) { $('#' + html_id).remove(); } + $("#application-body").append(content); + $('#' + html_id).modal(modal_options); + + // Code to center the dialog + const modalDialog = $('#' + html_id + ' .modal-dialog'); + const modalHeight = modalDialog.outerHeight(); + const userScreenHeight = window.outerHeight; + + if (modalHeight > userScreenHeight) { + return modalDialog.css('overflow', 'auto'); //set to overflow if no fit + } else { + return modalDialog.css('margin-top', //center it if it does fit + ((userScreenHeight / 2) - (modalHeight / 2))); + } + }, + + enableOnChecked(targetSelector, sourceSelector) { + $(document).on('turbolinks:load', () => { + return this.disableButton(targetSelector); + }); + + return $(sourceSelector).on('click', () => { + if ($(sourceSelector).is(':checked')) { + return this.enableButton(targetSelector); + } else { + return this.disableButton(targetSelector); + } + }); + }, + + syntaxHighlight(code) { + let json = typeof code === !'string' ? JSON.stringify(code, undefined, 2) : code; + + json = json.replace(/&/g, '&').replace(//g, '>'); + + return json.replace( + /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, + function(match) { + let cls = 'number'; + if (/^"/.test(match)) { + if (/:$/.test(match)) { + cls = 'key'; + } else { + cls = 'string'; + } + } else if (/true|false/.test(match)) { + cls = 'boolean'; + } else if (/null/.test(match)) { + cls = 'null'; + } + + return '' + match + ''; + }); + } + }; +})(); + + +if (((base = exports = this)).Exercises == null) { base.Exercises = {}; } +exports.Exercises.Ui = Ui; diff --git a/app/assets/javascripts/utils/ui.js.coffee b/app/assets/javascripts/utils/ui.js.coffee deleted file mode 100644 index fff5b2e6..00000000 --- a/app/assets/javascripts/utils/ui.js.coffee +++ /dev/null @@ -1,64 +0,0 @@ -Ui = do () -> - - disableButton: (selector) -> - $(selector).attr('disabled', 'disabled') - $(selector).addClass('ui-state-disabled ui-button-disabled') - $(selector).attr('aria-disabled', true) - - enableButton: (selector) -> - $(selector).removeAttr('disabled') - $(selector).removeAttr('aria-disabled') - $(selector).removeClass('ui-state-disabled ui-button-disabled') - $(selector).button() - - renderAndOpenDialog: (html_id, content, modal_options = {}) -> - if $('#' + html_id).exists() then $('#' + html_id).remove() - $("#application-body").append(content) - $('#' + html_id).modal(modal_options) - - # Code to center the dialog - modalDialog = $('#' + html_id + ' .modal-dialog') - modalHeight = modalDialog.outerHeight() - userScreenHeight = window.outerHeight - - if modalHeight > userScreenHeight - modalDialog.css('overflow', 'auto'); #set to overflow if no fit - else - modalDialog.css('margin-top', #center it if it does fit - ((userScreenHeight / 2) - (modalHeight / 2))) - - enableOnChecked: (targetSelector, sourceSelector) -> - $(document).on 'turbolinks:load', => - @disableButton(targetSelector) - - $(sourceSelector).on 'click', => - if $(sourceSelector).is(':checked') - @enableButton(targetSelector) - else - @disableButton(targetSelector) - - syntaxHighlight: (code) -> - json = if typeof code is not 'string' then JSON.stringify(code, undefined, 2) else code - - json = json.replace(/&/g, '&').replace(//g, '>') - - return json.replace( - /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, - (match) -> - cls = 'number' - if (/^"/.test(match)) - if (/:$/.test(match)) - cls = 'key' - else - cls = 'string' - else if (/true|false/.test(match)) - cls = 'boolean' - else if (/null/.test(match)) - cls = 'null' - - return '' + match + '' - ) - - -(exports = this).Exercises ?= {} -exports.Exercises.Ui = Ui diff --git a/app/controllers/admin/delegations_controller.rb b/app/controllers/admin/delegations_controller.rb index 73bcfe06..471a0fb1 100644 --- a/app/controllers/admin/delegations_controller.rb +++ b/app/controllers/admin/delegations_controller.rb @@ -35,7 +35,7 @@ def edit # PATCH /admin/delegations/1 def update - if @delegation.update_attributes(delegation_params) + if @delegation.update(delegation_params) redirect_to admin_delegations_url, notice: "Delegation from #{ @delegation.delegator.name} to #{@delegation.delegate.name} updated." else diff --git a/app/controllers/admin/publications_controller.rb b/app/controllers/admin/publications_controller.rb index 711d7a9d..213c8072 100644 --- a/app/controllers/admin/publications_controller.rb +++ b/app/controllers/admin/publications_controller.rb @@ -1,5 +1,5 @@ class Admin::PublicationsController < Admin::BaseController - around_action :respond_to_html, except: :users + around_action :respond_to_html, except: [ :users, :collaborators ] before_action :set_variables, except: :users # GET /admin/publications diff --git a/app/controllers/oauth/applications_controller.rb b/app/controllers/oauth/applications_controller.rb index b63d6c60..1bbd62f7 100644 --- a/app/controllers/oauth/applications_controller.rb +++ b/app/controllers/oauth/applications_controller.rb @@ -59,7 +59,7 @@ def update OSU::AccessPolicy.require_action_allowed!(:update, @user, @application) app_params = application_params(@user) - if @application.update_attributes(app_params) + if @application.update(app_params) flash[:notice] = I18n.t( :notice, scope: %i[doorkeeper flash applications update] ) diff --git a/config/application.rb b/config/application.rb index fb7b1213..1a266410 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,7 +26,7 @@ module Exercises class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.2 + config.load_defaults 6.0 # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializer diff --git a/config/environments/development.rb b/config/environments/development.rb index efa151f0..6c793ede 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -29,9 +29,9 @@ end # Don't care if the mailer can't send. - config.action_mailer.raise_delivery_errors = false + # config.action_mailer.raise_delivery_errors = false - config.action_mailer.perform_caching = false + # config.action_mailer.perform_caching = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/config/environments/production.rb b/config/environments/production.rb index 39202d3d..cf0a6592 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -57,7 +57,7 @@ # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "exercises_production" - config.action_mailer.perform_caching = false + # 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. diff --git a/config/environments/test.rb b/config/environments/test.rb index c3cb9714..1ab0af69 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -5,7 +5,7 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - + config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application @@ -19,10 +19,10 @@ 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } - # Show full error reports and disable caching. + # Show full error reports and disable controller caching but use in-memory cache for specs. config.consider_all_requests_local = true config.action_controller.perform_caching = false - config.cache_store = :null_store + config.cache_store = :memory_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false @@ -30,12 +30,12 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - config.action_mailer.perform_caching = false + # config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. - config.action_mailer.delivery_method = :test + # config.action_mailer.delivery_method = :test # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/models.rb b/config/initializers/models.rb index 48bc9370..d2ce0c13 100644 --- a/config/initializers/models.rb +++ b/config/initializers/models.rb @@ -24,7 +24,7 @@ def association_attributes(associations = [], next if objects.nil? if objects.respond_to?(:collect) - hash[name.to_s] = objects.map do |object| + hash[name.to_s] = objects.collect do |object| object.association_attributes( subtree, slice: slice, diff --git a/config/initializers/new_framework_defaults_6_0.rb b/config/initializers/new_framework_defaults_6_0.rb deleted file mode 100644 index 92240ef5..00000000 --- a/config/initializers/new_framework_defaults_6_0.rb +++ /dev/null @@ -1,45 +0,0 @@ -# Be sure to restart your server when you modify this file. -# -# This file contains migration options to ease your Rails 6.0 upgrade. -# -# Once upgraded flip defaults one by one to migrate to the new default. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. - -# Don't force requests from old versions of IE to be UTF-8 encoded. -# Rails.application.config.action_view.default_enforce_utf8 = false - -# Embed purpose and expiry metadata inside signed and encrypted -# cookies for increased security. -# -# This option is not backwards compatible with earlier Rails versions. -# It's best enabled when your entire app is migrated and stable on 6.0. -# Rails.application.config.action_dispatch.use_cookies_with_metadata = true - -# Change the return value of `ActionDispatch::Response#content_type` to Content-Type header without modification. -# Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false - -# Return false instead of self when enqueuing is aborted from a callback. -# Rails.application.config.active_job.return_false_on_aborted_enqueue = true - -# Send Active Storage analysis and purge jobs to dedicated queues. -# Rails.application.config.active_storage.queues.analysis = :active_storage_analysis -# Rails.application.config.active_storage.queues.purge = :active_storage_purge - -# When assigning to a collection of attachments declared via `has_many_attached`, replace existing -# attachments instead of appending. Use #attach to add new attachments without replacing existing ones. -# Rails.application.config.active_storage.replace_on_assign_to_many = true - -# Use ActionMailer::MailDeliveryJob for sending parameterized and normal mail. -# -# The default delivery jobs (ActionMailer::Parameterized::DeliveryJob, ActionMailer::DeliveryJob), -# will be removed in Rails 6.1. This setting is not backwards compatible with earlier Rails versions. -# If you send mail in the background, job workers need to have a copy of -# MailDeliveryJob to ensure all delivery jobs are processed properly. -# Make sure your entire app is migrated and stable on 6.0 before using this setting. -# Rails.application.config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" - -# Enable the same cache key to be reused when the object being cached of type -# `ActiveRecord::Relation` changes by moving the volatile information (max updated at and count) -# of the relation's cache key into the cache version to support recycling cache key. -# Rails.application.config.active_record.collection_cache_versioning = true diff --git a/spec/models/publication_group_spec.rb b/spec/models/publication_group_spec.rb index 86136fcf..97b6dfc5 100644 --- a/spec/models/publication_group_spec.rb +++ b/spec/models/publication_group_spec.rb @@ -48,7 +48,7 @@ end it 'sets nickname to null when blank' do - subject.update_attributes(nickname: '') + subject.update(nickname: '') expect(subject.reload.nickname).to be_nil end diff --git a/spec/requests/api/v1/exercises_controller_spec.rb b/spec/requests/api/v1/exercises_controller_spec.rb index 278bfd76..78a27315 100644 --- a/spec/requests/api/v1/exercises_controller_spec.rb +++ b/spec/requests/api/v1/exercises_controller_spec.rb @@ -310,7 +310,7 @@ end it "returns the latest version of a Exercise if \"@latest\" is requested" do - @exercise_1.publication.update_attributes(version: 1000) + @exercise_1.publication.update(version: 1000) api_get api_exercise_url("#{@exercise.number}@latest"), @user_1_token expect(response).to have_http_status(:ok) expect(response.body_as_hash).to match(a_hash_including(uuid: @exercise_1.uuid)) diff --git a/spec/requests/oauth/applications_controller_spec.rb b/spec/requests/oauth/applications_controller_spec.rb index 65bdad87..f4436fec 100644 --- a/spec/requests/oauth/applications_controller_spec.rb +++ b/spec/requests/oauth/applications_controller_spec.rb @@ -110,7 +110,7 @@ it "updates the requested application and redirects to it" do expect_any_instance_of(Doorkeeper::Application).to( - receive(:update_attributes).with(dummy_params).and_call_original + receive(:update).with(dummy_params).and_call_original ) patch oauth_application_url(user_1_application_1), diff --git a/spec/requests/webview_controller_spec.rb b/spec/requests/webview_controller_spec.rb index 92a6df50..f86fe683 100644 --- a/spec/requests/webview_controller_spec.rb +++ b/spec/requests/webview_controller_spec.rb @@ -1,7 +1,6 @@ require 'rails_helper' RSpec.describe WebviewController, type: :request do - let!(:contract) do FinePrint::Contract.create!( name: 'general_terms_of_use', @@ -66,7 +65,11 @@ context 'GET /dashboard' do it 'requires agreement to contracts' do + begin get dashboard_url + rescue Exception => e + debugger + end expect(response).to redirect_to(fine_print.new_contract_signature_url(contract)) end end @@ -95,5 +98,4 @@ end end end - end diff --git a/spec/routines/attach_file_spec.rb b/spec/routines/attach_file_spec.rb index 250efa72..d635db2f 100644 --- a/spec/routines/attach_file_spec.rb +++ b/spec/routines/attach_file_spec.rb @@ -42,11 +42,16 @@ "parent_id" => attachment.parent.id, "parent_type" => "Exercise" ), - 'large_url' => a_string_starting_with("/attachments/large_"), - 'medium_url' => a_string_starting_with("/attachments/medium_"), - 'small_url' => a_string_starting_with("/attachments/small_"), - 'url' => a_string_starting_with("/attachments/") + 'large_url' => a_string_starting_with( + "https://not-a-real-bucket.s3.amazonaws.com/test/large_" + ), + 'medium_url' => a_string_starting_with( + "https://not-a-real-bucket.s3.amazonaws.com/test/medium_" + ), + 'small_url' => a_string_starting_with( + "https://not-a-real-bucket.s3.amazonaws.com/test/small_" + ), + 'url' => a_string_starting_with("https://not-a-real-bucket.s3.amazonaws.com/test/") ) - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a1a195d3..c5f43e38 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -75,7 +75,7 @@ # Allows RSpec to persist some state between runs in order to support # the `--only-failures` and `--next-failure` CLI options. We recommend # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = 'rspec.failures' + config.example_status_persistence_file_path = '.rspec_last_failures' end RSpec::Matchers.define_negated_matcher :not_change, :change diff --git a/vendor/assets/javascripts/sandbox.js b/vendor/assets/javascripts/sandbox.js new file mode 100644 index 00000000..4c69e855 --- /dev/null +++ b/vendor/assets/javascripts/sandbox.js @@ -0,0 +1,62 @@ +/* + * decaffeinate suggestions: + * DS101: Remove unnecessary use of Array.from + * DS205: Consider reworking code to avoid use of IIFEs + * DS207: Consider shorter variations of null checks + * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md + */ +// https://github.com/versal/sandbox-js + +window.sandbox = function(options) { + let src; + if (options == null) { options = {}; } + options = $.extend(true, {}, { + html: '', css: '', js: '', + external: { js: {}, css: {} }, + dialogs: true, + onLog() {} + }, options); + + const { js, html, css, external } = options; + + const iframe = $('