Permalink
Browse files

fixed inherited ext types

1 parent b6def39 commit 88826f11c7026b9cc3a146ecb959c8cf107ae978 @christopheraue christopheraue committed Oct 13, 2016
Showing with 30 additions and 2 deletions.
  1. +4 −2 ext/msgpack/packer_ext_registry.h
  2. +26 −0 spec/packer_spec.rb
@@ -85,8 +85,10 @@ static inline VALUE msgpack_packer_ext_registry_lookup(msgpack_packer_ext_regist
VALUE superclass = args[1];
if(superclass != Qnil) {
- rb_hash_aset(pkrg->cache, ext_class, superclass);
- return superclass;
+ VALUE superclass_type = rb_hash_lookup(pkrg->hash, superclass);
+ rb_hash_aset(pkrg->cache, ext_class, superclass_type);
+ *ext_type_result = FIX2INT(rb_ary_entry(superclass_type, 0));
+ return rb_ary_entry(superclass_type, 1);
}
return Qnil;
View
@@ -324,6 +324,32 @@ def self.from_msgpack_ext(data)
expect(two[:packer]).to eq(:to_msgpack_ext)
end
+ context 'when it has no ext type but a super class has' do
+ before { stub_const('Value', Class.new) }
+ before do
+ Value.class_eval do
+ def to_msgpack_ext
+ 'value_msgpacked'
+ end
+ end
+ end
+ before { packer.register_type(0x01, Value, :to_msgpack_ext) }
+
+ context "when it is a child class" do
+ before { stub_const('InheritedValue', Class.new(Value)) }
+ subject { packer.pack(InheritedValue.new).to_s }
+
+ it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" }
+
+ context "when it is a grandchild class" do
+ before { stub_const('InheritedTwiceValue', Class.new(InheritedValue)) }
+ subject { packer.pack(InheritedTwiceValue.new).to_s }
+
+ it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" }
+ end
+ end
+ end
+
context 'when registering a type for symbols' do
before { packer.register_type(0x00, ::Symbol, :to_msgpack_ext) }

0 comments on commit 88826f1

Please sign in to comment.