Skip to content

Commit

Permalink
Remove support to Marshal load Rails 5.x ActiveModel::AttributeSet
Browse files Browse the repository at this point in the history
…format
  • Loading branch information
rafaelfranca committed Nov 17, 2021
1 parent 2996732 commit 1f3cfb2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
4 changes: 4 additions & 0 deletions activemodel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Remove support to Marshal load Rails 5.x `ActiveModel::AttributeSet` format.

*Rafael Mendonça França*

* Remove support to Marshal and YAML load Rails 5.x error format.

*Rafael Mendonça França*
Expand Down
11 changes: 1 addition & 10 deletions activemodel/lib/active_model/attribute_set/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,7 @@ def marshal_dump
end

def marshal_load(values)
if values.is_a?(Hash)
ActiveSupport::Deprecation.warn(<<~MSG)
Marshalling load from legacy attributes format is deprecated and will be removed in Rails 7.0.
MSG
empty_hash = {}.freeze
initialize(empty_hash, empty_hash, empty_hash, empty_hash, values)
@materialized = true
else
initialize(*values)
end
initialize(*values)
end

protected
Expand Down
12 changes: 2 additions & 10 deletions activemodel/test/cases/attribute_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def serialize(value)
assert_equal({ foo: "1" }, attributes.to_hash)
end

test "marshalling dump/load legacy materialized attribute hash" do
test "marshalling dump/load materialized attribute hash" do
builder = AttributeSet::Builder.new(foo: Type::String.new)

def builder.build_from_database(values = {}, additional_types = {})
Expand All @@ -242,16 +242,8 @@ def builder.build_from_database(values = {}, additional_types = {})

attributes = builder.build_from_database(foo: "1")

attributes.instance_variable_get(:@attributes).instance_eval do
class << self
def marshal_dump
materialize # legacy marshal format before Rails 5.1
end
end
end

data = Marshal.dump(attributes)
attributes = assert_deprecated { Marshal.load(data) }
attributes = Marshal.load(data)
assert_equal({ foo: "1" }, attributes.to_hash)
end

Expand Down
2 changes: 2 additions & 0 deletions guides/source/7_0_release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ Please refer to the [Changelog][active-model] for detailed changes.

* Remove support to Marshal and YAML load Rails 5.x error format.

* Remove support to Marshal load Rails 5.x `ActiveModel::AttributeSet` format.

### Deprecations

### Notable changes
Expand Down

0 comments on commit 1f3cfb2

Please sign in to comment.