From bd323b3c99437cf1a50d7b4c23a64f296859c56a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 29 Dec 2004 21:03:21 +0000 Subject: Moved support from both Action Pack and Active Record into a separate module called Active Support that can be included using svn:externals in both git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@273 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/dependencies/service_one.rb | 5 + activesupport/test/dependencies/service_two.rb | 2 + activesupport/test/dependencies_test.rb | 39 ++++++++ activesupport/test/inflector_test.rb | 122 +++++++++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 activesupport/test/dependencies/service_one.rb create mode 100644 activesupport/test/dependencies/service_two.rb create mode 100644 activesupport/test/dependencies_test.rb create mode 100644 activesupport/test/inflector_test.rb (limited to 'activesupport/test') 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 -- cgit v1.2.3