Kouhei Sutou 2019-03-26 15:48:23 +0900 (Tue, 26 Mar 2019) Revision: 895654c7a52d4af4422faf9462ff92bd1e5b2648 https://github.com/ranguba/chupa-text-http-server/commit/895654c7a52d4af4422faf9462ff92bd1e5b2648 Message: Upgrade to Rails 5.2 Added files: config/initializers/content_security_policy.rb config/initializers/new_framework_defaults_5_2.rb Modified files: .travis.yml Gemfile app/controllers/extractions_controller.rb app/views/extractions/_form.html.erb bin/bundle bin/setup bin/update bin/yarn config/application.rb config/boot.rb config/cable.yml config/environments/development.rb config/environments/production.rb config/environments/test.rb config/initializers/application_controller_renderer.rb config/puma.rb config/spring.rb Modified: .travis.yml (+4 -0) =================================================================== --- .travis.yml 2019-03-26 15:01:35 +0900 (66961d5) +++ .travis.yml 2019-03-26 15:48:23 +0900 (717ce25) @@ -9,6 +9,10 @@ rvm: dist: xenial +addons: + apt: + update: true + before_install: - ln -s Gemfile.local{.example,} Modified: Gemfile (+22 -15) =================================================================== --- Gemfile 2019-03-26 15:01:35 +0900 (5877126) +++ Gemfile 2019-03-26 15:48:23 +0900 (628c2d9) @@ -1,21 +1,16 @@ source 'https://rubygems.org' - -git_source(:github) do |repo_name| - repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") - "https://github.com/#{repo_name}.git" -end - +git_source(:github) { |repo| "https://github.com/#{repo}.git" } # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 5.1.2' +gem 'rails', '~> 5.2.2' # Use Puma as the app server -gem 'puma', '~> 3.7' +gem 'puma', '~> 3.11' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # See https://github.com/rails/execjs#readme for more supported runtimes -# gem 'therubyracer', platforms: :ruby +# gem 'mini_racer', platforms: :ruby # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2' @@ -24,20 +19,22 @@ gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production -# gem 'redis', '~> 3.0' +# gem 'redis', '~> 4.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' +# Use ActiveStorage variant +# gem 'mini_magick', '~> 4.8' + # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.1.0', require: false + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] - # Adds support for Capybara system testing and selenium driver - gem 'capybara', '~> 2.13' - gem 'selenium-webdriver' - gem 'test-unit-rails' end group :development do @@ -49,10 +46,20 @@ group :development do gem 'spring-watcher-listen', '~> 2.0.0' end +group :test do + # Adds support for Capybara system testing and selenium driver + gem 'capybara', '>= 2.15' + gem 'selenium-webdriver' + # Easy installation and use of chromedriver to run system tests with Chrome + gem 'chromedriver-helper' + # Use test-unit + gem 'test-unit-rails' +end + # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] -gem 'bootstrap', github: 'twbs/bootstrap-rubygem' +gem 'bootstrap' gem 'jquery-rails' gem 'chupa-text'#, path: '../chupa-text' Modified: app/controllers/extractions_controller.rb (+9 -3) =================================================================== --- app/controllers/extractions_controller.rb 2019-03-26 15:01:35 +0900 (0f80f04) +++ app/controllers/extractions_controller.rb 2019-03-26 15:48:23 +0900 (00d3c79) @@ -26,8 +26,14 @@ class ExtractionsController < ApplicationController private # Never trust parameters from the scary internet, only allow the white list through. def extraction_params - params - .except(:format, :utf8, :authenticity_token, :commit) - .permit(:data, :uri) + if params[:extraction] + # For form + params.require(:extraction).permit(:data, :uri) + else + # For API + params + .except(:format, :utf8, :authenticity_token, :commit) + .permit(:data, :uri) + end end end Modified: app/views/extractions/_form.html.erb (+6 -3) =================================================================== --- app/views/extractions/_form.html.erb 2019-03-26 15:01:35 +0900 (68bcbd5) +++ app/views/extractions/_form.html.erb 2019-03-26 15:48:23 +0900 (5c0b589) @@ -1,4 +1,7 @@ -<%= form_with(model: extraction, local: true, url: extraction_path, method: :post) do |form| %> +<%= form_with(model: extraction, + local: true, + url: extraction_path, + method: :post) do |form| %> <% if extraction.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(extraction.errors.count, "error") %> prohibited this extraction from being saved:</h2> @@ -13,12 +16,12 @@ <div class="field"> <%= form.label :data %> - <%= form.file_field :data, id: :extraction_data, name: :data %> + <%= form.file_field :data %> </div> <div class="field"> <%= form.label :uri, "URI (optional)" %> - <%= form.text_field :uri, id: :extraction_uri, name: :uri %> + <%= form.text_field :uri %> </div> <div class="actions"> Modified: bin/bundle (+1 -1) =================================================================== --- bin/bundle 2019-03-26 15:01:35 +0900 (66e9889) +++ bin/bundle 2019-03-26 15:48:23 +0900 (f19acf5) @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') Modified: bin/setup (+1 -3) =================================================================== --- bin/setup 2019-03-26 15:01:35 +0900 (93a2160) +++ bin/setup 2019-03-26 15:48:23 +0900 (aacb6b9) @@ -1,10 +1,9 @@ #!/usr/bin/env ruby -require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -21,7 +20,6 @@ chdir APP_ROOT do # Install JavaScript dependencies if using Yarn # system('bin/yarn') - puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' Modified: bin/update (+4 -2) =================================================================== --- bin/update 2019-03-26 15:01:35 +0900 (dc15867) +++ bin/update 2019-03-26 15:48:23 +0900 (0a083e7) @@ -1,10 +1,9 @@ #!/usr/bin/env ruby -require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -18,6 +17,9 @@ chdir APP_ROOT do system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') + # Install JavaScript dependencies if using Yarn + # system('bin/yarn') + puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' Modified: bin/yarn (+3 -3) =================================================================== --- bin/yarn 2019-03-26 15:01:35 +0900 (c2bacef) +++ bin/yarn 2019-03-26 15:48:23 +0900 (460dd56) @@ -1,8 +1,8 @@ #!/usr/bin/env ruby -VENDOR_PATH = File.expand_path('..', __dir__) -Dir.chdir(VENDOR_PATH) do +APP_ROOT = File.expand_path('..', __dir__) +Dir.chdir(APP_ROOT) do begin - exec "yarnpkg #{ARGV.join(" ")}" + exec "yarnpkg", *ARGV rescue Errno::ENOENT $stderr.puts "Yarn executable was not detected in the system." $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" Modified: config/application.rb (+4 -2) =================================================================== --- config/application.rb 2019-03-26 15:01:35 +0900 (b59921a) +++ config/application.rb 2019-03-26 15:48:23 +0900 (b03a67f) @@ -5,6 +5,7 @@ require "rails" 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_view/railtie" @@ -22,7 +23,8 @@ module ChupaTextHttpServer config.load_defaults 5.1 # 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. end end Modified: config/boot.rb (+1 -0) =================================================================== --- config/boot.rb 2019-03-26 15:01:35 +0900 (30f5120) +++ config/boot.rb 2019-03-26 15:48:23 +0900 (b9e460c) @@ -1,3 +1,4 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. Modified: config/cable.yml (+2 -2) =================================================================== --- config/cable.yml 2019-03-26 15:01:35 +0900 (a6f54b1) +++ config/cable.yml 2019-03-26 15:48:23 +0900 (41bb6d1) @@ -6,5 +6,5 @@ test: production: adapter: redis - url: redis://localhost:6379/1 - channel_prefix: chupa-text-http-server_production + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: chupa_text_http_server_production Modified: config/environments/development.rb (+3 -2) =================================================================== --- config/environments/development.rb 2019-03-26 15:01:35 +0900 (6e33d11) +++ config/environments/development.rb 2019-03-26 15:48:23 +0900 (4f0e58d) @@ -13,12 +13,13 @@ 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.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 Modified: config/environments/production.rb (+4 -5) =================================================================== --- config/environments/production.rb 2019-03-26 15:01:35 +0900 (090a481) +++ config/environments/production.rb 2019-03-26 15:48:23 +0900 (5e996e0) @@ -14,10 +14,9 @@ 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. @@ -59,7 +58,7 @@ Rails.application.configure do # 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 = "chupa-text-http-server_#{Rails.env}" + # config.active_job.queue_name_prefix = "chupa_text_http_server_#{Rails.env}" # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). Modified: config/environments/test.rb (+1 -1) =================================================================== --- config/environments/test.rb 2019-03-26 15:01:35 +0900 (6fd7f98) +++ config/environments/test.rb 2019-03-26 15:48:23 +0900 (bf3aeb3) @@ -15,7 +15,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}" } # Show full error reports and disable caching. Modified: config/initializers/application_controller_renderer.rb (+6 -4) =================================================================== --- config/initializers/application_controller_renderer.rb 2019-03-26 15:01:35 +0900 (51639b6) +++ config/initializers/application_controller_renderer.rb 2019-03-26 15:48:23 +0900 (89d2efa) @@ -1,6 +1,8 @@ # 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 Added: config/initializers/content_security_policy.rb (+25 -0) 100644 =================================================================== --- /dev/null +++ config/initializers/content_security_policy.rb 2019-03-26 15:48:23 +0900 (d3bcaa5) @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# 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 +# Rails.application.config.content_security_policy_report_only = true Added: config/initializers/new_framework_defaults_5_2.rb (+38 -0) 100644 =================================================================== --- /dev/null +++ config/initializers/new_framework_defaults_5_2.rb 2019-03-26 15:48:23 +0900 (e549fee) @@ -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 Modified: config/puma.rb (+1 -23) =================================================================== --- config/puma.rb 2019-03-26 15:01:35 +0900 (1e19380) +++ config/puma.rb 2019-03-26 15:48:23 +0900 (a5eccf8) @@ -26,31 +26,9 @@ environment ENV.fetch("RAILS_ENV") { "development" } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. If you use this option -# you need to make sure to reconnect any threads in the `on_worker_boot` -# block. +# process behavior so workers use less memory. # # preload_app! -# If you are preloading your application and using Active Record, it's -# recommended that you close any connections to the database before workers -# are forked to prevent connection leakage. -# -# before_fork do -# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) -# end - -# The code in the `on_worker_boot` will be called if you are using -# clustered mode by specifying a number of `workers`. After each worker -# process is booted, this block will be run. If you are using the `preload_app!` -# option, you will want to use this block to reconnect to any threads -# or connections that may have been created at application boot, as Ruby -# cannot share connections between processes. -# -# on_worker_boot do -# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) -# end -# - # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart Modified: config/spring.rb (+2 -2) =================================================================== --- config/spring.rb 2019-03-26 15:01:35 +0900 (c9119b4) +++ config/spring.rb 2019-03-26 15:48:23 +0900 (9fa7863) @@ -1,6 +1,6 @@ -%w( +%w[ .ruby-version .rbenv-vars tmp/restart.txt tmp/caching-dev.txt -).each { |path| Spring.watch(path) } +].each { |path| Spring.watch(path) } -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190326/66355971/attachment-0001.html>