Merge branch 'THRIFT-143'


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@714070 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_rb_generator.cc b/compiler/cpp/src/generate/t_rb_generator.cc
index f878ad7..4d90b10 100644
--- a/compiler/cpp/src/generate/t_rb_generator.cc
+++ b/compiler/cpp/src/generate/t_rb_generator.cc
@@ -448,7 +448,7 @@
   generate_rdoc(out, tstruct);
   indent(out) << "class " << type_name(tstruct);
   if (is_exception) {
-    out << " < StandardError";
+    out << " < Thrift::Exception";
   }
   out << endl;
 
diff --git a/lib/rb/Rakefile b/lib/rb/Rakefile
index 6ddca52..b5aa2ad 100644
--- a/lib/rb/Rakefile
+++ b/lib/rb/Rakefile
@@ -4,7 +4,7 @@
 
 THRIFT = '../../compiler/cpp/thrift'
 
-task :default => [:spec, :test]
+task :default => [:'gen-rb', :spec, :test]
 
 Spec::Rake::SpecTask.new do |t|
   t.spec_files = FileList['spec/**/*_spec.rb']
diff --git a/lib/rb/lib/thrift/struct.rb b/lib/rb/lib/thrift/struct.rb
index 4b99168..d01b4ce 100644
--- a/lib/rb/lib/thrift/struct.rb
+++ b/lib/rb/lib/thrift/struct.rb
@@ -82,6 +82,7 @@
     end
 
     def read(iprot)
+      validate
       # TODO(kevinclark): Make sure transport is C readable
       if iprot.respond_to?(:decode_binary)
         iprot.decode_binary(self, iprot.trans)
diff --git a/lib/rb/spec/ThriftSpec.thrift b/lib/rb/spec/ThriftSpec.thrift
index e04662b..51758a3 100644
--- a/lib/rb/spec/ThriftSpec.thrift
+++ b/lib/rb/spec/ThriftSpec.thrift
@@ -32,6 +32,11 @@
   11: list<Hello> hellos
 }
 
+exception Xception {
+  1: string message,
+  2: i32 code = 1
+}
+
 service NonblockingService {
   Hello greeting(1:bool english)
   bool block()
diff --git a/lib/rb/spec/gen-rb/ThriftSpec_types.rb b/lib/rb/spec/gen-rb/ThriftSpec_types.rb
index 6e5fed4..613c8de 100644
--- a/lib/rb/spec/gen-rb/ThriftSpec_types.rb
+++ b/lib/rb/spec/gen-rb/ThriftSpec_types.rb
@@ -96,6 +96,24 @@
         SETS => {:type => Thrift::Types::LIST, :name => 'sets', :element => {:type => Thrift::Types::SET, :element => {:type => Thrift::Types::I16}}},
         HELLOS => {:type => Thrift::Types::LIST, :name => 'hellos', :element => {:type => Thrift::Types::STRUCT, :class => Hello}}
       }
+      def validate
+      end
+
+    end
+
+    class Xception < Thrift::Exception
+      include Thrift::Struct
+      MESSAGE = 1
+      CODE = 2
+
+      Thrift::Struct.field_accessor self, :message, :code
+      FIELDS = {
+        MESSAGE => {:type => Thrift::Types::STRING, :name => 'message'},
+        CODE => {:type => Thrift::Types::I32, :name => 'code', :default => 1}
+      }
+      def validate
+      end
+
     end
 
   end
diff --git a/lib/rb/spec/struct_spec.rb b/lib/rb/spec/struct_spec.rb
index 7c52d16..4dc8714 100644
--- a/lib/rb/spec/struct_spec.rb
+++ b/lib/rb/spec/struct_spec.rb
@@ -5,15 +5,6 @@
   include Thrift
   include SpecNamespace
 
-  class Xception < Thrift::Exception
-    include Thrift::Struct
-    attr_accessor :message, :code
-    FIELDS = {
-      1 => {:type => Thrift::Types::STRING, :name => 'message'},
-      2 => {:type => Thrift::Types::I32, :name => 'code', :default => 1}
-    }
-  end
-
   describe Struct do
     it "should iterate over all fields properly" do
       fields = {}
@@ -209,7 +200,7 @@
         e.code.should == 1
         # ensure it gets serialized properly, this is the really important part
         prot = mock("Protocol")
-        prot.should_receive(:write_struct_begin).with("ThriftStructSpec::Xception")
+        prot.should_receive(:write_struct_begin).with("SpecNamespace::Xception")
         prot.should_receive(:write_struct_end)
         prot.should_receive(:write_field).with('message', Types::STRING, 1, "something happened")
         prot.should_receive(:write_field).with('code', Types::I32, 2, 1)
@@ -226,7 +217,7 @@
         e.message.should == "something happened"
         e.code.should == 5
         prot = mock("Protocol")
-        prot.should_receive(:write_struct_begin).with("ThriftStructSpec::Xception")
+        prot.should_receive(:write_struct_begin).with("SpecNamespace::Xception")
         prot.should_receive(:write_struct_end)
         prot.should_receive(:write_field).with('message', Types::STRING, 1, "something happened")
         prot.should_receive(:write_field).with('code', Types::I32, 2, 5)