From 4dbce79e95e3f56a9b48992dea4531493a5008cc Mon Sep 17 00:00:00 2001 From: Christopher Dell Date: Wed, 19 Nov 2014 15:08:56 +0100 Subject: Fix I18n regression introduced by #13832 Previously, when the `:raise` options was set to `false`, it would get overwritten to `true`, preventing custom exception handlers to be used. --- actionview/test/template/translation_helper_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'actionview/test/template/translation_helper_test.rb') diff --git a/actionview/test/template/translation_helper_test.rb b/actionview/test/template/translation_helper_test.rb index 362f05ea70..0eccfed8f6 100644 --- a/actionview/test/template/translation_helper_test.rb +++ b/actionview/test/template/translation_helper_test.rb @@ -1,11 +1,20 @@ require 'abstract_unit' +module I18n + class CustomExceptionHandler + def self.call(exception, locale, key, options) + 'from CustomExceptionHandler' + end + end +end + class TranslationHelperTest < ActiveSupport::TestCase include ActionView::Helpers::TranslationHelper attr_reader :request, :view setup do + I18n.exception_handler = nil I18n.backend.store_translations(:en, :translations => { :templates => { @@ -72,6 +81,16 @@ class TranslationHelperTest < ActiveSupport::TestCase end end + def test_uses_custom_exception_handler_when_specified + I18n.exception_handler = I18n::CustomExceptionHandler + assert_equal 'from CustomExceptionHandler', translate(:"translations.missing", raise: false) + end + + def test_uses_custom_exception_handler_when_specified_for_html + I18n.exception_handler = I18n::CustomExceptionHandler + assert_equal 'from CustomExceptionHandler', translate(:"translations.missing_html", raise: false) + end + def test_i18n_translate_defaults_to_nil_rescue_format expected = 'translation missing: en.translations.missing' assert_equal expected, I18n.translate(:"translations.missing") -- cgit v1.2.3