test/i18n_test.rb in i18n-0.8.1 vs test/i18n_test.rb in i18n-0.8.3
- old
+ new
@@ -4,10 +4,11 @@
class I18nTest < I18n::TestCase
def setup
super
store_translations(:en, :currency => { :format => { :separator => '.', :delimiter => ',', } })
store_translations(:nl, :currency => { :format => { :separator => ',', :delimiter => '.', } })
+ store_translations(:en, "true" => "Yes", "false" => "No")
end
test "exposes its VERSION constant" do
assert I18n::VERSION
end
@@ -213,19 +214,31 @@
test "translate given an empty string as a key raises an I18n::ArgumentError" do
assert_raise(I18n::ArgumentError) { I18n.t("") }
end
+ test "translate given nil as a key raises an I18n::ArgumentError" do
+ assert_raise(I18n::ArgumentError) { I18n.t(nil) }
+ end
+
test "translate given an unavailable locale rases an I18n::InvalidLocale" do
begin
I18n.config.enforce_available_locales = true
assert_raise(I18n::InvalidLocale) { I18n.t(:foo, :locale => 'klingon') }
ensure
I18n.config.enforce_available_locales = false
end
end
+ test "translate given true as a key works" do
+ assert_equal "Yes", I18n.t(true)
+ end
+
+ test "translate given false as a key works" do
+ assert_equal "No", I18n.t(false)
+ end
+
test "available_locales can be replaced at runtime" do
begin
I18n.config.enforce_available_locales = true
assert_raise(I18n::InvalidLocale) { I18n.t(:foo, :locale => 'klingon') }
old_locales, I18n.config.available_locales = I18n.config.available_locales, [:klingon]
@@ -247,10 +260,18 @@
test "exists? given a non-existing key will return false" do
assert_equal false, I18n.exists?(:bogus)
end
+ test "exists? given an empty string will raise an error" do
+ assert_raise(I18n::ArgumentError) { I18n.exists?("") }
+ end
+
+ test "exists? given nil will raise an error" do
+ assert_raise(I18n::ArgumentError) { I18n.exists?(nil) }
+ end
+
test "exists? given an existing dot-separated key will return true" do
assert_equal true, I18n.exists?('currency.format.delimiter')
end
test "exists? given a non-existing dot-separated key will return false" do
@@ -394,21 +415,21 @@
assert_equal false, I18n.config.enforce_available_locales
ensure
I18n.config.enforce_available_locales = false
end
end
-
+
test 'I18n.reload! reloads the set of locales that are enforced' do
begin
# Clear the backend that affects the available locales and somehow can remain
# set from the last running test.
# For instance, it contains enough translations to cause a false positive with
# this test when ran with --seed=50992
I18n.backend = I18n::Backend::Simple.new
-
+
assert !I18n.available_locales.include?(:de), "Available locales should not include :de at this point"
-
+
I18n.enforce_available_locales = true
assert_raise(I18n::InvalidLocale) { I18n.default_locale = :de }
assert_raise(I18n::InvalidLocale) { I18n.locale = :de }
@@ -420,14 +441,14 @@
I18n.reload!
store_translations(:en, :foo => 'Foo in :en')
store_translations(:de, :foo => 'Foo in :de')
store_translations(:pl, :foo => 'Foo in :pl')
-
+
assert I18n.available_locales.include?(:de), ":de should now be allowed"
assert I18n.available_locales.include?(:en), ":en should now be allowed"
assert I18n.available_locales.include?(:pl), ":pl should now be allowed"
-
+
assert_nothing_raised { I18n.default_locale = I18n.locale = :en }
assert_nothing_raised { I18n.default_locale = I18n.locale = :de }
assert_nothing_raised { I18n.default_locale = I18n.locale = :pl }
ensure
I18n.enforce_available_locales = false