Author: kclark
Date: Fri Dec 12 18:39:20 2008
New Revision: 726156

URL: http://svn.apache.org/viewvc?rev=726156&view=rev
Log:
rb: Thrift.check_type should check struct classes [THRIFT-185]

Author: Piotr Kozikowski

Modified:
    incubator/thrift/trunk/lib/rb/lib/thrift/types.rb
    incubator/thrift/trunk/lib/rb/spec/types_spec.rb

Modified: incubator/thrift/trunk/lib/rb/lib/thrift/types.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/lib/thrift/types.rb?rev=726156&r1=726155&r2=726156&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/lib/thrift/types.rb (original)
+++ incubator/thrift/trunk/lib/rb/lib/thrift/types.rb Fri Dec 12 18:39:20 2008
@@ -60,6 +60,8 @@
       value.each do |el|
         check_type(el, field[:element], "#{name}.element", false)
       end
+    when Types::STRUCT
+      raise TypeError, "Expected #{field[:class]}, received #{value.class} for 
field #{name}" unless field[:class] == value.class
     end
   end
 

Modified: incubator/thrift/trunk/lib/rb/spec/types_spec.rb
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/rb/spec/types_spec.rb?rev=726156&r1=726155&r2=726156&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/rb/spec/types_spec.rb (original)
+++ incubator/thrift/trunk/lib/rb/spec/types_spec.rb Fri Dec 12 18:39:20 2008
@@ -37,7 +37,7 @@
       lambda { Thrift.check_type("3",            {:type => Types::STRING}, 
:foo) }.should_not raise_error(TypeError)
       lambda { Thrift.check_type(3,              {:type => Types::STRING}, 
:foo) }.should raise_error(TypeError)
       hello = SpecNamespace::Hello.new
-      lambda { Thrift.check_type(hello,          {:type => Types::STRUCT}, 
:foo) }.should_not raise_error(TypeError)
+      lambda { Thrift.check_type(hello,          {:type => Types::STRUCT, 
:class => SpecNamespace::Hello}, :foo) }.should_not raise_error(TypeError)
       lambda { Thrift.check_type("foo",          {:type => Types::STRUCT}, 
:foo) }.should raise_error(TypeError)
       lambda { Thrift.check_type({:foo => 1},    {:type => Types::MAP},    
:foo) }.should_not raise_error(TypeError)
       lambda { Thrift.check_type([1],            {:type => Types::MAP},    
:foo) }.should raise_error(TypeError)
@@ -74,6 +74,9 @@
       lambda { Thrift.check_type(Set.new([1, 2]), field, :foo) }.should_not 
raise_error(TypeError)
       lambda { Thrift.check_type(Set.new([1, nil, 2]), field, :foo) }.should 
raise_error(TypeError)
       lambda { Thrift.check_type(Set.new([1, 2.3, 2]), field, :foo) }.should 
raise_error(TypeError)
+      
+      field = {:type => Types::STRUCT, :class => SpecNamespace::Hello}
+      lambda { Thrift.check_type(SpecNamespace::BoolStruct, field, :foo) 
}.should raise_error(TypeError)
     end
 
     it "should give the TypeError a readable message" do


Reply via email to