2009-10-20 20:20:01 -04:00
|
|
|
require 'cases/helper'
|
2009-12-23 06:28:02 -05:00
|
|
|
require 'models/person'
|
2009-10-20 20:20:01 -04:00
|
|
|
|
|
|
|
class ActiveModelI18nTests < ActiveModel::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
I18n.backend = I18n::Backend::Simple.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_translated_model_attributes
|
2009-12-23 06:28:02 -05:00
|
|
|
I18n.backend.store_translations 'en', :activemodel => {:attributes => {:person => {:name => 'person name attribute'} } }
|
|
|
|
assert_equal 'person name attribute', Person.human_attribute_name('name')
|
2009-10-20 20:20:01 -04:00
|
|
|
end
|
2010-01-06 20:45:50 -05:00
|
|
|
|
|
|
|
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
|
2009-10-20 20:20:01 -04:00
|
|
|
|
|
|
|
def test_translated_model_attributes_with_symbols
|
2009-12-23 06:28:02 -05:00
|
|
|
I18n.backend.store_translations 'en', :activemodel => {:attributes => {:person => {:name => 'person name attribute'} } }
|
|
|
|
assert_equal 'person name attribute', Person.human_attribute_name(:name)
|
2009-10-20 20:20:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_translated_model_attributes_with_ancestor
|
2009-12-23 06:28:02 -05:00
|
|
|
I18n.backend.store_translations 'en', :activemodel => {:attributes => {:child => {:name => 'child name attribute'} } }
|
|
|
|
assert_equal 'child name attribute', Child.human_attribute_name('name')
|
2009-10-20 20:20:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_translated_model_attributes_with_ancestors_fallback
|
2009-12-23 06:28:02 -05:00
|
|
|
I18n.backend.store_translations 'en', :activemodel => {:attributes => {:person => {:name => 'person name attribute'} } }
|
|
|
|
assert_equal 'person name attribute', Child.human_attribute_name('name')
|
2009-10-20 20:20:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_translated_model_names
|
2009-12-23 06:28:02 -05:00
|
|
|
I18n.backend.store_translations 'en', :activemodel => {:models => {:person => 'person model'} }
|
|
|
|
assert_equal 'person model', Person.model_name.human
|
2009-10-20 20:20:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_translated_model_names_with_sti
|
2009-12-23 06:28:02 -05:00
|
|
|
I18n.backend.store_translations 'en', :activemodel => {:models => {:child => 'child model'} }
|
|
|
|
assert_equal 'child model', Child.model_name.human
|
2009-10-20 20:20:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_translated_model_names_with_ancestors_fallback
|
2009-12-23 06:28:02 -05:00
|
|
|
I18n.backend.store_translations 'en', :activemodel => {:models => {:person => 'person model'} }
|
|
|
|
assert_equal 'person model', Child.model_name.human
|
2009-10-20 20:20:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|