Skip to content

Commit 8069cc8

Browse files
committed
Remove deprecated support to passing coder and class as second argument to serialize
1 parent 39997a0 commit 8069cc8

File tree

4 files changed

+7
-45
lines changed

4 files changed

+7
-45
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 passing coder and class as second argument to `serialize`.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated support to `ActiveRecord::Base#read_attribute(:id)` to return the custom primary key value.
26

37
*Rafael Mendonça França*

activerecord/lib/active_record/attribute_methods/serialization.rb

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,29 +180,7 @@ module ClassMethods
180180
# serialize :preferences, coder: Rot13JSON
181181
# end
182182
#
183-
def serialize(attr_name, class_name_or_coder = nil, coder: nil, type: Object, yaml: {}, **options)
184-
unless class_name_or_coder.nil?
185-
if class_name_or_coder == ::JSON || [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
186-
ActiveRecord.deprecator.warn(<<~MSG)
187-
Passing the coder as positional argument is deprecated and will be removed in Rails 7.2.
188-
189-
Please pass the coder as a keyword argument:
190-
191-
serialize #{attr_name.inspect}, coder: #{class_name_or_coder}
192-
MSG
193-
coder = class_name_or_coder
194-
else
195-
ActiveRecord.deprecator.warn(<<~MSG)
196-
Passing the class as positional argument is deprecated and will be removed in Rails 7.2.
197-
198-
Please pass the class as a keyword argument:
199-
200-
serialize #{attr_name.inspect}, type: #{class_name_or_coder.name}
201-
MSG
202-
type = class_name_or_coder
203-
end
204-
end
205-
183+
def serialize(attr_name, coder: nil, type: Object, yaml: {}, **options)
206184
coder ||= default_column_serializer
207185
unless coder
208186
raise ArgumentError, <<~MSG.squish

activerecord/test/cases/serialized_attribute_test.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -693,26 +693,4 @@ def test_supports_permitted_classes_for_default_column_serializer
693693
topic = Topic.new(content: Time.now)
694694
assert topic.save
695695
end
696-
697-
def test_recognizes_coder_as_deprecated_positional_argument
698-
some_coder = Struct.new(:foo) do
699-
def self.dump(value)
700-
value.foo
701-
end
702-
703-
def self.load(value)
704-
new(value)
705-
end
706-
end
707-
708-
assert_deprecated(/Please pass the coder as a keyword argument/, ActiveRecord.deprecator) do
709-
Topic.serialize(:content, some_coder)
710-
end
711-
end
712-
713-
def test_recognizes_type_as_deprecated_positional_argument
714-
assert_deprecated(/Please pass the class as a keyword argument/, ActiveRecord.deprecator) do
715-
Topic.serialize(:content, Hash)
716-
end
717-
end
718696
end

guides/source/7_2_release_notes.md

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

141141
* Remove deprecated support to `ActiveRecord::Base#read_attribute(:id)` to return the custom primary key value.
142142

143+
* Remove deprecated support to passing coder and class as second argument to `serialize`.
144+
143145
### Deprecations
144146

145147
* Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`

0 commit comments

Comments
 (0)