Skip to content

Commit 6bf4ca7

Browse files
authored
Implement message-pack methods on Data class (#1115)
1 parent 13efaae commit 6bf4ca7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/active_record/connection_adapters/sqlserver/type/data.rb

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ def eql?(other)
3636
self.class == other.class && value == other.value
3737
end
3838
alias :== :eql?
39+
40+
def self.from_msgpack_ext(string)
41+
type, value = string.chomp!("msgpack_ext").split(',')
42+
43+
Data.new(value, type.constantize)
44+
end
45+
46+
def to_msgpack_ext
47+
[type.class.to_s, value].join(',') + "msgpack_ext"
48+
end
3949
end
4050
end
4151
end

test/cases/coerced_tests.rb

+13
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,19 @@ def thread_encrypting_and_decrypting(thread_label)
25862586
end
25872587
end
25882588

2589+
# Need to use `install_unregistered_type_fallback` instead of `install_unregistered_type_error` so that message-pack
2590+
# can read and write `ActiveRecord::ConnectionAdapters::SQLServer::Type::Data` objects.
2591+
class ActiveRecordMessagePackTest < ActiveRecord::TestCase
2592+
private
2593+
def serializer
2594+
@serializer ||= ::MessagePack::Factory.new.tap do |factory|
2595+
ActiveRecord::MessagePack::Extensions.install(factory)
2596+
ActiveSupport::MessagePack::Extensions.install(factory)
2597+
ActiveSupport::MessagePack::Extensions.install_unregistered_type_fallback(factory)
2598+
end
2599+
end
2600+
end
2601+
25892602
# TODO: Need to uncoerce the 'SerializedAttributeTest' tests before releasing adapter for Rails 7.1
25902603
class SerializedAttributeTest < ActiveRecord::TestCase
25912604
coerce_all_tests!

0 commit comments

Comments
 (0)