Skip to content

Commit

Permalink
ActiveModel::Name#i18n_key: Fix doc and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Dec 6, 2011
1 parent 8aa7b86 commit d834755
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activemodel/lib/active_model/naming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def _singularize(string, replacement='_')
# BookCover.model_name # => "BookCover"
# BookCover.model_name.human # => "Book cover"
#
# BookCover.model_name.i18n_key # => "book_cover"
# BookModule::BookCover.model_name.i18n_key # => "book_module.book_cover"
# BookCover.model_name.i18n_key # => :book_cover
# BookModule::BookCover.model_name.i18n_key # => :"book_module/book_cover"
#
# Providing the functionality that ActiveModel::Naming provides in your object
# is required to pass the Active Model Lint test. So either extending the provided
Expand Down
20 changes: 20 additions & 0 deletions activemodel/test/cases/naming_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def test_partial_path
def test_human
assert_equal 'Track back', @model_name.human
end

def test_i18n_key
assert_equal :"post/track_back", @model_name.i18n_key
end
end

class NamingWithNamespacedModelInIsolatedNamespaceTest < ActiveModel::TestCase
Expand Down Expand Up @@ -74,6 +78,10 @@ def test_route_key
def test_param_key
assert_equal 'post', @model_name.param_key
end

def test_i18n_key
assert_equal :"blog/post", @model_name.i18n_key
end
end

class NamingWithNamespacedModelInSharedNamespaceTest < ActiveModel::TestCase
Expand Down Expand Up @@ -114,6 +122,10 @@ def test_route_key
def test_param_key
assert_equal 'blog_post', @model_name.param_key
end

def test_i18n_key
assert_equal :"blog/post", @model_name.i18n_key
end
end

class NamingWithSuppliedModelNameTest < ActiveModel::TestCase
Expand Down Expand Up @@ -154,6 +166,10 @@ def test_route_key
def test_param_key
assert_equal 'article', @model_name.param_key
end

def test_i18n_key
assert_equal :"article", @model_name.i18n_key
end
end

class NamingUsingRelativeModelNameTest < ActiveModel::TestCase
Expand Down Expand Up @@ -188,6 +204,10 @@ def test_route_key
def test_param_key
assert_equal 'post', @model_name.param_key
end

def test_i18n_key
assert_equal :"blog/post", @model_name.i18n_key
end
end

class NamingHelpersTest < Test::Unit::TestCase
Expand Down

0 comments on commit d834755

Please sign in to comment.