From 9ed7285084cf1f67b0a6e3ca130cf67b74040fc6 Mon Sep 17 00:00:00 2001 From: tomoya Date: Tue, 25 Jul 2017 12:21:29 +0900 Subject: [PATCH 01/41] [add]routes for rails api mode --- config/routes.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index c9f7305..29aef22 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,4 +5,6 @@ get '/' => 'letters#index', :as => :letters get ':id(/:style)' => 'letters#show', :as => :letter get ':id/attachments/:file' => 'letters#attachment' + post 'clear' => 'letters#clear' + post ':id' => 'letters#destroy' end From 734ef652b1e41ccb85c1d2451dbef240617ab330 Mon Sep 17 00:00:00 2001 From: Shigenobu Nishikawa Date: Thu, 25 Mar 2021 15:44:22 +0900 Subject: [PATCH 02/41] explicit letter class --- app/controllers/letter_opener_web/letters_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/letter_opener_web/letters_controller.rb b/app/controllers/letter_opener_web/letters_controller.rb index f5aa7c6..93adc1e 100644 --- a/app/controllers/letter_opener_web/letters_controller.rb +++ b/app/controllers/letter_opener_web/letters_controller.rb @@ -10,7 +10,7 @@ class LettersController < ApplicationController before_action :load_letter, only: %i[show attachment destroy] def index - @letters = Letter.search + @letters = LetterOpenerWeb::Letter.search end def show @@ -31,7 +31,7 @@ def attachment end def clear - Letter.destroy_all + LetterOpenerWeb::Letter.destroy_all redirect_to routes.letters_path end @@ -47,7 +47,7 @@ def check_style end def load_letter - @letter = Letter.find(params[:id]) + @letter = LetterOpenerWeb::Letter.find(params[:id]) head :not_found unless @letter.exists? end From 913c684ff0978ec71835364dae6d56da9cc3d417 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 2 Oct 2021 11:06:34 -0300 Subject: [PATCH 03/41] Begin the work on 2.0.0 --- lib/letter_opener_web/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/letter_opener_web/version.rb b/lib/letter_opener_web/version.rb index ae25a45..a9aeac5 100644 --- a/lib/letter_opener_web/version.rb +++ b/lib/letter_opener_web/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module LetterOpenerWeb - VERSION = '1.4.1' + VERSION = '2.0.0-beta1' end From 4cbba91bdd6154b44d839d75c321633930c53d3e Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 2 Oct 2021 11:07:14 -0300 Subject: [PATCH 04/41] Update docs, changelog and license years --- CHANGELOG.md | 2 ++ LICENSE.txt | 2 +- README.md | 47 ++++++++++++++++++++++++++++------------------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b7ad22..1f8ee65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## [Unreleased](https://github.com/fgrehm/letter_opener_web/compare/v1.4.1...next) + ## [1.4.1](https://github.com/fgrehm/letter_opener_web/compare/v1.4.0...v1.4.1) (Oct 5, 2021) - Ensure letter is within letters base path [#110](https://github.com/fgrehm/letter_opener_web/pull/110) diff --git a/LICENSE.txt b/LICENSE.txt index 6824867..7eef989 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2013-2018 Fabio Rehm +Copyright (c) 2013-2021 Fabio Rehm MIT License diff --git a/README.md b/README.md index 9dc3b13..38de095 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ First add the gem to your development environment and run the `bundle` command t ```ruby group :development do - gem 'letter_opener_web', '~> 1.0' + gem 'letter_opener_web', '~> 2.0' end ``` @@ -33,8 +33,9 @@ And make sure you have [`:letter_opener` delivery method](https://github.com/rya configured for your app. Then visit `http://localhost:3000/letter_opener` after sending an email and have fun. -If you are running the app from a [Vagrant](http://vagrantup.com) machine, you -might want to skip `letter_opener`'s `launchy` calls and avoid messages like these: +If you are running the app from a [Vagrant](http://vagrantup.com) machine or Docker +container, you might want to skip `letter_opener`'s `launchy` calls and avoid messages +like these: ```terminal 12:33:42 web.1 | Failure in opening /vagrant/tmp/letter_opener/1358825621_ba83a22/rich.html @@ -43,19 +44,16 @@ environment variable LAUNCHY_DEBUG=true or the '-d' commandline option and file https://github.com/copiousfreetime/launchy/issues/new ``` -In that case (or if you just want to browse mails using the web interface), you -can set `:letter_opener_web` as your delivery method on your -`config/environments/development.rb`: +In that case (or if you really just want to browse mails using the web interface and +don't care about opening emails automatically), you can set `:letter_opener_web` as +your delivery method on your `config/environments/development.rb`: ```ruby config.action_mailer.delivery_method = :letter_opener_web - -# If not everyone on the team is using vagrant -config.action_mailer.delivery_method = ENV['USER'] == 'vagrant' ? :letter_opener_web : :letter_opener ``` -If you're using `:letter_opener_web` as your delivery method, you can change the location of the letters by adding the -following to an initializer (or in development.rb): +If you're using `:letter_opener_web` as your delivery method, you can change the location of +the letters by adding the following to an initializer (or in development.rb): ```ruby LetterOpenerWeb.configure do |config| @@ -63,11 +61,14 @@ LetterOpenerWeb.configure do |config| end ``` -## Usage on Heroku +## Usage on pre-production environments + +Some people use this gem on staging / pre-production environments to avoid having real emails +being sent out. To set that up you'll need to: -Some people use this gem on staging environments on Heroku and to set that up -is just a matter of moving the gem out of the `development` group and enabling -the route for all environments on your `routes.rb`. +1. Move the gem out of the `development` group in your `Gemfile` +2. Set `config.action_mailer.delivery_method` on the appropriate `config/environments/.rb` +3. Enable the route for the environments on your `routes.rb`. In other words, your `Gemfile` will have: @@ -79,20 +80,28 @@ And your `routes.rb`: ```ruby Your::Application.routes.draw do - mount LetterOpenerWeb::Engine, at: "/letter_opener" + # If you have a dedicated config/environments/staging.rb + mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.staging? + + # If you use RAILS_ENV=production in staging environments, you'll need another + # way to disable it in "real production" + mount LetterOpenerWeb::Engine, at: "/letter_opener" unless ENV["PRODUCTION_FOR_REAL"] end ``` You might also want to have a look at the sources for the [demo](http://letter-opener-web.herokuapp.com) available at https://github.com/fgrehm/letter_opener_web_demo. -**NOTICE: Using this gem on Heroku will only work if your app has just one Dyno and does not send emails from background jobs. For updates on this matter please subscribe to [GH-35](https://github.com/fgrehm/letter_opener_web/issues/35)** +**NOTICE: Using this gem on Heroku will only work if your app has just one Dyno +and does not send emails from background jobs. For updates on this matter please +subscribe to [GH-35](https://github.com/fgrehm/letter_opener_web/issues/35)** ## Acknowledgements Special thanks to [@alexrothenberg](https://github.com/alexrothenberg) for some -ideas on [this pull request](https://github.com/ryanb/letter_opener/pull/12). - +ideas on [this pull request](https://github.com/ryanb/letter_opener/pull/12) and +[@pseudomuto](https://github.com/pseudomuto) for keeping the project alive for a +few years. ## Contributing From 66d7493a0362cb1e394944342db24bbf57c6bb95 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 2 Oct 2021 11:38:20 -0300 Subject: [PATCH 05/41] Modernize project and dummmy app for tests --- .rubocop.yml | 2 +- letter_opener_web.gemspec | 14 ++-- lib/letter_opener_web.rb | 1 + .../letters_controller_spec.rb | 2 +- spec/dummy/Rakefile | 4 +- spec/dummy/app/assets/config/manifest.js | 2 - .../app/assets/stylesheets/application.css | 16 ----- .../app/channels/application_cable/channel.rb | 4 ++ .../channels/application_cable/connection.rb | 4 ++ .../app/controllers/application_controller.rb | 3 - spec/dummy/app/controllers/home_controller.rb | 10 --- spec/dummy/app/helpers/application_helper.rb | 2 - .../packs}/application.js | 2 + spec/dummy/app/jobs/application_job.rb | 7 ++ spec/dummy/app/mailers/application_mailer.rb | 2 - spec/dummy/app/mailers/contact_mailer.rb | 14 ---- spec/dummy/app/models/application_record.rb | 3 + spec/dummy/app/models/concerns/.keep | 0 .../views/contact_mailer/new_message.html.erb | 21 ------ .../views/contact_mailer/new_message.text.erb | 3 - spec/dummy/app/views/home/index.html.erb | 50 -------------- .../app/views/layouts/application.html.erb | 11 ++- spec/dummy/bin/bundle | 5 -- spec/dummy/bin/rails | 6 +- spec/dummy/bin/rake | 6 +- spec/dummy/bin/setup | 17 ++--- spec/dummy/bin/update | 31 --------- spec/dummy/config.ru | 5 +- spec/dummy/config/application.rb | 40 +++++++---- spec/dummy/config/boot.rb | 4 +- spec/dummy/config/environment.rb | 4 +- spec/dummy/config/environments/development.rb | 50 ++++++++++++-- spec/dummy/config/environments/production.rb | 67 ++++++++++++++----- spec/dummy/config/environments/test.rb | 36 ++++++++-- .../application_controller_renderer.rb | 11 +-- spec/dummy/config/initializers/assets.rb | 11 ++- .../initializers/backtrace_silencers.rb | 8 +-- .../initializers/content_security_policy.rb | 28 ++++++++ .../config/initializers/cookies_serializer.rb | 2 - .../initializers/filter_parameter_logging.rb | 6 +- spec/dummy/config/initializers/inflections.rb | 1 - spec/dummy/config/initializers/mime_types.rb | 1 - .../initializers/new_framework_defaults.rb | 10 --- .../config/initializers/permissions_policy.rb | 11 +++ .../config/initializers/session_store.rb | 5 -- .../config/initializers/wrap_parameters.rb | 2 - spec/dummy/config/locales/en.yml | 12 +++- spec/dummy/config/puma.rb | 42 +++++------- spec/dummy/config/routes.rb | 7 +- spec/dummy/config/secrets.yml | 22 ------ spec/dummy/config/spring.rb | 8 --- spec/dummy/public/404.html | 12 ++-- spec/dummy/public/422.html | 12 ++-- spec/dummy/public/500.html | 12 ++-- spec/dummy/storage/.keep | 0 spec/letter_opener_web_spec.rb | 4 +- spec/models/letter_opener_web/letter_spec.rb | 2 +- 57 files changed, 307 insertions(+), 370 deletions(-) create mode 100644 spec/dummy/app/channels/application_cable/channel.rb create mode 100644 spec/dummy/app/channels/application_cable/connection.rb delete mode 100644 spec/dummy/app/controllers/home_controller.rb rename spec/dummy/app/{assets/javascripts => javascript/packs}/application.js (93%) create mode 100644 spec/dummy/app/jobs/application_job.rb delete mode 100644 spec/dummy/app/mailers/contact_mailer.rb create mode 100644 spec/dummy/app/models/application_record.rb create mode 100644 spec/dummy/app/models/concerns/.keep delete mode 100644 spec/dummy/app/views/contact_mailer/new_message.html.erb delete mode 100644 spec/dummy/app/views/contact_mailer/new_message.text.erb delete mode 100644 spec/dummy/app/views/home/index.html.erb delete mode 100755 spec/dummy/bin/bundle delete mode 100755 spec/dummy/bin/update create mode 100644 spec/dummy/config/initializers/content_security_policy.rb delete mode 100644 spec/dummy/config/initializers/new_framework_defaults.rb create mode 100644 spec/dummy/config/initializers/permissions_policy.rb delete mode 100644 spec/dummy/config/initializers/session_store.rb delete mode 100644 spec/dummy/config/secrets.yml delete mode 100644 spec/dummy/config/spring.rb create mode 100644 spec/dummy/storage/.keep diff --git a/.rubocop.yml b/.rubocop.yml index df53d75..1940b3e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,6 @@ --- AllCops: - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.7 Exclude: - "spec/dummy/bin/**/*" - "tmp/**/*" diff --git a/letter_opener_web.gemspec b/letter_opener_web.gemspec index b9d442f..c404f4e 100644 --- a/letter_opener_web.gemspec +++ b/letter_opener_web.gemspec @@ -20,12 +20,12 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ['lib'] - gem.add_dependency 'actionmailer', '>= 3.2' - gem.add_dependency 'letter_opener', '~> 1.0' - gem.add_dependency 'railties', '>= 3.2' + gem.add_dependency 'actionmailer', '>= 5.2' + gem.add_dependency 'letter_opener', '~> 1.7' + gem.add_dependency 'railties', '>= 5.2' - gem.add_development_dependency 'rails', '~> 5.0' - gem.add_development_dependency 'rspec-rails', '~> 3.0' - gem.add_development_dependency 'rubocop', '~> 0.79' - gem.add_development_dependency 'shoulda-matchers', '~> 2.5' + gem.add_development_dependency 'rails', '~> 6.1' + gem.add_development_dependency 'rspec-rails', '~> 5.0' + gem.add_development_dependency 'rubocop', '~> 1.22' + gem.add_development_dependency 'shoulda-matchers', '~> 5.0' end diff --git a/lib/letter_opener_web.rb b/lib/letter_opener_web.rb index b9efa30..38e6e59 100644 --- a/lib/letter_opener_web.rb +++ b/lib/letter_opener_web.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'letter_opener_web/version' require 'letter_opener_web/engine' require 'rexml/document' diff --git a/spec/controllers/letter_opener_web/letters_controller_spec.rb b/spec/controllers/letter_opener_web/letters_controller_spec.rb index 553f21e..baca0bc 100644 --- a/spec/controllers/letter_opener_web/letters_controller_spec.rb +++ b/spec/controllers/letter_opener_web/letters_controller_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe LetterOpenerWeb::LettersController do +RSpec.describe LetterOpenerWeb::LettersController do routes { LetterOpenerWeb::Engine.routes } after(:each) { LetterOpenerWeb.reset! } diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile index 488c551..9a5ea73 100644 --- a/spec/dummy/Rakefile +++ b/spec/dummy/Rakefile @@ -1,8 +1,6 @@ -# frozen_string_literal: true - # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative 'config/application' +require_relative "config/application" Rails.application.load_tasks diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js index 4f5fffa..59220aa 100644 --- a/spec/dummy/app/assets/config/manifest.js +++ b/spec/dummy/app/assets/config/manifest.js @@ -1,5 +1,3 @@ - //= link_tree ../images -//= link_directory ../javascripts .js //= link_directory ../stylesheets .css //= link letter_opener_web_manifest.js diff --git a/spec/dummy/app/assets/stylesheets/application.css b/spec/dummy/app/assets/stylesheets/application.css index 618306e..0ebd7fe 100644 --- a/spec/dummy/app/assets/stylesheets/application.css +++ b/spec/dummy/app/assets/stylesheets/application.css @@ -13,19 +13,3 @@ *= require_tree . *= require_self */ - -body { - padding-top: 20px; -} - -.alert { - margin-top: 20px; -} - -h1, .footer { - text-align: center; -} - -.icon-white { - background-image: url(<%=asset_path "letter_opener_web/glyphicons-halflings-white.png"%>); -} diff --git a/spec/dummy/app/channels/application_cable/channel.rb b/spec/dummy/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/spec/dummy/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/spec/dummy/app/channels/application_cable/connection.rb b/spec/dummy/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..0ff5442 --- /dev/null +++ b/spec/dummy/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb index 280cc28..09705d1 100644 --- a/spec/dummy/app/controllers/application_controller.rb +++ b/spec/dummy/app/controllers/application_controller.rb @@ -1,5 +1,2 @@ -# frozen_string_literal: true - class ApplicationController < ActionController::Base - protect_from_forgery with: :exception end diff --git a/spec/dummy/app/controllers/home_controller.rb b/spec/dummy/app/controllers/home_controller.rb deleted file mode 100644 index 68c072c..0000000 --- a/spec/dummy/app/controllers/home_controller.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -class HomeController < ApplicationController - def index; end - - def create - ContactMailer.new_message(params[:email], params[:message], params[:attachment]).deliver - redirect_to '/', notice: "Email sent successfully, please check letter_opener_web's inbox." - end -end diff --git a/spec/dummy/app/helpers/application_helper.rb b/spec/dummy/app/helpers/application_helper.rb index 15b06f0..de6be79 100644 --- a/spec/dummy/app/helpers/application_helper.rb +++ b/spec/dummy/app/helpers/application_helper.rb @@ -1,4 +1,2 @@ -# frozen_string_literal: true - module ApplicationHelper end diff --git a/spec/dummy/app/assets/javascripts/application.js b/spec/dummy/app/javascript/packs/application.js similarity index 93% rename from spec/dummy/app/assets/javascripts/application.js rename to spec/dummy/app/javascript/packs/application.js index e54c646..67ce467 100644 --- a/spec/dummy/app/assets/javascripts/application.js +++ b/spec/dummy/app/javascript/packs/application.js @@ -10,4 +10,6 @@ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // +//= require rails-ujs +//= require activestorage //= require_tree . diff --git a/spec/dummy/app/jobs/application_job.rb b/spec/dummy/app/jobs/application_job.rb new file mode 100644 index 0000000..d394c3d --- /dev/null +++ b/spec/dummy/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/spec/dummy/app/mailers/application_mailer.rb b/spec/dummy/app/mailers/application_mailer.rb index d84cb6e..286b223 100644 --- a/spec/dummy/app/mailers/application_mailer.rb +++ b/spec/dummy/app/mailers/application_mailer.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/spec/dummy/app/mailers/contact_mailer.rb b/spec/dummy/app/mailers/contact_mailer.rb deleted file mode 100644 index 3aaa884..0000000 --- a/spec/dummy/app/mailers/contact_mailer.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -class ContactMailer < ApplicationMailer - default to: 'admin@letter_opener_web.org', from: 'no-reply@letter_opener_web.org' - - def new_message(from, message, attachment) - @from = from - @message = message - - attachments[attachment.original_filename] = attachment.tempfile.read if attachment.present? - - mail(subject: 'Testing letter_opener_web') - end -end diff --git a/spec/dummy/app/models/application_record.rb b/spec/dummy/app/models/application_record.rb new file mode 100644 index 0000000..10a4cba --- /dev/null +++ b/spec/dummy/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/spec/dummy/app/models/concerns/.keep b/spec/dummy/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/views/contact_mailer/new_message.html.erb b/spec/dummy/app/views/contact_mailer/new_message.html.erb deleted file mode 100644 index 9b2bce5..0000000 --- a/spec/dummy/app/views/contact_mailer/new_message.html.erb +++ /dev/null @@ -1,21 +0,0 @@ - - -

