From 0fc531392d1f606054a6d6e394304c72a846d4c8 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 29 Oct 2011 01:07:54 -0700 Subject: let demodulize do less work, and add tests This is also faster on 1.9. --- activesupport/test/inflector_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/test/inflector_test.rb') diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 5c956e0075..7d15b3c7e5 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -194,6 +194,8 @@ class InflectorTest < Test::Unit::TestCase def test_demodulize assert_equal "Account", ActiveSupport::Inflector.demodulize("MyApplication::Billing::Account") + assert_equal "Account", ActiveSupport::Inflector.demodulize("Account") + assert_equal "", ActiveSupport::Inflector.demodulize("") end def test_foreign_key -- cgit v1.2.3 From 11f6795b238172c4a13176062bd38b83285799b7 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 29 Oct 2011 18:03:35 -0700 Subject: defines Module#qualified_const_(defined?|get|set) and String#deconstantize This commit also implements a faster version of #demodulize I was unable to isolate with git add --patch. Not a big fan of the name #deconstantize. It complements #demodulize getting rid of the rightmost constant, hence the name, but it is unrelated to the well-known #constantize. So unsure. Could not come with anything better, please feel free to rename. --- activesupport/test/inflector_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'activesupport/test/inflector_test.rb') diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 7d15b3c7e5..6b7e839e43 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -198,6 +198,18 @@ class InflectorTest < Test::Unit::TestCase assert_equal "", ActiveSupport::Inflector.demodulize("") end + def test_deconstantize + assert_equal "MyApplication::Billing", ActiveSupport::Inflector.deconstantize("MyApplication::Billing::Account") + assert_equal "::MyApplication::Billing", ActiveSupport::Inflector.deconstantize("::MyApplication::Billing::Account") + + assert_equal "MyApplication", ActiveSupport::Inflector.deconstantize("MyApplication::Billing") + assert_equal "::MyApplication", ActiveSupport::Inflector.deconstantize("::MyApplication::Billing") + + assert_equal "", ActiveSupport::Inflector.deconstantize("Account") + assert_equal "", ActiveSupport::Inflector.deconstantize("::Account") + assert_equal "", ActiveSupport::Inflector.deconstantize("") + end + def test_foreign_key ClassNameToForeignKeyWithUnderscore.each do |klass, foreign_key| assert_equal(foreign_key, ActiveSupport::Inflector.foreign_key(klass)) -- cgit v1.2.3