From d480eb8cbb2840dd71584fff3343912678fd6d9b Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 12:19:11 +0100 Subject: [PATCH 01/42] Activate Github Actions --- .github/workflows/test.yml | 48 ++++++++++++++++++++++++++++++++++++++ test/test_helper.rb | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..15b528b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,48 @@ +name: CI Tests + +on: + push: + branches: [master] + pull_request: + branches: ['**'] + +jobs: + test: + services: + postgres: + image: postgres + env: + POSTGRES_USER: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + mysql: + image: mysql:5.7 + env: + MYSQL_HOST: 127.0.0.1 + MYSQL_DB: i18n_unittest + MYSQL_USER: root + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_PASSWORD: '' + ports: + - "3306:3306" + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest, macos-latest] + ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 'head'] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - run: bundle exec rake diff --git a/test/test_helper.rb b/test/test_helper.rb index f3197f2..23962b0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,7 +17,7 @@ require 'i18n/backend/active_record' case ENV['DB'] when 'postgres' - ::ActiveRecord::Base.establish_connection adapter: 'postgresql', database: 'i18n_unittest', username: ENV['PG_USER'] || 'i18n', password: '', host: 'localhost' + ::ActiveRecord::Base.establish_connection adapter: 'postgresql', database: 'i18n_unittest', username: ENV['PG_USER'] || 'postgres', password: '', host: 'localhost' when 'mysql' ::ActiveRecord::Base.establish_connection adapter: 'mysql2', database: 'i18n_unittest', username: 'root', password: '', host: 'localhost' else From bcba7e6439284cda79a9e135d7cb5a959a156a61 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 12:24:53 +0100 Subject: [PATCH 02/42] Use ruby 2.7 for the time being --- .github/workflows/test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15b528b..353b41e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,8 +36,10 @@ jobs: strategy: fail-fast: true matrix: - os: [ubuntu-latest, macos-latest] - ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 'head'] + # os: [ubuntu-latest, macos-latest] + # ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 'head'] + os: [ubuntu-latest] + ruby: [2.7] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 From cf7adc1793a53ca3460f1b896bb9cbd37186ab5a Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 12:33:52 +0100 Subject: [PATCH 03/42] Postgres fixes --- .github/workflows/test.yml | 2 +- test/test_helper.rb | 30 +++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 353b41e..e315d4c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: postgres: image: postgres env: - POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres options: >- --health-cmd pg_isready --health-interval 10s diff --git a/test/test_helper.rb b/test/test_helper.rb index 23962b0..96c2726 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,32 +17,44 @@ require 'i18n/backend/active_record' case ENV['DB'] when 'postgres' - ::ActiveRecord::Base.establish_connection adapter: 'postgresql', database: 'i18n_unittest', username: ENV['PG_USER'] || 'postgres', password: '', host: 'localhost' + ::ActiveRecord::Base.establish_connection( + adapter: 'postgresql', + database: 'i18n_unittest', + username: ENV['PG_USER'] || 'postgres', + password: ENV['PG_PASSWORD'] || 'postgres', + host: 'localhost' + ) when 'mysql' - ::ActiveRecord::Base.establish_connection adapter: 'mysql2', database: 'i18n_unittest', username: 'root', password: '', host: 'localhost' + ::ActiveRecord::Base.establish_connection( + adapter: 'mysql2', + database: 'i18n_unittest', + username: 'root', + password: '', + host: 'localhost' + ) else ::ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' end ::ActiveRecord::Migration.verbose = false - ::ActiveRecord::Schema.define(:version => 1) do - create_table :translations, :force => true do |t| + ::ActiveRecord::Schema.define(version: 1) do + create_table :translations, force: true do |t| t.string :locale t.string :key t.text :value t.text :interpolations - t.boolean :is_proc, :default => false + t.boolean :is_proc, default: false end - add_index :translations, [:locale, :key], :unique => true + add_index :translations, [:locale, :key], unique: true end end TEST_CASE = defined?(Minitest::Test) ? Minitest::Test : MiniTest::Unit::TestCase class TEST_CASE - alias :assert_raise :assert_raises - alias :assert_not_equal :refute_equal + alias assert_raise assert_raises + alias assert_not_equal refute_equal - def assert_nothing_raised(*args) + def assert_nothing_raised(*_args) yield end end From 0b6ff226516a07ebc5e4122b26654e008918af7c Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 12:57:12 +0100 Subject: [PATCH 04/42] MySQL fixes --- .github/workflows/test.yml | 7 ++----- test/test_helper.rb | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e315d4c..685d09c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,13 +21,10 @@ jobs: mysql: image: mysql:5.7 env: - MYSQL_HOST: 127.0.0.1 MYSQL_DB: i18n_unittest - MYSQL_USER: root - MYSQL_ALLOW_EMPTY_PASSWORD: yes - MYSQL_PASSWORD: '' + MYSQL_ALLOW_EMPTY_PASSWORD: true ports: - - "3306:3306" + - '3306:3306' options: >- --health-cmd="mysqladmin ping" --health-interval=10s diff --git a/test/test_helper.rb b/test/test_helper.rb index 96c2726..2d0058c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -28,8 +28,8 @@ ::ActiveRecord::Base.establish_connection( adapter: 'mysql2', database: 'i18n_unittest', - username: 'root', - password: '', + username: ENV['MYSQL_USER'] || 'root', + password: ENV['MYSQL_PASSWORD'] || '', host: 'localhost' ) else From 2503c59de6fa713494af5f849297b01528d9f45a Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 13:08:46 +0100 Subject: [PATCH 05/42] bundle install --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8990895..efd1940 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - i18n-active_record (0.4.0) + i18n-active_record (0.4.1) i18n (>= 0.5.0) GEM @@ -48,4 +48,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 2.1.4 + 2.2.29 From 416db5cc3389ea0fff3b08f39adaafb6bfa7b470 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 13:20:35 +0100 Subject: [PATCH 06/42] Gemfile clean up --- Gemfile.lock | 7 ++++--- test/test_helper.rb | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index efd1940..db4dd7b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,12 +22,13 @@ GEM i18n (1.8.10) concurrent-ruby (~> 1.0) minitest (5.14.4) - mocha (1.12.0) + mocha (1.2.1) + metaclass (~> 0.0.1) mysql2 (0.5.3) pg (1.2.3) - rake (13.0.3) + rake (13.0.1) sqlite3 (1.4.2) - test_declarative (0.0.6) + test_declarative (0.0.5) tzinfo (2.0.4) concurrent-ruby (~> 1.0) zeitwerk (2.4.2) diff --git a/test/test_helper.rb b/test/test_helper.rb index 2d0058c..48a6fbf 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,6 +15,7 @@ puts "can't use ActiveRecord backend because: #{e.message}" rescue ::ActiveRecord::ConnectionNotEstablished require 'i18n/backend/active_record' + case ENV['DB'] when 'postgres' ::ActiveRecord::Base.establish_connection( @@ -35,6 +36,7 @@ else ::ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' end + ::ActiveRecord::Migration.verbose = false ::ActiveRecord::Schema.define(version: 1) do create_table :translations, force: true do |t| From c09e1e0881310623d657db6506b989ae91dc34b2 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 13:48:49 +0100 Subject: [PATCH 07/42] Fix the execute status --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index f892328..1145591 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ require 'bundler/gem_tasks' def execute(command) puts command - system command + system command, exception: true end def bundle_options From 75971cbf055ae52ae21047ac124e7861b1a41e18 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 13:51:14 +0100 Subject: [PATCH 08/42] Expose PG port --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 685d09c..b8d7fda 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,8 @@ jobs: image: postgres env: POSTGRES_PASSWORD: postgres + ports: + - 5432:5432 options: >- --health-cmd pg_isready --health-interval 10s From d3ccc5032abddfaa337606fad3fce078fb65afac Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 13:55:04 +0100 Subject: [PATCH 09/42] Specify DB name --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8d7fda..34ae3e2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,6 +12,7 @@ jobs: postgres: image: postgres env: + POSTGRES_DB: i18n_unittest POSTGRES_PASSWORD: postgres ports: - 5432:5432 From c1cc37490d107e388c5e6387e47eb1dbdd88cd75 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 16:03:54 +0100 Subject: [PATCH 10/42] Start MySQL server --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 34ae3e2..3774aae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,4 +47,6 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - run: bundle exec rake + - run: | + sudo /etc/init.d/mysql start + bundle exec rake From 1aa82990be0240acc3a1c526f75ee850e42e3a5a Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Thu, 21 Oct 2021 16:55:33 +0100 Subject: [PATCH 11/42] Revert --- .github/workflows/test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3774aae..34ae3e2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,6 +47,4 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - run: | - sudo /etc/init.d/mysql start - bundle exec rake + - run: bundle exec rake From a85fcc975165b9837f7bb8b7a96faf6600aea180 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 11:55:10 +0100 Subject: [PATCH 12/42] Try 127.0.0.1 --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 48a6fbf..8039c70 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -31,7 +31,7 @@ database: 'i18n_unittest', username: ENV['MYSQL_USER'] || 'root', password: ENV['MYSQL_PASSWORD'] || '', - host: 'localhost' + host: '127.0.0.1' ) else ::ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' From 6d9cf89a0d57855d9414b1d45489c6fb4f96f8c3 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 12:04:21 +0100 Subject: [PATCH 13/42] Use MYSQL_DATABASE --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 34ae3e2..28bba1e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: mysql: image: mysql:5.7 env: - MYSQL_DB: i18n_unittest + MYSQL_DATABASE: i18n_unittest MYSQL_ALLOW_EMPTY_PASSWORD: true ports: - '3306:3306' From 1d7960a828c96432f84a40cf8982677b6c94dfed Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 13:37:41 +0100 Subject: [PATCH 14/42] Clean up tests a bit --- lib/i18n/backend/active_record/missing.rb | 2 +- test/active_record_test.rb | 40 +++++++++++++---------- test/missing_test.rb | 2 +- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/i18n/backend/active_record/missing.rb b/lib/i18n/backend/active_record/missing.rb index b04e92f..f493d28 100644 --- a/lib/i18n/backend/active_record/missing.rb +++ b/lib/i18n/backend/active_record/missing.rb @@ -36,7 +36,7 @@ module Missing include Flatten def store_default_translations(locale, key, options = {}) - count, scope, default, separator = options.values_at(:count, :scope, :default, :separator) + count, scope, _, separator = options.values_at(:count, :scope, :default, :separator) separator ||= I18n.default_separator key = normalize_flat_keys(locale, key, scope, separator) diff --git a/test/active_record_test.rb b/test/active_record_test.rb index 8b3dc9c..16ac26e 100644 --- a/test/active_record_test.rb +++ b/test/active_record_test.rb @@ -22,10 +22,9 @@ def setup end test "store_translations does not allow ambiguous keys (1)" do - I18n::Backend::ActiveRecord::Translation.delete_all - I18n.backend.store_translations(:en, :foo => 'foo') - I18n.backend.store_translations(:en, :foo => { :bar => 'bar' }) - I18n.backend.store_translations(:en, :foo => { :baz => 'baz' }) + store_translations(:en, :foo => 'foo') + store_translations(:en, :foo => { :bar => 'bar' }) + store_translations(:en, :foo => { :baz => 'baz' }) translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').all assert_equal %w(bar baz), translations.map(&:value) @@ -34,10 +33,9 @@ def setup end test "store_translations does not allow ambiguous keys (2)" do - I18n::Backend::ActiveRecord::Translation.delete_all - I18n.backend.store_translations(:en, :foo => { :bar => 'bar' }) - I18n.backend.store_translations(:en, :foo => { :baz => 'baz' }) - I18n.backend.store_translations(:en, :foo => 'foo') + store_translations(:en, :foo => { :bar => 'bar' }) + store_translations(:en, :foo => { :baz => 'baz' }) + store_translations(:en, :foo => 'foo') translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').all assert_equal %w(foo), translations.map(&:value) @@ -46,7 +44,8 @@ def setup end test "can store translations with keys that are translations containing special chars" do - I18n.backend.store_translations(:es, :"Pagina's" => "Pagina's" ) + store_translations(:es, :"Pagina's" => "Pagina's" ) + assert_equal "Pagina's", I18n.t(:"Pagina's", :locale => :es) end @@ -60,12 +59,11 @@ def setup end test "available_locales returns uniq locales" do - I18n::Backend::ActiveRecord::Translation.delete_all - I18n.backend.store_translations(:en, :foo => { :bar => 'bar' }) - I18n.backend.store_translations(:en, :foo => { :baz => 'baz' }) - I18n.backend.store_translations(:de, :foo1 => 'foo') - I18n.backend.store_translations(:de, :foo2 => 'foo') - I18n.backend.store_translations(:uk, :foo3 => 'foo') + store_translations(:en, :foo => { :bar => 'bar' }) + store_translations(:en, :foo => { :baz => 'baz' }) + store_translations(:de, :foo1 => 'foo') + store_translations(:de, :foo2 => 'foo') + store_translations(:uk, :foo3 => 'foo') available_locales = I18n::Backend::ActiveRecord::Translation.available_locales assert_equal 3, available_locales.size @@ -87,24 +85,27 @@ def setup end test "fetching subtree of translations" do - I18n::Backend::ActiveRecord::Translation.delete_all - I18n.backend.store_translations(:en, foo: { bar: { fizz: 'buzz', spuz: 'zazz' }, baz: { fizz: 'buzz' } }) + store_translations(:en, foo: { bar: { fizz: 'buzz', spuz: 'zazz' }, baz: { fizz: 'buzz' } }) + assert_equal I18n.t(:foo), { bar: { fizz: 'buzz', spuz: 'zazz' }, baz: { fizz: 'buzz' } } end test "build_translation_hash_by_key" do translation = I18n::Backend::ActiveRecord::Translation.new(value: 'translation', key: 'foo.bar.fizz.buzz') expected_hash = { 'bar' => { 'fizz' => { 'buzz' => 'translation' } } } + assert_equal I18n.backend.send(:build_translation_hash_by_key, 'foo', translation), expected_hash end test "returning all keys via ." do expected_hash = {:foo => { :bar => 'bar', :baz => 'baz' }} + assert_equal expected_hash, I18n.t('.') end test "accessing keys with a trailing/leading period" do expected_hash = { :bar => 'bar', :baz => 'baz' } + assert_equal expected_hash, I18n.t('foo') assert_equal expected_hash, I18n.t('.foo') assert_equal expected_hash, I18n.t('foo.') @@ -121,10 +122,13 @@ def setup test "intially unitinitialized" do refute I18n.backend.initialized? + I18n.backend.init_translations assert I18n.backend.initialized? + I18n.backend.reload! refute I18n.backend.initialized? + I18n.backend.init_translations assert I18n.backend.initialized? end @@ -132,12 +136,14 @@ def setup test "translations returns all translations" do expected_hash = { :en => { :foo => { :bar => 'bar', :baz => 'baz' } } } I18n.backend.init_translations + assert_equal expected_hash, I18n.backend.send(:translations) assert I18n.backend.initialized? end test "translations initialized with do_init argument" do expected_hash = { :en => { :foo => { :bar => 'bar', :baz => 'baz' } } } + refute I18n.backend.initialized? assert_equal expected_hash, I18n.backend.send(:translations, do_init: true) assert I18n.backend.initialized? diff --git a/test/missing_test.rb b/test/missing_test.rb index 3b68e88..8011af6 100644 --- a/test/missing_test.rb +++ b/test/missing_test.rb @@ -90,4 +90,4 @@ def setup I18n::Backend::ActiveRecord.config.cache_translations = true end end -end +end \ No newline at end of file From e7cd7f9293f5f0f07837968c5e7d27932855036c Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 14:55:06 +0100 Subject: [PATCH 15/42] Involve Gemfiles --- .github/workflows/test.yml | 6 ++++-- gemfiles/Gemfile.rails_3 | 2 +- gemfiles/Gemfile.rails_3.lock | 12 ++++++------ gemfiles/Gemfile.rails_4 | 2 +- gemfiles/Gemfile.rails_4.lock | 12 ++++++------ gemfiles/Gemfile.rails_5.lock | 4 ++-- gemfiles/Gemfile.rails_6.lock | 4 ++-- gemfiles/Gemfile.rails_head.lock | 28 +++++++++++++--------------- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 28bba1e..77e6a25 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,9 +38,11 @@ jobs: matrix: # os: [ubuntu-latest, macos-latest] # ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 'head'] - os: [ubuntu-latest] ruby: [2.7] - runs-on: ${{ matrix.os }} + rails_version: [3, 4, 5, 6, 'head'] + runs-on: ubuntu-latest + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.rails_${{ matrix.rails_version }} steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 diff --git a/gemfiles/Gemfile.rails_3 b/gemfiles/Gemfile.rails_3 index fbb82cf..3b205f0 100644 --- a/gemfiles/Gemfile.rails_3 +++ b/gemfiles/Gemfile.rails_3 @@ -5,7 +5,7 @@ gemspec path: '..' gem 'activerecord', '~> 3.2.0' gem 'sqlite3' gem 'mysql2' -gem 'pg', '~> 0.18.0' +gem 'pg' gem 'minitest' gem 'test_declarative' diff --git a/gemfiles/Gemfile.rails_3.lock b/gemfiles/Gemfile.rails_3.lock index ce2906c..e2cd51a 100644 --- a/gemfiles/Gemfile.rails_3.lock +++ b/gemfiles/Gemfile.rails_3.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n-active_record (0.4.0) + i18n-active_record (0.4.1) i18n (>= 0.5.0) GEM @@ -26,10 +26,10 @@ GEM mocha (1.2.1) metaclass (~> 0.0.1) multi_json (1.12.1) - mysql2 (0.4.5) - pg (0.18.4) + mysql2 (0.5.3) + pg (1.2.3) rake (13.0.1) - sqlite3 (1.3.13) + sqlite3 (1.4.2) test_declarative (0.0.5) tzinfo (0.3.52) @@ -43,10 +43,10 @@ DEPENDENCIES minitest mocha mysql2 - pg (~> 0.18.0) + pg rake sqlite3 test_declarative BUNDLED WITH - 2.0.2 + 2.2.16 diff --git a/gemfiles/Gemfile.rails_4 b/gemfiles/Gemfile.rails_4 index 772435c..616652e 100644 --- a/gemfiles/Gemfile.rails_4 +++ b/gemfiles/Gemfile.rails_4 @@ -5,7 +5,7 @@ gemspec path: '..' gem 'activerecord', '~> 4.2.0' gem 'sqlite3' gem 'mysql2' -gem 'pg', '~> 0.18.0' +gem 'pg' gem 'minitest' gem 'test_declarative' diff --git a/gemfiles/Gemfile.rails_4.lock b/gemfiles/Gemfile.rails_4.lock index 348a008..978a0fe 100644 --- a/gemfiles/Gemfile.rails_4.lock +++ b/gemfiles/Gemfile.rails_4.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n-active_record (0.4.0) + i18n-active_record (0.4.1) i18n (>= 0.5.0) GEM @@ -26,10 +26,10 @@ GEM minitest (5.10.1) mocha (1.2.1) metaclass (~> 0.0.1) - mysql2 (0.4.5) - pg (0.18.4) + mysql2 (0.5.3) + pg (1.2.3) rake (13.0.1) - sqlite3 (1.3.13) + sqlite3 (1.4.2) test_declarative (0.0.5) thread_safe (0.3.6) tzinfo (1.2.2) @@ -45,10 +45,10 @@ DEPENDENCIES minitest mocha mysql2 - pg (~> 0.18.0) + pg rake sqlite3 test_declarative BUNDLED WITH - 2.0.2 + 2.2.16 diff --git a/gemfiles/Gemfile.rails_5.lock b/gemfiles/Gemfile.rails_5.lock index 189dfa1..5bac9f8 100644 --- a/gemfiles/Gemfile.rails_5.lock +++ b/gemfiles/Gemfile.rails_5.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n-active_record (0.4.0) + i18n-active_record (0.4.1) i18n (>= 0.5.0) GEM @@ -49,4 +49,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 2.1.4 + 2.2.16 diff --git a/gemfiles/Gemfile.rails_6.lock b/gemfiles/Gemfile.rails_6.lock index 7b6c249..bdca0ac 100644 --- a/gemfiles/Gemfile.rails_6.lock +++ b/gemfiles/Gemfile.rails_6.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n-active_record (0.4.0) + i18n-active_record (0.4.1) i18n (>= 0.5.0) GEM @@ -48,4 +48,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 2.1.4 + 2.2.16 diff --git a/gemfiles/Gemfile.rails_head.lock b/gemfiles/Gemfile.rails_head.lock index c698fac..2f154b3 100644 --- a/gemfiles/Gemfile.rails_head.lock +++ b/gemfiles/Gemfile.rails_head.lock @@ -1,42 +1,40 @@ GIT remote: https://github.com/rails/rails - revision: a8c462d37c1e482fa0a0fc16014fc9ad1d97032f + revision: 2451a568aff34816f1df7bd92b158fb059771337 branch: main specs: - activemodel (7.0.0.alpha) - activesupport (= 7.0.0.alpha) - activerecord (7.0.0.alpha) - activemodel (= 7.0.0.alpha) - activesupport (= 7.0.0.alpha) - activesupport (7.0.0.alpha) + activemodel (7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + activerecord (7.0.0.alpha2) + activemodel (= 7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + activesupport (7.0.0.alpha2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) PATH remote: .. specs: - i18n-active_record (0.4.0) + i18n-active_record (0.4.1) i18n (>= 0.5.0) GEM remote: https://rubygems.org/ specs: - concurrent-ruby (1.1.8) - i18n (1.8.9) + concurrent-ruby (1.1.9) + i18n (1.8.10) concurrent-ruby (~> 1.0) minitest (5.14.4) - mocha (1.12.0) + mocha (1.13.0) mysql2 (0.5.3) pg (1.2.3) - rake (13.0.3) + rake (13.0.6) sqlite3 (1.4.2) test_declarative (0.0.6) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - zeitwerk (2.4.2) PLATFORMS ruby @@ -54,4 +52,4 @@ DEPENDENCIES test_declarative BUNDLED WITH - 2.1.4 + 2.2.16 From 3fb98225cf6a5dc3eb63d4820c835251806eba4d Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 15:02:06 +0100 Subject: [PATCH 16/42] Add exclude rule --- .github/workflows/test.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77e6a25..a6ae6d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,13 +36,27 @@ jobs: strategy: fail-fast: true matrix: - # os: [ubuntu-latest, macos-latest] # ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 'head'] ruby: [2.7] - rails_version: [3, 4, 5, 6, 'head'] + rails: [3, 4, 5, 6, 'head'] + exclude: + - ruby: 2.3 + rails: 6 + - ruby: 2.4 + rails: 6 + - ruby: 2.3 + rails: head + - ruby: 2.4 + rails: head + - ruby: 2.5 + rails: head + - ruby: 2.6 + rails: head + - ruby: 2.7 + rails: 3 runs-on: ubuntu-latest env: - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.rails_${{ matrix.rails_version }} + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.rails_${{ matrix.rails }} steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 From 4a97e5e9569b04d76bae1a3f91ea4aff53460641 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 15:08:38 +0100 Subject: [PATCH 17/42] More exclude rules --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a6ae6d1..9982226 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,6 +54,8 @@ jobs: rails: head - ruby: 2.7 rails: 3 + - ruby: 2.7 + rails: 4 runs-on: ubuntu-latest env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.rails_${{ matrix.rails }} From 476d9f937b372f0a1feb6ad934930cac3158d07c Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 15:13:57 +0100 Subject: [PATCH 18/42] More ruby versions --- .github/workflows/test.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9982226..9ed1ce3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,8 +36,7 @@ jobs: strategy: fail-fast: true matrix: - # ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 'head'] - ruby: [2.7] + ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 'head'] rails: [3, 4, 5, 6, 'head'] exclude: - ruby: 2.3 @@ -56,6 +55,14 @@ jobs: rails: 3 - ruby: 2.7 rails: 4 + - ruby: 3.0 + rails: 3 + - ruby: 3.0 + rails: 4 + - ruby: head + rails: 3 + - ruby: head + rails: 4 runs-on: ubuntu-latest env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.rails_${{ matrix.rails }} From d6233a29204878a92cb59a08aeedba9220e50914 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 15:19:09 +0100 Subject: [PATCH 19/42] Specify job name --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9ed1ce3..2a78d62 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,6 +63,7 @@ jobs: rails: 3 - ruby: head rails: 4 + name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.rails }}' runs-on: ubuntu-latest env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.rails_${{ matrix.rails }} From 7f5dfe6f21e63f5a02f1a2e72286b65d41a93cdc Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 15:41:08 +0100 Subject: [PATCH 20/42] exceptionless execute --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 1145591..3869973 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,7 @@ require 'bundler/gem_tasks' def execute(command) puts command - system command, exception: true + abort unless system(command) end def bundle_options From 0fd69160586c5987137f3886b2b206c05fcb566b Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 15:46:12 +0100 Subject: [PATCH 21/42] Do not fail fast --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a78d62..407c732 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,7 @@ jobs: --health-timeout=5s --health-retries=3 strategy: - fail-fast: true + fail-fast: false matrix: ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 'head'] rails: [3, 4, 5, 6, 'head'] From 2458671abe923d25f9b724e5ff6fe28f776a3c8a Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 17:06:30 +0100 Subject: [PATCH 22/42] Update deps --- gemfiles/Gemfile.rails_3.lock | 18 +++++++++--------- gemfiles/Gemfile.rails_4.lock | 30 +++++++++++++++--------------- gemfiles/Gemfile.rails_5.lock | 20 ++++++++++---------- gemfiles/Gemfile.rails_6.lock | 22 +++++++++++----------- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/gemfiles/Gemfile.rails_3.lock b/gemfiles/Gemfile.rails_3.lock index e2cd51a..f9bfced 100644 --- a/gemfiles/Gemfile.rails_3.lock +++ b/gemfiles/Gemfile.rails_3.lock @@ -20,18 +20,18 @@ GEM multi_json (~> 1.0) arel (3.0.3) builder (3.0.4) - i18n (0.8.1) - metaclass (0.0.4) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) - multi_json (1.12.1) + concurrent-ruby (1.1.9) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + minitest (5.14.4) + mocha (1.13.0) + multi_json (1.15.0) mysql2 (0.5.3) pg (1.2.3) - rake (13.0.1) + rake (13.0.6) sqlite3 (1.4.2) - test_declarative (0.0.5) - tzinfo (0.3.52) + test_declarative (0.0.6) + tzinfo (0.3.60) PLATFORMS ruby diff --git a/gemfiles/Gemfile.rails_4.lock b/gemfiles/Gemfile.rails_4.lock index 978a0fe..3289ee6 100644 --- a/gemfiles/Gemfile.rails_4.lock +++ b/gemfiles/Gemfile.rails_4.lock @@ -7,32 +7,32 @@ PATH GEM remote: https://rubygems.org/ specs: - activemodel (4.2.8) - activesupport (= 4.2.8) + activemodel (4.2.11.3) + activesupport (= 4.2.11.3) builder (~> 3.1) - activerecord (4.2.8) - activemodel (= 4.2.8) - activesupport (= 4.2.8) + activerecord (4.2.11.3) + activemodel (= 4.2.11.3) + activesupport (= 4.2.11.3) arel (~> 6.0) - activesupport (4.2.8) + activesupport (4.2.11.3) i18n (~> 0.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.4) - builder (3.2.3) - i18n (0.8.1) - metaclass (0.0.4) - minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) + builder (3.2.4) + concurrent-ruby (1.1.9) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + minitest (5.14.4) + mocha (1.13.0) mysql2 (0.5.3) pg (1.2.3) - rake (13.0.1) + rake (13.0.6) sqlite3 (1.4.2) - test_declarative (0.0.5) + test_declarative (0.0.6) thread_safe (0.3.6) - tzinfo (1.2.2) + tzinfo (1.2.9) thread_safe (~> 0.1) PLATFORMS diff --git a/gemfiles/Gemfile.rails_5.lock b/gemfiles/Gemfile.rails_5.lock index 5bac9f8..2a99ed4 100644 --- a/gemfiles/Gemfile.rails_5.lock +++ b/gemfiles/Gemfile.rails_5.lock @@ -7,26 +7,26 @@ PATH GEM remote: https://rubygems.org/ specs: - activemodel (5.2.4.5) - activesupport (= 5.2.4.5) - activerecord (5.2.4.5) - activemodel (= 5.2.4.5) - activesupport (= 5.2.4.5) + activemodel (5.2.6) + activesupport (= 5.2.6) + activerecord (5.2.6) + activemodel (= 5.2.6) + activesupport (= 5.2.6) arel (>= 9.0) - activesupport (5.2.4.5) + activesupport (5.2.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) arel (9.0.0) - concurrent-ruby (1.1.8) - i18n (1.8.9) + concurrent-ruby (1.1.9) + i18n (1.8.10) concurrent-ruby (~> 1.0) minitest (5.14.4) - mocha (1.12.0) + mocha (1.13.0) mysql2 (0.5.3) pg (1.2.3) - rake (13.0.3) + rake (13.0.6) sqlite3 (1.4.2) test_declarative (0.0.6) thread_safe (0.3.6) diff --git a/gemfiles/Gemfile.rails_6.lock b/gemfiles/Gemfile.rails_6.lock index bdca0ac..0ba96ee 100644 --- a/gemfiles/Gemfile.rails_6.lock +++ b/gemfiles/Gemfile.rails_6.lock @@ -7,30 +7,30 @@ PATH GEM remote: https://rubygems.org/ specs: - activemodel (6.1.3) - activesupport (= 6.1.3) - activerecord (6.1.3) - activemodel (= 6.1.3) - activesupport (= 6.1.3) - activesupport (6.1.3) + activemodel (6.1.4.1) + activesupport (= 6.1.4.1) + activerecord (6.1.4.1) + activemodel (= 6.1.4.1) + activesupport (= 6.1.4.1) + activesupport (6.1.4.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) - concurrent-ruby (1.1.8) - i18n (1.8.9) + concurrent-ruby (1.1.9) + i18n (1.8.10) concurrent-ruby (~> 1.0) minitest (5.14.4) - mocha (1.12.0) + mocha (1.13.0) mysql2 (0.5.3) pg (1.2.3) - rake (13.0.3) + rake (13.0.6) sqlite3 (1.4.2) test_declarative (0.0.6) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - zeitwerk (2.4.2) + zeitwerk (2.5.1) PLATFORMS ruby From 81f507cf63aa4a50722ddb79da8e719e8efe212a Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 17:35:38 +0100 Subject: [PATCH 23/42] Clean up tests --- test/active_record_test.rb | 3 ++- test/missing_test.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/active_record_test.rb b/test/active_record_test.rb index 16ac26e..35d18e7 100644 --- a/test/active_record_test.rb +++ b/test/active_record_test.rb @@ -11,6 +11,7 @@ def setup def teardown I18n::Backend::ActiveRecord::Translation.destroy_all I18n::Backend::ActiveRecord.instance_variable_set :@config, I18n::Backend::ActiveRecord::Configuration.new + super end @@ -157,4 +158,4 @@ def setup I18n::Backend::ActiveRecord.config.cache_translations = true end end -end +end \ No newline at end of file diff --git a/test/missing_test.rb b/test/missing_test.rb index 8011af6..3b68e88 100644 --- a/test/missing_test.rb +++ b/test/missing_test.rb @@ -90,4 +90,4 @@ def setup I18n::Backend::ActiveRecord.config.cache_translations = true end end -end \ No newline at end of file +end From 395bbcbdc8d02bf0617c1f6a7ac7928e4cef5f44 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 17:49:25 +0100 Subject: [PATCH 24/42] Try original gemfiles --- gemfiles/Gemfile.rails_3 | 2 +- gemfiles/Gemfile.rails_3.lock | 30 ++++++++++++------------- gemfiles/Gemfile.rails_4 | 2 +- gemfiles/Gemfile.rails_4.lock | 42 +++++++++++++++++------------------ 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/gemfiles/Gemfile.rails_3 b/gemfiles/Gemfile.rails_3 index 3b205f0..fbb82cf 100644 --- a/gemfiles/Gemfile.rails_3 +++ b/gemfiles/Gemfile.rails_3 @@ -5,7 +5,7 @@ gemspec path: '..' gem 'activerecord', '~> 3.2.0' gem 'sqlite3' gem 'mysql2' -gem 'pg' +gem 'pg', '~> 0.18.0' gem 'minitest' gem 'test_declarative' diff --git a/gemfiles/Gemfile.rails_3.lock b/gemfiles/Gemfile.rails_3.lock index f9bfced..ce2906c 100644 --- a/gemfiles/Gemfile.rails_3.lock +++ b/gemfiles/Gemfile.rails_3.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n-active_record (0.4.1) + i18n-active_record (0.4.0) i18n (>= 0.5.0) GEM @@ -20,18 +20,18 @@ GEM multi_json (~> 1.0) arel (3.0.3) builder (3.0.4) - concurrent-ruby (1.1.9) - i18n (0.9.5) - concurrent-ruby (~> 1.0) - minitest (5.14.4) - mocha (1.13.0) - multi_json (1.15.0) - mysql2 (0.5.3) - pg (1.2.3) - rake (13.0.6) - sqlite3 (1.4.2) - test_declarative (0.0.6) - tzinfo (0.3.60) + i18n (0.8.1) + metaclass (0.0.4) + minitest (5.10.1) + mocha (1.2.1) + metaclass (~> 0.0.1) + multi_json (1.12.1) + mysql2 (0.4.5) + pg (0.18.4) + rake (13.0.1) + sqlite3 (1.3.13) + test_declarative (0.0.5) + tzinfo (0.3.52) PLATFORMS ruby @@ -43,10 +43,10 @@ DEPENDENCIES minitest mocha mysql2 - pg + pg (~> 0.18.0) rake sqlite3 test_declarative BUNDLED WITH - 2.2.16 + 2.0.2 diff --git a/gemfiles/Gemfile.rails_4 b/gemfiles/Gemfile.rails_4 index 616652e..772435c 100644 --- a/gemfiles/Gemfile.rails_4 +++ b/gemfiles/Gemfile.rails_4 @@ -5,7 +5,7 @@ gemspec path: '..' gem 'activerecord', '~> 4.2.0' gem 'sqlite3' gem 'mysql2' -gem 'pg' +gem 'pg', '~> 0.18.0' gem 'minitest' gem 'test_declarative' diff --git a/gemfiles/Gemfile.rails_4.lock b/gemfiles/Gemfile.rails_4.lock index 3289ee6..348a008 100644 --- a/gemfiles/Gemfile.rails_4.lock +++ b/gemfiles/Gemfile.rails_4.lock @@ -1,38 +1,38 @@ PATH remote: .. specs: - i18n-active_record (0.4.1) + i18n-active_record (0.4.0) i18n (>= 0.5.0) GEM remote: https://rubygems.org/ specs: - activemodel (4.2.11.3) - activesupport (= 4.2.11.3) + activemodel (4.2.8) + activesupport (= 4.2.8) builder (~> 3.1) - activerecord (4.2.11.3) - activemodel (= 4.2.11.3) - activesupport (= 4.2.11.3) + activerecord (4.2.8) + activemodel (= 4.2.8) + activesupport (= 4.2.8) arel (~> 6.0) - activesupport (4.2.11.3) + activesupport (4.2.8) i18n (~> 0.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.4) - builder (3.2.4) - concurrent-ruby (1.1.9) - i18n (0.9.5) - concurrent-ruby (~> 1.0) - minitest (5.14.4) - mocha (1.13.0) - mysql2 (0.5.3) - pg (1.2.3) - rake (13.0.6) - sqlite3 (1.4.2) - test_declarative (0.0.6) + builder (3.2.3) + i18n (0.8.1) + metaclass (0.0.4) + minitest (5.10.1) + mocha (1.2.1) + metaclass (~> 0.0.1) + mysql2 (0.4.5) + pg (0.18.4) + rake (13.0.1) + sqlite3 (1.3.13) + test_declarative (0.0.5) thread_safe (0.3.6) - tzinfo (1.2.9) + tzinfo (1.2.2) thread_safe (~> 0.1) PLATFORMS @@ -45,10 +45,10 @@ DEPENDENCIES minitest mocha mysql2 - pg + pg (~> 0.18.0) rake sqlite3 test_declarative BUNDLED WITH - 2.2.16 + 2.0.2 From dd4977bf1ebf25416cb1381f7715cca85859c4d6 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 18:09:50 +0100 Subject: [PATCH 25/42] Revert Gemfiles for 3 and 4 --- gemfiles/Gemfile.rails_3.lock | 2 +- gemfiles/Gemfile.rails_4.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gemfiles/Gemfile.rails_3.lock b/gemfiles/Gemfile.rails_3.lock index ce2906c..94aac4a 100644 --- a/gemfiles/Gemfile.rails_3.lock +++ b/gemfiles/Gemfile.rails_3.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n-active_record (0.4.0) + i18n-active_record (0.4.1) i18n (>= 0.5.0) GEM diff --git a/gemfiles/Gemfile.rails_4.lock b/gemfiles/Gemfile.rails_4.lock index 348a008..9a1d2e7 100644 --- a/gemfiles/Gemfile.rails_4.lock +++ b/gemfiles/Gemfile.rails_4.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - i18n-active_record (0.4.0) + i18n-active_record (0.4.1) i18n (>= 0.5.0) GEM From c36437aa94af372fd2f9696dd8020256dd5c28ec Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 18:12:39 +0100 Subject: [PATCH 26/42] Bump mysql in 3 and 4 --- gemfiles/Gemfile.rails_3.lock | 2 +- gemfiles/Gemfile.rails_4.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gemfiles/Gemfile.rails_3.lock b/gemfiles/Gemfile.rails_3.lock index 94aac4a..2e8cdef 100644 --- a/gemfiles/Gemfile.rails_3.lock +++ b/gemfiles/Gemfile.rails_3.lock @@ -26,7 +26,7 @@ GEM mocha (1.2.1) metaclass (~> 0.0.1) multi_json (1.12.1) - mysql2 (0.4.5) + mysql2 (0.5.3) pg (0.18.4) rake (13.0.1) sqlite3 (1.3.13) diff --git a/gemfiles/Gemfile.rails_4.lock b/gemfiles/Gemfile.rails_4.lock index 9a1d2e7..1741c77 100644 --- a/gemfiles/Gemfile.rails_4.lock +++ b/gemfiles/Gemfile.rails_4.lock @@ -26,7 +26,7 @@ GEM minitest (5.10.1) mocha (1.2.1) metaclass (~> 0.0.1) - mysql2 (0.4.5) + mysql2 (0.5.3) pg (0.18.4) rake (13.0.1) sqlite3 (1.3.13) From 5f3318c0add0c728359ec883cfe4880608c9d915 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 18:22:03 +0100 Subject: [PATCH 27/42] Rails 3 fixes --- test/missing_test.rb | 2 +- test/test_helper.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/missing_test.rb b/test/missing_test.rb index 3b68e88..8011af6 100644 --- a/test/missing_test.rb +++ b/test/missing_test.rb @@ -90,4 +90,4 @@ def setup I18n::Backend::ActiveRecord.config.cache_translations = true end end -end +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 8039c70..799fdfc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -85,6 +85,14 @@ def store_translations(locale, data) I18n.backend.store_translations(locale, data) end + def update_attributes(record, attrs) + if ActiveRecord::VERSION::MAJOR < 4 + record.update_attributes(attrs) + else + record.update(attrs) + end + end + def locales_dir File.dirname(__FILE__) + '/test_data/locales' end From 9cf6190d3f0e82eed33dd4f8b1c01e4ffa6112d4 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 18:25:10 +0100 Subject: [PATCH 28/42] Bump cache version --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 407c732..b40f1e7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -73,4 +73,5 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true # runs 'bundle install' and caches installed gems automatically + cache-version: 1 - run: bundle exec rake From 1a5e6b4562078988cd29e880ab1fbb234bc4dd64 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Fri, 22 Oct 2021 18:29:10 +0100 Subject: [PATCH 29/42] Drop ruby 2.3 --- .github/workflows/test.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b40f1e7..28760eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,15 +36,9 @@ jobs: strategy: fail-fast: false matrix: - ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 'head'] + ruby: [2.4, 2.5, 2.6, 2.7, 3.0, 'head'] rails: [3, 4, 5, 6, 'head'] exclude: - - ruby: 2.3 - rails: 6 - - ruby: 2.4 - rails: 6 - - ruby: 2.3 - rails: head - ruby: 2.4 rails: head - ruby: 2.5 From 1f875b072567d888ce51181a85c1ddb3b3169ef8 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 13:57:23 +0100 Subject: [PATCH 30/42] Post rebase fixes and cleanup --- Gemfile.lock | 3 +- lib/i18n/backend/active_record.rb | 162 +++++++++--------- .../backend/active_record/configuration.rb | 3 +- lib/i18n/backend/active_record/missing.rb | 15 +- lib/i18n/backend/active_record/translation.rb | 6 +- test/active_record_test.rb | 65 +++---- test/api_test.rb | 1 + test/missing_test.rb | 38 ++-- 8 files changed, 152 insertions(+), 141 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index db4dd7b..482fc35 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,8 +22,7 @@ GEM i18n (1.8.10) concurrent-ruby (~> 1.0) minitest (5.14.4) - mocha (1.2.1) - metaclass (~> 0.0.1) + mocha (1.13.0) mysql2 (0.5.3) pg (1.2.3) rake (13.0.1) diff --git a/lib/i18n/backend/active_record.rb b/lib/i18n/backend/active_record.rb index 15e5042..58a4489 100644 --- a/lib/i18n/backend/active_record.rb +++ b/lib/i18n/backend/active_record.rb @@ -9,6 +9,9 @@ class ActiveRecord autoload :Translation, 'i18n/backend/active_record/translation' autoload :Configuration, 'i18n/backend/active_record/configuration' + include Base + include Flatten + class << self def configure yield(config) if block_given? @@ -19,114 +22,111 @@ def config end end - module Implementation - include Base, Flatten + def initialize(*args) + super - def available_locales - begin - Translation.available_locales - rescue ::ActiveRecord::StatementInvalid - [] - end - end + reload! + end - def store_translations(locale, data, options = {}) - escape = options.fetch(:escape, true) - flatten_translations(locale, data, escape, false).each do |key, value| - translation = Translation.locale(locale).lookup(expand_keys(key)) + def available_locales + Translation.available_locales + rescue ::ActiveRecord::StatementInvalid + [] + end - if ActiveRecord.config.cleanup_with_destroy - translation.destroy_all - else - translation.delete_all - end + def store_translations(locale, data, options = {}) + escape = options.fetch(:escape, true) - Translation.create(:locale => locale.to_s, :key => key.to_s, :value => value) + flatten_translations(locale, data, escape, false).each do |key, value| + translation = Translation.locale(locale).lookup(expand_keys(key)) + + if ActiveRecord.config.cleanup_with_destroy + translation.destroy_all + else + translation.delete_all end - reload! if ActiveRecord.config.cache_translations + Translation.create(locale: locale.to_s, key: key.to_s, value: value) end - def reload! - @translations = nil + reload! if ActiveRecord.config.cache_translations + end - self - end + def reload! + @translations = nil - def initialized? - !@translations.nil? - end + self + end - def init_translations - @translations = Translation.to_hash - end + def initialized? + !@translations.nil? + end - def translations(do_init: false) - init_translations if do_init || !initialized? - @translations ||= {} - end + def init_translations + @translations = Translation.to_hash + end - protected + def translations(do_init: false) + init_translations if do_init || !initialized? + @translations ||= {} + end - def lookup(locale, key, scope = [], options = {}) - key = normalize_flat_keys(locale, key, scope, options[:separator]) - if key.first == '.' - key = key[1..-1] - end - if key.last == '.' - key = key[0..-2] - end + protected - if ActiveRecord.config.cache_translations - init_translations if @translations.nil? || @translations.empty? + def lookup(locale, key, scope = [], options = {}) + key = normalize_flat_keys(locale, key, scope, options[:separator]) + key = key[1..-1] if key.first == '.' + key = key[0..-2] if key.last == '.' - keys = ([locale] + key.split(I18n::Backend::Flatten::FLATTEN_SEPARATOR)).map(&:to_sym) + if ActiveRecord.config.cache_translations + init_translations if @translations.nil? || @translations.empty? - return translations.dig(*keys) - end + keys = ([locale] + key.split(I18n::Backend::Flatten::FLATTEN_SEPARATOR)).map(&:to_sym) - result = if key == '' - Translation.locale(locale).all - else - Translation.locale(locale).lookup(key) - end + return translations.dig(*keys) + end - if result.empty? - nil - elsif result.first.key == key - result.first.value - else - result = result.inject({}) do |hash, translation| - hash.deep_merge build_translation_hash_by_key(key, translation) - end - result.deep_symbolize_keys - end + result = if key == '' + Translation.locale(locale).all + else + Translation.locale(locale).lookup(key) end - def build_translation_hash_by_key(lookup_key, translation) - hash = {} - if lookup_key == '' - chop_range = 0..-1 - else - chop_range = (lookup_key.size + FLATTEN_SEPARATOR.size)..-1 + if result.empty? + nil + elsif result.first.key == key + result.first.value + else + result = result.inject({}) do |hash, translation| + hash.deep_merge build_translation_hash_by_key(key, translation) end - translation_nested_keys = translation.key.slice(chop_range).split(FLATTEN_SEPARATOR) - translation_nested_keys.each.with_index.inject(hash) do |iterator, (key, index)| - iterator[key] = translation_nested_keys[index + 1] ? {} : translation.value - iterator[key] - end - hash + result.deep_symbolize_keys end + end - # For a key :'foo.bar.baz' return ['foo', 'foo.bar', 'foo.bar.baz'] - def expand_keys(key) - key.to_s.split(FLATTEN_SEPARATOR).inject([]) do |keys, key| - keys << [keys.last, key].compact.join(FLATTEN_SEPARATOR) - end + def build_translation_hash_by_key(lookup_key, translation) + hash = {} + + chop_range = if lookup_key == '' + 0..-1 + else + (lookup_key.size + FLATTEN_SEPARATOR.size)..-1 end + translation_nested_keys = translation.key.slice(chop_range).split(FLATTEN_SEPARATOR) + translation_nested_keys.each.with_index.inject(hash) do |iterator, (key, index)| + iterator[key] = translation_nested_keys[index + 1] ? {} : translation.value + iterator[key] + end + + hash end - include Implementation + # For a key :'foo.bar.baz' return ['foo', 'foo.bar', 'foo.bar.baz'] + def expand_keys(key) + key.to_s.split(FLATTEN_SEPARATOR).inject([]) do |keys, k| + keys << [keys.last, k].compact.join(FLATTEN_SEPARATOR) + end + end end end end diff --git a/lib/i18n/backend/active_record/configuration.rb b/lib/i18n/backend/active_record/configuration.rb index 4d4176c..f3f72fb 100644 --- a/lib/i18n/backend/active_record/configuration.rb +++ b/lib/i18n/backend/active_record/configuration.rb @@ -2,8 +2,7 @@ module I18n module Backend class ActiveRecord class Configuration - attr_accessor :cleanup_with_destroy - attr_accessor :cache_translations + attr_accessor :cleanup_with_destroy, :cache_translations def initialize @cleanup_with_destroy = false diff --git a/lib/i18n/backend/active_record/missing.rb b/lib/i18n/backend/active_record/missing.rb index f493d28..7f3db4e 100644 --- a/lib/i18n/backend/active_record/missing.rb +++ b/lib/i18n/backend/active_record/missing.rb @@ -40,23 +40,24 @@ def store_default_translations(locale, key, options = {}) separator ||= I18n.default_separator key = normalize_flat_keys(locale, key, scope, separator) - unless ActiveRecord::Translation.locale(locale).lookup(key).exists? - interpolations = options.keys - I18n::RESERVED_KEYS - keys = count ? I18n.t('i18n.plural.keys', :locale => locale).map { |k| [key, k].join(FLATTEN_SEPARATOR) } : [key] - keys.each { |key| store_default_translation(locale, key, interpolations) } - end + return if ActiveRecord::Translation.locale(locale).lookup(key).exists? + + interpolations = options.keys - I18n::RESERVED_KEYS + keys = count ? I18n.t('i18n.plural.keys', locale: locale).map { |k| [key, k].join(FLATTEN_SEPARATOR) } : [key] + keys.each { |k| store_default_translation(locale, k, interpolations) } end def store_default_translation(locale, key, interpolations) - translation = ActiveRecord::Translation.new :locale => locale.to_s, :key => key + translation = ActiveRecord::Translation.new locale: locale.to_s, key: key translation.interpolations = interpolations translation.save end def translate(locale, key, options = {}) result = catch(:exception) { super } + if result.is_a?(I18n::MissingTranslation) - self.store_default_translations(locale, key, options) + store_default_translations(locale, key, options) throw(:exception, result) else result diff --git a/lib/i18n/backend/active_record/translation.rb b/lib/i18n/backend/active_record/translation.rb index c3b7e61..7d99024 100644 --- a/lib/i18n/backend/active_record/translation.rb +++ b/lib/i18n/backend/active_record/translation.rb @@ -57,12 +57,12 @@ class Translation < ::ActiveRecord::Base class << self def locale(locale) - where(:locale => locale.to_s) + where(locale: locale.to_s) end def lookup(keys, *separator) column_name = connection.quote_column_name('key') - keys = Array(keys).map! { |key| key.to_s } + keys = Array(keys).map!(&:to_s) unless separator.empty? warn "[DEPRECATION] Giving a separator to Translation.lookup is deprecated. " << @@ -91,7 +91,7 @@ def to_hash end def interpolates?(key) - self.interpolations.include?(key) if self.interpolations + interpolations&.include?(key) end def value diff --git a/test/active_record_test.rb b/test/active_record_test.rb index 35d18e7..9b449e0 100644 --- a/test/active_record_test.rb +++ b/test/active_record_test.rb @@ -4,14 +4,15 @@ class I18nBackendActiveRecordTest < I18n::TestCase def setup super + I18n::Backend::ActiveRecord::Translation.destroy_all I18n.backend = I18n::Backend::ActiveRecord.new - store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' }) + + store_translations(:en, foo: { bar: 'bar', baz: 'baz' }) end def teardown - I18n::Backend::ActiveRecord::Translation.destroy_all I18n::Backend::ActiveRecord.instance_variable_set :@config, I18n::Backend::ActiveRecord::Configuration.new - + super end @@ -23,20 +24,20 @@ def setup end test "store_translations does not allow ambiguous keys (1)" do - store_translations(:en, :foo => 'foo') - store_translations(:en, :foo => { :bar => 'bar' }) - store_translations(:en, :foo => { :baz => 'baz' }) + store_translations(:en, foo: 'foo') + store_translations(:en, foo: { bar: 'bar' }) + store_translations(:en, foo: { baz: 'baz' }) translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').all assert_equal %w(bar baz), translations.map(&:value) - assert_equal({ :bar => 'bar', :baz => 'baz' }, I18n.t(:foo)) + assert_equal({ bar: 'bar', baz: 'baz' }, I18n.t(:foo)) end test "store_translations does not allow ambiguous keys (2)" do - store_translations(:en, :foo => { :bar => 'bar' }) - store_translations(:en, :foo => { :baz => 'baz' }) - store_translations(:en, :foo => 'foo') + store_translations(:en, foo: { bar: 'bar' }) + store_translations(:en, foo: { baz: 'baz' }) + store_translations(:en, foo: 'foo') translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo').all assert_equal %w(foo), translations.map(&:value) @@ -45,9 +46,9 @@ def setup end test "can store translations with keys that are translations containing special chars" do - store_translations(:es, :"Pagina's" => "Pagina's" ) - - assert_equal "Pagina's", I18n.t(:"Pagina's", :locale => :es) + store_translations(:es, "Pagina's": "Pagina's") + + assert_equal "Pagina's", I18n.t(:"Pagina's", locale: :es) end test "missing translations table does not cause an error in #available_locales" do @@ -60,11 +61,11 @@ def setup end test "available_locales returns uniq locales" do - store_translations(:en, :foo => { :bar => 'bar' }) - store_translations(:en, :foo => { :baz => 'baz' }) - store_translations(:de, :foo1 => 'foo') - store_translations(:de, :foo2 => 'foo') - store_translations(:uk, :foo3 => 'foo') + store_translations(:en, foo: { bar: 'bar' }) + store_translations(:en, foo: { baz: 'baz' }) + store_translations(:de, foo1: 'foo') + store_translations(:de, foo2: 'foo') + store_translations(:uk, foo3: 'foo') available_locales = I18n::Backend::ActiveRecord::Translation.available_locales assert_equal 3, available_locales.size @@ -87,26 +88,26 @@ def setup test "fetching subtree of translations" do store_translations(:en, foo: { bar: { fizz: 'buzz', spuz: 'zazz' }, baz: { fizz: 'buzz' } }) - + assert_equal I18n.t(:foo), { bar: { fizz: 'buzz', spuz: 'zazz' }, baz: { fizz: 'buzz' } } end test "build_translation_hash_by_key" do translation = I18n::Backend::ActiveRecord::Translation.new(value: 'translation', key: 'foo.bar.fizz.buzz') expected_hash = { 'bar' => { 'fizz' => { 'buzz' => 'translation' } } } - + assert_equal I18n.backend.send(:build_translation_hash_by_key, 'foo', translation), expected_hash end test "returning all keys via ." do - expected_hash = {:foo => { :bar => 'bar', :baz => 'baz' }} - + expected_hash = { foo: { bar: 'bar', baz: 'baz' }} + assert_equal expected_hash, I18n.t('.') end test "accessing keys with a trailing/leading period" do - expected_hash = { :bar => 'bar', :baz => 'baz' } - + expected_hash = { bar: 'bar', baz: 'baz' } + assert_equal expected_hash, I18n.t('foo') assert_equal expected_hash, I18n.t('.foo') assert_equal expected_hash, I18n.t('foo.') @@ -123,28 +124,28 @@ def setup test "intially unitinitialized" do refute I18n.backend.initialized? - + I18n.backend.init_translations assert I18n.backend.initialized? - + I18n.backend.reload! refute I18n.backend.initialized? - + I18n.backend.init_translations assert I18n.backend.initialized? end test "translations returns all translations" do - expected_hash = { :en => { :foo => { :bar => 'bar', :baz => 'baz' } } } + expected_hash = { en: { foo: { bar: 'bar', baz: 'baz' } } } I18n.backend.init_translations - + assert_equal expected_hash, I18n.backend.send(:translations) assert I18n.backend.initialized? end test "translations initialized with do_init argument" do - expected_hash = { :en => { :foo => { :bar => 'bar', :baz => 'baz' } } } - + expected_hash = { en: { foo: { bar: 'bar', baz: 'baz' } } } + refute I18n.backend.initialized? assert_equal expected_hash, I18n.backend.send(:translations, do_init: true) assert I18n.backend.initialized? @@ -158,4 +159,4 @@ def setup I18n::Backend::ActiveRecord.config.cache_translations = true end end -end \ No newline at end of file +end diff --git a/test/api_test.rb b/test/api_test.rb index 2616446..8c07271 100644 --- a/test/api_test.rb +++ b/test/api_test.rb @@ -3,6 +3,7 @@ class I18nActiveRecordApiTest < I18n::TestCase def setup I18n.backend = I18n::Backend::ActiveRecord.new + super end diff --git a/test/missing_test.rb b/test/missing_test.rb index 8011af6..81188b8 100644 --- a/test/missing_test.rb +++ b/test/missing_test.rb @@ -8,13 +8,15 @@ class BackendWithMissing < I18n::Backend::ActiveRecord def setup super + I18n::Backend::ActiveRecord::Translation.destroy_all I18n.backend = BackendWithMissing.new - store_translations(:en, :bar => 'Bar', :i18n => { :plural => { :keys => [:zero, :one, :other] } }) + + store_translations(:en, bar: 'Bar', i18n: { plural: { keys: [:zero, :one, :other] } }) end def teardown - I18n::Backend::ActiveRecord::Translation.destroy_all I18n::Backend::ActiveRecord.instance_variable_set :@config, I18n::Backend::ActiveRecord::Configuration.new + super end @@ -26,9 +28,10 @@ def setup end test "can persist interpolations" do - translation = I18n::Backend::ActiveRecord::Translation.new(:key => 'foo', :value => 'bar', :locale => :en) + translation = I18n::Backend::ActiveRecord::Translation.new(key: 'foo', value: 'bar', locale: :en) translation.interpolations = %w(count name) translation.save + assert translation.valid? end @@ -41,45 +44,52 @@ def setup test "lookup does not persist the key twice" do 2.times { I18n.t('foo.bar.baz') } + assert_equal 3, I18n::Backend::ActiveRecord::Translation.count assert I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key('foo.bar.baz') end test "lookup persists interpolation keys when looked up directly" do - I18n.t('foo.bar.baz', :cow => "lucy" ) # creates stub translation. + I18n.t('foo.bar.baz', cow: "lucy" ) # creates stub translation. translation_stub = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo.bar.baz').first + assert translation_stub.interpolates?(:cow) end test "creates one stub per pluralization" do - I18n.t('foo', :count => 999) + I18n.t('foo', count: 999) translations = I18n::Backend::ActiveRecord::Translation.locale(:en).where key: %w{ foo.zero foo.one foo.other } + assert_equal 3, translations.length end test "creates no stub for base key in pluralization" do - I18n.t('foo', :count => 999) + I18n.t('foo', count: 999) + assert_equal 3, I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo").count assert !I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key("foo") end test "creates a stub when a custom separator is used" do - I18n.t('foo|baz', :separator => '|') - I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz").first.update(:value => 'baz!') - assert_equal 'baz!', I18n.t('foo|baz', :separator => '|') + I18n.t('foo|baz', separator: '|') + update_attributes(I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz").first, value: 'baz!') + + assert_equal 'baz!', I18n.t('foo|baz', separator: '|') end test "creates a stub per pluralization when a custom separator is used" do - I18n.t('foo|bar', :count => 999, :separator => '|') + I18n.t('foo|bar', count: 999, separator: '|') translations = I18n::Backend::ActiveRecord::Translation.locale(:en).where key: %w{ foo.bar.zero foo.bar.one foo.bar.other } + assert_equal 3, translations.length end test "creates a stub when a custom separator is used and the key contains the flatten separator (a dot character)" do key = 'foo|baz.zab' - I18n.t(key, :separator => '|') - I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz\001zab").first.update(:value => 'baz!') - assert_equal 'baz!', I18n.t(key, :separator => '|') + I18n.t(key, separator: '|') + update_attributes(I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz\001zab").first, value: 'baz!') + + assert_equal 'baz!', I18n.t(key, separator: '|') end end @@ -90,4 +100,4 @@ def setup I18n::Backend::ActiveRecord.config.cache_translations = true end end -end \ No newline at end of file +end From cc43ec715acd63c40097c6961dca3a5b01a4f1eb Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 14:12:57 +0100 Subject: [PATCH 31/42] Deps --- gemfiles/Gemfile.rails_3.lock | 4 +--- gemfiles/Gemfile.rails_4.lock | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/gemfiles/Gemfile.rails_3.lock b/gemfiles/Gemfile.rails_3.lock index 2e8cdef..f46a080 100644 --- a/gemfiles/Gemfile.rails_3.lock +++ b/gemfiles/Gemfile.rails_3.lock @@ -21,10 +21,8 @@ GEM arel (3.0.3) builder (3.0.4) i18n (0.8.1) - metaclass (0.0.4) minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) + mocha (1.13.0) multi_json (1.12.1) mysql2 (0.5.3) pg (0.18.4) diff --git a/gemfiles/Gemfile.rails_4.lock b/gemfiles/Gemfile.rails_4.lock index 1741c77..b35c83b 100644 --- a/gemfiles/Gemfile.rails_4.lock +++ b/gemfiles/Gemfile.rails_4.lock @@ -22,10 +22,8 @@ GEM arel (6.0.4) builder (3.2.3) i18n (0.8.1) - metaclass (0.0.4) minitest (5.10.1) - mocha (1.2.1) - metaclass (~> 0.0.1) + mocha (1.13.0) mysql2 (0.5.3) pg (0.18.4) rake (13.0.1) From 42aea79211aaa826bffaee6535a0922cffb55376 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 14:23:48 +0100 Subject: [PATCH 32/42] Simplified Rakefile --- .github/workflows/test.yml | 11 ++++++- Rakefile | 59 +------------------------------------- 2 files changed, 11 insertions(+), 59 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 28760eb..b5bb56e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,4 +68,13 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true # runs 'bundle install' and caches installed gems automatically cache-version: 1 - - run: bundle exec rake + - name: Run tests for SQLite + run: bundle exec rake + - name: Run tests for PostgreSQL + env: + DB: postgres + run: bundle exec rake + - name: Run tests for MySQL + env: + DB: mysql + run: bundle exec rake diff --git a/Rakefile b/Rakefile index 3869973..4f45d1c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,66 +1,9 @@ -require 'rake' require 'rake/testtask' -require 'bundler/gem_tasks' -def execute(command) - puts command - abort unless system(command) -end - -def bundle_options - return '' unless ENV['BUNDLE_GEMFILE'] - - "--gemfile #{ENV['BUNDLE_GEMFILE']}" -end - -def each_database(&block) - ['sqlite', 'postgres', 'mysql'].each &block -end - -namespace :bundle do - task :env do - ar = ENV['AR'].to_s - - next if ar.empty? - - gemfile = "gemfiles/Gemfile.rails_#{ar}" - raise "Cannot find gemfile at #{gemfile}" unless File.exist?(gemfile) - - ENV['BUNDLE_GEMFILE'] = gemfile - puts "Using gemfile: #{gemfile}" - end - - task install: :env do - execute "bundle install #{bundle_options}" - end - - task update: :env do - execute "bundle update #{bundle_options}" - end - - task :install_all do - [nil, '3', '4', '5', '6', 'head'].each do |ar| - opt = ar && "AR=#{ar}" - execute "rake bundle:install #{opt}" - end - end -end - -task :test do - each_database { |db| execute "rake #{db}:test" } -end - -Rake::TestTask.new :_test do |t| +Rake::TestTask.new :test do |t| t.libs << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = false end -each_database do |db| - namespace db do - task(:env) { ENV['DB'] = db } - task test: ['env', 'bundle:env', '_test'] - end -end - task default: :test From 771ed9106b6e5e3ca879a742110df03745cacb8f Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 14:48:35 +0100 Subject: [PATCH 33/42] Remove rails 3 from CI --- .github/workflows/test.yml | 10 ++----- gemfiles/Gemfile.rails_3 | 13 --------- gemfiles/Gemfile.rails_3.lock | 50 ----------------------------------- 3 files changed, 2 insertions(+), 71 deletions(-) delete mode 100644 gemfiles/Gemfile.rails_3 delete mode 100644 gemfiles/Gemfile.rails_3.lock diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b5bb56e..45a4243 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,7 @@ jobs: fail-fast: false matrix: ruby: [2.4, 2.5, 2.6, 2.7, 3.0, 'head'] - rails: [3, 4, 5, 6, 'head'] + rails: [4, 5, 6, 'head'] exclude: - ruby: 2.4 rails: head @@ -45,16 +45,10 @@ jobs: rails: head - ruby: 2.6 rails: head - - ruby: 2.7 - rails: 3 - ruby: 2.7 rails: 4 - - ruby: 3.0 - rails: 3 - ruby: 3.0 rails: 4 - - ruby: head - rails: 3 - ruby: head rails: 4 name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.rails }}' @@ -66,7 +60,7 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically + bundler-cache: true cache-version: 1 - name: Run tests for SQLite run: bundle exec rake diff --git a/gemfiles/Gemfile.rails_3 b/gemfiles/Gemfile.rails_3 deleted file mode 100644 index fbb82cf..0000000 --- a/gemfiles/Gemfile.rails_3 +++ /dev/null @@ -1,13 +0,0 @@ -source 'https://rubygems.org' - -gemspec path: '..' - -gem 'activerecord', '~> 3.2.0' -gem 'sqlite3' -gem 'mysql2' -gem 'pg', '~> 0.18.0' - -gem 'minitest' -gem 'test_declarative' -gem 'mocha' -gem 'rake' diff --git a/gemfiles/Gemfile.rails_3.lock b/gemfiles/Gemfile.rails_3.lock deleted file mode 100644 index f46a080..0000000 --- a/gemfiles/Gemfile.rails_3.lock +++ /dev/null @@ -1,50 +0,0 @@ -PATH - remote: .. - specs: - i18n-active_record (0.4.1) - i18n (>= 0.5.0) - -GEM - remote: https://rubygems.org/ - specs: - activemodel (3.2.22.5) - activesupport (= 3.2.22.5) - builder (~> 3.0.0) - activerecord (3.2.22.5) - activemodel (= 3.2.22.5) - activesupport (= 3.2.22.5) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activesupport (3.2.22.5) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - arel (3.0.3) - builder (3.0.4) - i18n (0.8.1) - minitest (5.10.1) - mocha (1.13.0) - multi_json (1.12.1) - mysql2 (0.5.3) - pg (0.18.4) - rake (13.0.1) - sqlite3 (1.3.13) - test_declarative (0.0.5) - tzinfo (0.3.52) - -PLATFORMS - ruby - -DEPENDENCIES - activerecord (~> 3.2.0) - bundler - i18n-active_record! - minitest - mocha - mysql2 - pg (~> 0.18.0) - rake - sqlite3 - test_declarative - -BUNDLED WITH - 2.0.2 From 4f0082be4a7e6846ca0d076ddcf01c198522eb54 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 15:03:47 +0100 Subject: [PATCH 34/42] Cleanup --- test/missing_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/missing_test.rb b/test/missing_test.rb index 81188b8..bd4a8f4 100644 --- a/test/missing_test.rb +++ b/test/missing_test.rb @@ -72,7 +72,7 @@ def setup test "creates a stub when a custom separator is used" do I18n.t('foo|baz', separator: '|') - update_attributes(I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz").first, value: 'baz!') + I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz").first.update(value: 'baz!') assert_equal 'baz!', I18n.t('foo|baz', separator: '|') end @@ -87,7 +87,7 @@ def setup test "creates a stub when a custom separator is used and the key contains the flatten separator (a dot character)" do key = 'foo|baz.zab' I18n.t(key, separator: '|') - update_attributes(I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz\001zab").first, value: 'baz!') + I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz\001zab").first.update(value: 'baz!') assert_equal 'baz!', I18n.t(key, separator: '|') end From 41daeaaecf2f6780b3dec5ae7cbf558c864037d6 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 15:21:25 +0100 Subject: [PATCH 35/42] More exclusions --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 45a4243..b66ed8c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,8 +49,12 @@ jobs: rails: 4 - ruby: 3.0 rails: 4 + - ruby: 3.0 + rails: 5 - ruby: head rails: 4 + - ruby: head + rails: 5 name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.rails }}' runs-on: ubuntu-latest env: From c71b5a081d9e1db45656df4f85e12ea69671e0d9 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 15:42:42 +0100 Subject: [PATCH 36/42] More exclusion --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b66ed8c..e3fc3fd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,6 +39,8 @@ jobs: ruby: [2.4, 2.5, 2.6, 2.7, 3.0, 'head'] rails: [4, 5, 6, 'head'] exclude: + - ruby: 2.4 + rails: 6 - ruby: 2.4 rails: head - ruby: 2.5 From 9fd09e4cf486468981be95dc497145da1009f347 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 15:50:50 +0100 Subject: [PATCH 37/42] Downgrade mysql for rails 4 --- gemfiles/Gemfile.rails_4.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/Gemfile.rails_4.lock b/gemfiles/Gemfile.rails_4.lock index b35c83b..00d7f04 100644 --- a/gemfiles/Gemfile.rails_4.lock +++ b/gemfiles/Gemfile.rails_4.lock @@ -24,7 +24,7 @@ GEM i18n (0.8.1) minitest (5.10.1) mocha (1.13.0) - mysql2 (0.5.3) + mysql2 (0.4.10) pg (0.18.4) rake (13.0.1) sqlite3 (1.3.13) From b02098099b6a0a958e4d1e3762032b1325e3aca9 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 16:41:00 +0100 Subject: [PATCH 38/42] Update README --- README.md | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a1f6506..2e86d2b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # I18n::Backend::ActiveRecord This repository contains the I18n ActiveRecord backend and support code that has been extracted from the "I18n": http://github.com/svenfuchs/i18n. -It is fully compatible with Rails 3, 4, 5 and 6. +It is fully compatible with Rails 4, 5 and 6. ## Installation @@ -77,11 +77,37 @@ I18n::Backend::ActiveRecord.configure do |config| end ``` +To configure the ActiveRecord backend to cache translations(might be useful in production) use: + +```ruby +I18n::Backend::ActiveRecord.configure do |config| + config.cache_translations = true # defaults to false +end +``` + ## Usage You can now use `I18n.t('Your String')` to lookup translations in the database. -## Missing Translations -> Interpolations +## Missing Translations + +### Usage + +In order to make the `I18n::Backend::ActiveRecord::Missing` module working correctly pluralization rules should be configured properly. +The `i18n.plural.keys` translation key should be present in any of the backends. +(See https://github.com/svenfuchs/i18n-active_record/blob/master/lib/i18n/backend/active_record/missing.rb for more information) + +```yaml +en: + i18n: + plural: + keys: + - :zero + - :one + - :other +``` + +### Interpolations The `interpolations` field in the `translations` table is used by `I18n::Backend::ActiveRecord::Missing` to store the interpolations seen the first time this Translation was requested. This will help translators understand what interpolations to expect, and thus to include when providing the translations. @@ -93,7 +119,20 @@ The `interpolations` field is otherwise unused since the "value" in `Translation ## Contributing -To run the test suite for all databases use `rake test` or using only SQLite with `rake sqlite:test` +### Test suite + +The test suite can be run with: + + bundle exec rake + +By default it runs the tests for SQLite database, to specify a database the `DB` env variable can be used: + + DB=postgres bundle exec rake + DB=mysql bundle exec rake + +There are multiple gemfiles(mostly used for CI) and they can be activated with the `--gemfile` option: + + bundle exec --gemfile gemfiles/Gemfile.rails_4 rake ## Maintainers From 05267e6b7793fcc67c3f68a4eebc2d53cdb478be Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 16:49:46 +0100 Subject: [PATCH 39/42] Cleanup --- test/test_helper.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 799fdfc..8039c70 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -85,14 +85,6 @@ def store_translations(locale, data) I18n.backend.store_translations(locale, data) end - def update_attributes(record, attrs) - if ActiveRecord::VERSION::MAJOR < 4 - record.update_attributes(attrs) - else - record.update(attrs) - end - end - def locales_dir File.dirname(__FILE__) + '/test_data/locales' end From 6d7ead5091986bc0ee8ac7b56df5add7d8a77d6e Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 16:51:53 +0100 Subject: [PATCH 40/42] Remove .travis.yml --- .travis.yml | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f6308e7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,49 +0,0 @@ -language: ruby -cache: bundler - -notifications: - email: false - -services: - - postgresql - - mysql - -before_install: - - gem install bundler -v 2.0.2 - -before_script: - - mysql -e 'create database i18n_unittest;' - - psql -c 'create database i18n_unittest;' -U postgres - -rvm: - - 2.3 - - 2.4 - - 2.5 - - 2.6 - - 2.7 - -gemfile: - - gemfiles/Gemfile.rails_3 - - gemfiles/Gemfile.rails_4 - - gemfiles/Gemfile.rails_5 - - gemfiles/Gemfile.rails_6 - - gemfiles/Gemfile.rails_head - -env: - - PG_USER=postgres - -matrix: - fast_finish: true - exclude: - - rvm: 2.3 - gemfile: gemfiles/Gemfile.rails_6 - - rvm: 2.4 - gemfile: gemfiles/Gemfile.rails_6 - - rvm: 2.3 - gemfile: gemfiles/Gemfile.rails_head - - rvm: 2.4 - gemfile: gemfiles/Gemfile.rails_head - - rvm: 2.5 - gemfile: gemfiles/Gemfile.rails_head - - rvm: 2.6 - gemfile: gemfiles/Gemfile.rails_head From 919f41b02255ca100145c01a42e811c3c711334b Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 16:52:15 +0100 Subject: [PATCH 41/42] Fail fast! --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e3fc3fd..c7d01e2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,7 @@ jobs: --health-timeout=5s --health-retries=3 strategy: - fail-fast: false + fail-fast: true matrix: ruby: [2.4, 2.5, 2.6, 2.7, 3.0, 'head'] rails: [4, 5, 6, 'head'] From 55331037ba7544a195206b83d42efe11ab13f1d4 Mon Sep 17 00:00:00 2001 From: Tim Masliuchenko Date: Tue, 26 Oct 2021 17:13:11 +0100 Subject: [PATCH 42/42] Add a badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e86d2b..96f6b88 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# I18n::Backend::ActiveRecord +# I18n::Backend::ActiveRecord ![Build Status](https://github.com/svenfuchs/i18n-active_record/actions/workflows/test.yml/badge.svg) This repository contains the I18n ActiveRecord backend and support code that has been extracted from the "I18n": http://github.com/svenfuchs/i18n. It is fully compatible with Rails 4, 5 and 6.