1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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)`
This commit is contained in:
Fumiaki MATSUSHIMA 2016-03-28 23:04:36 +09:00
parent 475109c517
commit 37a298b043
2 changed files with 19 additions and 4 deletions

View file

@ -3,7 +3,7 @@ module ActiveSupport
def load(source) def load(source)
super(source) super(source)
rescue ArgumentError, NameError => exc 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 # try loading the class/module
loaded = $1.constantize loaded = $1.constantize

View file

@ -29,7 +29,12 @@ class MarshalTest < ActiveSupport::TestCase
ActiveSupport::Dependencies.clear ActiveSupport::Dependencies.clear
with_autoloading_fixtures do 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
end end
@ -43,7 +48,12 @@ class MarshalTest < ActiveSupport::TestCase
ActiveSupport::Dependencies.clear ActiveSupport::Dependencies.clear
with_autoloading_fixtures do 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
end end
@ -128,7 +138,12 @@ class MarshalTest < ActiveSupport::TestCase
ActiveSupport::Dependencies.clear ActiveSupport::Dependencies.clear
with_autoloading_fixtures do 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 end
end end