New message!

- -

- - <%= @from %> -

- -

- -

- -
- <%= simple_format @message %> -
diff --git a/spec/dummy/app/views/contact_mailer/new_message.text.erb b/spec/dummy/app/views/contact_mailer/new_message.text.erb deleted file mode 100644 index d33a779..0000000 --- a/spec/dummy/app/views/contact_mailer/new_message.text.erb +++ /dev/null @@ -1,3 +0,0 @@ -# New message from: <%= @from %> - -<%= @message %> diff --git a/spec/dummy/app/views/home/index.html.erb b/spec/dummy/app/views/home/index.html.erb deleted file mode 100644 index 3239c30..0000000 --- a/spec/dummy/app/views/home/index.html.erb +++ /dev/null @@ -1,50 +0,0 @@ -

letter_opener_web Demo

- -
-
- -
- <%= form_tag root_path, multipart: true do %> - Contact form -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
- -
-
-
- <% end %> - - -
- - <% if flash[:notice].present? %> -
- <%= flash[:notice] %> -
- <% end %> -
-
diff --git a/spec/dummy/app/views/layouts/application.html.erb b/spec/dummy/app/views/layouts/application.html.erb index 7ccee89..b74860f 100644 --- a/spec/dummy/app/views/layouts/application.html.erb +++ b/spec/dummy/app/views/layouts/application.html.erb @@ -2,17 +2,14 @@ Dummy + <%= csrf_meta_tags %> + <%= csp_meta_tag %> - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= stylesheet_link_tag '//maxcdn.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css' %> + <%= stylesheet_link_tag 'application', media: 'all' %> -
- <%= yield %> -
- - <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= yield %> diff --git a/spec/dummy/bin/bundle b/spec/dummy/bin/bundle deleted file mode 100755 index 58115ec..0000000 --- a/spec/dummy/bin/bundle +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -load Gem.bin_path('bundler', 'bundle') diff --git a/spec/dummy/bin/rails b/spec/dummy/bin/rails index a31728a..6fb4e40 100755 --- a/spec/dummy/bin/rails +++ b/spec/dummy/bin/rails @@ -1,6 +1,4 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +require_relative "../config/boot" +require "rails/commands" diff --git a/spec/dummy/bin/rake b/spec/dummy/bin/rake index c199955..4fbf10b 100755 --- a/spec/dummy/bin/rake +++ b/spec/dummy/bin/rake @@ -1,6 +1,4 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/spec/dummy/bin/setup b/spec/dummy/bin/setup index 629e358..5792302 100755 --- a/spec/dummy/bin/setup +++ b/spec/dummy/bin/setup @@ -1,19 +1,16 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -require 'pathname' -require 'fileutils' -include FileUtils +require "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 ==") 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 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 ==' @@ -22,11 +19,11 @@ chdir APP_ROOT do # 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/spec/dummy/bin/update b/spec/dummy/bin/update deleted file mode 100755 index fdac831..0000000 --- a/spec/dummy/bin/update +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -require 'pathname' -require 'fileutils' -include FileUtils - -# path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) - -def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") -end - -chdir APP_ROOT do - # This script is a way to update your development environment automatically. - # Add necessary update steps to this file. - - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') - - puts "\n== Updating database ==" - system! 'bin/rails db:migrate' - - 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/spec/dummy/config.ru b/spec/dummy/config.ru index 842bccc..4a3c09a 100644 --- a/spec/dummy/config.ru +++ b/spec/dummy/config.ru @@ -1,7 +1,6 @@ -# frozen_string_literal: true - # This file is used by Rack-based servers to start the application. -require_relative 'config/environment' +require_relative "config/environment" run Rails.application +Rails.application.load_server diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 2ffb3d8..b5eacc3 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -1,23 +1,35 @@ -# frozen_string_literal: true +require_relative "boot" -require_relative 'boot' - -require 'active_model/railtie' -require 'action_controller/railtie' -require 'action_mailer/railtie' -require 'action_view/railtie' -require 'sprockets/railtie' -require 'rails/test_unit/railtie' +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" +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -require 'letter_opener_web' +require "letter_opener_web" module Dummy class Application < Rails::Application - # 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. + config.load_defaults Rails::VERSION::STRING.to_f - config.action_mailer.delivery_method = :letter_opener_web + # 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/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb index 6d2cba0..91e5081 100644 --- a/spec/dummy/config/boot.rb +++ b/spec/dummy/config/boot.rb @@ -1,7 +1,5 @@ -# frozen_string_literal: true - # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__) diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb index d5abe55..cac5315 100644 --- a/spec/dummy/config/environment.rb +++ b/spec/dummy/config/environment.rb @@ -1,7 +1,5 @@ -# frozen_string_literal: true - # Load the Rails application. -require_relative 'application' +require_relative "application" # Initialize the Rails application. Rails.application.initialize! diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index b5751dc..507948e 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -1,10 +1,10 @@ -# frozen_string_literal: true +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 @@ -14,15 +14,45 @@ # Show full error reports. config.consider_all_requests_local = true - config.action_controller.perform_caching = false - 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 + + # Store uploaded files on the local file system (see config/storage.yml for options). + # config.active_storage.service = :local # 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. @@ -31,10 +61,16 @@ # Suppress logger output for asset requests. config.assets.quiet = true - # Raises error for missing translations - # config.action_view.raise_on_missing_translations = 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/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index cd801ae..cb4ca21 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: true +require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -16,27 +16,31 @@ 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 + # 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 + # 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 - # `config.assets.precompile` and `config.assets.version` have 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' + # config.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 - # Mount Action Cable outside main process or domain + # Store uploaded files on the local file system (see config/storage.yml for options). + # config.active_storage.service = :local + + # 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.*/ ] @@ -44,19 +48,20 @@ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug + # 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 = [:request_id] + config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Use a real queuing backend for Active Job (and separate queues per environment) + # 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 = "dummy_#{Rails.env}" + # config.active_job.queue_name_prefix = "dummy_production" + config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. @@ -70,16 +75,46 @@ # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify + # 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' + # require "syslog/logger" # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV['RAILS_LOG_TO_STDOUT'].present? + if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + 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/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index 451f7cc..f706432 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -1,12 +1,13 @@ -# frozen_string_literal: true +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 # Do not eager load code on boot. This avoids loading your whole application @@ -14,9 +15,16 @@ # preloads Rails for running tests, you may have to set it to true. config.eager_load = false + # 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 @@ -24,6 +32,11 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false + # Store uploaded files on the local file system in a temporary directory. + # config.active_storage.service = :test + + 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. @@ -32,6 +45,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/spec/dummy/config/initializers/application_controller_renderer.rb b/spec/dummy/config/initializers/application_controller_renderer.rb index 315ac48..89d2efa 100644 --- a/spec/dummy/config/initializers/application_controller_renderer.rb +++ b/spec/dummy/config/initializers/application_controller_renderer.rb @@ -1,7 +1,8 @@ -# frozen_string_literal: true # 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 diff --git a/spec/dummy/config/initializers/assets.rb b/spec/dummy/config/initializers/assets.rb index 678efe9..9c7a620 100644 --- a/spec/dummy/config/initializers/assets.rb +++ b/spec/dummy/config/initializers/assets.rb @@ -1,13 +1,12 @@ -# frozen_string_literal: true - # 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' +# 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 # 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 ) diff --git a/spec/dummy/config/initializers/backtrace_silencers.rb b/spec/dummy/config/initializers/backtrace_silencers.rb index d0f0d3b..33699c3 100644 --- a/spec/dummy/config/initializers/backtrace_silencers.rb +++ b/spec/dummy/config/initializers/backtrace_silencers.rb @@ -1,8 +1,8 @@ -# frozen_string_literal: true # 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/spec/dummy/config/initializers/content_security_policy.rb b/spec/dummy/config/initializers/content_security_policy.rb new file mode 100644 index 0000000..41c4301 --- /dev/null +++ b/spec/dummy/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/spec/dummy/config/initializers/cookies_serializer.rb b/spec/dummy/config/initializers/cookies_serializer.rb index ee8dff9..5a6a32d 100644 --- a/spec/dummy/config/initializers/cookies_serializer.rb +++ b/spec/dummy/config/initializers/cookies_serializer.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/spec/dummy/config/initializers/filter_parameter_logging.rb b/spec/dummy/config/initializers/filter_parameter_logging.rb index 7a4f47b..4b34a03 100644 --- a/spec/dummy/config/initializers/filter_parameter_logging.rb +++ b/spec/dummy/config/initializers/filter_parameter_logging.rb @@ -1,6 +1,6 @@ -# frozen_string_literal: true - # 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/spec/dummy/config/initializers/inflections.rb b/spec/dummy/config/initializers/inflections.rb index aa7435f..ac033bf 100644 --- a/spec/dummy/config/initializers/inflections.rb +++ b/spec/dummy/config/initializers/inflections.rb @@ -1,4 +1,3 @@ -# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/spec/dummy/config/initializers/mime_types.rb b/spec/dummy/config/initializers/mime_types.rb index 6e1d16f..dc18996 100644 --- a/spec/dummy/config/initializers/mime_types.rb +++ b/spec/dummy/config/initializers/mime_types.rb @@ -1,4 +1,3 @@ -# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/spec/dummy/config/initializers/new_framework_defaults.rb b/spec/dummy/config/initializers/new_framework_defaults.rb deleted file mode 100644 index 268ca84..0000000 --- a/spec/dummy/config/initializers/new_framework_defaults.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. -# -# This file contains migration options to ease your Rails 5.0 upgrade. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. - -# Configure SSL options to enable HSTS with subdomains. Previous versions had false. -Rails.application.config.ssl_options = { hsts: { subdomains: true } } diff --git a/spec/dummy/config/initializers/permissions_policy.rb b/spec/dummy/config/initializers/permissions_policy.rb new file mode 100644 index 0000000..00f64d7 --- /dev/null +++ b/spec/dummy/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/spec/dummy/config/initializers/session_store.rb b/spec/dummy/config/initializers/session_store.rb deleted file mode 100644 index 969d977..0000000 --- a/spec/dummy/config/initializers/session_store.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. - -Rails.application.config.session_store :cookie_store, key: '_dummy_session' diff --git a/spec/dummy/config/initializers/wrap_parameters.rb b/spec/dummy/config/initializers/wrap_parameters.rb index 2f3c0db..bbfc396 100644 --- a/spec/dummy/config/initializers/wrap_parameters.rb +++ b/spec/dummy/config/initializers/wrap_parameters.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/spec/dummy/config/locales/en.yml b/spec/dummy/config/locales/en.yml index 0653957..cf9b342 100644 --- a/spec/dummy/config/locales/en.yml +++ b/spec/dummy/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/spec/dummy/config/puma.rb b/spec/dummy/config/puma.rb index 03a2824..d9b3e83 100644 --- a/spec/dummy/config/puma.rb +++ b/spec/dummy/config/puma.rb @@ -1,24 +1,31 @@ -# frozen_string_literal: true - # Puma can serve each request in a thread from an internal thread pool. -# The `threads` method setting takes two numbers a minimum and maximum. +# The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum -# and maximum, this matches the default thread size of Active Record. +# and maximum; this matches the default thread size of Active Record. +# +max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count + +# Specifies the `worker_timeout` threshold that Puma will use to wait before +# terminating a worker in development environments. # -threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }.to_i -threads threads_count, threads_count +worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" -# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch('PORT') { 3000 } +port ENV.fetch("PORT") { 3000 } # 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/server.pid" } # Specifies the number of `workers` to boot in clustered mode. -# Workers are forked webserver processes. If using threads and workers together +# Workers are forked web server processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. # Workers do not work on JRuby or Windows (both of which do not support # processes). @@ -28,22 +35,9 @@ # 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! -# 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 `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, 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 diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb index c13cda8..52f12fe 100644 --- a/spec/dummy/config/routes.rb +++ b/spec/dummy/config/routes.rb @@ -1,8 +1,3 @@ -# frozen_string_literal: true - Rails.application.routes.draw do - mount LetterOpenerWeb::Engine => '/letter_opener' - - root to: 'home#index' - post '/', to: 'home#create' + mount LetterOpenerWeb::Engine => "/letter_opener_web" end diff --git a/spec/dummy/config/secrets.yml b/spec/dummy/config/secrets.yml deleted file mode 100644 index 05e3837..0000000 --- a/spec/dummy/config/secrets.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key is used for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! - -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -# You can use `rails secret` to generate a secure secret key. - -# Make sure the secrets in this file are kept private -# if you're sharing your code publicly. - -development: - secret_key_base: a620e35d747d88c5fc8892b46a0fbb32b6b9975b2edcb4aaf1b76a8e46b70cca77d55c55ff1146a14ea9ee91eec9a6a5ebda33745cb5c05a58968d2b318af86b - -test: - secret_key_base: a18afce29fc99e78cd2abf56c7b4bade7bba4da68ca781dbaa3cb53afe9819f6cf0a42667a6d0c9a23bfe34ce070eeaef32f14b67887d25c9333d9371df30ee6 - -# Do not keep production secrets in the repository, -# instead read values from the environment. -production: - secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/spec/dummy/config/spring.rb b/spec/dummy/config/spring.rb deleted file mode 100644 index c5933e4..0000000 --- a/spec/dummy/config/spring.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -%w[ - .ruby-version - .rbenv-vars - tmp/restart.txt - tmp/caching-dev.txt -].each { |path| Spring.watch(path) } diff --git a/spec/dummy/public/404.html b/spec/dummy/public/404.html index b612547..2be3af2 100644 --- a/spec/dummy/public/404.html +++ b/spec/dummy/public/404.html @@ -4,7 +4,7 @@ The page you were looking for doesn't exist (404) - +
diff --git a/spec/dummy/public/422.html b/spec/dummy/public/422.html index a21f82b..c08eac0 100644 --- a/spec/dummy/public/422.html +++ b/spec/dummy/public/422.html @@ -4,7 +4,7 @@ The change you wanted was rejected (422) - +
diff --git a/spec/dummy/public/500.html b/spec/dummy/public/500.html index 061abc5..78a030a 100644 --- a/spec/dummy/public/500.html +++ b/spec/dummy/public/500.html @@ -4,7 +4,7 @@ We're sorry, but something went wrong (500) - +
diff --git a/spec/dummy/storage/.keep b/spec/dummy/storage/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/letter_opener_web_spec.rb b/spec/letter_opener_web_spec.rb index bf87a6d..79f7fce 100644 --- a/spec/letter_opener_web_spec.rb +++ b/spec/letter_opener_web_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'spec_helper' +require 'rails_helper' -describe LetterOpenerWeb do +RSpec.describe LetterOpenerWeb do subject { described_class } after(:each) { described_class.reset! } diff --git a/spec/models/letter_opener_web/letter_spec.rb b/spec/models/letter_opener_web/letter_spec.rb index cbe318d..a505620 100644 --- a/spec/models/letter_opener_web/letter_spec.rb +++ b/spec/models/letter_opener_web/letter_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe LetterOpenerWeb::Letter do +RSpec.describe LetterOpenerWeb::Letter do let(:location) { Pathname.new(__dir__).join('..', '..', 'tmp').cleanpath } def rich_text(mail_id) From a2316717c43cf86f9a21dfd229ba06f6a8f95295 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 2 Oct 2021 11:38:50 -0300 Subject: [PATCH 06/41] Fix tests --- spec/controllers/letter_opener_web/letters_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/controllers/letter_opener_web/letters_controller_spec.rb b/spec/controllers/letter_opener_web/letters_controller_spec.rb index baca0bc..4b868f8 100644 --- a/spec/controllers/letter_opener_web/letters_controller_spec.rb +++ b/spec/controllers/letter_opener_web/letters_controller_spec.rb @@ -19,7 +19,7 @@ it 'returns an HTML 200 response' do expect(response.status).to eq(200) - expect(response.content_type).to eq('text/html') + expect(response.content_type).to eq('text/html; charset=utf-8') end end @@ -38,7 +38,7 @@ it 'renders an HTML 200 response' do expect(response.status).to eq(200) - expect(response.content_type).to eq('text/html') + expect(response.content_type).to eq('text/html; charset=utf-8') end end From ccb5de92fc9779a2d6a476a5f9b3c592c95e5c52 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 2 Oct 2021 11:41:47 -0300 Subject: [PATCH 07/41] Upgrade rubocop and fix offenses --- .rubocop.yml | 12 ----------- .../letters_controller_spec.rb | 2 +- spec/dummy/Rakefile | 4 +++- .../app/channels/application_cable/channel.rb | 2 ++ .../channels/application_cable/connection.rb | 2 ++ .../app/controllers/application_controller.rb | 2 ++ spec/dummy/app/helpers/application_helper.rb | 2 ++ spec/dummy/app/jobs/application_job.rb | 2 ++ spec/dummy/app/mailers/application_mailer.rb | 2 ++ spec/dummy/app/models/application_record.rb | 2 ++ spec/dummy/config.ru | 4 +++- spec/dummy/config/application.rb | 14 +++++++------ spec/dummy/config/boot.rb | 4 +++- spec/dummy/config/environment.rb | 4 +++- spec/dummy/config/environments/development.rb | 4 +++- spec/dummy/config/environments/production.rb | 10 ++++++---- spec/dummy/config/environments/test.rb | 4 +++- .../application_controller_renderer.rb | 1 + spec/dummy/config/initializers/assets.rb | 1 + .../initializers/backtrace_silencers.rb | 4 +++- .../initializers/content_security_policy.rb | 1 + .../config/initializers/cookies_serializer.rb | 2 ++ .../initializers/filter_parameter_logging.rb | 6 ++++-- spec/dummy/config/initializers/inflections.rb | 1 + spec/dummy/config/initializers/mime_types.rb | 1 + .../config/initializers/permissions_policy.rb | 1 + .../config/initializers/wrap_parameters.rb | 2 ++ spec/dummy/config/puma.rb | 14 +++++++------ spec/dummy/config/routes.rb | 4 +++- spec/models/letter_opener_web/letter_spec.rb | 20 +++++++++---------- 30 files changed, 85 insertions(+), 49 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1940b3e..07eacda 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,18 +6,6 @@ AllCops: - "tmp/**/*" - "vendor/**/*" -Layout/HeredocIndentation: - Enabled: false - -Style/Documentation: - Enabled: false - -Style/ClassAndModuleChildren: - EnforcedStyle: nested - -Style/SingleLineBlockParams: - Enabled: false - Metrics/BlockLength: Exclude: - spec/**/*_spec.rb diff --git a/spec/controllers/letter_opener_web/letters_controller_spec.rb b/spec/controllers/letter_opener_web/letters_controller_spec.rb index 4b868f8..ce0c772 100644 --- a/spec/controllers/letter_opener_web/letters_controller_spec.rb +++ b/spec/controllers/letter_opener_web/letters_controller_spec.rb @@ -89,7 +89,7 @@ it 'sends the file as an inline attachment' do allow(controller).to receive(:send_file) { controller.head :ok } - get :attachment, params: { id: id, file: file_name.gsub(/\.\w+/, ''), format: File.extname(file_name)[1..-1] } + get :attachment, params: { id: id, file: file_name.gsub(/\.\w+/, ''), format: File.extname(file_name)[1..] } expect(response.status).to eq(200) expect(controller).to have_received(:send_file) diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile index 9a5ea73..488c551 100644 --- a/spec/dummy/Rakefile +++ b/spec/dummy/Rakefile @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative "config/application" +require_relative 'config/application' Rails.application.load_tasks diff --git a/spec/dummy/app/channels/application_cable/channel.rb b/spec/dummy/app/channels/application_cable/channel.rb index d672697..9aec230 100644 --- a/spec/dummy/app/channels/application_cable/channel.rb +++ b/spec/dummy/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/spec/dummy/app/channels/application_cable/connection.rb b/spec/dummy/app/channels/application_cable/connection.rb index 0ff5442..8d6c2a1 100644 --- a/spec/dummy/app/channels/application_cable/connection.rb +++ b/spec/dummy/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb index 09705d1..7944f9f 100644 --- a/spec/dummy/app/controllers/application_controller.rb +++ b/spec/dummy/app/controllers/application_controller.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base end diff --git a/spec/dummy/app/helpers/application_helper.rb b/spec/dummy/app/helpers/application_helper.rb index de6be79..15b06f0 100644 --- a/spec/dummy/app/helpers/application_helper.rb +++ b/spec/dummy/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/spec/dummy/app/jobs/application_job.rb b/spec/dummy/app/jobs/application_job.rb index d394c3d..bef3959 100644 --- a/spec/dummy/app/jobs/application_job.rb +++ b/spec/dummy/app/jobs/application_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked diff --git a/spec/dummy/app/mailers/application_mailer.rb b/spec/dummy/app/mailers/application_mailer.rb index 286b223..d84cb6e 100644 --- a/spec/dummy/app/mailers/application_mailer.rb +++ b/spec/dummy/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/spec/dummy/app/models/application_record.rb b/spec/dummy/app/models/application_record.rb index 10a4cba..71fbba5 100644 --- a/spec/dummy/app/models/application_record.rb +++ b/spec/dummy/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru index 4a3c09a..6dc8321 100644 --- a/spec/dummy/config.ru +++ b/spec/dummy/config.ru @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. -require_relative "config/environment" +require_relative 'config/environment' run Rails.application Rails.application.load_server diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index b5eacc3..89afc85 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -1,16 +1,18 @@ -require_relative "boot" +# frozen_string_literal: true -require "rails" +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_controller/railtie' +require 'action_mailer/railtie' # require "action_mailbox/engine" # require "action_text/engine" -require "action_view/railtie" +require 'action_view/railtie' # require "action_cable/engine" # require "sprockets/railtie" # require "rails/test_unit/railtie" @@ -18,7 +20,7 @@ # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -require "letter_opener_web" +require 'letter_opener_web' module Dummy class Application < Rails::Application diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb index 91e5081..6d2cba0 100644 --- a/spec/dummy/config/boot.rb +++ b/spec/dummy/config/boot.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) -require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__) diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb index cac5315..d5abe55 100644 --- a/spec/dummy/config/environment.rb +++ b/spec/dummy/config/environment.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Load the Rails application. -require_relative "application" +require_relative 'application' # Initialize the Rails application. Rails.application.initialize! diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index 507948e..80fdae8 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -1,4 +1,6 @@ -require "active_support/core_ext/integer/time" +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index cb4ca21..c6ef419 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -1,4 +1,6 @@ -require "active_support/core_ext/integer/time" +# frozen_string_literal: true + +require 'active_support/core_ext/integer/time' Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -53,7 +55,7 @@ config.log_level = :info # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -88,8 +90,8 @@ # 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) + if ENV['RAILS_LOG_TO_STDOUT'].present? + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index f706432..3187519 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -1,4 +1,6 @@ -require "active_support/core_ext/integer/time" +# frozen_string_literal: true + +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 diff --git a/spec/dummy/config/initializers/application_controller_renderer.rb b/spec/dummy/config/initializers/application_controller_renderer.rb index 89d2efa..f4556db 100644 --- a/spec/dummy/config/initializers/application_controller_renderer.rb +++ b/spec/dummy/config/initializers/application_controller_renderer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # ActiveSupport::Reloader.to_prepare do diff --git a/spec/dummy/config/initializers/assets.rb b/spec/dummy/config/initializers/assets.rb index 9c7a620..6f260d5 100644 --- a/spec/dummy/config/initializers/assets.rb +++ b/spec/dummy/config/initializers/assets.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # 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. diff --git a/spec/dummy/config/initializers/backtrace_silencers.rb b/spec/dummy/config/initializers/backtrace_silencers.rb index 33699c3..d43cc1d 100644 --- a/spec/dummy/config/initializers/backtrace_silencers.rb +++ b/spec/dummy/config/initializers/backtrace_silencers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # 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. @@ -5,4 +7,4 @@ # 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"] +Rails.backtrace_cleaner.remove_silencers! if ENV['BACKTRACE'] diff --git a/spec/dummy/config/initializers/content_security_policy.rb b/spec/dummy/config/initializers/content_security_policy.rb index 41c4301..98230c9 100644 --- a/spec/dummy/config/initializers/content_security_policy.rb +++ b/spec/dummy/config/initializers/content_security_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Define an application-wide content security policy diff --git a/spec/dummy/config/initializers/cookies_serializer.rb b/spec/dummy/config/initializers/cookies_serializer.rb index 5a6a32d..ee8dff9 100644 --- a/spec/dummy/config/initializers/cookies_serializer.rb +++ b/spec/dummy/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/spec/dummy/config/initializers/filter_parameter_logging.rb b/spec/dummy/config/initializers/filter_parameter_logging.rb index 4b34a03..3babc73 100644 --- a/spec/dummy/config/initializers/filter_parameter_logging.rb +++ b/spec/dummy/config/initializers/filter_parameter_logging.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # 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 += [ - :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +Rails.application.config.filter_parameters += %i[ + passw secret token _key crypt salt certificate otp ssn ] diff --git a/spec/dummy/config/initializers/inflections.rb b/spec/dummy/config/initializers/inflections.rb index ac033bf..aa7435f 100644 --- a/spec/dummy/config/initializers/inflections.rb +++ b/spec/dummy/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/spec/dummy/config/initializers/mime_types.rb b/spec/dummy/config/initializers/mime_types.rb index dc18996..6e1d16f 100644 --- a/spec/dummy/config/initializers/mime_types.rb +++ b/spec/dummy/config/initializers/mime_types.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/spec/dummy/config/initializers/permissions_policy.rb b/spec/dummy/config/initializers/permissions_policy.rb index 00f64d7..50bcf4e 100644 --- a/spec/dummy/config/initializers/permissions_policy.rb +++ b/spec/dummy/config/initializers/permissions_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Define an application-wide HTTP permissions policy. For further # information see https://developers.google.com/web/updates/2018/06/feature-policy # diff --git a/spec/dummy/config/initializers/wrap_parameters.rb b/spec/dummy/config/initializers/wrap_parameters.rb index bbfc396..2f3c0db 100644 --- a/spec/dummy/config/initializers/wrap_parameters.rb +++ b/spec/dummy/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/spec/dummy/config/puma.rb b/spec/dummy/config/puma.rb index d9b3e83..8ae6a78 100644 --- a/spec/dummy/config/puma.rb +++ b/spec/dummy/config/puma.rb @@ -1,28 +1,30 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) +min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `worker_timeout` threshold that Puma will use to wait before # terminating a worker in development environments. # -worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" +worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development' # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT', 3000) # 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/server.pid" } +pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid') # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb index 52f12fe..a214ddb 100644 --- a/spec/dummy/config/routes.rb +++ b/spec/dummy/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do - mount LetterOpenerWeb::Engine => "/letter_opener_web" + mount LetterOpenerWeb::Engine => '/letter_opener_web' end diff --git a/spec/models/letter_opener_web/letter_spec.rb b/spec/models/letter_opener_web/letter_spec.rb index a505620..6a4f6a4 100644 --- a/spec/models/letter_opener_web/letter_spec.rb +++ b/spec/models/letter_opener_web/letter_spec.rb @@ -4,16 +4,16 @@ let(:location) { Pathname.new(__dir__).join('..', '..', 'tmp').cleanpath } def rich_text(mail_id) - <<-MAIL -Rich text for #{mail_id} - - - - Link text - -Bar - -
inside address
+ <<~MAIL + Rich text for #{mail_id} + + + + Link text + + Bar + +
inside address
MAIL end From 6b02f8ab72831b709f1fed8a4a5feb9692d4ad65 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 2 Oct 2021 11:43:23 -0300 Subject: [PATCH 08/41] Moar rubocop stuff --- .rubocop.yml | 2 ++ .rubocop_todo.yml | 19 +++++++++++++++++++ letter_opener_web.gemspec | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 07eacda..9722530 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,6 @@ --- +inherit_from: .rubocop_todo.yml + AllCops: TargetRubyVersion: 2.7 Exclude: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..856ab10 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,19 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2021-10-02 14:42:36 UTC using RuboCop version 1.22.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 5 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'app/controllers/letter_opener_web/letters_controller.rb' + - 'app/models/letter_opener_web/letter.rb' + - 'lib/letter_opener_web.rb' + - 'lib/letter_opener_web/delivery_method.rb' + - 'lib/letter_opener_web/engine.rb' diff --git a/letter_opener_web.gemspec b/letter_opener_web.gemspec index c404f4e..0d9594e 100644 --- a/letter_opener_web.gemspec +++ b/letter_opener_web.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |gem| gem.summary = gem.description gem.homepage = 'https://github.com/fgrehm/letter_opener_web' gem.license = 'MIT' - gem.required_ruby_version = '>= 2.5' + gem.required_ruby_version = '>= 2.7' gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) gem.executables = gem.files.grep(%r{^exe/}).map { |f| File.basename(f) } From 709b6fd83b58fd59ecae18b3a3214b259025ef35 Mon Sep 17 00:00:00 2001 From: Ryunosuke Sato Date: Fri, 1 Jan 2021 13:58:11 +0900 Subject: [PATCH 09/41] Add rexml gem into dependency It has been removed from default gems since Ruby 3.0. Ref: https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/ To use it via bundler, we should specify it as dependency. --- letter_opener_web.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/letter_opener_web.gemspec b/letter_opener_web.gemspec index 0d9594e..9101b50 100644 --- a/letter_opener_web.gemspec +++ b/letter_opener_web.gemspec @@ -23,6 +23,7 @@ Gem::Specification.new do |gem| gem.add_dependency 'actionmailer', '>= 5.2' gem.add_dependency 'letter_opener', '~> 1.7' gem.add_dependency 'railties', '>= 5.2' + gem.add_dependency 'rexml' gem.add_development_dependency 'rails', '~> 6.1' gem.add_development_dependency 'rspec-rails', '~> 5.0' From a3596bdc99498b177874ea073db419b4569111a9 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 2 Oct 2021 11:48:38 -0300 Subject: [PATCH 10/41] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f8ee65..f1e761a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased](https://github.com/fgrehm/letter_opener_web/compare/v1.4.1...next) +#### BUGFIXES + + - Add rexml gem into dependency for Ruby 3.0 [#160](https://github.com/fgrehm/letter_opener_web/pull/106) + ## [1.4.1](https://github.com/fgrehm/letter_opener_web/compare/v1.4.0...v1.4.1) (Oct 5, 2021) - Ensure letter is within letters base path [#110](https://github.com/fgrehm/letter_opener_web/pull/110) From 55f8b57ff145a0b1897651ece5f3b93d131b1968 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Tue, 5 Oct 2021 22:17:12 -0300 Subject: [PATCH 11/41] Major UI revamp, including bootstrap upgrade and better folder structure / vendoring for assets --- app/models/letter_opener_web/letter.rb | 23 +- .../letter_opener_web/_javascripts.html.erb | 583 +----------------- .../letter_opener_web/_styles.html.erb | 66 +- .../letter_opener_web/js/_favcount.html.erb | 104 ++++ .../letter_opener_web/js/_jquery.html.erb | 556 +++++++++++++++++ .../letter_opener_web/letters.html.erb | 7 +- .../styles/_bootstrap.html.erb | 9 + .../letter_opener_web/styles/_icon.html.erb | 2 + .../styles/_letters.html.erb | 79 +++ .../letter_opener_web/letters/_item.html.erb | 5 + .../letter_opener_web/letters/index.html.erb | 55 +- 11 files changed, 819 insertions(+), 670 deletions(-) create mode 100644 app/views/layouts/letter_opener_web/js/_favcount.html.erb create mode 100644 app/views/layouts/letter_opener_web/js/_jquery.html.erb create mode 100644 app/views/layouts/letter_opener_web/styles/_bootstrap.html.erb create mode 100644 app/views/layouts/letter_opener_web/styles/_icon.html.erb create mode 100644 app/views/layouts/letter_opener_web/styles/_letters.html.erb create mode 100644 app/views/letter_opener_web/letters/_item.html.erb diff --git a/app/models/letter_opener_web/letter.rb b/app/models/letter_opener_web/letter.rb index 3072441..1cd49a0 100644 --- a/app/models/letter_opener_web/letter.rb +++ b/app/models/letter_opener_web/letter.rb @@ -33,6 +33,18 @@ def initialize(params) @sent_at = params[:sent_at] end + def headers + html = read_file(:plain) if style_exists?('plain') + html ||= read_file(:rich) + + # NOTE: This is ugly, we should look into using nokogiri and making that a + # dependency of this gem + match_data = html.match(%r{\s*]+id="container">\s*]+id="message_headers">\s*(
.+
)}m) + return remove_attachments_link(match_data[1]).html_safe if match_data[1].present? + + 'UNABLE TO PARSE HEADERS' + end + def plain_text @plain_text ||= adjust_link_targets(read_file(:plain)) end @@ -67,6 +79,15 @@ def valid? private + def remove_attachments_link(headers) + xml = REXML::Document.new(headers) + if xml.root.elements.size == 10 + xml.delete_element('//dd[last()]') + xml.delete_element('//dt[last()]') + end + xml.to_s + end + def base_dir LetterOpenerWeb.config.letters_location.join(id).cleanpath end @@ -88,7 +109,7 @@ def base_dir_within_letters_location? end def adjust_link_targets(contents) - # We cannot feed the whole file to an XML parser as some mails are + # We cannot feed the whole file to a XML parser as some mails are # "complete" (as in they have the whole structure) and letter_opener # prepends some information about the mail being sent, making REXML # complain about it diff --git a/app/views/layouts/letter_opener_web/_javascripts.html.erb b/app/views/layouts/letter_opener_web/_javascripts.html.erb index bcf9eeb..31d0a22 100644 --- a/app/views/layouts/letter_opener_web/_javascripts.html.erb +++ b/app/views/layouts/letter_opener_web/_javascripts.html.erb @@ -1,564 +1,31 @@ - diff --git a/app/views/layouts/letter_opener_web/_styles.html.erb b/app/views/layouts/letter_opener_web/_styles.html.erb index b055664..0ae8458 100644 --- a/app/views/layouts/letter_opener_web/_styles.html.erb +++ b/app/views/layouts/letter_opener_web/_styles.html.erb @@ -1,63 +1,3 @@ - \ No newline at end of file +<%= render "layouts/letter_opener_web/styles/icon" %> +<%= render "layouts/letter_opener_web/styles/bootstrap" %> +<%= render "layouts/letter_opener_web/styles/letters" %> diff --git a/app/views/layouts/letter_opener_web/js/_favcount.html.erb b/app/views/layouts/letter_opener_web/js/_favcount.html.erb new file mode 100644 index 0000000..c9063af --- /dev/null +++ b/app/views/layouts/letter_opener_web/js/_favcount.html.erb @@ -0,0 +1,104 @@ + diff --git a/app/views/layouts/letter_opener_web/js/_jquery.html.erb b/app/views/layouts/letter_opener_web/js/_jquery.html.erb new file mode 100644 index 0000000..3ab1d10 --- /dev/null +++ b/app/views/layouts/letter_opener_web/js/_jquery.html.erb @@ -0,0 +1,556 @@ + diff --git a/app/views/layouts/letter_opener_web/letters.html.erb b/app/views/layouts/letter_opener_web/letters.html.erb index d49862b..7bde6ef 100644 --- a/app/views/layouts/letter_opener_web/letters.html.erb +++ b/app/views/layouts/letter_opener_web/letters.html.erb @@ -3,12 +3,13 @@ LetterOpenerWeb <%= render "layouts/letter_opener_web/styles" %> - <%= render "layouts/letter_opener_web/javascripts" %> - + <% if respond_to? :csp_meta_tag %> + <%= csp_meta_tag %> + <% end %> <%= csrf_meta_tags %> <%= yield %> + <%= render "layouts/letter_opener_web/javascripts" %> diff --git a/app/views/layouts/letter_opener_web/styles/_bootstrap.html.erb b/app/views/layouts/letter_opener_web/styles/_bootstrap.html.erb new file mode 100644 index 0000000..ac881a2 --- /dev/null +++ b/app/views/layouts/letter_opener_web/styles/_bootstrap.html.erb @@ -0,0 +1,9 @@ + diff --git a/app/views/layouts/letter_opener_web/styles/_icon.html.erb b/app/views/layouts/letter_opener_web/styles/_icon.html.erb new file mode 100644 index 0000000..c2141c1 --- /dev/null +++ b/app/views/layouts/letter_opener_web/styles/_icon.html.erb @@ -0,0 +1,2 @@ + diff --git a/app/views/layouts/letter_opener_web/styles/_letters.html.erb b/app/views/layouts/letter_opener_web/styles/_letters.html.erb new file mode 100644 index 0000000..cd8c706 --- /dev/null +++ b/app/views/layouts/letter_opener_web/styles/_letters.html.erb @@ -0,0 +1,79 @@ + diff --git a/app/views/letter_opener_web/letters/_item.html.erb b/app/views/letter_opener_web/letters/_item.html.erb new file mode 100644 index 0000000..6e5bc5a --- /dev/null +++ b/app/views/letter_opener_web/letters/_item.html.erb @@ -0,0 +1,5 @@ +<% classes = %w(list-group-item list-group-action message-headers) %> +<% classes << 'active' if active %> +<%= link_to(letter_path(letter, style: letter.default_style), class: classes, target: 'mail') do %> + <%= letter.headers %> +<% end %> diff --git a/app/views/letter_opener_web/letters/index.html.erb b/app/views/letter_opener_web/letters/index.html.erb index 535e51f..6cda0d0 100644 --- a/app/views/letter_opener_web/letters/index.html.erb +++ b/app/views/letter_opener_web/letters/index.html.erb @@ -1,58 +1,23 @@

