From 19e49831e8f8f0dc68a4affa6221c4f03a55fb48 Mon Sep 17 00:00:00 2001 From: Ricardo Vela <97992712+argvniyx-enroute@users.noreply.github.com> Date: Mon, 29 Apr 2024 09:15:59 -0600 Subject: [PATCH] Add Rails 7.1 testing (#35) ### Summary I stumbled upon an error when trying to add Rails 7.1 support to a `journaled` dependent: in `audit_log.rb`, we call `skip_audit_log` on certain ActiveRecord classes which no longer inherit from `ActiveRecord::Base` in 7.1, so that would raise with a `NoMethodError`. This PR: - Bumps `.ruby-version` to 3.2.2 (most if not all of us are using >=3.0) as our daily driver, so it's a bit of an ergonomic change) - Includes rubocop autocorrect changes (the _vast_ majority of these are the `frozen_string_literal: true` lints; mostly felt the need to do this to unblock running `be rake` locally) - Skips calling `skip_audit_log` on ActiveRecord classes when on Rails 7.1 - Only sets `legacy_connection_handling` when on Rails 7.0 ### Other Information There might be some other things worth considering (not ignoring lockfiles(?), actually using the new connection handling (even if it is only a dummy app)) but I didn't want to drag out a PR that's already pretty big. --- .github/workflows/tests.yml | 3 ++ .ruby-version | 2 +- Appraisals | 6 ++++ Gemfile | 2 ++ Rakefile | 2 ++ app/controllers/concerns/journaled/actor.rb | 2 ++ app/jobs/journaled/application_job.rb | 2 ++ app/jobs/journaled/delivery_job.rb | 4 ++- app/models/concerns/journaled/changes.rb | 2 ++ app/models/journaled/actor_uri_provider.rb | 2 ++ app/models/journaled/audit_log/event.rb | 4 ++- app/models/journaled/change.rb | 2 ++ app/models/journaled/change_definition.rb | 2 ++ app/models/journaled/change_writer.rb | 2 ++ app/models/journaled/event.rb | 2 ++ .../journaled/json_schema_model/validator.rb | 2 ++ .../journaled/not_truly_exceptional_error.rb | 2 ++ app/models/journaled/writer.rb | 2 ++ bin/rails | 2 ++ config/initializers/change_protection.rb | 2 ++ config/spring.rb | 2 ++ gemfiles/rails_5_2.gemfile | 2 ++ gemfiles/rails_6_0.gemfile | 2 ++ gemfiles/rails_6_1.gemfile | 2 ++ gemfiles/rails_7_0.gemfile | 2 ++ gemfiles/rails_7_1.gemfile | 9 +++++ journaled.gemspec | 4 ++- lib/journaled.rb | 2 ++ lib/journaled/audit_log.rb | 30 +++++++++++----- lib/journaled/connection.rb | 2 ++ lib/journaled/current.rb | 2 ++ lib/journaled/engine.rb | 2 ++ lib/journaled/errors.rb | 2 ++ lib/journaled/relation_change_protection.rb | 2 ++ lib/journaled/rspec.rb | 2 ++ lib/journaled/transaction_ext.rb | 2 ++ lib/journaled/version.rb | 4 ++- spec/dummy/Rakefile | 2 ++ spec/dummy/bin/bundle | 2 ++ spec/dummy/bin/rails | 2 ++ spec/dummy/bin/rake | 2 ++ spec/dummy/config.ru | 2 ++ spec/dummy/config/application.rb | 4 ++- spec/dummy/config/boot.rb | 2 ++ spec/dummy/config/environment.rb | 2 ++ spec/dummy/config/environments/development.rb | 2 ++ spec/dummy/config/environments/test.rb | 2 ++ .../initializers/backtrace_silencers.rb | 2 ++ .../config/initializers/cookies_serializer.rb | 2 ++ .../initializers/filter_parameter_logging.rb | 2 ++ spec/dummy/config/initializers/inflections.rb | 2 ++ spec/dummy/config/initializers/mime_types.rb | 2 ++ .../config/initializers/session_store.rb | 2 ++ .../config/initializers/wrap_parameters.rb | 2 ++ spec/dummy/config/routes.rb | 2 ++ spec/jobs/journaled/delivery_job_spec.rb | 2 ++ spec/lib/journaled/audit_log_spec.rb | 35 ++++++++++++------- spec/lib/journaled/connection_spec.rb | 2 ++ spec/lib/journaled_spec.rb | 2 ++ spec/models/concerns/journaled/actor_spec.rb | 2 ++ .../models/concerns/journaled/changes_spec.rb | 2 ++ .../models/database_change_protection_spec.rb | 2 ++ .../journaled/actor_uri_provider_spec.rb | 2 ++ spec/models/journaled/change_writer_spec.rb | 2 ++ spec/models/journaled/event_spec.rb | 2 ++ .../json_schema_model/validator_spec.rb | 2 ++ spec/models/journaled/writer_spec.rb | 2 ++ spec/rails_helper.rb | 2 ++ spec/spec_helper.rb | 2 ++ spec/support/environment_spec_helper.rb | 2 ++ 70 files changed, 197 insertions(+), 26 deletions(-) create mode 100644 gemfiles/rails_7_1.gemfile diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a1f8860..5157c2a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,6 +15,7 @@ jobs: - gemfiles/rails_6_0.gemfile - gemfiles/rails_6_1.gemfile - gemfiles/rails_7_0.gemfile + - gemfiles/rails_7_1.gemfile exclude: - ruby: '3.1' gemfile: gemfiles/rails_5_2.gemfile @@ -22,6 +23,8 @@ jobs: gemfile: gemfiles/rails_5_2.gemfile - ruby: '2.6' gemfile: gemfiles/rails_7_0.gemfile + - ruby: '2.6' + gemfile: gemfiles/rails_7_1.gemfile steps: - uses: actions/checkout@v2 diff --git a/.ruby-version b/.ruby-version index a603bb5..be94e6f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.5 +3.2.2 diff --git a/Appraisals b/Appraisals index 87af99c..2ac660e 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,5 @@ +# frozen_string_literal: true + appraise 'rails-5-2' do gem 'railties', '~> 5.2.0' end @@ -13,3 +15,7 @@ end appraise 'rails-7-0' do gem 'railties', '~> 7.0.0' end + +appraise 'rails-7-1' do + gem 'railties', '~> 7.1.0' +end diff --git a/Gemfile b/Gemfile index fa75df1..7f4f5e9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec diff --git a/Rakefile b/Rakefile index ed3bce9..6080c6d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + begin require 'bundler/setup' rescue LoadError diff --git a/app/controllers/concerns/journaled/actor.rb b/app/controllers/concerns/journaled/actor.rb index 990ae90..65b89ef 100644 --- a/app/controllers/concerns/journaled/actor.rb +++ b/app/controllers/concerns/journaled/actor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Journaled::Actor extend ActiveSupport::Concern diff --git a/app/jobs/journaled/application_job.rb b/app/jobs/journaled/application_job.rb index 6fa64ed..c89d48f 100644 --- a/app/jobs/journaled/application_job.rb +++ b/app/jobs/journaled/application_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Journaled class ApplicationJob < Journaled.job_base_class_name.constantize end diff --git a/app/jobs/journaled/delivery_job.rb b/app/jobs/journaled/delivery_job.rb index c0e74d9..77e6cf8 100644 --- a/app/jobs/journaled/delivery_job.rb +++ b/app/jobs/journaled/delivery_job.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Journaled class DeliveryJob < ApplicationJob - DEFAULT_REGION = 'us-east-1'.freeze + DEFAULT_REGION = 'us-east-1' rescue_from(Aws::Kinesis::Errors::InternalFailure, Aws::Kinesis::Errors::ServiceUnavailable, Aws::Kinesis::Errors::Http503Error) do |e| Rails.logger.error "Kinesis Error - Server Error occurred - #{e.class}" diff --git a/app/models/concerns/journaled/changes.rb b/app/models/concerns/journaled/changes.rb index d181fd9..16f536d 100644 --- a/app/models/concerns/journaled/changes.rb +++ b/app/models/concerns/journaled/changes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Journaled::Changes extend ActiveSupport::Concern diff --git a/app/models/journaled/actor_uri_provider.rb b/app/models/journaled/actor_uri_provider.rb index d54514e..c46563d 100644 --- a/app/models/journaled/actor_uri_provider.rb +++ b/app/models/journaled/actor_uri_provider.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Journaled::ActorUriProvider include Singleton diff --git a/app/models/journaled/audit_log/event.rb b/app/models/journaled/audit_log/event.rb index 856578d..5143468 100644 --- a/app/models/journaled/audit_log/event.rb +++ b/app/models/journaled/audit_log/event.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # FIXME: This cannot be included in lib/ because Journaled::Event is autoloaded via app/models # Autoloading Journaled::Event isn't strictly necessary, and for compatibility it would # make sense to move it to lib/. @@ -83,7 +85,7 @@ def filter_params def filtered_attributes attrs = record.attributes.dup.symbolize_keys - attrs.each do |key, _value| + attrs.each_key do |key| attrs[key] = '[FILTERED]' if filter_key?(key) end end diff --git a/app/models/journaled/change.rb b/app/models/journaled/change.rb index 51c6361..4f30b4e 100644 --- a/app/models/journaled/change.rb +++ b/app/models/journaled/change.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Journaled::Change include Journaled::Event diff --git a/app/models/journaled/change_definition.rb b/app/models/journaled/change_definition.rb index a9d03e4..2debd8c 100644 --- a/app/models/journaled/change_definition.rb +++ b/app/models/journaled/change_definition.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Journaled::ChangeDefinition attr_reader :attribute_names, :logical_operation diff --git a/app/models/journaled/change_writer.rb b/app/models/journaled/change_writer.rb index e307cb2..f2beeec 100644 --- a/app/models/journaled/change_writer.rb +++ b/app/models/journaled/change_writer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Journaled::ChangeWriter attr_reader :model, :change_definition diff --git a/app/models/journaled/event.rb b/app/models/journaled/event.rb index 880f0ca..191a790 100644 --- a/app/models/journaled/event.rb +++ b/app/models/journaled/event.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Journaled::Event extend ActiveSupport::Concern diff --git a/app/models/journaled/json_schema_model/validator.rb b/app/models/journaled/json_schema_model/validator.rb index 3ad98e0..6d16284 100644 --- a/app/models/journaled/json_schema_model/validator.rb +++ b/app/models/journaled/json_schema_model/validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Journaled::JsonSchemaModel::Validator def initialize(schema_name) @schema_name = schema_name diff --git a/app/models/journaled/not_truly_exceptional_error.rb b/app/models/journaled/not_truly_exceptional_error.rb index ea0ba46..102b86f 100644 --- a/app/models/journaled/not_truly_exceptional_error.rb +++ b/app/models/journaled/not_truly_exceptional_error.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class Journaled::NotTrulyExceptionalError < RuntimeError end diff --git a/app/models/journaled/writer.rb b/app/models/journaled/writer.rb index c6db5a5..0d5a8e1 100644 --- a/app/models/journaled/writer.rb +++ b/app/models/journaled/writer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Journaled::Writer EVENT_METHOD_NAMES = %i( journaled_schema_name diff --git a/bin/rails b/bin/rails index cc1a716..dd63bec 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. ENGINE_ROOT = File.expand_path('..', __dir__) diff --git a/config/initializers/change_protection.rb b/config/initializers/change_protection.rb index 732f63e..2764534 100644 --- a/config/initializers/change_protection.rb +++ b/config/initializers/change_protection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if Rails::VERSION::MAJOR > 5 || (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2) require 'journaled/relation_change_protection' ActiveRecord::Relation.class_eval { prepend Journaled::RelationChangeProtection } diff --git a/config/spring.rb b/config/spring.rb index 6b95e4d..eb6fec9 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + Spring.application_root = './spec/dummy' diff --git a/gemfiles/rails_5_2.gemfile b/gemfiles/rails_5_2.gemfile index 8b2627f..c8fd593 100644 --- a/gemfiles/rails_5_2.gemfile +++ b/gemfiles/rails_5_2.gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" diff --git a/gemfiles/rails_6_0.gemfile b/gemfiles/rails_6_0.gemfile index 4cd55a8..55af0bd 100644 --- a/gemfiles/rails_6_0.gemfile +++ b/gemfiles/rails_6_0.gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" diff --git a/gemfiles/rails_6_1.gemfile b/gemfiles/rails_6_1.gemfile index 4c467fe..087e991 100644 --- a/gemfiles/rails_6_1.gemfile +++ b/gemfiles/rails_6_1.gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile index 495c72d..52cdeee 100644 --- a/gemfiles/rails_7_0.gemfile +++ b/gemfiles/rails_7_0.gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by Appraisal source "https://rubygems.org" diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile new file mode 100644 index 0000000..a68d818 --- /dev/null +++ b/gemfiles/rails_7_1.gemfile @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "railties", "~> 7.1.0" + +gemspec path: "../" diff --git a/journaled.gemspec b/journaled.gemspec index 484a546..a3a04dd 100644 --- a/journaled.gemspec +++ b/journaled.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.push File.expand_path('lib', __dir__) # Maintain your gem's version: @@ -34,7 +36,7 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec-rails" s.add_development_dependency "spring" s.add_development_dependency "spring-commands-rspec" - s.add_development_dependency "sqlite3" + s.add_development_dependency "sqlite3", '~> 1.4' s.add_development_dependency "timecop" s.add_development_dependency "uncruft" s.add_development_dependency "webmock" diff --git a/lib/journaled.rb b/lib/journaled.rb index 772ef9a..c1018a3 100644 --- a/lib/journaled.rb +++ b/lib/journaled.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "aws-sdk-kinesis" require "active_job" require "json-schema" diff --git a/lib/journaled/audit_log.rb b/lib/journaled/audit_log.rb index 77f4b43..84a0f10 100644 --- a/lib/journaled/audit_log.rb +++ b/lib/journaled/audit_log.rb @@ -1,17 +1,31 @@ +# frozen_string_literal: true + require 'active_support/core_ext/module/attribute_accessors_per_thread' module Journaled module AuditLog extend ActiveSupport::Concern - DEFAULT_EXCLUDED_CLASSES = %w( - Delayed::Job - PaperTrail::Version - ActiveStorage::Attachment - ActiveStorage::Blob - ActiveRecord::InternalMetadata - ActiveRecord::SchemaMigration - ).freeze + DEFAULT_EXCLUDED_CLASSES = + if Gem::Version.new(Rails.version) < Gem::Version.new('7.1') + %w( + Delayed::Job + PaperTrail::Version + ActiveStorage::Attachment + ActiveStorage::Blob + ActiveRecord::InternalMetadata + ActiveRecord::SchemaMigration + ) + else + # ActiveRecord::InternalMetadata and SchemaMigration do not inherit from + # ActiveRecord::Base in Rails 7.1 so we do not need to exclude them. + %w( + Delayed::Job + PaperTrail::Version + ActiveStorage::Attachment + ActiveStorage::Blob + ) + end.freeze mattr_accessor(:default_ignored_columns) { %i(created_at updated_at) } mattr_accessor(:default_stream_name) { Journaled.default_stream_name } diff --git a/lib/journaled/connection.rb b/lib/journaled/connection.rb index 8ea1eeb..d85e5f7 100644 --- a/lib/journaled/connection.rb +++ b/lib/journaled/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Journaled module Connection class << self diff --git a/lib/journaled/current.rb b/lib/journaled/current.rb index e9b05fa..6ea63a7 100644 --- a/lib/journaled/current.rb +++ b/lib/journaled/current.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Journaled class Current < ActiveSupport::CurrentAttributes attribute :tags diff --git a/lib/journaled/engine.rb b/lib/journaled/engine.rb index c3ee996..6094464 100644 --- a/lib/journaled/engine.rb +++ b/lib/journaled/engine.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Journaled class Engine < ::Rails::Engine config.after_initialize do diff --git a/lib/journaled/errors.rb b/lib/journaled/errors.rb index 3697abb..86bdf80 100644 --- a/lib/journaled/errors.rb +++ b/lib/journaled/errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Journaled class TransactionSafetyError < StandardError; end end diff --git a/lib/journaled/relation_change_protection.rb b/lib/journaled/relation_change_protection.rb index 61e5888..3c51117 100644 --- a/lib/journaled/relation_change_protection.rb +++ b/lib/journaled/relation_change_protection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Journaled::RelationChangeProtection def update_all(updates, opts = { force: false }) # rubocop:disable Metrics/AbcSize unless opts[:force] || !@klass.respond_to?(:journaled_attribute_names) || @klass.journaled_attribute_names.empty? diff --git a/lib/journaled/rspec.rb b/lib/journaled/rspec.rb index 09793da..2ab7134 100644 --- a/lib/journaled/rspec.rb +++ b/lib/journaled/rspec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rspec/expectations' RSpec::Matchers.define :journal_changes_to do |*attribute_names, as:| diff --git a/lib/journaled/transaction_ext.rb b/lib/journaled/transaction_ext.rb index 0aad406..70f6793 100644 --- a/lib/journaled/transaction_ext.rb +++ b/lib/journaled/transaction_ext.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_record/connection_adapters/abstract/transaction' module Journaled diff --git a/lib/journaled/version.rb b/lib/journaled/version.rb index fb4f47a..cae7161 100644 --- a/lib/journaled/version.rb +++ b/lib/journaled/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Journaled - VERSION = "5.3.1".freeze + VERSION = "5.3.2" end diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile index f7a26dd..e51cf0e 100644 --- a/spec/dummy/Rakefile +++ b/spec/dummy/Rakefile @@ -1,3 +1,5 @@ +# 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. diff --git a/spec/dummy/bin/bundle b/spec/dummy/bin/bundle index f19acf5..2dbb717 100755 --- a/spec/dummy/bin/bundle +++ b/spec/dummy/bin/bundle @@ -1,3 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/spec/dummy/bin/rails b/spec/dummy/bin/rails index 0739660..a31728a 100755 --- a/spec/dummy/bin/rails +++ b/spec/dummy/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/spec/dummy/bin/rake b/spec/dummy/bin/rake index 1724048..c199955 100755 --- a/spec/dummy/bin/rake +++ b/spec/dummy/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru index 9797be5..667e328 100644 --- a/spec/dummy/config.ru +++ b/spec/dummy/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require ::File.expand_path('config/environment', __dir__) diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 615667c..f0703b1 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path('boot', __dir__) require "active_record/railtie" @@ -12,6 +14,6 @@ module Dummy class Application < Rails::Application config.autoloader = Rails::VERSION::MAJOR >= 7 ? :zeitwerk : :classic config.active_record.sqlite3.represent_boolean_as_integer = true if Rails::VERSION::MAJOR < 6 - config.active_record.legacy_connection_handling = false if Rails::VERSION::MAJOR >= 7 + config.active_record.legacy_connection_handling = false if Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 0 end end diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb index c9aef85..6d2cba0 100644 --- a/spec/dummy/config/boot.rb +++ b/spec/dummy/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb index 0b8bdd8..32d57aa 100644 --- a/spec/dummy/config/environment.rb +++ b/spec/dummy/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require File.expand_path('application', __dir__) diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index d9ef347..cbeec41 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index 3504dd6..5041daa 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/spec/dummy/config/initializers/backtrace_silencers.rb b/spec/dummy/config/initializers/backtrace_silencers.rb index 59385cd..4b63f28 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. diff --git a/spec/dummy/config/initializers/cookies_serializer.rb b/spec/dummy/config/initializers/cookies_serializer.rb index 7f70458..0a23b25 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. Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/spec/dummy/config/initializers/filter_parameter_logging.rb b/spec/dummy/config/initializers/filter_parameter_logging.rb index 4a994e1..7a4f47b 100644 --- a/spec/dummy/config/initializers/filter_parameter_logging.rb +++ b/spec/dummy/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# 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. diff --git a/spec/dummy/config/initializers/inflections.rb b/spec/dummy/config/initializers/inflections.rb index ac033bf..dc84742 100644 --- a/spec/dummy/config/initializers/inflections.rb +++ b/spec/dummy/config/initializers/inflections.rb @@ -1,3 +1,5 @@ +# 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..be6fedc 100644 --- a/spec/dummy/config/initializers/mime_types.rb +++ b/spec/dummy/config/initializers/mime_types.rb @@ -1,3 +1,5 @@ +# 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/session_store.rb b/spec/dummy/config/initializers/session_store.rb index e766b67..969d977 100644 --- a/spec/dummy/config/initializers/session_store.rb +++ b/spec/dummy/config/initializers/session_store.rb @@ -1,3 +1,5 @@ +# 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 33725e9..246168a 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/routes.rb b/spec/dummy/config/routes.rb index 3f66539..189947f 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 # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/spec/jobs/journaled/delivery_job_spec.rb b/spec/jobs/journaled/delivery_job_spec.rb index 1bf62e1..4f1bf33 100644 --- a/spec/jobs/journaled/delivery_job_spec.rb +++ b/spec/jobs/journaled/delivery_job_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Journaled::DeliveryJob do diff --git a/spec/lib/journaled/audit_log_spec.rb b/spec/lib/journaled/audit_log_spec.rb index d3e57b4..a886640 100644 --- a/spec/lib/journaled/audit_log_spec.rb +++ b/spec/lib/journaled/audit_log_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Journaled::AuditLog do @@ -78,14 +80,23 @@ def encrypted_attribute?(_key) describe '.excluded_classes' do let(:defaults) do - %w( - Delayed::Job - PaperTrail::Version - ActiveStorage::Attachment - ActiveStorage::Blob - ActiveRecord::InternalMetadata - ActiveRecord::SchemaMigration - ) + if Gem::Version.new(Rails.version) < Gem::Version.new('7.1') + %w( + Delayed::Job + PaperTrail::Version + ActiveStorage::Attachment + ActiveStorage::Blob + ActiveRecord::InternalMetadata + ActiveRecord::SchemaMigration + ) + else + %w( + Delayed::Job + PaperTrail::Version + ActiveStorage::Attachment + ActiveStorage::Blob + ) + end end it 'defaults to DJ and papertrail, but is configurable, and will disable audit logging' do @@ -209,9 +220,9 @@ def encrypted_attribute?(_key) define_attribute_methods(*attrs) attrs.each do |attr| - define_method("#{attr}=") do |val| - send("#{attr}_will_change!") unless val == send(attr) - instance_variable_set("@#{attr}", val) + define_method(:"#{attr}=") do |val| + send(:"#{attr}_will_change!") unless val == send(attr) + instance_variable_set(:"@#{attr}", val) end end @@ -232,7 +243,7 @@ def destroy end def assign_attrs(**attrs) - attrs.each { |attr, value| send("#{attr}=", value) } + attrs.each { |attr, value| send(:"#{attr}=", value) } end end end diff --git a/spec/lib/journaled/connection_spec.rb b/spec/lib/journaled/connection_spec.rb index 332cf63..3e6deeb 100644 --- a/spec/lib/journaled/connection_spec.rb +++ b/spec/lib/journaled/connection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Journaled::Connection do diff --git a/spec/lib/journaled_spec.rb b/spec/lib/journaled_spec.rb index e09cfb7..914ed69 100644 --- a/spec/lib/journaled_spec.rb +++ b/spec/lib/journaled_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Journaled do diff --git a/spec/models/concerns/journaled/actor_spec.rb b/spec/models/concerns/journaled/actor_spec.rb index ee34a25..a59f8cd 100644 --- a/spec/models/concerns/journaled/actor_spec.rb +++ b/spec/models/concerns/journaled/actor_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' # This is a controller mixin, but testing as a model spec! diff --git a/spec/models/concerns/journaled/changes_spec.rb b/spec/models/concerns/journaled/changes_spec.rb index 91ea6c0..738043c 100644 --- a/spec/models/concerns/journaled/changes_spec.rb +++ b/spec/models/concerns/journaled/changes_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Journaled::Changes do diff --git a/spec/models/database_change_protection_spec.rb b/spec/models/database_change_protection_spec.rb index ae61658..de8b79b 100644 --- a/spec/models/database_change_protection_spec.rb +++ b/spec/models/database_change_protection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' if Rails::VERSION::MAJOR > 5 || (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2) diff --git a/spec/models/journaled/actor_uri_provider_spec.rb b/spec/models/journaled/actor_uri_provider_spec.rb index da81444..c060822 100644 --- a/spec/models/journaled/actor_uri_provider_spec.rb +++ b/spec/models/journaled/actor_uri_provider_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Journaled::ActorUriProvider do diff --git a/spec/models/journaled/change_writer_spec.rb b/spec/models/journaled/change_writer_spec.rb index c86d572..f56202a 100644 --- a/spec/models/journaled/change_writer_spec.rb +++ b/spec/models/journaled/change_writer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Journaled::ChangeWriter do diff --git a/spec/models/journaled/event_spec.rb b/spec/models/journaled/event_spec.rb index 68641cb..6f60746 100644 --- a/spec/models/journaled/event_spec.rb +++ b/spec/models/journaled/event_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Journaled::Event do diff --git a/spec/models/journaled/json_schema_model/validator_spec.rb b/spec/models/journaled/json_schema_model/validator_spec.rb index 2b4be79..3f64b70 100644 --- a/spec/models/journaled/json_schema_model/validator_spec.rb +++ b/spec/models/journaled/json_schema_model/validator_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Journaled::JsonSchemaModel::Validator do diff --git a/spec/models/journaled/writer_spec.rb b/spec/models/journaled/writer_spec.rb index b04d984..5e548c6 100644 --- a/spec/models/journaled/writer_spec.rb +++ b/spec/models/journaled/writer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Journaled::Writer do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 77c149f..735fc9d 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test' require 'spec_helper' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c2d3eeb..639fd6d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + rails_env = ENV['RAILS_ENV'] ||= 'test' require 'uncruft' require 'active_support/testing/time_helpers' diff --git a/spec/support/environment_spec_helper.rb b/spec/support/environment_spec_helper.rb index 12bd4ca..6e8edc1 100644 --- a/spec/support/environment_spec_helper.rb +++ b/spec/support/environment_spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EnvironmentSpecHelper def with_env(opts = {}) old = {}