Skip to content

Commit 09e26d0

Browse files
authored
Merge pull request #709 from voxik/ruby-3.4
Ruby 3.4 `Hash#inspect` compatibility.
2 parents 3b65f65 + 2af0b5b commit 09e26d0

File tree

11 files changed

+65
-18
lines changed

11 files changed

+65
-18
lines changed

.github/workflows/ruby.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,35 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
ruby_version: [3.3, 3.2, 3.1, '3.0', jruby]
20+
ruby_version: [head, 3.3, 3.2, 3.1, '3.0', jruby]
2121
gemfile:
2222
- Gemfile
2323
- gemfiles/Gemfile.rails-6.0.x
2424
- gemfiles/Gemfile.rails-6.1.x
2525
- gemfiles/Gemfile.rails-7.0.x
2626
- gemfiles/Gemfile.rails-7.1.x
27+
- gemfiles/Gemfile.rails-7.2.x
28+
- gemfiles/Gemfile.rails-8.0.x
2729
- gemfiles/Gemfile.rails-main
2830
exclude:
29-
# Ruby 3.0 is not supported by Rails main (requires at least Ruby 3.1)
31+
# Rails 8+ requires at least Ruby 3.2
32+
- ruby_version: '3.1'
33+
gemfile: gemfiles/Gemfile.rails-main
3034
- ruby_version: '3.0'
3135
gemfile: gemfiles/Gemfile.rails-main
36+
- ruby_version: '3.1'
37+
gemfile: gemfiles/Gemfile.rails-8.0.x
38+
- ruby_version: '3.0'
39+
gemfile: gemfiles/Gemfile.rails-8.0.x
40+
# Rails 7.2.x requires at least Ruby 3.1
41+
- ruby_version: '3.0'
42+
gemfile: gemfiles/Gemfile.rails-7.2.x
3243
# JRuby is not supported by Rails 7.0.x
3344
- ruby_version: jruby
3445
gemfile: gemfiles/Gemfile.rails-7.0.x
35-
# JRuby is not supported by Rails main
46+
# JRuby is not supported by Rails 8+
47+
- ruby_version: jruby
48+
gemfile: gemfiles/Gemfile.rails-8.0.x
3649
- ruby_version: jruby
3750
gemfile: gemfiles/Gemfile.rails-main
3851

gemfiles/Gemfile.rails-6.1.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ gem 'test_declarative', '0.0.6'
88
gem 'rake'
99
gem 'minitest', '~> 5.14'
1010
gem 'racc'
11+
gem 'base64'
12+
gem 'mutex_m'
1113

1214
platforms :mri do
1315
gem 'oj'

gemfiles/Gemfile.rails-7.2.x

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec :path => '..'
4+
5+
gem 'activesupport', '~> 7.2'
6+
gem 'mocha', '~> 2'
7+
gem 'test_declarative', '0.0.6'
8+
gem 'rake'
9+
gem 'minitest', '~> 5.1'
10+
gem 'racc'
11+
12+
platforms :mri do
13+
gem 'oj'
14+
end

gemfiles/Gemfile.rails-8.0.x

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec :path => '..'
4+
5+
gem 'activesupport', '~> 8.0'
6+
gem 'mocha', '~> 2'
7+
gem 'test_declarative', '0.0.6'
8+
gem 'rake'
9+
gem 'minitest', '~> 5.1'
10+
gem 'racc'
11+
12+
platforms :mri do
13+
gem 'oj'
14+
end

