From 3718ccd2a61c2c189913bcfd487912f592fa0660 Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Thu, 8 Sep 2011 10:21:50 +0200 Subject: remove support of symbols on classify and camelize --- activesupport/test/inflector_test.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'activesupport/test/inflector_test.rb') diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index b9e299af75..6484811d34 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -10,7 +10,7 @@ module Ace end end -class InflectorTest < Test::Unit::TestCase +class InflectorTest < ActiveSupport::TestCase include InflectorTestCases def test_pluralize_plurals @@ -248,12 +248,6 @@ class InflectorTest < Test::Unit::TestCase end end - def test_classify_with_symbol - assert_nothing_raised do - assert_equal 'FooBar', ActiveSupport::Inflector.classify(:foo_bars) - end - end - def test_classify_with_leading_schema_name assert_equal 'FooBar', ActiveSupport::Inflector.classify('schema.foo_bar') end @@ -319,12 +313,6 @@ class InflectorTest < Test::Unit::TestCase end end - def test_symbol_to_lower_camel - SymbolToLowerCamel.each do |symbol, lower_camel| - assert_equal(lower_camel, ActiveSupport::Inflector.camelize(symbol, false)) - end - end - %w{plurals singulars uncountables humans}.each do |inflection_type| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def test_clear_#{inflection_type} @@ -380,6 +368,14 @@ class InflectorTest < Test::Unit::TestCase ActiveSupport::Inflector.inflections.instance_variable_set :@humans, cached_values[3] end + [:pluralize, :singularize, :camelize, :underscore, :humanize, :titleize, :tableize, :classify, :dasherize, :demodulize].each do |method| + test "should deprecate symbols on #{method}" do + assert_deprecated(/Using symbols in inflections is deprecated/) do + ActiveSupport::Inflector.send(method, :foo) + end + end + end + Irregularities.each do |irregularity| singular, plural = *irregularity ActiveSupport::Inflector.inflections do |inflect| -- cgit v1.2.3 From 6b010c2690de9ffce4878a9471c8adb33d4a21a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 8 Sep 2011 20:49:08 +0200 Subject: Revert removing gsub and sub from safe buffer. --- activesupport/test/inflector_test.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'activesupport/test/inflector_test.rb') diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 6484811d34..b9e299af75 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -10,7 +10,7 @@ module Ace end end -class InflectorTest < ActiveSupport::TestCase +class InflectorTest < Test::Unit::TestCase include InflectorTestCases def test_pluralize_plurals @@ -248,6 +248,12 @@ class InflectorTest < ActiveSupport::TestCase end end + def test_classify_with_symbol + assert_nothing_raised do + assert_equal 'FooBar', ActiveSupport::Inflector.classify(:foo_bars) + end + end + def test_classify_with_leading_schema_name assert_equal 'FooBar', ActiveSupport::Inflector.classify('schema.foo_bar') end @@ -313,6 +319,12 @@ class InflectorTest < ActiveSupport::TestCase end end + def test_symbol_to_lower_camel + SymbolToLowerCamel.each do |symbol, lower_camel| + assert_equal(lower_camel, ActiveSupport::Inflector.camelize(symbol, false)) + end + end + %w{plurals singulars uncountables humans}.each do |inflection_type| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def test_clear_#{inflection_type} @@ -368,14 +380,6 @@ class InflectorTest < ActiveSupport::TestCase ActiveSupport::Inflector.inflections.instance_variable_set :@humans, cached_values[3] end - [:pluralize, :singularize, :camelize, :underscore, :humanize, :titleize, :tableize, :classify, :dasherize, :demodulize].each do |method| - test "should deprecate symbols on #{method}" do - assert_deprecated(/Using symbols in inflections is deprecated/) do - ActiveSupport::Inflector.send(method, :foo) - end - end - end - Irregularities.each do |irregularity| singular, plural = *irregularity ActiveSupport::Inflector.inflections do |inflect| -- cgit v1.2.3 From 310565f537b5eeb134e9a4bb0801358432f03e04 Mon Sep 17 00:00:00 2001 From: Ryan Oblak Date: Thu, 22 Sep 2011 12:17:42 -0700 Subject: Added ActiveSupport::Inflector.safe_constantize and String#safe_constantize; refactored common constantize tests into ConstantizeTestCases --- activesupport/test/inflector_test.rb | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'activesupport/test/inflector_test.rb') diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index b9e299af75..5c956e0075 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -2,16 +2,11 @@ require 'abstract_unit' require 'active_support/inflector' require 'inflector_test_cases' - -module Ace - module Base - class Case - end - end -end +require 'constantize_test_cases' class InflectorTest < Test::Unit::TestCase include InflectorTestCases + include ConstantizeTestCases def test_pluralize_plurals assert_equal "plurals", ActiveSupport::Inflector.pluralize("plurals") @@ -282,17 +277,15 @@ class InflectorTest < Test::Unit::TestCase end def test_constantize - assert_nothing_raised { assert_equal Ace::Base::Case, ActiveSupport::Inflector.constantize("Ace::Base::Case") } - assert_nothing_raised { assert_equal Ace::Base::Case, ActiveSupport::Inflector.constantize("::Ace::Base::Case") } - assert_nothing_raised { assert_equal InflectorTest, ActiveSupport::Inflector.constantize("InflectorTest") } - assert_nothing_raised { assert_equal InflectorTest, ActiveSupport::Inflector.constantize("::InflectorTest") } - assert_raise(NameError) { ActiveSupport::Inflector.constantize("UnknownClass") } - assert_raise(NameError) { ActiveSupport::Inflector.constantize("An invalid string") } - assert_raise(NameError) { ActiveSupport::Inflector.constantize("InvalidClass\n") } + run_constantize_tests_on do |string| + ActiveSupport::Inflector.constantize(string) + end end - - def test_constantize_does_lexical_lookup - assert_raise(NameError) { ActiveSupport::Inflector.constantize("Ace::Base::InflectorTest") } + + def test_safe_constantize + run_safe_constantize_tests_on do |string| + ActiveSupport::Inflector.safe_constantize(string) + end end def test_ordinal -- cgit v1.2.3 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