diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 432e09a4..6e9cdf84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,7 @@ jobs: - rails60 - rails61 - rails70 + - rails71 db: [POSTGRES, MYSQL, SQLITE] exclude: # MySQL has issues on Ruby 2.3 @@ -96,6 +97,16 @@ jobs: - appraisal: rails70 ruby: 2.6 + # Rails 7.1 supports Ruby 2.7+ + - appraisal: rails71 + ruby: 2.3 + - appraisal: rails71 + ruby: 2.4 + - appraisal: rails71 + ruby: 2.5 + - appraisal: rails71 + ruby: 2.6 + services: postgres: image: postgres diff --git a/Appraisals b/Appraisals index e41dacfa..e724b7b4 100644 --- a/Appraisals +++ b/Appraisals @@ -7,6 +7,7 @@ appraise "rails50" do gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.3.6" gem "psych", "~> 3.1" + gem "loofah", "2.20.0" end appraise "rails51" do @@ -15,6 +16,7 @@ appraise "rails51" do gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.3.6" gem "psych", "~> 3.1" + gem "loofah", "2.20.0" end appraise "rails52" do @@ -23,6 +25,7 @@ appraise "rails52" do gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.3.6" gem "psych", "~> 3.1" + gem "loofah", "2.20.0" end appraise "rails60" do @@ -45,3 +48,10 @@ appraise "rails70" do gem "pg", ">= 1.1" gem "sqlite3", ">= 1.4" end + +appraise "rails71" do + gem "rails", ">= 7.1.0.beta1", "< 7.2" + gem "mysql2", ">= 0.4.4" + gem "pg", ">= 1.1" + gem "sqlite3", ">= 1.4" +end diff --git a/audited.gemspec b/audited.gemspec index fdcf636e..74638004 100644 --- a/audited.gemspec +++ b/audited.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |gem| gem.required_ruby_version = ">= 2.3.0" - gem.add_dependency "activerecord", ">= 5.0", "< 7.1" + gem.add_dependency "activerecord", ">= 5.0", "< 7.2" gem.add_dependency "request_store", "~> 1.2" gem.add_development_dependency "appraisal" diff --git a/gemfiles/rails50.gemfile b/gemfiles/rails50.gemfile index 250ead6a..92d5f8c4 100644 --- a/gemfiles/rails50.gemfile +++ b/gemfiles/rails50.gemfile @@ -7,5 +7,6 @@ gem "mysql2", ">= 0.3.18", "< 0.6.0" gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.3.6" gem "psych", "~> 3.1" +gem "loofah", "2.20.0" gemspec name: "audited", path: "../" diff --git a/gemfiles/rails51.gemfile b/gemfiles/rails51.gemfile index 40dc0bae..fa43c66f 100644 --- a/gemfiles/rails51.gemfile +++ b/gemfiles/rails51.gemfile @@ -7,5 +7,6 @@ gem "mysql2", ">= 0.3.18", "< 0.6.0" gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.3.6" gem "psych", "~> 3.1" +gem "loofah", "2.20.0" gemspec name: "audited", path: "../" diff --git a/gemfiles/rails52.gemfile b/gemfiles/rails52.gemfile index 9bbc2592..b8d7a12b 100644 --- a/gemfiles/rails52.gemfile +++ b/gemfiles/rails52.gemfile @@ -7,5 +7,6 @@ gem "mysql2", ">= 0.4.4", "< 0.6.0" gem "pg", ">= 0.18", "< 2.0" gem "sqlite3", "~> 1.3.6" gem "psych", "~> 3.1" +gem "loofah", "2.20.0" gemspec name: "audited", path: "../" diff --git a/gemfiles/rails71.gemfile b/gemfiles/rails71.gemfile new file mode 100644 index 00000000..e34fc967 --- /dev/null +++ b/gemfiles/rails71.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", ">= 7.1.0.beta1", "< 7.2" +gem "mysql2", ">= 0.4.4" +gem "pg", ">= 1.1" +gem "sqlite3", ">= 1.4" + +gemspec name: "audited", path: "../" diff --git a/lib/audited.rb b/lib/audited.rb index d548711e..7f500d3d 100644 --- a/lib/audited.rb +++ b/lib/audited.rb @@ -22,7 +22,8 @@ def audit_class # remove audit_model in next major version it was only shortly present in 5.1.0 alias_method :audit_model, :audit_class - deprecate audit_model: "use Audited.audit_class instead of Audited.audit_model. This method will be removed." + deprecate audit_model: "use Audited.audit_class instead of Audited.audit_model. This method will be removed.", + deprecator: ActiveSupport::Deprecation.new('6.0.0', 'Audited') def store RequestStore.store[:audited_store] ||= {} diff --git a/lib/audited/audit.rb b/lib/audited/audit.rb index 7201adac..7117d19c 100644 --- a/lib/audited/audit.rb +++ b/lib/audited/audit.rb @@ -49,7 +49,11 @@ class Audit < ::ActiveRecord::Base cattr_accessor :audited_class_names self.audited_class_names = Set.new - serialize :audited_changes, YAMLIfTextColumnType + if Rails.version >= "7.1" + serialize :audited_changes, coder: YAMLIfTextColumnType + else + serialize :audited_changes, YAMLIfTextColumnType + end scope :ascending, -> { reorder(version: :asc) } scope :descending, -> { reorder(version: :desc) } diff --git a/spec/audited/audit_spec.rb b/spec/audited/audit_spec.rb index 546bbe36..c18abdb5 100644 --- a/spec/audited/audit_spec.rb +++ b/spec/audited/audit_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -SingleCov.covered! uncovered: 1 # Rails version check +SingleCov.covered! uncovered: 2 # Rails version check class CustomAudit < Audited::Audit def custom_method diff --git a/spec/rails_app/config/application.rb b/spec/rails_app/config/application.rb index 7c2bec71..dca65709 100644 --- a/spec/rails_app/config/application.rb +++ b/spec/rails_app/config/application.rb @@ -5,11 +5,34 @@ class Application < Rails::Application config.root = File.expand_path("../../", __FILE__) config.i18n.enforce_available_locales = true - if !Rails.version.start_with?("5.0") && !Rails.version.start_with?("5.1") && config.active_record.respond_to?(:yaml_column_permitted_classes=) + if Rails.version.start_with?("7.1") && config.active_record.respond_to?(:yaml_column_permitted_classes=) + config.active_record.yaml_column_permitted_classes = [ + String, + Symbol, + Integer, + NilClass, + Float, + Time, + Date, + FalseClass, + Hash, + Array, + DateTime, + TrueClass, + BigDecimal, + ActiveSupport::TimeWithZone, + ActiveSupport::TimeZone, + ActiveSupport::HashWithIndifferentAccess + ] + elsif !Rails.version.start_with?("5.0") && !Rails.version.start_with?("5.1") && config.active_record.respond_to?(:yaml_column_permitted_classes=) config.active_record.yaml_column_permitted_classes = %w[String Symbol Integer NilClass Float Time Date FalseClass Hash Array DateTime TrueClass BigDecimal ActiveSupport::TimeWithZone ActiveSupport::TimeZone ActiveSupport::HashWithIndifferentAccess] end + + if Rails.version >= "7.1" + config.active_support.cache_format_version = 7.1 + end end end diff --git a/spec/support/active_record/models.rb b/spec/support/active_record/models.rb index 5c5def30..9acceb43 100644 --- a/spec/support/active_record/models.rb +++ b/spec/support/active_record/models.rb @@ -8,7 +8,12 @@ class User < ::ActiveRecord::Base attribute :non_column_attr if Rails.version >= "5.1" attr_protected :logins if respond_to?(:attr_protected) enum status: {active: 0, reliable: 1, banned: 2} - serialize :phone_numbers, Array + + if Rails.version >= "7.1" + serialize :phone_numbers, type: Array + else + serialize :phone_numbers, Array + end def name=(val) write_attribute(:name, CGI.escapeHTML(val))