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

add optional second argument to ActiveSupport core extension for Marshal#load so it can take a proc

This commit is contained in:
Jeff Latz 2017-02-14 14:47:30 -05:00
parent 87b2b6c512
commit a72498f776
3 changed files with 21 additions and 2 deletions

View file

@ -1,3 +1,9 @@
* In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional
argument for `Marshal#load( source [, proc] )`. This way we don't have to do
`Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc.
*Jeff Latz*
## Rails 5.1.0.beta1 (February 23, 2017) ##
* Cache `ActiveSupport::TimeWithZone#to_datetime` before freezing.

View file

@ -1,7 +1,7 @@
module ActiveSupport
module MarshalWithAutoloading # :nodoc:
def load(source)
super(source)
def load(source, proc = nil)
super(source, proc)
rescue ArgumentError, NameError => exc
if exc.message.match(%r|undefined class/module (.+?)(?:::)?\z|)
# try loading the class/module

View file

@ -19,6 +19,19 @@ class MarshalTest < ActiveSupport::TestCase
end
end
test "that Marshal#load still works when passed a proc" do
example_string = "test"
example_proc = Proc.new do |o|
if o.is_a?(String)
o.capitalize!
end
end
dumped = Marshal.dump(example_string)
assert_equal Marshal.load(dumped, example_proc), "Test"
end
test "that a missing class is autoloaded from string" do
dumped = nil
with_autoloading_fixtures do