class ActiveModelI18nTests
Public Instance Methods
setup()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 7 def setup I18n.backend = I18n::Backend::Simple.new end
teardown()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 11 def teardown I18n.backend.reload! end
test_human_attribute_name_does_not_modify_options()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 108 def test_human_attribute_name_does_not_modify_options options = { default: "Cool gender" } Person.human_attribute_name("gender", options) assert_equal({ default: "Cool gender" }, options) end
test_human_does_not_modify_options()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 102 def test_human_does_not_modify_options options = { default: "person model" } Person.model_name.human(options) assert_equal({ default: "person model" }, options) end
test_translated_deeply_nested_model_attributes()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 67 def test_translated_deeply_nested_model_attributes I18n.backend.store_translations "en", activemodel: { attributes: { "person/contacts/addresses": { street: "Deeply Nested Address Street" } } } assert_equal "Deeply Nested Address Street", Person.human_attribute_name("contacts.addresses.street") end
test_translated_model_attributes()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 15 def test_translated_model_attributes I18n.backend.store_translations "en", activemodel: { attributes: { person: { name: "person name attribute" } } } assert_equal "person name attribute", Person.human_attribute_name("name") end
test_translated_model_attributes_falling_back_to_default()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 34 def test_translated_model_attributes_falling_back_to_default assert_equal "Name", Person.human_attribute_name("name") end
test_translated_model_attributes_using_default_option()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 25 def test_translated_model_attributes_using_default_option assert_equal "name default attribute", Person.human_attribute_name("name", default: "name default attribute") end
test_translated_model_attributes_using_default_option_as_symbol()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 29 def test_translated_model_attributes_using_default_option_as_symbol I18n.backend.store_translations "en", default_name: "name default attribute" assert_equal "name default attribute", Person.human_attribute_name("name", default: :default_name) end
test_translated_model_attributes_using_default_option_as_symbol_and_falling_back_to_default()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 38 def test_translated_model_attributes_using_default_option_as_symbol_and_falling_back_to_default assert_equal "Name", Person.human_attribute_name("name", default: :default_name) end
test_translated_model_attributes_with_ancestor()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 47 def test_translated_model_attributes_with_ancestor I18n.backend.store_translations "en", activemodel: { attributes: { child: { name: "child name attribute" } } } assert_equal "child name attribute", Child.human_attribute_name("name") end
test_translated_model_attributes_with_ancestors_fallback()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 52 def test_translated_model_attributes_with_ancestors_fallback I18n.backend.store_translations "en", activemodel: { attributes: { person: { name: "person name attribute" } } } assert_equal "person name attribute", Child.human_attribute_name("name") end
test_translated_model_attributes_with_attribute_matching_namespaced_model_name()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 57 def test_translated_model_attributes_with_attribute_matching_namespaced_model_name I18n.backend.store_translations "en", activemodel: { attributes: { person: { gender: "person gender" }, "person/gender": { attribute: "person gender attribute" } } } assert_equal "person gender", Person.human_attribute_name("gender") assert_equal "person gender attribute", Person::Gender.human_attribute_name("attribute") end
test_translated_model_attributes_with_default()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 20 def test_translated_model_attributes_with_default I18n.backend.store_translations "en", attributes: { name: "name default attribute" } assert_equal "name default attribute", Person.human_attribute_name("name") end
test_translated_model_attributes_with_symbols()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 42 def test_translated_model_attributes_with_symbols I18n.backend.store_translations "en", activemodel: { attributes: { person: { name: "person name attribute" } } } assert_equal "person name attribute", Person.human_attribute_name(:name) end
test_translated_model_names()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 82 def test_translated_model_names I18n.backend.store_translations "en", activemodel: { models: { person: "person model" } } assert_equal "person model", Person.model_name.human end
test_translated_model_names_with_ancestors_fallback()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 97 def test_translated_model_names_with_ancestors_fallback I18n.backend.store_translations "en", activemodel: { models: { person: "person model" } } assert_equal "person model", Child.model_name.human end
test_translated_model_names_with_sti()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 87 def test_translated_model_names_with_sti I18n.backend.store_translations "en", activemodel: { models: { child: "child model" } } assert_equal "child model", Child.model_name.human end
test_translated_model_with_namespace()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 92 def test_translated_model_with_namespace I18n.backend.store_translations "en", activemodel: { models: { 'person/gender': "gender model" } } assert_equal "gender model", Person::Gender.model_name.human end
test_translated_nested_model_attributes()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 72 def test_translated_nested_model_attributes I18n.backend.store_translations "en", activemodel: { attributes: { "person/addresses": { street: "Person Address Street" } } } assert_equal "Person Address Street", Person.human_attribute_name("addresses.street") end
test_translated_nested_model_attributes_with_namespace_fallback()
click to toggle source
# File activemodel/test/cases/translation_test.rb, line 77 def test_translated_nested_model_attributes_with_namespace_fallback I18n.backend.store_translations "en", activemodel: { attributes: { addresses: { street: "Cool Address Street" } } } assert_equal "Cool Address Street", Person.human_attribute_name("addresses.street") end