diff options
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb | 3 | ||||
-rw-r--r-- | activesupport/test/autoloading_fixtures/loads_constant.rb | 5 | ||||
-rw-r--r-- | activesupport/test/autoloading_fixtures/requires_constant.rb | 5 | ||||
-rw-r--r-- | activesupport/test/dependencies_test.rb | 51 | ||||
-rw-r--r-- | activesupport/test/deprecation/proxy_wrappers_test.rb | 22 | ||||
-rw-r--r-- | activesupport/test/rescuable_test.rb | 37 | ||||
-rw-r--r-- | activesupport/test/test_xml_mini.rb | 49 |
7 files changed, 172 insertions, 0 deletions
diff --git a/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb new file mode 100644 index 0000000000..e3d1218c96 --- /dev/null +++ b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb @@ -0,0 +1,3 @@ +module LoadedConstant +end + diff --git a/activesupport/test/autoloading_fixtures/loads_constant.rb b/activesupport/test/autoloading_fixtures/loads_constant.rb new file mode 100644 index 0000000000..0b30dc8bca --- /dev/null +++ b/activesupport/test/autoloading_fixtures/loads_constant.rb @@ -0,0 +1,5 @@ +module LoadsConstant +end + +# The _ = assignment is to prevent warnings +_ = RequiresConstant diff --git a/activesupport/test/autoloading_fixtures/requires_constant.rb b/activesupport/test/autoloading_fixtures/requires_constant.rb new file mode 100644 index 0000000000..14804a0de0 --- /dev/null +++ b/activesupport/test/autoloading_fixtures/requires_constant.rb @@ -0,0 +1,5 @@ +require "loaded_constant" + +module RequiresConstant +end + diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index d7bde185bd..f98d823f00 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -213,6 +213,50 @@ class DependenciesTest < Test::Unit::TestCase end end + def test_doesnt_break_normal_require + path = File.expand_path("../autoloading_fixtures/load_path", __FILE__) + original_path = $:.dup + original_features = $".dup + $:.push(path) + + with_autoloading_fixtures do + # The _ = assignments are to prevent warnings + _ = RequiresConstant + assert defined?(RequiresConstant) + assert defined?(LoadedConstant) + ActiveSupport::Dependencies.clear + _ = RequiresConstant + assert defined?(RequiresConstant) + assert defined?(LoadedConstant) + end + ensure + remove_constants(:RequiresConstant, :LoadedConstant, :LoadsConstant) + $".replace(original_features) + $:.replace(original_path) + end + + def test_doesnt_break_normal_require_nested + path = File.expand_path("../autoloading_fixtures/load_path", __FILE__) + original_path = $:.dup + original_features = $".dup + $:.push(path) + + with_autoloading_fixtures do + # The _ = assignments are to prevent warnings + _ = LoadsConstant + assert defined?(LoadsConstant) + assert defined?(LoadedConstant) + ActiveSupport::Dependencies.clear + _ = LoadsConstant + assert defined?(LoadsConstant) + assert defined?(LoadedConstant) + end + ensure + remove_constants(:RequiresConstant, :LoadedConstant, :LoadsConstant) + $".replace(original_features) + $:.replace(original_path) + end + def failing_test_access_thru_and_upwards_fails with_autoloading_fixtures do assert ! defined?(ModuleFolder) @@ -797,4 +841,11 @@ class DependenciesTest < Test::Unit::TestCase ensure ActiveSupport::Dependencies.hook! end + +private + def remove_constants(*constants) + constants.each do |constant| + Object.send(:remove_const, constant) if Object.const_defined?(constant) + end + end end diff --git a/activesupport/test/deprecation/proxy_wrappers_test.rb b/activesupport/test/deprecation/proxy_wrappers_test.rb new file mode 100644 index 0000000000..c507eff38e --- /dev/null +++ b/activesupport/test/deprecation/proxy_wrappers_test.rb @@ -0,0 +1,22 @@ +require 'abstract_unit' +require 'active_support/deprecation' + +class ProxyWrappersTest < Test::Unit::TestCase + Waffles = false + NewWaffles = :hamburgers + + def test_deprecated_object_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message") + assert !proxy + end + + def test_deprecated_instance_variable_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(nil, :waffles) + assert !proxy + end + + def test_deprecated_constant_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(Waffles, NewWaffles) + assert !proxy + end +end
\ No newline at end of file diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb index ff77e16edd..1c74ce8b2a 100644 --- a/activesupport/test/rescuable_test.rb +++ b/activesupport/test/rescuable_test.rb @@ -9,11 +9,16 @@ end class MadRonon < StandardError end +class CoolError < StandardError +end + class Stargate attr_accessor :result include ActiveSupport::Rescuable + rescue_from WraithAttack, :with => :sos_first + rescue_from WraithAttack, :with => :sos rescue_from NuclearExplosion do @@ -45,11 +50,30 @@ class Stargate def sos @result = 'killed' end + + def sos_first + @result = 'sos_first' + end + +end + +class CoolStargate < Stargate + attr_accessor :result + + include ActiveSupport::Rescuable + + rescue_from CoolError, :with => :sos_cool_error + + def sos_cool_error + @result = 'sos_cool_error' + end end + class RescueableTest < Test::Unit::TestCase def setup @stargate = Stargate.new + @cool_stargate = CoolStargate.new end def test_rescue_from_with_method @@ -66,4 +90,17 @@ class RescueableTest < Test::Unit::TestCase @stargate.dispatch :ronanize assert_equal 'dex', @stargate.result end + + def test_rescues_defined_later_are_added_at_end_of_the_rescue_handlers_array + expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon"] + result = @stargate.send(:rescue_handlers).collect {|e| e.first} + assert_equal expected, result + end + + def test_children_should_inherit_rescue_defintions_from_parents_and_child_rescue_should_be_appended + expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon", "CoolError"] + result = @cool_stargate.send(:rescue_handlers).collect {|e| e.first} + assert_equal expected, result + end + end diff --git a/activesupport/test/test_xml_mini.rb b/activesupport/test/test_xml_mini.rb new file mode 100644 index 0000000000..585eb15c6e --- /dev/null +++ b/activesupport/test/test_xml_mini.rb @@ -0,0 +1,49 @@ +require 'abstract_unit' +require 'active_support/xml_mini' + +class XmlMiniTest < Test::Unit::TestCase + def test_rename_key_dasherizes_by_default + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key") + end + + def test_rename_key_does_nothing_with_dasherize_true + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => true) + end + + def test_rename_key_does_nothing_with_dasherize_false + assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => false) + end + + def test_rename_key_camelizes_with_camelize_true + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) + end + + def test_rename_key_camelizes_with_camelize_true + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) + end + + def test_rename_key_does_not_dasherize_leading_underscores + assert_equal "_id", ActiveSupport::XmlMini.rename_key("_id") + end + + def test_rename_key_with_leading_underscore_dasherizes_interior_underscores + assert_equal "_my-key", ActiveSupport::XmlMini.rename_key("_my_key") + end + + def test_rename_key_does_not_dasherize_trailing_underscores + assert_equal "id_", ActiveSupport::XmlMini.rename_key("id_") + end + + def test_rename_key_with_trailing_underscore_dasherizes_interior_underscores + assert_equal "my-key_", ActiveSupport::XmlMini.rename_key("my_key_") + end + + def test_rename_key_does_not_dasherize_multiple_leading_underscores + assert_equal "__id", ActiveSupport::XmlMini.rename_key("__id") + end + + def test_rename_key_does_not_dasherize_multiple_leading_underscores + assert_equal "id__", ActiveSupport::XmlMini.rename_key("id__") + end + +end |