From 07c118748ef9faa4c4b08e13e62128d4a00d0762 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Fri, 10 Nov 2023 15:50:16 -0600 Subject: [PATCH] Rails 7 Upgrade (#1178) # What it does Upgrades the application to Rails 7. # Why it is important Getting on the latest version of Rails unlocks a few underlying features we can use to implement improvements to the application. # Implementation notes * This builds on and supersedes #1138 * This holds off on switching to `vips` for image processing. We will probably do that as part of follow on work on ActiveStorage variants. * The [upgrade guide](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-6-1-to-rails-7-0) suggests there are changes to `button_to`. No system tests are failing but we should audit the behavior to make sure everything still works. --------- Co-authored-by: Joshua Flark --- .github/workflows/ci.yml | 4 +- Gemfile | 9 +- Gemfile.lock | 148 +++++++++--------- app/controllers/signup/payments_controller.rb | 2 +- app/helpers/date_helper.rb | 6 +- app/lib/member_exporter.rb | 2 +- app/models/membership.rb | 4 +- app/views/admin/items/histories/show.html.erb | 2 +- .../admin/reports/memberships/index.html.erb | 2 +- .../potential_volunteers/index.html.erb | 2 +- .../membership_reminder.text.erb | 2 +- config/application.rb | 14 +- docker-compose.yml | 4 +- gems/active_storage_log_suppressor/.gitignore | 8 - gems/active_storage_log_suppressor/Gemfile | 15 -- .../active_storage_log_suppressor/MIT-LICENSE | 20 --- gems/active_storage_log_suppressor/README.md | 25 --- .../active_storage_log_suppressor.gemspec | 20 --- .../lib/active_storage_log_suppressor.rb | 7 - .../active_storage_log_suppressor/filters.rb | 60 ------- .../active_storage_log_suppressor/railtie.rb | 34 ---- .../active_storage_log_suppressor/version.rb | 5 - .../active_storage_log_suppressor_tasks.rake | 4 - .../application_controller_test.rb | 8 +- test/controllers/concerns/lending_test.rb | 10 +- .../signup/payments_controller_test.rb | 8 +- test/factories/item_attachments.rb | 2 +- test/factories/items.rb | 2 +- test/fixtures/libraries.yml | 4 +- test/models/loan_test.rb | 2 +- test/system/admin/memberships_test.rb | 4 +- test/test_helper.rb | 14 ++ 32 files changed, 133 insertions(+), 320 deletions(-) delete mode 100644 gems/active_storage_log_suppressor/.gitignore delete mode 100644 gems/active_storage_log_suppressor/Gemfile delete mode 100644 gems/active_storage_log_suppressor/MIT-LICENSE delete mode 100644 gems/active_storage_log_suppressor/README.md delete mode 100644 gems/active_storage_log_suppressor/active_storage_log_suppressor.gemspec delete mode 100644 gems/active_storage_log_suppressor/lib/active_storage_log_suppressor.rb delete mode 100644 gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/filters.rb delete mode 100644 gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/railtie.rb delete mode 100644 gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/version.rb delete mode 100644 gems/active_storage_log_suppressor/lib/tasks/active_storage_log_suppressor_tasks.rake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2597af194..a0cb9289d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: services: postgres: - image: postgres:11 + image: postgres:13.12 env: POSTGRES_HOST: localhost POSTGRES_USER: postgres @@ -167,4 +167,4 @@ jobs: bundler-cache: true - name: ERB Lint - run: bundle exec erblint --lint-all \ No newline at end of file + run: bundle exec erblint --lint-all diff --git a/Gemfile b/Gemfile index c76fc5467..f2276383c 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,12 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby "3.1.4" -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem "rails", "~> 6.1.4" +# Bundle edge Rails instead: gem "rails", github: "rails/rails" +gem "rails", "~> 7.0.0" + +# Since Rails 7 sprockets is optional; we still use it so we need to depend on +# the gem explicitly +gem "sprockets-rails" # Use postgresql as the database for Active Record gem "pg", ">= 0.18", "< 2.0" @@ -76,7 +80,6 @@ group :development do gem "listen" gem "solargraph" gem "solargraph-standardrb" - gem "active_storage_log_suppressor", path: "gems/active_storage_log_suppressor" gem "lefthook" gem "erb_lint", "~> 0.1.1" end diff --git a/Gemfile.lock b/Gemfile.lock index 2646d369c..92bc71668 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,77 +5,77 @@ GIT audited (5.0.2) activerecord (>= 5.0, < 7.1) -PATH - remote: gems/active_storage_log_suppressor - specs: - active_storage_log_suppressor (0.1.1) - rails (>= 6.0.0) - GEM remote: https://rubygems.org/ specs: - actioncable (6.1.4.3) - actionpack (= 6.1.4.3) - activesupport (= 6.1.4.3) + actioncable (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.4.3) - actionpack (= 6.1.4.3) - activejob (= 6.1.4.3) - activerecord (= 6.1.4.3) - activestorage (= 6.1.4.3) - activesupport (= 6.1.4.3) + actionmailbox (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) mail (>= 2.7.1) - actionmailer (6.1.4.3) - actionpack (= 6.1.4.3) - actionview (= 6.1.4.3) - activejob (= 6.1.4.3) - activesupport (= 6.1.4.3) + net-imap + net-pop + net-smtp + actionmailer (7.0.8) + actionpack (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activesupport (= 7.0.8) mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp rails-dom-testing (~> 2.0) - actionpack (6.1.4.3) - actionview (= 6.1.4.3) - activesupport (= 6.1.4.3) - rack (~> 2.0, >= 2.0.9) + actionpack (7.0.8) + actionview (= 7.0.8) + activesupport (= 7.0.8) + rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.4.3) - actionpack (= 6.1.4.3) - activerecord (= 6.1.4.3) - activestorage (= 6.1.4.3) - activesupport (= 6.1.4.3) + actiontext (7.0.8) + actionpack (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.4.3) - activesupport (= 6.1.4.3) + actionview (7.0.8) + activesupport (= 7.0.8) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.4.3) - activesupport (= 6.1.4.3) + activejob (7.0.8) + activesupport (= 7.0.8) globalid (>= 0.3.6) - activemodel (6.1.4.3) - activesupport (= 6.1.4.3) - activerecord (6.1.4.3) - activemodel (= 6.1.4.3) - activesupport (= 6.1.4.3) + activemodel (7.0.8) + activesupport (= 7.0.8) + activerecord (7.0.8) + activemodel (= 7.0.8) + activesupport (= 7.0.8) activerecord-postgres_enum (2.0.1) activerecord (>= 5.2) pg - activestorage (6.1.4.3) - actionpack (= 6.1.4.3) - activejob (= 6.1.4.3) - activerecord (= 6.1.4.3) - activesupport (= 6.1.4.3) - marcel (~> 1.0.0) + activestorage (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activesupport (= 7.0.8) + marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.4.3) + activesupport (7.0.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) acts_as_list (1.1.0) activerecord (>= 4.2) acts_as_tenant (0.5.1) @@ -136,7 +136,7 @@ GEM crass (1.0.6) cssbundling-rails (1.3.2) railties (>= 6.0.0) - date (3.3.3) + date (3.3.4) devise (4.8.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -201,8 +201,8 @@ GEM locale (>= 2.0.5) prime text (>= 1.3.0) - globalid (1.0.0) - activesupport (>= 5.0) + globalid (1.2.1) + activesupport (>= 6.1) hashie (5.0.0) html_tokenizer (0.0.7) http (5.0.4) @@ -282,14 +282,14 @@ GEM multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) - net-imap (0.3.6) + net-imap (0.4.4) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-smtp (0.4.0) net-protocol nio4r (2.5.9) nokogiri (1.15.4) @@ -340,21 +340,20 @@ GEM rack rack-test (2.1.0) rack (>= 1.3) - rails (6.1.4.3) - actioncable (= 6.1.4.3) - actionmailbox (= 6.1.4.3) - actionmailer (= 6.1.4.3) - actionpack (= 6.1.4.3) - actiontext (= 6.1.4.3) - actionview (= 6.1.4.3) - activejob (= 6.1.4.3) - activemodel (= 6.1.4.3) - activerecord (= 6.1.4.3) - activestorage (= 6.1.4.3) - activesupport (= 6.1.4.3) + rails (7.0.8) + actioncable (= 7.0.8) + actionmailbox (= 7.0.8) + actionmailer (= 7.0.8) + actionpack (= 7.0.8) + actiontext (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activemodel (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) bundler (>= 1.15.0) - railties (= 6.1.4.3) - sprockets-rails (>= 2.0.0) + railties (= 7.0.8) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -366,12 +365,13 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (6.1.4.3) - actionpack (= 6.1.4.3) - activesupport (= 6.1.4.3) + railties (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) method_source - rake (>= 0.13) + rake (>= 12.2) thor (~> 1.0) + zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) rb-fsevent (0.11.0) @@ -459,7 +459,7 @@ GEM text (1.3.1) thor (1.2.2) tilt (2.0.10) - timeout (0.4.0) + timeout (0.4.1) translation (1.29) gettext (~> 3.2, >= 3.2.5, <= 3.4.2) turbolinks (5.2.1) @@ -485,7 +485,7 @@ GEM railties (>= 6.0.0) webrick (1.7.0) websocket (1.2.10) - websocket-driver (0.7.5) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) @@ -498,7 +498,6 @@ PLATFORMS ruby DEPENDENCIES - active_storage_log_suppressor! activerecord-postgres_enum acts_as_list acts_as_tenant @@ -535,7 +534,7 @@ DEPENDENCIES pg_search puma pundit - rails (~> 6.1.4) + rails (~> 7.0.0) rails-controller-testing reverse_markdown scenic @@ -543,6 +542,7 @@ DEPENDENCIES sentry-raven solargraph solargraph-standardrb + sprockets-rails spy square.rb standard diff --git a/app/controllers/signup/payments_controller.rb b/app/controllers/signup/payments_controller.rb index f47756c39..e4d795263 100644 --- a/app/controllers/signup/payments_controller.rb +++ b/app/controllers/signup/payments_controller.rb @@ -19,7 +19,7 @@ def create result = checkout.checkout_url(amount: @form.amount, email: @member.email, return_to: callback_signup_payments_url, member_id: @member.id, date: Date.current) if result.success? - redirect_to result.value + redirect_to result.value, allow_other_host: true else errors = result.error Rails.logger.error(errors) diff --git a/app/helpers/date_helper.rb b/app/helpers/date_helper.rb index 8567039cc..514519a54 100644 --- a/app/helpers/date_helper.rb +++ b/app/helpers/date_helper.rb @@ -1,10 +1,10 @@ module DateHelper def date_with_time_title(time) - tag.span(time.to_s(:short_date), title: time.to_s(:short_datetime)) + tag.span(time.to_fs(:short_date), title: time.to_fs(:short_datetime)) end def time_ago_with_time_title(time) - tag.span(time_ago_in_words(time) + " ago", title: time.to_s(:short_datetime)) + tag.span(time_ago_in_words(time) + " ago", title: time.to_fs(:short_datetime)) end def checked_out_date(datetime, day_of_week: false) @@ -21,6 +21,6 @@ def appointment_date_and_time(appointment, include_time: true) def display_date(datetime, format) return unless datetime - tag.time(datetime.to_s(format), datetime: datetime.utc) + tag.time(datetime.to_fs(format), datetime: datetime.utc) end end diff --git a/app/lib/member_exporter.rb b/app/lib/member_exporter.rb index f39524199..41f613f2f 100644 --- a/app/lib/member_exporter.rb +++ b/app/lib/member_exporter.rb @@ -61,7 +61,7 @@ def year_values(member) started_at = member["#{year}_started_at"] amount = member["#{year}_amount"].to_i if started_at - [amount / 100, started_at.to_s(:short_date)] + [amount / 100, started_at.to_fs(:short_date)] elsif amount > 0 [amount / 100, nil] else diff --git a/app/models/membership.rb b/app/models/membership.rb index c5cb1c009..227b447fc 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -50,9 +50,9 @@ def status_text if pending? "pending" elsif ended? - "ended on #{ended_at.to_s(:month_day_year)}" + "ended on #{ended_at.to_fs(:month_day_year)}" else - "ends on #{ended_at.to_s(:month_day_year)}" + "ends on #{ended_at.to_fs(:month_day_year)}" end end diff --git a/app/views/admin/items/histories/show.html.erb b/app/views/admin/items/histories/show.html.erb index 3b6a3c388..ed3f39694 100644 --- a/app/views/admin/items/histories/show.html.erb +++ b/app/views/admin/items/histories/show.html.erb @@ -7,7 +7,7 @@
-

<%= audit.created_at.to_s(:short) %> by +

<%= audit.created_at.to_fs(:short) %> by <% if audit.user.present? %> <%= audit.user.email %> <% end %> diff --git a/app/views/admin/reports/memberships/index.html.erb b/app/views/admin/reports/memberships/index.html.erb index 673aafea3..0ebf9913a 100644 --- a/app/views/admin/reports/memberships/index.html.erb +++ b/app/views/admin/reports/memberships/index.html.erb @@ -24,7 +24,7 @@ <%= member.status %> <%= member.loans_count %> - <%= member.expires_on.to_date.to_s(:long) if member.expires_on %> + <%= member.expires_on&.to_date&.to_fs(:long) %> <%= member.amounts.map { |a| Money.new(a&.abs).format }.join(", ") %> <%= member.memberships_count %> diff --git a/app/views/admin/reports/potential_volunteers/index.html.erb b/app/views/admin/reports/potential_volunteers/index.html.erb index 69d32c0d5..eebf8a65e 100644 --- a/app/views/admin/reports/potential_volunteers/index.html.erb +++ b/app/views/admin/reports/potential_volunteers/index.html.erb @@ -26,7 +26,7 @@ <%= tag.div format_phone_number(member.phone_number), class: "responsive-table-cell" %> - <%= member.created_at.to_s(:short_date) %> + <%= member.created_at.to_fs(:short_date) %> <% end %> diff --git a/app/views/member_mailer/membership_reminder.text.erb b/app/views/member_mailer/membership_reminder.text.erb index 9ab4c0b18..96dfd9440 100644 --- a/app/views/member_mailer/membership_reminder.text.erb +++ b/app/views/member_mailer/membership_reminder.text.erb @@ -3,7 +3,7 @@ We'd love to see you! <%= HTMLToMarkdown.new.convert(render(partial: "member_mailer/reminder")) %> --------------------- -<%= HTMLToMarkdown.new.convert(render(partial: "signup/confirmations/instructions", formats: ["html"])) %> +<%= HTMLToMarkdown.new.convert(render(partial: "signup/confirmations/instructions", formats: [:html])) %> --- diff --git a/config/application.rb b/config/application.rb index cab646486..1b26ff51c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -20,23 +20,17 @@ module Circulate class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 6.1 - # config.autoloader = :classic + config.load_defaults 7.0 config.active_record.has_many_inversing = false - config.active_record.legacy_connection_handling = true - config.active_storage.track_variants = false config.active_storage.queues.analysis = :active_storage_analysis - - # config.active_storage.variant_processor = :vips + # Rails 7 changed the default image processor to :vips; we will have to + # get it installed in our Heroku environment before we can switch. + config.active_storage.variant_processor = :mini_magick config.active_job.queue_adapter = :sucker_punch - config.active_job.skip_after_callbacks_if_terminated = true - config.action_dispatch.cookies_same_site_protection = nil - config.action_view.form_with_generates_remote_forms = true - ActiveSupport.utc_to_local_returns_utc_offset_times = false # Settings in config/environments/* take precedence over those specified here. diff --git a/docker-compose.yml b/docker-compose.yml index 46872673d..f103f31b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: - example.com database: - image: postgres:12.4 + image: postgres:13.12 env_file: - config/docker.env volumes: @@ -48,4 +48,4 @@ volumes: db_data: networks: - default: \ No newline at end of file + default: diff --git a/gems/active_storage_log_suppressor/.gitignore b/gems/active_storage_log_suppressor/.gitignore deleted file mode 100644 index e15757127..000000000 --- a/gems/active_storage_log_suppressor/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.bundle/ -log/*.log -pkg/ -test/dummy/db/*.sqlite3 -test/dummy/db/*.sqlite3-journal -test/dummy/log/*.log -test/dummy/storage/ -test/dummy/tmp/ diff --git a/gems/active_storage_log_suppressor/Gemfile b/gems/active_storage_log_suppressor/Gemfile deleted file mode 100644 index 408c54d66..000000000 --- a/gems/active_storage_log_suppressor/Gemfile +++ /dev/null @@ -1,15 +0,0 @@ -source "https://rubygems.org" -git_source(:github) { |repo| "https://github.com/#{repo}.git" } - -# Declare your gem's dependencies in active_storage_log_suppressor.gemspec. -# Bundler will treat runtime dependencies like base dependencies, and -# development dependencies will be added by default to the :development group. -gemspec - -# Declare any dependencies that are still in development here instead of in -# your gemspec. These might include edge Rails or gems from your path or -# Git. Remember to move these dependencies to your gemspec before releasing -# your gem to rubygems.org. - -# To use a debugger -# gem 'byebug', group: [:development, :test] diff --git a/gems/active_storage_log_suppressor/MIT-LICENSE b/gems/active_storage_log_suppressor/MIT-LICENSE deleted file mode 100644 index 53b2c1fbb..000000000 --- a/gems/active_storage_log_suppressor/MIT-LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright 2019 Jim Benton - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/gems/active_storage_log_suppressor/README.md b/gems/active_storage_log_suppressor/README.md deleted file mode 100644 index 0f7caaef5..000000000 --- a/gems/active_storage_log_suppressor/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# ActiveStorageLogSuppressor - -ActiveStorage is really noisy as each image that appears on a page can result in up to two requests being logged through the Rails stack. - -This code hides log messages resulting from these requests by patching the base Rails frameworks classes. A few approaches are used to determine if the current context is within a request for an ActiveStorage file, depending on what information is available in each context. - -## Usage -Add this plugin to your application's `Gemfile`. It will only activate in `development` mode, but regardless, please do not attempt to run this in production. It is intended purely as a development tool. - -## Installation -Add the gem to the `:development` group in your `Gemfile`: - -```ruby -group :development do - gem 'active_storage_log_suppressor' -end -``` - -And then execute: -```bash -$ bundle -``` - -## License -The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). diff --git a/gems/active_storage_log_suppressor/active_storage_log_suppressor.gemspec b/gems/active_storage_log_suppressor/active_storage_log_suppressor.gemspec deleted file mode 100644 index ecf7f90aa..000000000 --- a/gems/active_storage_log_suppressor/active_storage_log_suppressor.gemspec +++ /dev/null @@ -1,20 +0,0 @@ -$:.push File.expand_path("lib", __dir__) - -# Maintain your gem's version: -require "active_storage_log_suppressor/version" - -# Describe your gem and declare its dependencies: -Gem::Specification.new do |spec| - spec.name = "active_storage_log_suppressor" - spec.version = ActiveStorageLogSuppressor::VERSION - spec.authors = ["Jim Benton"] - spec.email = ["jim@autonomousmachine.com"] - spec.homepage = "https://github.com/jim/active_storate_log_suppressor" - spec.summary = "Silences ActiveStorage requests in development mode." - spec.description = "Silences ActiveStorage requests in development mode." - spec.license = "MIT" - - spec.files = Dir["lib/**/*", "MIT-LICENSE", "Rakefile", "README.md"] - - spec.add_dependency "rails", ">= 6.0.0" -end diff --git a/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor.rb b/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor.rb deleted file mode 100644 index 0604e83ce..000000000 --- a/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -require "active_storage_log_suppressor/railtie" -require "active_storage_log_suppressor/filters" - -module ActiveStorageLogSuppressor -end diff --git a/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/filters.rb b/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/filters.rb deleted file mode 100644 index 6ae7306b8..000000000 --- a/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/filters.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -module ActiveStorageLogSuppressor - module ActionControllerLoggingFilters - def start_processing(event) - super unless event.payload[:controller].start_with? "ActiveStorage::" - end - - def process_action(event) - super unless event.payload[:controller].start_with? "ActiveStorage::" - end - - def redirect_to(event) - super unless event.payload[:location].include? "/rails/active_storage" - end - end - - module ActiveStorageLoggingFilters - private - - def info(event, colored_message) - end - - def debug(event, colored_message) - end - end - - module ActiveRecordLoggingFilters - def sql(event) - super unless Thread.current[:__active_support_request] - end - end - - module RackLoggerLoggingFilters - def call_app(request, env) - instrumenter = ActiveSupport::Notifications.instrumenter - instrumenter.start "request.action_dispatch", request: request - - if request.path.start_with? "/rails/active_storage" - Thread.current[:__active_support_request] = true - else - logger.info { started_request_message(request) } - end - - status, headers, body = @app.call(env) - body = ::Rack::BodyProxy.new(body) { finish(request) } - [status, headers, body] - rescue Exception # rubocop:disable Lint/RescueException - finish(request) - raise - ensure - ActiveSupport::LogSubscriber.flush_all! - end - - def finish(request) - Thread.current[:__active_support_request] = false - super - end - end -end diff --git a/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/railtie.rb b/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/railtie.rb deleted file mode 100644 index c1ba7156b..000000000 --- a/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/railtie.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -module ActiveStorageLogSuppressor - class Railtie < ::Rails::Railtie - initializer "active_support_log_suppressor.install" do |app| - if Rails.env.development? && !ENV.fetch("SHOW_ACTIVE_STORAGE_LOGS", false) - install! - end - end - - # ActiveStorage is really noisy as each image that appears on a page can result in up to two requests being - # logged through the Rails stack. - # - # This code selectively turns off logging in the various Rails components when an ActiveStorage - # request is detected. - def install! - message = "Hiding all ActiveStorage logging in development mode. Disable by setting SHOW_ACTIVE_STORAGE_LOGS." - Rails.logger.debug "[active_storage_log_suppressor] #{red(message)}" - - require "action_controller/log_subscriber" - ::ActionController::LogSubscriber.send :prepend, ActionControllerLoggingFilters - require "active_storage/log_subscriber" - ::ActiveStorage::LogSubscriber.send :prepend, ActiveStorageLoggingFilters - require "active_record/log_subscriber" - ::ActiveRecord::LogSubscriber.send :prepend, ActiveRecordLoggingFilters - require "rails/rack/logger" - ::Rails::Rack::Logger.send :prepend, RackLoggerLoggingFilters - end - - def red(message) - "\e[0;31m#{message}\033[0m" - end - end -end diff --git a/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/version.rb b/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/version.rb deleted file mode 100644 index 08b552fc3..000000000 --- a/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -module ActiveStorageLogSuppressor - VERSION = "0.1.1" -end diff --git a/gems/active_storage_log_suppressor/lib/tasks/active_storage_log_suppressor_tasks.rake b/gems/active_storage_log_suppressor/lib/tasks/active_storage_log_suppressor_tasks.rake deleted file mode 100644 index bc2d6d4c4..000000000 --- a/gems/active_storage_log_suppressor/lib/tasks/active_storage_log_suppressor_tasks.rake +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :active_storage_log_suppressor do -# # Task goes here -# end diff --git a/test/controllers/application_controller_test.rb b/test/controllers/application_controller_test.rb index f2fb68554..0de32e7ec 100644 --- a/test/controllers/application_controller_test.rb +++ b/test/controllers/application_controller_test.rb @@ -20,15 +20,15 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest end test "should redirect to previous page for admin after login if there is a referer" do - get new_user_session_path, headers: {referer: "http://www.example.com/original-page"} + get new_user_session_path, headers: {referer: "http://example.com/original-page"} post user_session_path, params: {user: {email: @admin_user.email, password: "password"}} - assert_redirected_to "http://www.example.com/original-page" + assert_redirected_to "http://example.com/original-page" end test "should redirect to previous page for member after login if there is a referer" do - get new_user_session_path, headers: {referer: "http://www.example.com/items/1"} + get new_user_session_path, headers: {referer: "http://example.com/items/1"} post user_session_path, params: {user: {email: @user.email, password: "password"}} - assert_redirected_to "http://www.example.com/items/1" + assert_redirected_to "http://example.com/items/1" end test "should not redirect to previous page for member after login if referer is not of the same domain" do diff --git a/test/controllers/concerns/lending_test.rb b/test/controllers/concerns/lending_test.rb index 3d7e2ff2b..b41057321 100644 --- a/test/controllers/concerns/lending_test.rb +++ b/test/controllers/concerns/lending_test.rb @@ -17,7 +17,7 @@ class LendingTest < ActiveSupport::TestCase assert_equal item.id, renewal.item_id assert_equal loan.member_id, renewal.member_id assert_equal loan.id, renewal.initial_loan_id - assert_equal sunday + 7.days, renewal.due_at + assert_timestamp_equal sunday + 7.days, renewal.due_at assert_equal 1, renewal.renewal_count assert renewal.uniquely_numbered end @@ -32,7 +32,7 @@ class LendingTest < ActiveSupport::TestCase renew_loan(loan, now: sunday) } - assert_equal sunday + 7.days, renewal.due_at + assert_timestamp_equal sunday + 7.days, renewal.due_at end test "renews a loan for a full period starting at due date" do @@ -46,7 +46,7 @@ class LendingTest < ActiveSupport::TestCase renew_loan(loan, now: sunday) } - assert_equal thursday + 7.days, renewal.due_at + assert_timestamp_equal thursday + 7.days, renewal.due_at end test "renews a loan due tomorrow" do @@ -63,7 +63,7 @@ class LendingTest < ActiveSupport::TestCase next_day = Loan.stub(:open_days, [0, 4]) { Loan.next_open_day(thursday + 7.days) } - assert_equal next_day, renewal.due_at + assert_timestamp_equal next_day, renewal.due_at end test "renews a renewal" do @@ -85,7 +85,7 @@ class LendingTest < ActiveSupport::TestCase } assert_equal loan.id, second_renewal.initial_loan_id - assert_equal sunday + 14.days, second_renewal.due_at + assert_timestamp_equal sunday + 14.days, second_renewal.due_at assert_equal 2, second_renewal.renewal_count end diff --git a/test/controllers/signup/payments_controller_test.rb b/test/controllers/signup/payments_controller_test.rb index afb7c7fc5..b295b32b9 100644 --- a/test/controllers/signup/payments_controller_test.rb +++ b/test/controllers/signup/payments_controller_test.rb @@ -23,7 +23,7 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest mock_checkout.expect :checkout_url, mock_result, [{ amount: Money.new(1200), email: @member.email, - return_to: "http://www.example.com/signup/payments/callback", + return_to: "http://example.com/signup/payments/callback", member_id: @member.id, date: Date.current }] @@ -51,7 +51,7 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest post signup_payments_url, params: {membership_payment_form: {amount_dollars: "12"}} end - assert_redirected_to "http://www.example.com/signup/payments/new" + assert_redirected_to "http://example.com/signup/payments/new" follow_redirect! assert_select ".toast-error", /There was a problem connecting to our payment processor/ @@ -99,7 +99,7 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest end end - assert_redirected_to "http://www.example.com/signup/confirmation" + assert_redirected_to "http://example.com/signup/confirmation" follow_redirect! assert_select ".toast-error", /There was an error processing your payment/ @@ -151,7 +151,7 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest assert_equal 200, response.status assert_equal i + 1, session[:attempts] else - assert_redirected_to "http://www.example.com/signup/confirmation" + assert_redirected_to "http://example.com/signup/confirmation" assert_match(/There was an error processing your payment/, flash[:error]) refute session[:attempts] end diff --git a/test/factories/item_attachments.rb b/test/factories/item_attachments.rb index dad27e0e0..bd4aa4f69 100644 --- a/test/factories/item_attachments.rb +++ b/test/factories/item_attachments.rb @@ -2,6 +2,6 @@ factory :item_attachment do kind { "manual" } other_kind { "MyString" } - file { Rack::Test::UploadedFile.new(Rails.root.join("test", "fixtures", "files", "tool-image.jpg"), "image/jpg") } + file { Rack::Test::UploadedFile.new(Rails.root.join("test", "fixtures", "files", "tool-image.jpg"), "image/jpeg") } end end diff --git a/test/factories/items.rb b/test/factories/items.rb index b06098f14..ba039425c 100644 --- a/test/factories/items.rb +++ b/test/factories/items.rb @@ -28,7 +28,7 @@ end trait :with_image do - image { Rack::Test::UploadedFile.new(Rails.root.join("test", "fixtures", "files", "tool-image.jpg"), "image/jpg") } + image { Rack::Test::UploadedFile.new(Rails.root.join("test", "fixtures", "files", "tool-image.jpg"), "image/jpeg") } end end end diff --git a/test/fixtures/libraries.yml b/test/fixtures/libraries.yml index a788f345f..a71a8dbbf 100644 --- a/test/fixtures/libraries.yml +++ b/test/fixtures/libraries.yml @@ -1,10 +1,10 @@ chicago_tool_library: name: "Chicago Tool Library" - hostname: "www.example.com" + hostname: "example.com" city: Chicago email: team@chicagotoollibrary.org address: |- The Chicago Tool Library 1048 W 37th Street Suite 102 Chicago, IL 60609 - chicagotoollibrary.org \ No newline at end of file + chicagotoollibrary.org diff --git a/test/models/loan_test.rb b/test/models/loan_test.rb index 047ef5faf..0f2248f61 100644 --- a/test/models/loan_test.rb +++ b/test/models/loan_test.rb @@ -90,7 +90,7 @@ class LoanTest < ActiveSupport::TestCase sunday = Time.utc(2020, 1, 26).end_of_day - assert_equal sunday, loan.due_at + assert_timestamp_equal sunday, loan.due_at end test "returns the same day as the next open day" do diff --git a/test/system/admin/memberships_test.rb b/test/system/admin/memberships_test.rb index fdd9781c9..c7b63f93c 100644 --- a/test/system/admin/memberships_test.rb +++ b/test/system/admin/memberships_test.rb @@ -25,8 +25,8 @@ def setup end click_on "Membership" - assert_content membership.started_at.to_s(:long_date) - assert_content membership.ended_at.to_s(:long_date) + assert_content membership.started_at.to_fs(:long_date) + assert_content membership.ended_at.to_fs(:long_date) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index df93341b9..b98467e12 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -21,6 +21,20 @@ def assert_size(expected, subject) assert_equal expected, subject.size, "wrong size; got #{subject.size} instead of #{expected}" end + # Postgres stores time at microsecond precision, while Ruby's Time classes + # operate at nanosecond precision. To simplify comparison, this helper + # truncates the nanosecond portion of the expected argument. + # + # While it is not required for the equality check to pass, this also converts + # the expected argument to a TimeWithZone, which is what ActiveRecord + # timestamps will be. This makes the output on failure a little cleaner as + # the to_s representations will line up. + # + # See: https://stackoverflow.com/questions/57703148/rails-timewithzone-doesnt-match + def assert_timestamp_equal(expected, subject) + assert_equal expected.in_time_zone.floor(6), subject, "expected timestamps to match to within microsecond precision" + end + class << self def env_tags @env_tags ||= ENV.fetch("TAGS", "").split