diff options
author | José Valim <jose.valim@gmail.com> | 2010-09-04 00:31:35 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-04 00:31:43 +0200 |
commit | 23a9455962f0362cf242ffa96db7a9e7fdb0804b (patch) | |
tree | c046d1285d078649db6833fa1b73a6c23f7f16ea /activemodel/test | |
parent | 63032c1162e96d3380168ca63ac42aa044dbebd6 (diff) | |
parent | c3c1a1e14859e6716970283caeab0c4c3720862e (diff) | |
download | rails-23a9455962f0362cf242ffa96db7a9e7fdb0804b.tar.gz rails-23a9455962f0362cf242ffa96db7a9e7fdb0804b.tar.bz2 rails-23a9455962f0362cf242ffa96db7a9e7fdb0804b.zip |
This commit merges most of the work done by Piotr Sarnacki in his Ruby Summer of Code project.
His work brings several capabilities from app to engines, as routes, middleware stack, asset handling and much more. Please check Rails::Engine documentation for more refenrences.
Merge remote branch 'drogus/engines'
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/naming_test.rb | 99 | ||||
-rw-r--r-- | activemodel/test/models/blog_post.rb | 13 |
2 files changed, 112 insertions, 0 deletions
diff --git a/activemodel/test/cases/naming_test.rb b/activemodel/test/cases/naming_test.rb index 5a8bff378a..c6b663ef93 100644 --- a/activemodel/test/cases/naming_test.rb +++ b/activemodel/test/cases/naming_test.rb @@ -2,6 +2,7 @@ require 'cases/helper' require 'models/contact' require 'models/sheep' require 'models/track_back' +require 'models/blog_post' class NamingTest < ActiveModel::TestCase def setup @@ -29,6 +30,86 @@ class NamingTest < ActiveModel::TestCase end end +class NamingWithNamespacedModelInIsolatedNamespaceTest < ActiveModel::TestCase + def setup + @model_name = ActiveModel::Name.new(Blog::Post, Blog) + end + + def test_singular + assert_equal 'blog_post', @model_name.singular + end + + def test_plural + assert_equal 'blog_posts', @model_name.plural + end + + def test_element + assert_equal 'post', @model_name.element + end + + def test_collection + assert_equal 'blog/posts', @model_name.collection + end + + def test_partial_path + assert_equal 'blog/posts/post', @model_name.partial_path + end + + def test_human + assert_equal 'Post', @model_name.human + end + + def test_route_key + assert_equal 'posts', @model_name.route_key + end + + def test_param_key + assert_equal 'post', @model_name.param_key + end + + def test_recognizing_namespace + assert_equal 'Post', Blog::Post.model_name.instance_variable_get("@unnamespaced") + end +end + +class NamingWithNamespacedModelInSharedNamespaceTest < ActiveModel::TestCase + def setup + @model_name = ActiveModel::Name.new(Blog::Post) + end + + def test_singular + assert_equal 'blog_post', @model_name.singular + end + + def test_plural + assert_equal 'blog_posts', @model_name.plural + end + + def test_element + assert_equal 'post', @model_name.element + end + + def test_collection + assert_equal 'blog/posts', @model_name.collection + end + + def test_partial_path + assert_equal 'blog/posts/post', @model_name.partial_path + end + + def test_human + assert_equal 'Post', @model_name.human + end + + def test_route_key + assert_equal 'blog_posts', @model_name.route_key + end + + def test_param_key + assert_equal 'blog_post', @model_name.param_key + end +end + class NamingHelpersTest < Test::Unit::TestCase def setup @klass = Contact @@ -36,6 +117,8 @@ class NamingHelpersTest < Test::Unit::TestCase @singular = 'contact' @plural = 'contacts' @uncountable = Sheep + @route_key = 'contacts' + @param_key = 'contact' end def test_singular @@ -54,6 +137,22 @@ class NamingHelpersTest < Test::Unit::TestCase assert_equal @plural, plural(@klass) end + def test_route_key + assert_equal @route_key, route_key(@record) + end + + def test_route_key_for_class + assert_equal @route_key, route_key(@klass) + end + + def test_param_key + assert_equal @param_key, param_key(@record) + end + + def test_param_key_for_class + assert_equal @param_key, param_key(@klass) + end + def test_uncountable assert uncountable?(@uncountable), "Expected 'sheep' to be uncoutable" assert !uncountable?(@klass), "Expected 'contact' to be countable" diff --git a/activemodel/test/models/blog_post.rb b/activemodel/test/models/blog_post.rb new file mode 100644 index 0000000000..d289177259 --- /dev/null +++ b/activemodel/test/models/blog_post.rb @@ -0,0 +1,13 @@ +module Blog + def self._railtie + Object.new + end + + def self.table_name_prefix + "blog_" + end + + class Post + extend ActiveModel::Naming + end +end |