From a9e33bf0f699cd35ce2a1442a705c468b3e4ca45 Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Wed, 12 Dec 2012 23:11:04 +0100 Subject: [PATCH] THRIFT-1699 Native Union#read has extra read_field_end call Patch: Kevin Radloff --- lib/rb/ext/struct.c | 3 --- lib/rb/spec/union_spec.rb | 14 +++++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/rb/ext/struct.c b/lib/rb/ext/struct.c index 5a9a679f..8fbadbee 100644 --- a/lib/rb/ext/struct.c +++ b/lib/rb/ext/struct.c @@ -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); diff --git a/lib/rb/spec/union_spec.rb b/lib/rb/spec/union_spec.rb index db08cab7..dd84906a 100644 --- a/lib/rb/spec/union_spec.rb +++ b/lib/rb/spec/union_spec.rb @@ -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.") -- 2.17.1