mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow inspected records to be marshaled
Since 32b03b4615
, records which have had
`inspect` called on them can't be marshaled, because of this anonymous
`DelegateClass`. We can fix this by giving the class a concrete name.
This commit is contained in:
parent
1a40a48113
commit
2bdb58cc47
2 changed files with 18 additions and 4 deletions
|
@ -584,12 +584,16 @@ module ActiveRecord
|
|||
self.class.instance_method(:inspect).owner != ActiveRecord::Base.instance_method(:inspect).owner
|
||||
end
|
||||
|
||||
class InspectionMask < DelegateClass(::String)
|
||||
def pretty_print(pp)
|
||||
pp.text __getobj__
|
||||
end
|
||||
end
|
||||
private_constant :InspectionMask
|
||||
|
||||
def inspection_filter
|
||||
@inspection_filter ||= begin
|
||||
mask = DelegateClass(::String).new(ActiveSupport::ParameterFilter::FILTERED)
|
||||
def mask.pretty_print(pp)
|
||||
pp.text __getobj__
|
||||
end
|
||||
mask = InspectionMask.new(ActiveSupport::ParameterFilter::FILTERED)
|
||||
ActiveSupport::ParameterFilter.new(self.class.filter_attributes, mask: mask)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1173,6 +1173,16 @@ class BasicsTest < ActiveRecord::TestCase
|
|||
assert_equal expected.attributes, actual.attributes
|
||||
end
|
||||
|
||||
def test_marshal_inspected_round_trip
|
||||
expected = posts(:welcome)
|
||||
expected.inspect
|
||||
|
||||
marshalled = Marshal.dump(expected)
|
||||
actual = Marshal.load(marshalled)
|
||||
|
||||
assert_equal expected.attributes, actual.attributes
|
||||
end
|
||||
|
||||
def test_marshal_new_record_round_trip
|
||||
marshalled = Marshal.dump(Post.new)
|
||||
post = Marshal.load(marshalled)
|
||||
|
|
Loading…
Reference in a new issue