aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/inflector_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/inflector_test.rb')
-rw-r--r--activesupport/test/inflector_test.rb31
1 files changed, 31 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