1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix nil translation key lookup in controllers

This commit is contained in:
Jan Klimo 2020-12-22 21:17:51 +07:00
parent 903656f43f
commit 0c1028f4bb
2 changed files with 6 additions and 1 deletions

View file

@ -15,7 +15,7 @@ module AbstractController
# to translate many keys within the same controller / action and gives you a
# simple framework for scoping them consistently.
def translate(key, **options)
if key.start_with?(".")
if key&.start_with?(".")
path = controller_path.tr("/", ".")
defaults = [:"#{path}#{key}"]
defaults << options[:default] if options[:default]

View file

@ -65,6 +65,11 @@ module AbstractController
end
end
def test_nil_key_lookup
default = "foo"
assert_equal default, @controller.t(nil, default: default)
end
def test_lazy_lookup_with_symbol
@controller.stub :action_name, :index do
assert_equal "bar", @controller.t(:'.foo')