THRIFT-3176 ruby: Union incorrectly implements ==
Patch: István Karaszi
diff --git a/lib/rb/lib/thrift/union.rb b/lib/rb/lib/thrift/union.rb
index a7058f2..490c55c 100644
--- a/lib/rb/lib/thrift/union.rb
+++ b/lib/rb/lib/thrift/union.rb
@@ -87,12 +87,9 @@
end
def ==(other)
- other != nil && @setfield == other.get_set_field && @value == other.get_value
+ other.equal?(self) || other.instance_of?(self.class) && @setfield == other.get_set_field && @value == other.get_value
end
-
- def eql?(other)
- self.class == other.class && self == other
- end
+ alias_method :eql?, :==
def hash
[self.class.name, @setfield, @value].hash
@@ -176,4 +173,4 @@
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/rb/spec/union_spec.rb b/lib/rb/spec/union_spec.rb
index dd84906..a427090 100644
--- a/lib/rb/spec/union_spec.rb
+++ b/lib/rb/spec/union_spec.rb
@@ -53,6 +53,11 @@
union.should_not == nil
end
+ it "should not be equal with an empty String" do
+ union = SpecNamespace::My_union.new
+ union.should_not == ''
+ end
+
it "should not equate two different unions, i32 vs. string" do
union = SpecNamespace::My_union.new(:integer32, 25)
other_union = SpecNamespace::My_union.new(:some_characters, "blah!")