diff options
author | Fumiaki MATSUSHIMA <mtsmfm@gmail.com> | 2016-03-28 23:04:36 +0900 |
---|---|---|
committer | Fumiaki MATSUSHIMA <mtsmfm@gmail.com> | 2016-03-28 23:06:51 +0900 |
commit | 37a298b04350425b1055b7bead8560c3d5e7331d (patch) | |
tree | 6842b474d7441905a2988f633c2935414a1dcdba | |
parent | 475109c517e724c015ee13061416568a7d6b9757 (diff) | |
download | rails-37a298b04350425b1055b7bead8560c3d5e7331d.tar.gz rails-37a298b04350425b1055b7bead8560c3d5e7331d.tar.bz2 rails-37a298b04350425b1055b7bead8560c3d5e7331d.zip |
Fix marshal with autoloading for nested class/module
#24150 break autoloading for nested class/module.
There is test for nested class but it doesn't work correctly.
Following code will autoload `ClassFolder::ClassFolderSubclass` before `Marshal.load`:
`assert_kind_of ClassFolder::ClassFolderSubclass, Marshal.load(dumped)`
-rw-r--r-- | activesupport/lib/active_support/core_ext/marshal.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/marshal_test.rb | 21 |
2 files changed, 19 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/marshal.rb b/activesupport/lib/active_support/core_ext/marshal.rb index ca278cb2fa..5875ae5f71 100644 --- a/activesupport/lib/active_support/core_ext/marshal.rb +++ b/activesupport/lib/active_support/core_ext/marshal.rb @@ -3,7 +3,7 @@ module ActiveSupport def load(source) super(source) rescue ArgumentError, NameError => exc - if exc.message.match(%r|undefined class/module (.+)|) + if exc.message.match(%r|undefined class/module (.+?)(::)?\z|) # try loading the class/module loaded = $1.constantize diff --git a/activesupport/test/core_ext/marshal_test.rb b/activesupport/test/core_ext/marshal_test.rb index 07c0c0d8cb..380f64c6fd 100644 --- a/activesupport/test/core_ext/marshal_test.rb +++ b/activesupport/test/core_ext/marshal_test.rb @@ -29,7 +29,12 @@ class MarshalTest < ActiveSupport::TestCase ActiveSupport::Dependencies.clear with_autoloading_fixtures do - assert_kind_of EM, Marshal.load(dumped) + object = nil + assert_nothing_raised do + object = Marshal.load(dumped) + end + + assert_kind_of EM, object end end @@ -43,7 +48,12 @@ class MarshalTest < ActiveSupport::TestCase ActiveSupport::Dependencies.clear with_autoloading_fixtures do - assert_kind_of ClassFolder::ClassFolderSubclass, Marshal.load(dumped) + object = nil + assert_nothing_raised do + object = Marshal.load(dumped) + end + + assert_kind_of ClassFolder::ClassFolderSubclass, object end end @@ -128,7 +138,12 @@ class MarshalTest < ActiveSupport::TestCase ActiveSupport::Dependencies.clear with_autoloading_fixtures do - assert_kind_of EM, Marshal.load(f) + object = nil + assert_nothing_raised do + object = Marshal.load(f) + end + + assert_kind_of EM, object end end end |