From 05efa80feb263c4fac4a0dba0fea776d6fcd2988 Mon Sep 17 00:00:00 2001 From: Weston Ganger Date: Tue, 17 Oct 2023 13:30:58 -0700 Subject: [PATCH] Fix SchemaMigration parent class mismatch for Rails 7.1 --- CHANGELOG.md | 2 +- lib/active_record/mass_assignment_security.rb | 6 ++++-- test/attribute_sanitization_test.rb | 8 +------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65ce8dc..357b0f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -* Nothing yet +* [#31](https://github.com/westonganger/protected_attributes_continued/pull/31) - Fix SchemaMigration parent class mistmatch for Rails 7.1+ * [View Full Diff](https://github.com/westonganger/protected_attributes_continued/compare/v1.8.2...master) ## v1.8.2 - 2021-07-13 diff --git a/lib/active_record/mass_assignment_security.rb b/lib/active_record/mass_assignment_security.rb index 4c6edaf..f37b691 100644 --- a/lib/active_record/mass_assignment_security.rb +++ b/lib/active_record/mass_assignment_security.rb @@ -21,6 +21,8 @@ class ActiveRecord::Base include ActiveRecord::MassAssignmentSecurity::Inheritance end -class ActiveRecord::SchemaMigration < ActiveRecord::Base - attr_accessible :version +if ActiveRecord.version <= Gem::Version.new("7.0") + class ActiveRecord::SchemaMigration < ActiveRecord::Base + attr_accessible :version + end end diff --git a/test/attribute_sanitization_test.rb b/test/attribute_sanitization_test.rb index 237989f..0102f02 100644 --- a/test/attribute_sanitization_test.rb +++ b/test/attribute_sanitization_test.rb @@ -254,13 +254,7 @@ def test_create_with_bang_with_without_protection_with_attr_protected_attributes def test_protection_against_class_attribute_writers attribute_writers = [:logger, :configurations, :primary_key_prefix_type, :table_name_prefix, :table_name_suffix, :pluralize_table_names, :lock_optimistically, :default_scopes, :connection_handler, :nested_attributes_options, - :attribute_method_matchers, :time_zone_aware_attributes, :skip_time_zone_conversion_for_attributes] - - if Rails::VERSION::MAJOR <= 6 - attribute_writers += [:default_timezone, :schema_format, :timestamped_migrations] - end - - attribute_writers.push(:_attr_readonly) if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0 + :time_zone_aware_attributes, :skip_time_zone_conversion_for_attributes] attribute_writers.each do |method| assert_respond_to Task, method