diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-15 01:45:35 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-15 01:45:35 +0000 |
commit | b1999be5a7efd67e2602c37ed898aa8433661863 (patch) | |
tree | 03bc833276075d802d0ce0ad261baed3d7232533 /activesupport/test | |
parent | 88a3343ed57c01ca358da8473d15fc4d2b4a5bff (diff) | |
download | rails-b1999be5a7efd67e2602c37ed898aa8433661863.tar.gz rails-b1999be5a7efd67e2602c37ed898aa8433661863.tar.bz2 rails-b1999be5a7efd67e2602c37ed898aa8433661863.zip |
A hopefully more successful attempt at the Routing branch merge
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@617 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
6 files changed, 102 insertions, 0 deletions
diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 4523430ebe..cdab0f9ed0 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -1,6 +1,13 @@ require 'test/unit' require File.dirname(__FILE__) + '/../lib/inflector' +module A + module B + class C + end + end +end + class InflectorTest < Test::Unit::TestCase SingularToPlural = { "search" => "searches", @@ -50,6 +57,12 @@ class InflectorTest < Test::Unit::TestCase "SpecialGuest" => "special_guest", "ApplicationController" => "application_controller" } + + CamelWithModuleToUnderscoreWithSlash = { + "Admin::Product" => "admin/product", + "Users::Commission::Department" => "users/commission/department", + "UsersSection::CommissionDepartment" => "users_section/commission_department", + } ClassNameToForeignKeyWithUnderscore = { "Person" => "person_id", @@ -100,6 +113,18 @@ class InflectorTest < Test::Unit::TestCase assert_equal "html_tidy_generator", Inflector.underscore("HTMLTidyGenerator") end + def test_camelize_with_module + CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore| + assert_equal(camel, Inflector.camelize(underscore)) + end + end + + def test_underscore_with_slashes + CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore| + assert_equal(underscore, Inflector.underscore(camel)) + end + end + def test_demodulize assert_equal "Account", Inflector.demodulize("MyApplication::Billing::Account") end @@ -131,4 +156,10 @@ class InflectorTest < Test::Unit::TestCase assert_equal(human, Inflector.humanize(underscore)) end end + + def test_constantize + assert_equal A::B::C, Inflector.constantize("A::B::C") + assert_equal InflectorTest, Inflector.constantize("InflectorTest") + assert_raises(NameError) { Inflector.constantize("UnknownClass") } + end end
\ No newline at end of file diff --git a/activesupport/test/loading_module/admin/access_controller.rb b/activesupport/test/loading_module/admin/access_controller.rb new file mode 100644 index 0000000000..ddcbda8132 --- /dev/null +++ b/activesupport/test/loading_module/admin/access_controller.rb @@ -0,0 +1,2 @@ +class Admin::AccessController +end diff --git a/activesupport/test/loading_module/admin/user_controller.rb b/activesupport/test/loading_module/admin/user_controller.rb new file mode 100644 index 0000000000..f265f1597a --- /dev/null +++ b/activesupport/test/loading_module/admin/user_controller.rb @@ -0,0 +1,2 @@ +class Admin::UserController +end diff --git a/activesupport/test/loading_module/content_controller.rb b/activesupport/test/loading_module/content_controller.rb new file mode 100644 index 0000000000..f0870161e5 --- /dev/null +++ b/activesupport/test/loading_module/content_controller.rb @@ -0,0 +1,2 @@ +class ContentController +end diff --git a/activesupport/test/loading_module/resource_controller.rb b/activesupport/test/loading_module/resource_controller.rb new file mode 100644 index 0000000000..d948f366bf --- /dev/null +++ b/activesupport/test/loading_module/resource_controller.rb @@ -0,0 +1,2 @@ +class ResourceController +end diff --git a/activesupport/test/loading_module_tests.rb b/activesupport/test/loading_module_tests.rb new file mode 100644 index 0000000000..c1d8c7de62 --- /dev/null +++ b/activesupport/test/loading_module_tests.rb @@ -0,0 +1,63 @@ +require 'test/unit' +require '../lib/core_ext.rb' +require '../lib/dependencies.rb' + +STAGING_DIRECTORY = 'loading_module' + +class LoadingModuleTests < Test::Unit::TestCase + def setup + @loading_module = Dependencies::LoadingModule.new(STAGING_DIRECTORY) + Object.const_set(:Controllers, @loading_module) + end + def teardown + @loading_module.clear + Object.send :remove_const, :Controllers + end + + def test_setup + assert_kind_of Dependencies::LoadingModule, @loading_module + end + + def test_const_available + assert @loading_module.const_available?(:Admin) + assert @loading_module.const_available?(:ResourceController) + assert @loading_module.const_available?(:ContentController) + assert @loading_module.const_available?("ContentController") + + assert_equal false, @loading_module.const_available?(:AdminController) + assert_equal false, @loading_module.const_available?(:RandomName) + end + + def test_const_load_module + assert @loading_module.const_load!(:Admin) + assert_kind_of Module, @loading_module::Admin + assert_kind_of Dependencies::LoadingModule, @loading_module::Admin + end + + def test_const_load_controller + assert @loading_module.const_load!(:ContentController) + assert_kind_of Class, @loading_module::ContentController + end + + def test_const_load_nested_controller + assert @loading_module.const_load!(:Admin) + assert @loading_module::Admin.const_available?(:UserController) + assert @loading_module::Admin.const_load!(:UserController) + assert_kind_of Class, @loading_module::Admin::UserController + end + + def test_pretty_access + assert_kind_of Module, @loading_module::Admin + assert_kind_of Dependencies::LoadingModule, @loading_module::Admin + + assert_kind_of Class, @loading_module::Admin::UserController + assert_kind_of Class, @loading_module::Admin::AccessController + assert_kind_of Class, @loading_module::ResourceController + assert_kind_of Class, @loading_module::ContentController + end + + def test_missing_name + assert_raises(NameError) {@loading_module::PersonController} + assert_raises(NameError) {@loading_module::Admin::FishController} + end +end
\ No newline at end of file |