Skip to content

Commit

Permalink
Add support for Rails 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki24 committed Sep 24, 2023
1 parent 379aeed commit bbedccb
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- rails60
- rails61
- rails70
- rails71
db: [POSTGRES, MYSQL, SQLITE]
exclude:
# MySQL has issues on Ruby 2.3
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,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
2 changes: 1 addition & 1 deletion audited.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions gemfiles/rails71.gemfile
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: "../"
3 changes: 2 additions & 1 deletion lib/audited.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] ||= {}
Expand Down
6 changes: 5 additions & 1 deletion lib/audited/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 1 addition & 1 deletion spec/audited/audit_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 24 additions & 1 deletion spec/rails_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion spec/support/active_record/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit bbedccb

Please sign in to comment.