lib/i18n/tests/localization/procs.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Procs
3434
test "localize Date: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
3535
setup_time_proc_translations
3636
date = ::Date.new(2008, 3, 1)
37-
assert_equal '[Sat, 01 Mar 2008, {:foo=>"foo"}]', I18n.l(date, :format => :proc, :foo => 'foo', :locale => :ru)
37+
assert_equal %|[Sat, 01 Mar 2008, #{{:foo=>"foo"}}]|, I18n.l(date, :format => :proc, :foo => 'foo', :locale => :ru)
3838
end
3939

4040
test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object" do
@@ -46,7 +46,7 @@ module Procs
4646
test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
4747
setup_time_proc_translations
4848
datetime = ::DateTime.new(2008, 3, 1, 6)
49-
assert_equal '[Sat, 01 Mar 2008 06:00:00 +00:00, {:foo=>"foo"}]', I18n.l(datetime, :format => :proc, :foo => 'foo', :locale => :ru)
49+
assert_equal %|[Sat, 01 Mar 2008 06:00:00 +00:00, #{{:foo=>"foo"}}]|, I18n.l(datetime, :format => :proc, :foo => 'foo', :locale => :ru)
5050
end
5151

5252
test "localize Time: given a format that resolves to a Proc it calls the Proc with the object" do

lib/i18n/tests/procs.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,38 @@ module Tests
55
module Procs
66
test "lookup: given a translation is a proc it calls the proc with the key and interpolation values" do
77
I18n.backend.store_translations(:en, :a_lambda => lambda { |*args| I18n::Tests::Procs.filter_args(*args) })
8-
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo')
8+
assert_equal %|[:a_lambda, #{{:foo=>"foo"}}]|, I18n.t(:a_lambda, :foo => 'foo')
99
end
1010

1111
test "lookup: given a translation is a proc it passes the interpolation values as keyword arguments" do
1212
I18n.backend.store_translations(:en, :a_lambda => lambda { |key, foo:, **| I18n::Tests::Procs.filter_args(key, foo: foo) })
13-
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(:a_lambda, :foo => 'foo')
13+
assert_equal %|[:a_lambda, #{{:foo=>"foo"}}]|, I18n.t(:a_lambda, :foo => 'foo')
1414
end
1515

1616
test "defaults: given a default is a Proc it calls it with the key and interpolation values" do
1717
proc = lambda { |*args| I18n::Tests::Procs.filter_args(*args) }
18-
assert_equal '[nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
18+
assert_equal %|[nil, #{{:foo=>"foo"}}]|, I18n.t(nil, :default => proc, :foo => 'foo')
1919
end
2020

2121
test "defaults: given a default is a key that resolves to a Proc it calls it with the key and interpolation values" do
2222
the_lambda = lambda { |*args| I18n::Tests::Procs.filter_args(*args) }
2323
I18n.backend.store_translations(:en, :a_lambda => the_lambda)
24-
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => :a_lambda, :foo => 'foo')
25-
assert_equal '[:a_lambda, {:foo=>"foo"}]', I18n.t(nil, :default => [nil, :a_lambda], :foo => 'foo')
24+
assert_equal %|[:a_lambda, #{{:foo=>"foo"}}]|, I18n.t(nil, :default => :a_lambda, :foo => 'foo')
25+
assert_equal %|[:a_lambda, #{{:foo=>"foo"}}]|, I18n.t(nil, :default => [nil, :a_lambda], :foo => 'foo')
2626
end
2727

2828
test "interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do
2929
proc = lambda { |*args| I18n::Tests::Procs.filter_args(*args) }
30-
assert_match %r(\[\{:foo=>#<Proc.*>\}\]), I18n.t(nil, :default => '%{foo}', :foo => proc)
30+
if RUBY_VERSION < "3.4"
31+
assert_match %r(\[\{:foo=>#<Proc.*>\}\]), I18n.t(nil, :default => '%{foo}', :foo => proc)
32+
else
33+
assert_match %r(\[\{foo: #<Proc.*>\}\]), I18n.t(nil, :default => '%{foo}', :foo => proc)
34+
end
3135
end
3236

3337
test "interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do
3438
proc = lambda { |*args| "%{foo}: " + I18n::Tests::Procs.filter_args(*args) }
35-
assert_equal 'foo: [nil, {:foo=>"foo"}]', I18n.t(nil, :default => proc, :foo => 'foo')
39+
assert_equal %|foo: [nil, #{{:foo=>"foo"}}]|, I18n.t(nil, :default => proc, :foo => 'foo')
3640
end
3741

3842
test "pluralization: given a key resolves to a Proc that returns valid data then pluralization still works" do

test/backend/exceptions_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ def setup
3131

3232
test "exceptions: MissingInterpolationArgument message includes missing key, provided keys and full string" do
3333
exception = I18n::MissingInterpolationArgument.new('key', {:this => 'was given'}, 'string')
34-
assert_equal 'missing interpolation argument "key" in "string" ({:this=>"was given"} given)', exception.message
34+
assert_equal %|missing interpolation argument "key" in "string" (#{{:this=>"was given"}} given)|, exception.message
3535
end
3636
end

test/backend/interpolation_compiler_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_custom_missing_interpolation_argument_handler
8888
I18n.config.missing_interpolation_argument_handler = lambda do |key, values, string|
8989
"missing key is #{key}, values are #{values.inspect}, given string is '#{string}'"
9090
end
91-
assert_equal %|first missing key is last, values are {:first=>"first"}, given string is '%{first} %{last}'|,
91+
assert_equal %|first missing key is last, values are #{{:first=>"first"}.to_s}, given string is '%{first} %{last}'|,
9292
compile_and_interpolate('%{first} %{last}', :first => 'first')
9393
ensure
9494
I18n.config.missing_interpolation_argument_handler = old_handler

test/i18n/exceptions_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_invalid_locale_stores_locale
4343
test "InvalidPluralizationData message contains count, data and missing key" do
4444
force_invalid_pluralization_data do |exception|
4545
assert_match '1', exception.message
46-
assert_match '{:other=>"bar"}', exception.message
46+
assert_match %|#{{:other=>"bar"}}|, exception.message
4747
assert_match 'one', exception.message
4848
end
4949
end
@@ -58,7 +58,7 @@ def test_invalid_locale_stores_locale
5858

5959
test "MissingInterpolationArgument message contains the missing and given arguments" do
6060
force_missing_interpolation_argument do |exception|
61-
assert_equal 'missing interpolation argument :bar in "%{bar}" ({:baz=>"baz"} given)', exception.message
61+
assert_equal %|missing interpolation argument :bar in "%{bar}" (#{{:baz=>"baz"}.to_s} given)|, exception.message
6262
end
6363
end
6464

test/i18n/interpolate_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def teardown
9191
end
9292

9393
test "String interpolation can use custom missing interpolation handler" do
94-
assert_equal %|Masao missing key is last, values are {:first=>"Masao"}, given string is '%{first} %{last}'|,
94+
assert_equal %|Masao missing key is last, values are #{{:first=>"Masao"}.to_s}, given string is '%{first} %{last}'|,
9595
I18n.interpolate("%{first} %{last}", :first => 'Masao')
9696
end
9797
end

0 commit comments

Comments
 (0)