Skip to content

Commit 415709a

Browse files
committed
Remove deprecated support to YAML load ActiveRecord::Base instance in the Rails 4.2 and 4.1 formats
1 parent 99b54b6 commit 415709a

File tree

5 files changed

+13
-50
lines changed

5 files changed

+13
-50
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated support to YAML load `ActiveRecord::Base` instance in the Rails 4.2 and 4.1 formats.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated option `:spec_name` in the `configs_for` method.
26

37
*Rafael Mendonça França*

activerecord/lib/active_record/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def initialize(attributes = nil)
489489
# post.init_with(coder)
490490
# post.title # => 'hello world'
491491
def init_with(coder, &block)
492-
coder = LegacyYamlAdapter.convert(self.class, coder)
492+
coder = LegacyYamlAdapter.convert(coder)
493493
attributes = self.class.yaml_encoder.decode(coder)
494494
init_with_attributes(attributes, coder["new_record"], &block)
495495
end

activerecord/lib/active_record/legacy_yaml_adapter.rb

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,13 @@
22

33
module ActiveRecord
44
module LegacyYamlAdapter # :nodoc:
5-
def self.convert(klass, coder)
5+
def self.convert(coder)
66
return coder unless coder.is_a?(Psych::Coder)
77

88
case coder["active_record_yaml_version"]
99
when 1, 2 then coder
1010
else
11-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
12-
YAML loading from legacy format older than Rails 5.0 is deprecated
13-
and will be removed in Rails 7.0.
14-
MSG
15-
if coder["attributes"].is_a?(ActiveModel::AttributeSet)
16-
Rails420.convert(klass, coder)
17-
else
18-
Rails41.convert(klass, coder)
19-
end
20-
end
21-
end
22-
23-
module Rails420 # :nodoc:
24-
def self.convert(klass, coder)
25-
attribute_set = coder["attributes"]
26-
27-
klass.attribute_names.each do |attr_name|
28-
attribute = attribute_set[attr_name]
29-
if attribute.type.is_a?(Delegator)
30-
type_from_klass = klass.type_for_attribute(attr_name)
31-
attribute_set[attr_name] = attribute.with_type(type_from_klass)
32-
end
33-
end
34-
35-
coder
36-
end
37-
end
38-
39-
module Rails41 # :nodoc:
40-
def self.convert(klass, coder)
41-
attributes = klass.attributes_builder
42-
.build_from_database(coder["attributes"])
43-
new_record = coder["attributes"][klass.primary_key].blank?
44-
45-
{
46-
"attributes" => attributes,
47-
"new_record" => new_record,
48-
}
11+
raise("Active Record doesn't know how to load YAML with this format.")
4912
end
5013
end
5114
end

activerecord/test/cases/yaml_serialization_test.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,19 @@ def test_deserializing_rails_v1_mysql_yaml
112112
end
113113

114114
def test_deserializing_rails_41_yaml
115-
topic = assert_deprecated do
115+
error = assert_raises(RuntimeError) do
116116
yaml_load(yaml_fixture("rails_4_1"))
117117
end
118118

119-
assert_predicate topic, :new_record?
120-
assert_nil topic.id
121-
assert_equal "The First Topic", topic.title
122-
assert_equal({ omg: :lol }, topic.content)
119+
assert_equal "Active Record doesn't know how to load YAML with this format.", error.message
123120
end
124121

125122
def test_deserializing_rails_4_2_0_yaml
126-
topic = assert_deprecated do
123+
error = assert_raises(RuntimeError) do
127124
yaml_load(yaml_fixture("rails_4_2_0"))
128125
end
129126

130-
assert_not_predicate topic, :new_record?
131-
assert_equal 1, topic.id
132-
assert_equal "The First Topic", topic.title
133-
assert_equal("Have a nice day", topic.content)
127+
assert_equal "Active Record doesn't know how to load YAML with this format.", error.message
134128
end
135129

136130
def test_yaml_encoding_keeps_mutations

guides/source/7_0_release_notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ Please refer to the [Changelog][active-record] for detailed changes.
104104

105105
* Remove deprecated option `:spec_name` in the `configs_for` method.
106106

107+
* Remove deprecated support to YAML load `ActiveRecord::Base` instance in the Rails 4.2 and 4.1 formats.
108+
107109
### Deprecations
108110

109111
### Notable changes

0 commit comments

Comments
 (0)