From a37c33e14f852d287eafa67f68603d9d984d4cc8 Mon Sep 17 00:00:00 2001 From: Calvin Yu Date: Sat, 19 Dec 2020 04:45:53 -0500 Subject: [PATCH] Update Rails5 example --- examples/rails5/.ruby-version | 2 +- examples/rails5/Gemfile | 2 +- examples/rails5/Gemfile.lock | 146 +++++++++--------- examples/rails5/bin/rails | 5 - examples/rails5/bin/rake | 5 - examples/rails5/config/initializers/cors.rb | 11 +- .../new_framework_defaults_5_2.rb | 38 +++++ examples/rails5/config/puma.rb | 3 + examples/rails5/public/static.txt | 2 +- 9 files changed, 124 insertions(+), 90 deletions(-) create mode 100644 examples/rails5/config/initializers/new_framework_defaults_5_2.rb diff --git a/examples/rails5/.ruby-version b/examples/rails5/.ruby-version index bd4053b..37c2961 100644 --- a/examples/rails5/.ruby-version +++ b/examples/rails5/.ruby-version @@ -1 +1 @@ -2.6.3 \ No newline at end of file +2.7.2 diff --git a/examples/rails5/Gemfile b/examples/rails5/Gemfile index 787805b..b5585c5 100644 --- a/examples/rails5/Gemfile +++ b/examples/rails5/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '2.6.3' +ruby '2.7.2' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.2.3' diff --git a/examples/rails5/Gemfile.lock b/examples/rails5/Gemfile.lock index 3c9f95a..80a83d8 100644 --- a/examples/rails5/Gemfile.lock +++ b/examples/rails5/Gemfile.lock @@ -1,43 +1,43 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.2.3) - actionpack (= 5.2.3) + actioncable (5.2.4.4) + actionpack (= 5.2.4.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) - activejob (= 5.2.3) + actionmailer (5.2.4.4) + actionpack (= 5.2.4.4) + actionview (= 5.2.4.4) + activejob (= 5.2.4.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.3) - actionview (= 5.2.3) - activesupport (= 5.2.3) - rack (~> 2.0) + actionpack (5.2.4.4) + actionview (= 5.2.4.4) + activesupport (= 5.2.4.4) + 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.3) - activesupport (= 5.2.3) + actionview (5.2.4.4) + activesupport (= 5.2.4.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.3) - activesupport (= 5.2.3) + activejob (5.2.4.4) + activesupport (= 5.2.4.4) globalid (>= 0.3.6) - activemodel (5.2.3) - activesupport (= 5.2.3) - activerecord (5.2.3) - activemodel (= 5.2.3) - activesupport (= 5.2.3) + 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) - activestorage (5.2.3) - actionpack (= 5.2.3) - activerecord (= 5.2.3) + activestorage (5.2.4.4) + actionpack (= 5.2.4.4) + activerecord (= 5.2.4.4) marcel (~> 0.3.1) - activesupport (5.2.3) + activesupport (5.2.4.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -48,11 +48,11 @@ GEM io-like (~> 0.3.0) arel (9.0.0) bindex (0.8.1) - bootsnap (1.4.5) + bootsnap (1.5.1) msgpack (~> 1.0) - builder (3.2.3) - byebug (11.0.1) - capybara (3.29.0) + builder (3.2.4) + byebug (11.1.3) + capybara (3.34.0) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -71,76 +71,76 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.5) - crass (1.0.5) - erubi (1.9.0) + concurrent-ruby (1.1.7) + crass (1.0.6) + erubi (1.10.0) execjs (2.7.0) - ffi (1.11.2) + ffi (1.14.0) globalid (0.4.2) activesupport (>= 4.2.0) - i18n (1.7.0) + i18n (1.8.5) concurrent-ruby (~> 1.0) - io-like (0.3.0) - jbuilder (2.9.1) - activesupport (>= 4.2.0) + io-like (0.3.1) + jbuilder (2.10.1) + activesupport (>= 5.0.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.3.1) + loofah (2.8.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) marcel (0.3.3) mimemagic (~> 0.3.2) - method_source (0.9.2) - mimemagic (0.3.3) + method_source (1.0.0) + mimemagic (0.3.5) mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.13.0) - msgpack (1.3.1) - nio4r (2.5.2) - nokogiri (1.10.5) + minitest (5.14.2) + msgpack (1.3.3) + nio4r (2.5.4) + nokogiri (1.10.10) mini_portile2 (~> 2.4.0) - public_suffix (4.0.1) - puma (3.12.2) - rack (2.0.8) - rack-cors (1.1.0) + public_suffix (4.0.6) + puma (3.12.6) + rack (2.2.3) + rack-cors (1.1.1) rack (>= 2.0.0) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.3) - actioncable (= 5.2.3) - actionmailer (= 5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) - activejob (= 5.2.3) - activemodel (= 5.2.3) - activerecord (= 5.2.3) - activestorage (= 5.2.3) - activesupport (= 5.2.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) bundler (>= 1.3.0) - railties (= 5.2.3) + railties (= 5.2.4.4) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - railties (5.2.3) - actionpack (= 5.2.3) - activesupport (= 5.2.3) + railties (5.2.4.4) + actionpack (= 5.2.4.4) + activesupport (= 5.2.4.4) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) rake (13.0.1) - rb-fsevent (0.10.3) - rb-inotify (0.10.0) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) ffi (~> 1.0) - regexp_parser (1.6.0) + regexp_parser (1.8.2) ruby_dep (1.5.0) - rubyzip (2.0.0) + rubyzip (2.3.0) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -152,28 +152,28 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - selenium-webdriver (3.142.6) + selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) - spring (2.1.0) + spring (2.1.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.1) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.4.1) - thor (0.20.3) + sqlite3 (1.4.2) + thor (1.0.1) thread_safe (0.3.6) tilt (2.0.10) turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) - tzinfo (1.2.5) + tzinfo (1.2.9) thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) @@ -182,9 +182,9 @@ GEM activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket-driver (0.7.1) + websocket-driver (0.7.3) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) + websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) @@ -213,7 +213,7 @@ DEPENDENCIES web-console (>= 3.3.0) RUBY VERSION - ruby 2.6.3p62 + ruby 2.7.2p137 BUNDLED WITH 1.17.3 diff --git a/examples/rails5/bin/rails b/examples/rails5/bin/rails index 5badb2f..0739660 100755 --- a/examples/rails5/bin/rails +++ b/examples/rails5/bin/rails @@ -1,9 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError => e - raise unless e.message.include?('spring') -end APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/examples/rails5/bin/rake b/examples/rails5/bin/rake index d87d5f5..1724048 100755 --- a/examples/rails5/bin/rake +++ b/examples/rails5/bin/rake @@ -1,9 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError => e - raise unless e.message.include?('spring') -end require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/examples/rails5/config/initializers/cors.rb b/examples/rails5/config/initializers/cors.rb index 6468be1..50e0c3b 100644 --- a/examples/rails5/config/initializers/cors.rb +++ b/examples/rails5/config/initializers/cors.rb @@ -1,3 +1,8 @@ +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. + +# Read more: https://github.com/cyu/rack-cors + Rails.application.config.middleware.insert_before 0, Rack::Cors, debug: true, logger: (-> { Rails.logger }) do allow do origins '*' @@ -8,10 +13,8 @@ :max_age => 0 resource '*', - :headers => :any, - :methods => [:get, :post, :delete, :put, :patch, :options, :head], + headers: :any, + methods: [:get, :post, :put, :patch, :delete, :options, :head], :max_age => 0 end end - - diff --git a/examples/rails5/config/initializers/new_framework_defaults_5_2.rb b/examples/rails5/config/initializers/new_framework_defaults_5_2.rb new file mode 100644 index 0000000..c383d07 --- /dev/null +++ b/examples/rails5/config/initializers/new_framework_defaults_5_2.rb @@ -0,0 +1,38 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.2 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. + +# Make Active Record use stable #cache_key alongside new #cache_version method. +# This is needed for recyclable cache keys. +# Rails.application.config.active_record.cache_versioning = true + +# Use AES-256-GCM authenticated encryption for encrypted cookies. +# Also, embed cookie expiry in signed or 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 5.2. +# +# Existing cookies will be converted on read then written with the new scheme. +# Rails.application.config.action_dispatch.use_authenticated_cookie_encryption = true + +# Use AES-256-GCM authenticated encryption as default cipher for encrypting messages +# instead of AES-256-CBC, when use_authenticated_message_encryption is set to true. +# Rails.application.config.active_support.use_authenticated_message_encryption = true + +# Add default protection from forgery to ActionController::Base instead of in +# ApplicationController. +# Rails.application.config.action_controller.default_protect_from_forgery = true + +# Store boolean values are in sqlite3 databases as 1 and 0 instead of 't' and +# 'f' after migrating old data. +# Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true + +# Use SHA-1 instead of MD5 to generate non-sensitive digests, such as the ETag header. +# Rails.application.config.active_support.use_sha1_digests = true + +# Make `form_with` generate id attributes for any generated HTML tags. +# Rails.application.config.action_view.form_with_generates_ids = true diff --git a/examples/rails5/config/puma.rb b/examples/rails5/config/puma.rb index a5eccf8..b210207 100644 --- a/examples/rails5/config/puma.rb +++ b/examples/rails5/config/puma.rb @@ -15,6 +15,9 @@ # environment ENV.fetch("RAILS_ENV") { "development" } +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. diff --git a/examples/rails5/public/static.txt b/examples/rails5/public/static.txt index 3b18e51..802992c 100644 --- a/examples/rails5/public/static.txt +++ b/examples/rails5/public/static.txt @@ -1 +1 @@ -hello world +Hello world