THRIFT-1699 Native Union#read has extra read_field_end call
authorJens Geyer <jensg@apache.org>
Wed, 12 Dec 2012 22:11:04 +0000 (23:11 +0100)
committerJens Geyer <jensg@apache.org>
Wed, 12 Dec 2012 22:11:04 +0000 (23:11 +0100)
Patch: Kevin Radloff

lib/rb/ext/struct.c
lib/rb/spec/union_spec.rb

index 5a9a679..8fbadbe 100644 (file)
@@ -627,9 +627,6 @@ static VALUE rb_thrift_union_read(VALUE self, VALUE protocol) {
     rb_raise(rb_eRuntimeError, "too many fields in union!");
   }
 
-  // read field end
-  default_read_field_end(protocol);
-
   // read struct end
   default_read_struct_end(protocol);
 
index db08cab..dd84906 100644 (file)
@@ -93,7 +93,7 @@ describe 'Union' do
       lambda { union.some_characters }.should raise_error(RuntimeError, "some_characters is not union's set field.")
     end
 
-    it "should serialize correctly" do
+    it "should serialize to binary correctly" do
       trans = Thrift::MemoryBufferTransport.new
       proto = Thrift::BinaryProtocol.new(trans)
 
@@ -105,6 +105,18 @@ describe 'Union' do
       other_union.should == union
     end
 
+    it "should serialize to json correctly" do
+      trans = Thrift::MemoryBufferTransport.new
+      proto = Thrift::JsonProtocol.new(trans)
+
+      union = SpecNamespace::My_union.new(:integer32, 25)
+      union.write(proto)
+
+      other_union = SpecNamespace::My_union.new(:integer32, 25)
+      other_union.read(proto)
+      other_union.should == union
+    end
+
     it "should raise when validating unset union" do
       union = SpecNamespace::My_union.new
       lambda { union.validate }.should raise_error(StandardError, "Union fields are not set.")