diff options
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/dependencies/service_one.rb | 5 | ||||
-rw-r--r-- | activesupport/test/dependencies/service_two.rb | 2 | ||||
-rw-r--r-- | activesupport/test/dependencies_test.rb | 39 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 122 |
4 files changed, 168 insertions, 0 deletions
diff --git a/activesupport/test/dependencies/service_one.rb b/activesupport/test/dependencies/service_one.rb new file mode 100644 index 0000000000..f43bfea235 --- /dev/null +++ b/activesupport/test/dependencies/service_one.rb @@ -0,0 +1,5 @@ +$loaded_service_one ||= 0 +$loaded_service_one += 1 + +class ServiceOne +end
\ No newline at end of file diff --git a/activesupport/test/dependencies/service_two.rb b/activesupport/test/dependencies/service_two.rb new file mode 100644 index 0000000000..5205a78bb8 --- /dev/null +++ b/activesupport/test/dependencies/service_two.rb @@ -0,0 +1,2 @@ +class ServiceTwo +end
\ No newline at end of file diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb new file mode 100644 index 0000000000..cf704992a1 --- /dev/null +++ b/activesupport/test/dependencies_test.rb @@ -0,0 +1,39 @@ +require File.dirname(__FILE__) + '/../abstract_unit' +require 'action_controller/support/dependencies' + +$LOAD_PATH << File.dirname(__FILE__) + '/../fixtures/dependencies' + +class DependenciesTest < Test::Unit::TestCase + def teardown + Dependencies.clear + end + + def test_require_dependency + require_dependency("service_one") + require_dependency("service_two") + assert_equal 2, Dependencies.loaded.size + end + + def test_require_dependency_two_times + require_dependency("service_one") + require_dependency("service_one") + assert_equal 1, Dependencies.loaded.size + end + + def test_reloading_dependency + require_dependency("service_one") + require_dependency("service_one") + assert_equal 1, $loaded_service_one + + Dependencies.reload + assert_equal 2, $loaded_service_one + end + + def test_require_missing_dependency + assert_raises(LoadError) { require_dependency("missing_service") } + end + + def test_require_missing_association + assert_nothing_raised { require_association("missing_model") } + end +end
\ No newline at end of file diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb new file mode 100644 index 0000000000..7bcff70bdd --- /dev/null +++ b/activesupport/test/inflector_test.rb @@ -0,0 +1,122 @@ +require 'abstract_unit' + +class InflectorTest < Test::Unit::TestCase + SingularToPlural = { + "search" => "searches", + "switch" => "switches", + "fix" => "fixes", + "box" => "boxes", + "process" => "processes", + "address" => "addresses", + "case" => "cases", + "stack" => "stacks", + + "category" => "categories", + "query" => "queries", + "ability" => "abilities", + "agency" => "agencies", + "movie" => "movies", + + "wife" => "wives", + "safe" => "saves", + "half" => "halves", + + "salesperson" => "salespeople", + "person" => "people", + + "spokesman" => "spokesmen", + "man" => "men", + "woman" => "women", + + "basis" => "bases", + "diagnosis" => "diagnoses", + + "datum" => "data", + "medium" => "media", + + "node_child" => "node_children", + "child" => "children", + + "experience" => "experiences", + "day" => "days", + + "comment" => "comments", + "foobar" => "foobars" + } + + CamelToUnderscore = { + "Product" => "product", + "SpecialGuest" => "special_guest", + "ApplicationController" => "application_controller" + } + + ClassNameToForeignKeyWithUnderscore = { + "Person" => "person_id", + "MyApplication::Billing::Account" => "account_id" + } + + ClassNameToForeignKeyWithoutUnderscore = { + "Person" => "personid", + "MyApplication::Billing::Account" => "accountid" + } + + ClassNameToTableName = { + "PrimarySpokesman" => "primary_spokesmen", + "NodeChild" => "node_children" + } + + def test_pluralize + SingularToPlural.each do |singular, plural| + assert_equal(plural, Inflector.pluralize(singular)) + end + + assert_equal("plurals", Inflector.pluralize("plurals")) + end + + def test_singularize + SingularToPlural.each do |singular, plural| + assert_equal(singular, Inflector.singularize(plural)) + end + end + + def test_camelize + CamelToUnderscore.each do |camel, underscore| + assert_equal(camel, Inflector.camelize(underscore)) + end + end + + def test_underscore + CamelToUnderscore.each do |camel, underscore| + assert_equal(underscore, Inflector.underscore(camel)) + end + + assert_equal "html_tidy", Inflector.underscore("HTMLTidy") + assert_equal "html_tidy_generator", Inflector.underscore("HTMLTidyGenerator") + end + + def test_demodulize + assert_equal "Account", Inflector.demodulize("MyApplication::Billing::Account") + end + + def test_foreign_key + ClassNameToForeignKeyWithUnderscore.each do |klass, foreign_key| + assert_equal(foreign_key, Inflector.foreign_key(klass)) + end + + ClassNameToForeignKeyWithoutUnderscore.each do |klass, foreign_key| + assert_equal(foreign_key, Inflector.foreign_key(klass, false)) + end + end + + def test_tableize + ClassNameToTableName.each do |class_name, table_name| + assert_equal(table_name, Inflector.tableize(class_name)) + end + end + + def test_classify + ClassNameToTableName.each do |class_name, table_name| + assert_equal(class_name, Inflector.classify(table_name)) + end + end +end
\ No newline at end of file |