-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Rails 7.1 #686
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: "../" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be better to use Gem::Version.new(Rails.version) >= Gem::Version.new("7.1") see [8] pry(main)> Rails.version > "10.2.3"
=> true
[9] pry(main)> Gem::Version.new(Rails.version) >= Gem::Version.new("10.2.3")
=> false There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. String version comparison is bad, agreed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for pointing this out! |
||
serialize :audited_changes, coder: YAMLIfTextColumnType | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This addresses the deprecation warning below:
|
||
else | ||
serialize :audited_changes, YAMLIfTextColumnType | ||
end | ||
|
||
scope :ascending, -> { reorder(version: :asc) } | ||
scope :descending, -> { reorder(version: :desc) } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently the elements of permitted classes need to be actual class objects rather than strings. Otherwise there would be a nuch of failing tests with the error message below:
I have taken a look at Psych's code, and it does seem like that this has always been class objects rather than strings. Not sure where the original setting has derived, but either way, this should fix the test for Rails 7.1. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This addresses:
|
||
end | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This addresses:
|
||
else | ||
serialize :phone_numbers, Array | ||
end | ||
|
||
def name=(val) | ||
write_attribute(:name, CGI.escapeHTML(val)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This addresses: