Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoodrow committed Nov 12, 2023
1 parent c1329cf commit 3859217
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
6 changes: 1 addition & 5 deletions lib/globalize/active_record/act_macro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ def enable_serializable_attribute(attr_name)
serializer = serializer.object_class
end

if ::ActiveRecord.version >= Gem::Version.new("7.1.0")
translation_class.send :serialize, attr_name, type: serializer
else
translation_class.send :serialize, attr_name, serializer
end
translation_class.send :serialize, attr_name, serializer
end
end

Expand Down
18 changes: 9 additions & 9 deletions lib/patches/active_record/rails7_1/serialization.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module Globalize
module AttributeMethods
module Serialization
def serialize(attr_name, type: Object, **options)
super(attr_name, type: type, **options)
def serialize(attr_name, class_name_or_coder = Object, **options)
if class_name_or_coder == ::JSON || [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) }
options = options.merge(coder: class_name_or_coder, type: Object)
else
options = options.merge(coder: default_column_serializer, type: class_name_or_coder)
end

coder = if type == ::JSON
::ActiveRecord::Coders::JSON
elsif [:load, :dump].all? { |x| type.respond_to?(x) }
type
else
::ActiveRecord::Coders::YAMLColumn.new(attr_name, type)
end
super(attr_name, **options)

coder = build_column_serializer(attr_name, options[:coder], options[:type], options[:yaml])

self.globalize_serialized_attributes = globalize_serialized_attributes.dup
self.globalize_serialized_attributes[attr_name] = coder
Expand Down

0 comments on commit 3859217

Please sign in to comment.