diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8d8780..599e7df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,7 +36,7 @@ jobs: strategy: fail-fast: true matrix: - ruby: [2.5, 2.6, 2.7, '3.0', 3.1, 'head'] + ruby: [2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 'head'] rails: [4, 5, 6, 7, 'head'] exclude: - ruby: 2.5 @@ -57,6 +57,10 @@ jobs: rails: 4 - ruby: 3.1 rails: 5 + - ruby: 3.2 + rails: 4 + - ruby: 3.2 + rails: 5 - ruby: head rails: 4 - ruby: head diff --git a/Appraisals b/Appraisals index 9e53280..7e5679c 100644 --- a/Appraisals +++ b/Appraisals @@ -9,6 +9,7 @@ end appraise 'rails-5' do gem 'activerecord', '~> 5.2.0' + gem 'psych', '~> 3.1' end appraise 'rails-6' do diff --git a/gemfiles/rails_5.gemfile b/gemfiles/rails_5.gemfile index 00f7399..6afa2dc 100644 --- a/gemfiles/rails_5.gemfile +++ b/gemfiles/rails_5.gemfile @@ -6,5 +6,6 @@ gem "activerecord", "~> 5.2.0" gem "mysql2" gem "pg" gem "sqlite3" +gem "psych", "~> 3.1" gemspec path: "../" diff --git a/lib/i18n/backend/active_record/translation.rb b/lib/i18n/backend/active_record/translation.rb index ee03a64..66bd58b 100644 --- a/lib/i18n/backend/active_record/translation.rb +++ b/lib/i18n/backend/active_record/translation.rb @@ -53,8 +53,14 @@ class Translation < ::ActiveRecord::Base self.table_name = 'translations' - serialize :value - serialize :interpolations, Array + if ::ActiveRecord.version >= Gem::Version.new('7.1.0.alpha') + serialize :value, coder: YAML + serialize :interpolations, coder: YAML, type: Array + else + serialize :value + serialize :interpolations, Array + end + after_commit :invalidate_translations_cache class << self diff --git a/test/active_record_test.rb b/test/active_record_test.rb index 95170ae..612b3ca 100644 --- a/test/active_record_test.rb +++ b/test/active_record_test.rb @@ -123,7 +123,7 @@ def setup I18n.t('.') # Fixes test flakiness by loading available locales I18n::Backend::ActiveRecord::Translation.destroy_all - assert_equal 'translation missing: en.no key', I18n.t('.') + assert_match(/[Tt]ranslation missing: en\.no key/, I18n.t('.')) end test 'intially unitinitialized' do diff --git a/test/test_helper.rb b/test/test_helper.rb index 7a1b4e7..54885f2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,15 +10,15 @@ begin require 'active_record' - ::ActiveRecord::Base.connection + ActiveRecord::Base.connection rescue LoadError => e puts "can't use ActiveRecord backend because: #{e.message}" -rescue ::ActiveRecord::ConnectionNotEstablished +rescue ActiveRecord::ConnectionNotEstablished require 'i18n/backend/active_record' case ENV.fetch('DB', nil) when 'postgres' - ::ActiveRecord::Base.establish_connection( + ActiveRecord::Base.establish_connection( adapter: 'postgresql', database: 'i18n_unittest', username: ENV.fetch('PG_USER', 'postgres'), @@ -26,7 +26,7 @@ host: 'localhost' ) when 'mysql' - ::ActiveRecord::Base.establish_connection( + ActiveRecord::Base.establish_connection( adapter: 'mysql2', database: 'i18n_unittest', username: ENV.fetch('MYSQL_USER', 'root'), @@ -34,11 +34,11 @@ host: '127.0.0.1' ) else - ::ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' + ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' end - ::ActiveRecord::Migration.verbose = false - ::ActiveRecord::Schema.define(version: 1) do + ActiveRecord::Migration.verbose = false + ActiveRecord::Schema.define(version: 1) do create_table :translations, force: true do |t| t.string :locale t.string :key @@ -48,6 +48,12 @@ end add_index :translations, %i[locale key], unique: true end + + if ActiveRecord::Base.respond_to?(:yaml_column_permitted_classes=) + ActiveRecord::Base.yaml_column_permitted_classes = [Symbol] + elsif ActiveRecord.respond_to?(:yaml_column_permitted_classes=) + ActiveRecord.yaml_column_permitted_classes = [Symbol] + end end TEST_CASE = defined?(Minitest::Test) ? Minitest::Test : MiniTest::Unit::TestCase