Skip to content
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.0.alpha+ #142

Merged
merged 9 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ end

appraise 'rails-5' do
gem 'activerecord', '~> 5.2.0'
gem 'psych', '~> 3.1'
end

appraise 'rails-6' do
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ gem "activerecord", "~> 5.2.0"
gem "mysql2"
gem "pg"
gem "sqlite3"
gem "psych", "~> 3.1"

gemspec path: "../"
10 changes: 8 additions & 2 deletions lib/i18n/backend/active_record/translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/active_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@

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'),
password: ENV.fetch('PG_PASSWORD', 'postgres'),
host: 'localhost'
)
when 'mysql'
::ActiveRecord::Base.establish_connection(
ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
database: 'i18n_unittest',
username: ENV.fetch('MYSQL_USER', 'root'),
password: ENV.fetch('MYSQL_PASSWORD', ''),
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
Expand All @@ -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
Expand Down
Loading