Letters - - <%= link_to letters_path, class: 'btn refresh' do %> - + + <%= link_to letters_path, class: 'btn btn-primary refresh' do %> Refresh <% end %> <%= link_to clear_letters_path, method: 'delete', data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' do %> - Clear <% end %>

- - - - - - - - - - <% if first_letter = @letters.shift %> - - - - - - <% end %> - <% @letters.each do |letter| %> - - - - - - <% end %> - -
IDSent atAction
- <%= link_to(first_letter.id, letter_path(first_letter, style: first_letter.default_style), target: 'mail') %> - <%= first_letter.sent_at %> - <%= link_to delete_letter_path(first_letter), method: 'delete', data: { confirm: 'Are you sure you want to delete this email?' } do %> - - - - <% end %> -
- <%= link_to(letter.id, letter_path(letter, style: letter.default_style), target: 'mail') %> - <%= letter.sent_at %> - <%= link_to delete_letter_path(letter), :method => 'delete', data: { confirm: 'Are you sure you want to delete this email?' } do %> - - - - <% end %> -
+ <% if first_letter = @letters.shift %> +
+
+ <%= render partial: "item", locals: { letter: first_letter, active: true } %> + <%= render partial: "item", collection: @letters, as: :letter, locals: { active: false } %> +
+
+ <% end %>
From 57433f9845301cd6734237ddd2fb780c1b320741 Mon Sep 17 00:00:00 2001 From: Dominic Date: Wed, 13 Oct 2021 16:17:17 -0400 Subject: [PATCH 12/41] Add Rails' built-in CSRF protection --- app/controllers/letter_opener_web/application_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/letter_opener_web/application_controller.rb b/app/controllers/letter_opener_web/application_controller.rb index 96a79b5..a15267f 100644 --- a/app/controllers/letter_opener_web/application_controller.rb +++ b/app/controllers/letter_opener_web/application_controller.rb @@ -2,5 +2,6 @@ module LetterOpenerWeb class ApplicationController < ActionController::Base + protect_from_forgery with: :exception end end From c535f3595a45b2d2367cced6bbc4d76c89743d58 Mon Sep 17 00:00:00 2001 From: Dominic Date: Wed, 13 Oct 2021 16:21:28 -0400 Subject: [PATCH 13/41] Add Rails' CSP nonce to the script tag --- app/views/layouts/letter_opener_web/_javascripts.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/letter_opener_web/_javascripts.html.erb b/app/views/layouts/letter_opener_web/_javascripts.html.erb index bcf9eeb..4190df6 100644 --- a/app/views/layouts/letter_opener_web/_javascripts.html.erb +++ b/app/views/layouts/letter_opener_web/_javascripts.html.erb @@ -1,4 +1,4 @@ -