Skip to content
Browse files

Fix exeption handling in I18n#transliterate

  • Loading branch information...
1 parent d53b6fe commit 30c27fa329a880f7894868e4212b255df9bfa5b6 @knapo knapo committed Jun 9, 2011
Showing with 20 additions and 3 deletions.
  1. +2 −3 lib/i18n.rb
  2. +18 −0 test/i18n_test.rb
View
5 lib/i18n.rb
@@ -220,12 +220,11 @@ def transliterate(*args)
options = args.pop if args.last.is_a?(Hash)
key = args.shift
locale = options && options.delete(:locale) || config.locale
- raises = options && options.delete(:raise)
+ handling = options && (options.delete(:throw) && :throw || options.delete(:raise) && :raise)
replacement = options && options.delete(:replacement)
config.backend.transliterate(locale, key, replacement)
rescue I18n::ArgumentError => exception
- raise exception if raises
- handle_exception(exception, locale, key, options)
+ handle_exception(handling, exception, locale, key, options || {})
end
# Localizes certain objects, such as dates and numbers to local formatting.
View
18 test/i18n_test.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
require 'test_helper'
class I18nTest < Test::Unit::TestCase
@@ -233,4 +234,21 @@ def call(exception, locale, key, options); key; end
assert_raise(I18n::ArgumentError) { I18n.with_locale(:pl) { raise I18n::ArgumentError } }
assert_equal I18n.default_locale, I18n.locale
end
+
+ test "I18n.translitarate handles I18n::ArgumentError exception" do
+ I18n::Backend::Transliterator.stubs(:get).raises(I18n::ArgumentError)
+ I18n.exception_handler.expects(:call).raises(I18n::ArgumentError)
+ assert_raise(I18n::ArgumentError) {
+ I18n.transliterate("ąćó")
+ }
+ end
+
+ test "I18n.translitarate raises I18n::ArgumentError exception" do
+ I18n::Backend::Transliterator.stubs(:get).raises(I18n::ArgumentError)
+ I18n.exception_handler.expects(:call).never
+ assert_raise(I18n::ArgumentError) {
+ I18n.transliterate("ąćó", :raise => true)
+ }
+ end
+
end

0 comments on commit 30c27fa

Please sign in to comment.
Something went wrong with that request. Please try again.