diff options
author | 2019-07-22 18:56:58 +0200 | |
---|---|---|
committer | 2019-07-22 18:56:58 +0200 | |
commit | a1b7c2071bfaaadcfb2b8cbca8c5aafabb12923a (patch) | |
tree | 9c198fc51149a7601cb1164dcd4ac03079010efc | |
parent | Add ETag and Last-Modified headers based on specific package (diff) | |
download | packages-5-a1b7c2071bfaaadcfb2b8cbca8c5aafabb12923a.tar.gz packages-5-a1b7c2071bfaaadcfb2b8cbca8c5aafabb12923a.tar.bz2 packages-5-a1b7c2071bfaaadcfb2b8cbca8c5aafabb12923a.zip |
Update to Rails 5.1
This also fixes a bug in the fresh_when handling for the changelog
view, which was exposed by the update (due to ETag now taking the
flash message, if any, into account).
Signed-off-by: Hans de Graaff <graaff@gentoo.org>
-rw-r--r-- | Gemfile | 5 | ||||
-rw-r--r-- | Gemfile.lock | 88 | ||||
-rw-r--r-- | app/controllers/packages_controller.rb | 16 | ||||
-rwxr-xr-x | bin/setup | 4 | ||||
-rwxr-xr-x | bin/yarn | 11 | ||||
-rw-r--r-- | config/application.rb | 5 | ||||
-rw-r--r-- | config/environments/development.rb | 4 | ||||
-rw-r--r-- | config/environments/test.rb | 2 | ||||
-rw-r--r-- | config/initializers/assets.rb | 9 |
9 files changed, 88 insertions, 56 deletions
@@ -1,7 +1,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '5.0.7.2' +gem 'rails', '5.1.7' # Use mysql as the database for Active Record # gem 'mysql2' # Use SCSS for stylesheets @@ -49,6 +49,9 @@ group :development do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + # Enable event-based autoloading + gem 'listen' + # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 3.0' diff --git a/Gemfile.lock b/Gemfile.lock index f03a6b1..7b8ebb6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,44 +1,44 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.0.7.2) - actionpack (= 5.0.7.2) - nio4r (>= 1.2, < 3.0) + actioncable (5.1.7) + actionpack (= 5.1.7) + nio4r (~> 2.0) websocket-driver (~> 0.6.1) - actionmailer (5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) + actionmailer (5.1.7) + actionpack (= 5.1.7) + actionview (= 5.1.7) + activejob (= 5.1.7) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.7.2) - actionview (= 5.0.7.2) - activesupport (= 5.0.7.2) + actionpack (5.1.7) + actionview (= 5.1.7) + activesupport (= 5.1.7) rack (~> 2.0) - rack-test (~> 0.6.3) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.7.2) - activesupport (= 5.0.7.2) + actionview (5.1.7) + activesupport (= 5.1.7) builder (~> 3.1) - erubis (~> 2.7.0) + erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.0.7.2) - activesupport (= 5.0.7.2) + activejob (5.1.7) + activesupport (= 5.1.7) globalid (>= 0.3.6) - activemodel (5.0.7.2) - activesupport (= 5.0.7.2) - activerecord (5.0.7.2) - activemodel (= 5.0.7.2) - activesupport (= 5.0.7.2) - arel (~> 7.0) - activesupport (5.0.7.2) + activemodel (5.1.7) + activesupport (= 5.1.7) + activerecord (5.1.7) + activemodel (= 5.1.7) + activesupport (= 5.1.7) + arel (~> 8.0) + activesupport (5.1.7) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - arel (7.1.4) + arel (8.0.0) axiom-types (0.1.1) descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) @@ -75,7 +75,7 @@ GEM faraday multi_json equalizer (0.0.11) - erubis (2.7.0) + erubi (1.8.0) eventmachine (1.2.7) execjs (2.7.0) faraday (0.15.4) @@ -93,6 +93,10 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.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.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -115,19 +119,19 @@ GEM rack (2.0.7) rack-protection (2.0.5) rack - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.7.2) - actioncable (= 5.0.7.2) - actionmailer (= 5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) - activemodel (= 5.0.7.2) - activerecord (= 5.0.7.2) - activesupport (= 5.0.7.2) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.1.7) + actioncable (= 5.1.7) + actionmailer (= 5.1.7) + actionpack (= 5.1.7) + actionview (= 5.1.7) + activejob (= 5.1.7) + activemodel (= 5.1.7) + activerecord (= 5.1.7) + activesupport (= 5.1.7) bundler (>= 1.3.0) - railties (= 5.0.7.2) + railties (= 5.1.7) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.4) actionpack (>= 5.0.1.x) @@ -138,9 +142,9 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - railties (5.0.7.2) - actionpack (= 5.0.7.2) - activesupport (= 5.0.7.2) + railties (5.1.7) + actionpack (= 5.1.7) + activesupport (= 5.1.7) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) @@ -151,6 +155,7 @@ GEM rdiscount (2.2.0.1) rdoc (6.1.1) redis (4.1.2) + ruby_dep (1.5.0) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -214,9 +219,10 @@ DEPENDENCIES elasticsearch-rails (~> 5.0) jbuilder (~> 2.0) jquery-rails (~> 4.3.5) + listen nokogiri octicons_helper - rails (= 5.0.7.2) + rails (= 5.1.7) rails-controller-testing rdiscount sass-rails (~> 5.0) diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index de24b40..64cb289 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -37,15 +37,15 @@ class PackagesController < ApplicationController @package = Package.find_by(:atom, params[:id]) fail ActionController::RoutingError, 'No such package' unless @package - fresh_when etag: @package.updated_at, last_modified: @package.updated_at, public: true - - @changelog = Rails.cache.fetch("changelog/#{@package.atom}") do - Portage::Util::History.for(@package.category, @package.name, 5) - end + if stale?(etag: @package.updated_at, last_modified: @package.updated_at, public: true) + @changelog = Rails.cache.fetch("changelog/#{@package.atom}") do + Portage::Util::History.for(@package.category, @package.name, 5) + end - respond_to do |wants| - wants.html { render layout: false } - wants.json {} + respond_to do |wants| + wants.html { render layout: false } + wants.json {} + end end end @@ -18,6 +18,10 @@ 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== Copying sample files ==" # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' diff --git a/bin/yarn b/bin/yarn new file mode 100755 index 0000000..c2bacef --- /dev/null +++ b/bin/yarn @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +VENDOR_PATH = File.expand_path('..', __dir__) +Dir.chdir(VENDOR_PATH) do + begin + exec "yarnpkg #{ARGV.join(" ")}" + rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 + end +end diff --git a/config/application.rb b/config/application.rb index 9639248..136f5cc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -17,6 +17,9 @@ Bundler.require(*Rails.groups) module Packages class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + 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. @@ -37,6 +40,8 @@ module Packages config.autoload_paths << Rails.root.join('lib') config.active_job.queue_adapter = :sidekiq + + config.middleware.use ActionDispatch::Flash end end diff --git a/config/environments/development.rb b/config/environments/development.rb index d241472..5670ba7 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -18,7 +18,7 @@ Rails.application.configure do config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => 'public, max-age=172800' + 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" } else config.action_controller.perform_caching = false @@ -50,5 +50,5 @@ Rails.application.configure do # 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 + config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/config/environments/test.rb b/config/environments/test.rb index 1619c9b..4154d7e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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=3600' + 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}" } # Show full error reports and disable caching. diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 01ef3e6..4b828e8 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -3,9 +3,12 @@ # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = '1.0' -# Add additional assets to the asset load path +# 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. -# Rails.application.config.assets.precompile += %w( search.js ) +# 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 ) |