Skip to content

Commit

Permalink
Implement message-pack methods on Data class (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanharan authored Oct 12, 2023
1 parent 13efaae commit 6bf4ca7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/active_record/connection_adapters/sqlserver/type/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ def eql?(other)
self.class == other.class && value == other.value
end
alias :== :eql?

def self.from_msgpack_ext(string)
type, value = string.chomp!("msgpack_ext").split(',')

Data.new(value, type.constantize)
end

def to_msgpack_ext
[type.class.to_s, value].join(',') + "msgpack_ext"
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,19 @@ def thread_encrypting_and_decrypting(thread_label)
end
end

# Need to use `install_unregistered_type_fallback` instead of `install_unregistered_type_error` so that message-pack
# can read and write `ActiveRecord::ConnectionAdapters::SQLServer::Type::Data` objects.
class ActiveRecordMessagePackTest < ActiveRecord::TestCase
private
def serializer
@serializer ||= ::MessagePack::Factory.new.tap do |factory|
ActiveRecord::MessagePack::Extensions.install(factory)
ActiveSupport::MessagePack::Extensions.install(factory)
ActiveSupport::MessagePack::Extensions.install_unregistered_type_fallback(factory)
end
end
end

# TODO: Need to uncoerce the 'SerializedAttributeTest' tests before releasing adapter for Rails 7.1
class SerializedAttributeTest < ActiveRecord::TestCase
coerce_all_tests!
Expand Down

0 comments on commit 6bf4ca7

Please sign in to comment.