aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/string_ext_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-01-15 16:48:12 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-01-15 16:48:12 +0000
commita66b321bb022836709b0a55ba1c4a693beee286a (patch)
treecd68a05bf1d03eca92dbceb8f24e0101ba469d61 /activesupport/test/core_ext/string_ext_test.rb
parentd8805988a125720a315580050b7195537fb6e77a (diff)
downloadrails-a66b321bb022836709b0a55ba1c4a693beee286a.tar.gz
rails-a66b321bb022836709b0a55ba1c4a693beee286a.tar.bz2
rails-a66b321bb022836709b0a55ba1c4a693beee286a.zip
Added the meat for String inflection
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@414 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext/string_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
new file mode 100644
index 0000000000..317dbcf711
--- /dev/null
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -0,0 +1,64 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/core_ext/string'
+require File.dirname(__FILE__) + '/../../lib/misc'
+
+silence_warnings do
+ require File.dirname(__FILE__) + '/../inflector_test'
+end
+
+class StringInflectionsTest < Test::Unit::TestCase
+ def test_pluralize
+ InflectorTest::SingularToPlural.each do |singular, plural|
+ assert_equal(plural, singular.pluralize)
+ end
+
+ assert_equal("plurals", "plurals".pluralize)
+ end
+
+ def test_singularize
+ InflectorTest::SingularToPlural.each do |singular, plural|
+ assert_equal(singular, plural.singularize)
+ end
+ end
+
+ def test_camelize
+ InflectorTest::CamelToUnderscore.each do |camel, underscore|
+ assert_equal(camel, underscore.camelize)
+ end
+ end
+
+ def test_underscore
+ InflectorTest::CamelToUnderscore.each do |camel, underscore|
+ assert_equal(underscore, camel.underscore)
+ end
+
+ assert_equal "html_tidy", "HTMLTidy".underscore
+ assert_equal "html_tidy_generator", "HTMLTidyGenerator".underscore
+ end
+
+ def test_demodulize
+ assert_equal "Account", Inflector.demodulize("MyApplication::Billing::Account")
+ end
+
+ def test_foreign_key
+ InflectorTest::ClassNameToForeignKeyWithUnderscore.each do |klass, foreign_key|
+ assert_equal(foreign_key, klass.foreign_key)
+ end
+
+ InflectorTest::ClassNameToForeignKeyWithoutUnderscore.each do |klass, foreign_key|
+ assert_equal(foreign_key, klass.foreign_key(false))
+ end
+ end
+
+ def test_tableize
+ InflectorTest::ClassNameToTableName.each do |class_name, table_name|
+ assert_equal(table_name, class_name.tableize)
+ end
+ end
+
+ def test_classify
+ InflectorTest::ClassNameToTableName.each do |class_name, table_name|
+ assert_equal(class_name, table_name.classify)
+ end
+ end
+end