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

[BUG] Behavior of base backend is not consistent with the behavior of fallbacks backend for nil keys #543

Open
khiav223577 opened this issue Nov 25, 2020 · 0 comments

Comments

@khiav223577
Copy link

khiav223577 commented Nov 25, 2020

What I tried to do

See rails/rails#40676 for more details.

begin
  require "bundler/inline"
rescue LoadError => e
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise e
end

gemfile(true) do
  source "https://rubygems.org"
  gem "minitest"
  gem "i18n", "~> 1.8.5"
end

require "minitest/autorun"
require "logger"

I18n.available_locales = [:en]

class BugTest < Minitest::Test
  def test_i18n_t_with_original_backend
    assert_nil I18n.t(nil)
  end

  def test_i18n_t_with_fallback_backend
    original_backend = I18n.backend
    fallback_backend = Class.new(original_backend.class) do
      include I18n::Backend::Fallbacks
    end
    I18n.backend = fallback_backend.new

    assert_nil I18n.t(nil)

  ensure
    I18n.backend = original_backend
  end
end

What I expected to happen

Expect I18n.t(nil) to return nil (or throw MissingTranslation) both in base backend and fallbacks backend.

What actually happened

The behavior is not the same. It may cause unexpected problems when a rails app get released.

Versions of i18n, rails, and anything else you think is necessary

rails (5.2.4.4)
i18n (1.8.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant