diff --git a/example/Gemfile b/example/Gemfile index cacf5aff..a900cfa8 100644 --- a/example/Gemfile +++ b/example/Gemfile @@ -1,16 +1,19 @@ source 'https://rubygems.org' -ruby '2.3.3' +ruby '3.0.6' -gem 'rack-cors', :require => 'rack/cors' -gem 'rails', '4.2.5.1' +gem 'rack-cors', require: 'rack/cors' +gem 'rails', '6.1.6' gem 'sqlite3' gem 'spring', group: :development -gem 'raddocs', '0.4.0' +gem 'raddocs', '2.3.0', github: 'goodylabs/raddocs' +gem "sprockets-rails" +gem "sprockets", "~> 3.7.0" +gem 'thin' group :test, :development do gem 'byebug' gem 'awesome_print' gem 'rspec-rails' - gem 'rspec_api_documentation', :path => "../" + gem 'rspec_api_documentation', path: "../" end diff --git a/example/Gemfile.lock b/example/Gemfile.lock index fd2e4eef..a139ba30 100644 --- a/example/Gemfile.lock +++ b/example/Gemfile.lock @@ -1,7 +1,16 @@ +GIT + remote: https://github.com/goodylabs/raddocs.git + revision: c44571303c567dd2ffb6d54b2fe9df5ba3e1a12f + specs: + raddocs (2.3.0) + haml (>= 4.0) + json + sinatra (~> 2.0) + PATH remote: .. specs: - rspec_api_documentation (5.1.0) + rspec_api_documentation (6.1.0) activesupport (>= 3.0.0) mustache (~> 1.0, >= 0.99.4) rspec (~> 3.0) @@ -9,154 +18,219 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.5.1) - actionpack (= 4.2.5.1) - actionview (= 4.2.5.1) - activejob (= 4.2.5.1) + actioncable (6.1.6) + actionpack (= 6.1.6) + activesupport (= 6.1.6) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.1.6) + actionpack (= 6.1.6) + activejob (= 6.1.6) + activerecord (= 6.1.6) + activestorage (= 6.1.6) + activesupport (= 6.1.6) + mail (>= 2.7.1) + actionmailer (6.1.6) + actionpack (= 6.1.6) + actionview (= 6.1.6) + activejob (= 6.1.6) + activesupport (= 6.1.6) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.5.1) - actionview (= 4.2.5.1) - activesupport (= 4.2.5.1) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.5.1) - activesupport (= 4.2.5.1) - builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (4.2.5.1) - activesupport (= 4.2.5.1) - globalid (>= 0.3.0) - activemodel (4.2.5.1) - activesupport (= 4.2.5.1) + rails-dom-testing (~> 2.0) + actionpack (6.1.6) + actionview (= 6.1.6) + activesupport (= 6.1.6) + rack (~> 2.0, >= 2.0.9) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.6) + actionpack (= 6.1.6) + activerecord (= 6.1.6) + activestorage (= 6.1.6) + activesupport (= 6.1.6) + nokogiri (>= 1.8.5) + actionview (6.1.6) + activesupport (= 6.1.6) builder (~> 3.1) - activerecord (4.2.5.1) - activemodel (= 4.2.5.1) - activesupport (= 4.2.5.1) - arel (~> 6.0) - activesupport (4.2.5.1) - i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - arel (6.0.3) - awesome_print (1.7.0) - builder (3.2.2) - byebug (9.0.6) - concurrent-ruby (1.0.0) - diff-lcs (1.2.5) - erubis (2.7.0) - globalid (0.3.6) - activesupport (>= 4.1.0) - haml (4.0.7) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.6) + activesupport (= 6.1.6) + globalid (>= 0.3.6) + activemodel (6.1.6) + activesupport (= 6.1.6) + activerecord (6.1.6) + activemodel (= 6.1.6) + activesupport (= 6.1.6) + activestorage (6.1.6) + actionpack (= 6.1.6) + activejob (= 6.1.6) + activerecord (= 6.1.6) + activesupport (= 6.1.6) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (6.1.6) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + awesome_print (1.9.2) + builder (3.2.4) + byebug (11.1.3) + concurrent-ruby (1.2.3) + crass (1.0.6) + daemons (1.4.1) + date (3.3.4) + diff-lcs (1.5.1) + erubi (1.12.0) + eventmachine (1.2.7) + globalid (1.2.1) + activesupport (>= 6.1) + haml (6.3.0) + temple (>= 0.8.2) + thor tilt - i18n (0.7.0) - json (1.8.3) - loofah (2.0.3) - nokogiri (>= 1.5.9) - mail (2.6.3) - mime-types (>= 1.16, < 3) - mime-types (2.99) - mini_portile2 (2.0.0) - minitest (5.8.4) - mustache (1.0.5) - nokogiri (1.6.7.2) - mini_portile2 (~> 2.0.0.rc2) - rack (1.6.4) - rack-cors (0.4.1) - rack-protection (1.5.5) + i18n (1.14.3) + concurrent-ruby (~> 1.0) + racc (~> 1.7) + json (2.7.1) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + method_source (1.0.0) + mini_mime (1.1.5) + minitest (5.22.2) + mustache (1.1.1) + mustermann (2.0.2) + ruby2_keywords (~> 0.0.1) + net-imap (0.4.10) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.4.0.1) + net-protocol + nio4r (2.7.0) + nokogiri (1.16.2-x86_64-linux) + racc (~> 1.4) + racc (1.7.3) + rack (2.2.8.1) + rack-cors (2.0.2) + rack (>= 2.0.0) + rack-protection (2.2.4) rack - rack-test (0.6.3) - rack (>= 1.0) - raddocs (0.4.0) - haml (~> 4.0, >= 4.0.4) - json (~> 1.8, >= 1.8.1) - sinatra (~> 1.3, >= 1.3.0) - rails (4.2.5.1) - actionmailer (= 4.2.5.1) - actionpack (= 4.2.5.1) - actionview (= 4.2.5.1) - activejob (= 4.2.5.1) - activemodel (= 4.2.5.1) - activerecord (= 4.2.5.1) - activesupport (= 4.2.5.1) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.5.1) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.7) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (4.2.5.1) - actionpack (= 4.2.5.1) - activesupport (= 4.2.5.1) - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (10.5.0) - rspec (3.0.0) - rspec-core (~> 3.0.0) - rspec-expectations (~> 3.0.0) - rspec-mocks (~> 3.0.0) - rspec-core (3.0.4) - rspec-support (~> 3.0.0) - rspec-expectations (3.0.4) + rack-test (2.1.0) + rack (>= 1.3) + rails (6.1.6) + actioncable (= 6.1.6) + actionmailbox (= 6.1.6) + actionmailer (= 6.1.6) + actionpack (= 6.1.6) + actiontext (= 6.1.6) + actionview (= 6.1.6) + activejob (= 6.1.6) + activemodel (= 6.1.6) + activerecord (= 6.1.6) + activestorage (= 6.1.6) + activesupport (= 6.1.6) + bundler (>= 1.15.0) + railties (= 6.1.6) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (6.1.6) + actionpack (= 6.1.6) + activesupport (= 6.1.6) + method_source + rake (>= 12.2) + thor (~> 1.0) + rake (13.1.0) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.0.0) - rspec-mocks (3.0.4) - rspec-support (~> 3.0.0) - rspec-rails (3.0.2) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.0.0) - rspec-expectations (~> 3.0.0) - rspec-mocks (~> 3.0.0) - rspec-support (~> 3.0.0) - rspec-support (3.0.4) - sinatra (1.4.8) - rack (~> 1.5) - rack-protection (~> 1.4) - tilt (>= 1.3, < 3) - spring (1.1.3) - sprockets (3.5.2) + rspec-support (~> 3.13.0) + rspec-rails (6.1.1) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.12) + rspec-expectations (~> 3.12) + rspec-mocks (~> 3.12) + rspec-support (~> 3.12) + rspec-support (3.13.1) + ruby2_keywords (0.0.5) + sinatra (2.2.4) + mustermann (~> 2.0) + rack (~> 2.2) + rack-protection (= 2.2.4) + tilt (~> 2.0) + spring (4.1.3) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.0.1) - actionpack (>= 4.0) - activesupport (>= 4.0) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.3.9) - thor (0.19.1) - thread_safe (0.3.5) - tilt (2.0.8) - tzinfo (1.2.2) - thread_safe (~> 0.1) + sqlite3 (1.7.2-x86_64-linux) + temple (0.10.3) + thin (1.8.2) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (1.3.1) + tilt (2.3.0) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.6.13) PLATFORMS - ruby + x86_64-linux DEPENDENCIES awesome_print byebug rack-cors - raddocs (= 0.4.0) - rails (= 4.2.5.1) + raddocs (= 2.3.0)! + rails (= 6.1.6) rspec-rails rspec_api_documentation! spring + sprockets (~> 3.7.0) + sprockets-rails sqlite3 + thin RUBY VERSION - ruby 2.3.3p222 + ruby 3.0.6p216 BUNDLED WITH - 1.16.3 + 2.4.15 diff --git a/example/app/controllers/orders_controller.rb b/example/app/controllers/orders_controller.rb index 9ec2f703..d89c5cb5 100644 --- a/example/app/controllers/orders_controller.rb +++ b/example/app/controllers/orders_controller.rb @@ -4,7 +4,7 @@ class OrdersController < ApplicationController end def index - render :json => Order.all + render json: Order.all end def show @@ -18,13 +18,13 @@ def show def create order = Order.create(order_params) - render :json => order, :status => 201, :location => order_url(order) + render json: order, status: 201, location: order_url(order) end def update order = Order.find(params[:id]) order.update(order_params) - render :nothing => true, :status => 204 + head 204 end def destroy diff --git a/example/bin/rails b/example/bin/rails index 7feb6a30..21d3e02d 100755 --- a/example/bin/rails +++ b/example/bin/rails @@ -1,8 +1,5 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -APP_PATH = File.expand_path('../../config/application', __FILE__) -require_relative '../config/boot' -require 'rails/commands' +load File.expand_path("spring", __dir__) +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/example/bin/rake b/example/bin/rake index 8017a027..7327f471 100755 --- a/example/bin/rake +++ b/example/bin/rake @@ -1,8 +1,5 @@ #!/usr/bin/env ruby -begin - load File.expand_path("../spring", __FILE__) -rescue LoadError -end -require_relative '../config/boot' -require 'rake' +load File.expand_path("spring", __dir__) +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/example/bin/setup b/example/bin/setup new file mode 100755 index 00000000..57923026 --- /dev/null +++ b/example/bin/setup @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require "fileutils" + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:prepare' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/example/bin/spring b/example/bin/spring index 253ec37c..b4147e84 100755 --- a/example/bin/spring +++ b/example/bin/spring @@ -1,18 +1,14 @@ #!/usr/bin/env ruby - -# This file loads spring without using Bundler, in order to be fast -# It gets overwritten when you run the `spring binstub` command - -unless defined?(Spring) - require "rubygems" +if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"]) + gem "bundler" require "bundler" - if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m) - ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) - ENV["GEM_HOME"] = "" - Gem.paths = ENV - - gem "spring", match[1] + # Load Spring without loading other gems in the Gemfile, for speed. + Bundler.locked_gems&.specs&.find { |spec| spec.name == "spring" }&.tap do |spring| + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem "spring", spring.version require "spring/binstub" + rescue Gem::LoadError + # Ignore when Spring is not installed. end end diff --git a/example/config.ru b/example/config.ru index 5bc2a619..4a3c09a6 100644 --- a/example/config.ru +++ b/example/config.ru @@ -1,4 +1,6 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require_relative "config/environment" + run Rails.application +Rails.application.load_server diff --git a/example/config/application.rb b/example/config/application.rb index 26647b9d..e3c04507 100644 --- a/example/config/application.rb +++ b/example/config/application.rb @@ -1,11 +1,17 @@ -require File.expand_path('../boot', __FILE__) +require_relative "boot" +require "rails" # 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_mailbox/engine" +# require "action_text/engine" require "action_view/railtie" +# require "action_cable/engine" require "sprockets/railtie" # require "rails/test_unit/railtie" @@ -15,24 +21,15 @@ module Example class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.0 - config.middleware.insert_before 0, 'Rack::Cors' do - allow do - origins '*' - resource '*', :headers => :any, :methods => [:get, :post, :options, :put, :patch, :delete, :head] - end - end - - # 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. - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") end end diff --git a/example/config/boot.rb b/example/config/boot.rb index 5e5f0c1f..d69bd27d 100644 --- a/example/config/boot.rb +++ b/example/config/boot.rb @@ -1,4 +1,3 @@ -# Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/example/config/environment.rb b/example/config/environment.rb index ee8d90dc..e6dfbfad 100644 --- a/example/config/environment.rb +++ b/example/config/environment.rb @@ -1,5 +1,6 @@ # Load the Rails application. -require File.expand_path('../application', __FILE__) +# require_relative "application" +require File.expand_path("../application", __FILE__) # Initialize the Rails application. Rails.application.initialize! diff --git a/example/config/environments/development.rb b/example/config/environments/development.rb index ddf0e90c..4aa50264 100644 --- a/example/config/environments/development.rb +++ b/example/config/environments/development.rb @@ -1,27 +1,58 @@ +require "active_support/core_ext/integer/time" + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true + # Show full error reports. + config.consider_all_requests_local = true + + # and disable caching. config.action_controller.perform_caching = false + # 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 + config.action_mailer.perform_caching = false + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. @@ -32,6 +63,19 @@ # Raises helpful error messages. config.assets.raise_runtime_errors = true - # Raises error for missing translations - # config.action_view.raise_on_missing_translations = true + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + # config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true end diff --git a/example/config/environments/production.rb b/example/config/environments/production.rb index 47d3553b..12feaf07 100644 --- a/example/config/environments/production.rb +++ b/example/config/environments/production.rb @@ -1,3 +1,5 @@ +require "active_support/core_ext/integer/time" + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -14,21 +16,34 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = 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 + # 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 + # 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? + # Disable Rails's static asset server (Apache or nginx will already do this). config.serve_static_assets = false # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier + + # 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 + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = 'http://assets.example.com' + # Generate digests for assets URLs. config.assets.digest = true @@ -36,17 +51,20 @@ config.assets.version = '1.0' # 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 # 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. + # Include generic and useful information about system operation, but avoid logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). config.log_level = :info # Prepend all log lines with the following tags. # config.log_tags = [ :subdomain, :uuid ] + config.log_tags = [ :request_id ] # Use a different logger for distributed setups. # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) @@ -57,9 +75,14 @@ # 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 = "example_production" + # 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 ) + 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. @@ -75,9 +98,46 @@ # Disable automatic flushing of the log to improve performance. # config.autoflush_log = false + # Log disallowed deprecations. + config.active_support.disallowed_deprecation = :log + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new + # Use a different logger for distributed setups. + # require "syslog/logger" + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + # 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/example/config/environments/test.rb b/example/config/environments/test.rb index 053f5b66..70791305 100644 --- a/example/config/environments/test.rb +++ b/example/config/environments/test.rb @@ -1,24 +1,31 @@ +require "active_support/core_ext/integer/time" + +# 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 + config.cache_classes = false + config.action_view.cache_template_loading = true # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_assets = true - config.static_cache_control = 'public, max-age=3600' + # 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.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 @@ -26,6 +33,8 @@ # 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. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. @@ -34,6 +43,15 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Raises error for missing translations - # config.action_view.raise_on_missing_translations = true + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true end diff --git a/example/config/initializers/application_controller_renderer.rb b/example/config/initializers/application_controller_renderer.rb new file mode 100644 index 00000000..89d2efab --- /dev/null +++ b/example/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/example/config/initializers/assets.rb b/example/config/initializers/assets.rb new file mode 100644 index 00000000..fe48fc34 --- /dev/null +++ b/example/config/initializers/assets.rb @@ -0,0 +1,12 @@ +# Be sure to restart your server when you modify this file. + +# 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. +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# 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/example/config/initializers/backtrace_silencers.rb b/example/config/initializers/backtrace_silencers.rb index 59385cdf..33699c30 100644 --- a/example/config/initializers/backtrace_silencers.rb +++ b/example/config/initializers/backtrace_silencers.rb @@ -1,7 +1,8 @@ # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } +# Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) } -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. -# Rails.backtrace_cleaner.remove_silencers! +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code +# by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". +Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] diff --git a/example/config/initializers/content_security_policy.rb b/example/config/initializers/content_security_policy.rb new file mode 100644 index 00000000..41c43016 --- /dev/null +++ b/example/config/initializers/content_security_policy.rb @@ -0,0 +1,28 @@ +# 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) } + +# 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 +# Rails.application.config.content_security_policy_report_only = true diff --git a/example/config/initializers/cookies_serializer.rb b/example/config/initializers/cookies_serializer.rb index 7a06a89f..5a6a32d3 100644 --- a/example/config/initializers/cookies_serializer.rb +++ b/example/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.action_dispatch.cookies_serializer = :json \ No newline at end of file +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/example/config/initializers/cors.rb b/example/config/initializers/cors.rb new file mode 100644 index 00000000..ebdf0ee1 --- /dev/null +++ b/example/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# 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 do + allow do + origins '*' + + resource '*', + headers: :any, + methods: [:get, :post, :put, :patch, :delete, :options, :head] + end +end diff --git a/example/config/initializers/filter_parameter_logging.rb b/example/config/initializers/filter_parameter_logging.rb index 4a994e1e..4b34a036 100644 --- a/example/config/initializers/filter_parameter_logging.rb +++ b/example/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,6 @@ # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password] +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/example/config/initializers/new_framework_defaults_6_1.rb b/example/config/initializers/new_framework_defaults_6_1.rb new file mode 100644 index 00000000..9526b835 --- /dev/null +++ b/example/config/initializers/new_framework_defaults_6_1.rb @@ -0,0 +1,67 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 6.1 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. + +# Support for inversing belongs_to -> has_many Active Record associations. +# Rails.application.config.active_record.has_many_inversing = true + +# Track Active Storage variants in the database. +# Rails.application.config.active_storage.track_variants = true + +# Apply random variation to the delay when retrying failed jobs. +# Rails.application.config.active_job.retry_jitter = 0.15 + +# Stop executing `after_enqueue`/`after_perform` callbacks if +# `before_enqueue`/`before_perform` respectively halts with `throw :abort`. +# Rails.application.config.active_job.skip_after_callbacks_if_terminated = true + +# Specify cookies SameSite protection level: either :none, :lax, or :strict. +# +# This change is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.1. +# Rails.application.config.action_dispatch.cookies_same_site_protection = :lax + +# Generate CSRF tokens that are encoded in URL-safe Base64. +# +# This change is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.1. +# Rails.application.config.action_controller.urlsafe_csrf_tokens = true + +# Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an +# UTC offset or a UTC time. +# ActiveSupport.utc_to_local_returns_utc_offset_times = true + +# Change the default HTTP status code to `308` when redirecting non-GET/HEAD +# requests to HTTPS in `ActionDispatch::SSL` middleware. +# Rails.application.config.action_dispatch.ssl_default_redirect_status = 308 + +# Use new connection handling API. For most applications this won't have any +# effect. For applications using multiple databases, this new API provides +# support for granular connection swapping. +# Rails.application.config.active_record.legacy_connection_handling = false + +# Make `form_with` generate non-remote forms by default. +# Rails.application.config.action_view.form_with_generates_remote_forms = false + +# Set the default queue name for the analysis job to the queue adapter default. +# Rails.application.config.active_storage.queues.analysis = nil + +# Set the default queue name for the purge job to the queue adapter default. +# Rails.application.config.active_storage.queues.purge = nil + +# Set the default queue name for the incineration job to the queue adapter default. +# Rails.application.config.action_mailbox.queues.incineration = nil + +# Set the default queue name for the routing job to the queue adapter default. +# Rails.application.config.action_mailbox.queues.routing = nil + +# Set the default queue name for the mail deliver job to the queue adapter default. +# Rails.application.config.action_mailer.deliver_later_queue_name = nil + +# Generate a `Link` header that gives a hint to modern browsers about +# preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`. +# Rails.application.config.action_view.preload_links_header = true diff --git a/example/config/initializers/permissions_policy.rb b/example/config/initializers/permissions_policy.rb new file mode 100644 index 00000000..00f64d71 --- /dev/null +++ b/example/config/initializers/permissions_policy.rb @@ -0,0 +1,11 @@ +# Define an application-wide HTTP permissions policy. For further +# information see https://developers.google.com/web/updates/2018/06/feature-policy +# +# Rails.application.config.permissions_policy do |f| +# f.camera :none +# f.gyroscope :none +# f.microphone :none +# f.usb :none +# f.fullscreen :self +# f.payment :self, "https://secure.example.com" +# end diff --git a/example/config/initializers/rspec_api_documentation.rb b/example/config/initializers/rspec_api_documentation.rb new file mode 100644 index 00000000..3963ffe6 --- /dev/null +++ b/example/config/initializers/rspec_api_documentation.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module RspecApiDocumentation + class RackTestClient < ClientBase + def response_body + last_response.body.encode("utf-8") + end + end +end diff --git a/example/config/initializers/wrap_parameters.rb b/example/config/initializers/wrap_parameters.rb index 33725e95..bbfc3961 100644 --- a/example/config/initializers/wrap_parameters.rb +++ b/example/config/initializers/wrap_parameters.rb @@ -5,10 +5,10 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) + wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true +# self.include_root_in_json = true # end diff --git a/example/config/locales/en.yml b/example/config/locales/en.yml index 06539571..cf9b342d 100644 --- a/example/config/locales/en.yml +++ b/example/config/locales/en.yml @@ -16,8 +16,18 @@ # # This would use the information in config/locales/es.yml. # +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# '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/example/config/routes.rb b/example/config/routes.rb index 47affa09..4a2e7a37 100644 --- a/example/config/routes.rb +++ b/example/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do resources :orders - resources :uploads, :only => :create + resources :uploads, only: :create - mount Raddocs::App => "/docs", :anchor => false + mount Raddocs::App => "/docs", anchor: false end diff --git a/example/config/spring.rb b/example/config/spring.rb new file mode 100644 index 00000000..db5bf130 --- /dev/null +++ b/example/config/spring.rb @@ -0,0 +1,6 @@ +Spring.watch( + ".ruby-version", + ".rbenv-vars", + "tmp/restart.txt", + "tmp/caching-dev.txt" +) diff --git a/example/db/schema.rb b/example/db/schema.rb index a3b2ef4b..544685d7 100644 --- a/example/db/schema.rb +++ b/example/db/schema.rb @@ -1,22 +1,21 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140616151047) do +ActiveRecord::Schema.define(version: 2014_06_16_151047) do create_table "orders", force: :cascade do |t| - t.string "name" - t.boolean "paid" - t.string "email" + t.string "name" + t.boolean "paid" + t.string "email" t.datetime "created_at" t.datetime "updated_at" end diff --git a/example/spec/acceptance/orders_spec.rb b/example/spec/acceptance/orders_spec.rb index 4505aabc..cd279dbe 100644 --- a/example/spec/acceptance/orders_spec.rb +++ b/example/spec/acceptance/orders_spec.rb @@ -6,17 +6,17 @@ explanation "Orders are top-level business objects" - let(:order) { Order.create(:name => "Old Name", :paid => true, :email => "email@example.com") } + let(:order) { Order.create(name: "Old Name", paid: true, email: "email@example.com") } get "/orders" do - authentication :apiKey, "API_TOKEN", :name => "AUTH_TOKEN" + authentication :apiKey, "API_TOKEN", name: "AUTH_TOKEN" parameter :page, "Current page of orders", with_example: true let(:page) { 1 } before do 2.times do |i| - Order.create(:name => "Order #{i}", :email => "email#{i}@example.com", :paid => true) + Order.create(name: "Order #{i}", email: "email#{i}@example.com", paid: true) end end @@ -27,7 +27,7 @@ end head "/orders" do - authentication :apiKey, "API_TOKEN", :name => "AUTH_TOKEN" + authentication :apiKey, "API_TOKEN", name: "AUTH_TOKEN" example_request "Getting the headers" do expect(response_headers["Cache-Control"]).to eq("max-age=0, private, must-revalidate") @@ -35,17 +35,17 @@ end post "/orders" do - with_options :scope => :order, :with_example => true do - parameter :name, "Name of order", :required => true - parameter :paid, "If the order has been paid for", :required => true + with_options scope: :order, with_example: true do + parameter :name, "Name of order", required: true + parameter :paid, "If the order has been paid for", required: true parameter :email, "Email of user that placed the order" - parameter :data, "Array of string", :type => :array, :items => {:type => :string} + parameter :data, "Array of string", type: :array, items: {type: :string} end - with_options :scope => :order do - response_field :name, "Name of order", :type => :string - response_field :paid, "If the order has been paid for", :type => :boolean - response_field :email, "Email of user that placed the order", :type => :string + with_options scope: :order do + response_field :name, "Name of order", type: :string + response_field :paid, "If the order has been paid for", type: :boolean + response_field :email, "Email of user that placed the order", type: :string end let(:name) { "Order 1" } @@ -92,7 +92,7 @@ end put "/orders/:id" do - with_options :scope => :order, with_example: true do + with_options scope: :order, with_example: true do parameter :name, "Name of order" parameter :paid, "If the order has been paid for" parameter :email, "Email of user that placed the order" diff --git a/example/spec/acceptance/uploads_spec.rb b/example/spec/acceptance/uploads_spec.rb index b242ca54..258995c8 100644 --- a/example/spec/acceptance/uploads_spec.rb +++ b/example/spec/acceptance/uploads_spec.rb @@ -1,7 +1,7 @@ require 'acceptance_helper' resource "Uploads" do - authentication :basic, :api_key, :description => "Api Key description" + authentication :basic, :api_key, description: "Api Key description" let(:api_key) { "Basic #{Base64.encode64('user:password')}" } diff --git a/example/spec/acceptance_helper.rb b/example/spec/acceptance_helper.rb index 7b4e69f4..f61cabea 100644 --- a/example/spec/acceptance_helper.rb +++ b/example/spec/acceptance_helper.rb @@ -3,7 +3,7 @@ require 'rspec_api_documentation/dsl' RspecApiDocumentation.configure do |config| - config.format = [:open_api, :html] + config.format = [:open_api, :html, :json] config.curl_host = 'http://localhost:3000' config.api_name = "Example App API" config.api_explanation = "API Example Description" diff --git a/example/spec/rails_helper.rb b/example/spec/rails_helper.rb index b98cb0f7..388c4f3e 100644 --- a/example/spec/rails_helper.rb +++ b/example/spec/rails_helper.rb @@ -33,7 +33,7 @@ # You can disable this behaviour by removing the line below, and instead # explicitly tag your specs with their type, e.g.: # - # RSpec.describe UsersController, :type => :controller do + # RSpec.describe UsersController, type: :controller do # # ... # end #