summaryrefslogtreecommitdiff
path: root/lib/rb
diff options
context:
space:
mode:
authorRoger Meier <roger@apache.org>2015-06-01 22:01:09 +0200
committerRoger Meier <roger@apache.org>2015-06-01 22:01:09 +0200
commit56d38fb913791f7df476471d3c0294849140964a (patch)
tree4524eb28f89a84a29e5a7a1f3586e76947cafa2b /lib/rb
parent401d399ed0ceefebced795d450c61f5099a18ce1 (diff)
downloadthrift-56d38fb913791f7df476471d3c0294849140964a.tar.gz
THRIFT-3176 ruby: Union incorrectly implements ==
Patch: István Karaszi
Diffstat (limited to 'lib/rb')
-rw-r--r--lib/rb/lib/thrift/union.rb9
-rw-r--r--lib/rb/spec/union_spec.rb5
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/rb/lib/thrift/union.rb b/lib/rb/lib/thrift/union.rb
index a7058f2c4..490c55c40 100644
--- a/lib/rb/lib/thrift/union.rb
+++ b/lib/rb/lib/thrift/union.rb
@@ -87,12 +87,9 @@ module Thrift
end
def ==(other)
- other != nil && @setfield == other.get_set_field && @value == other.get_value
- end
-
- def eql?(other)
- self.class == other.class && self == other
+ other.equal?(self) || other.instance_of?(self.class) && @setfield == other.get_set_field && @value == other.get_value
end
+ alias_method :eql?, :==
def hash
[self.class.name, @setfield, @value].hash
@@ -176,4 +173,4 @@ module Thrift
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 dd84906ae..a4270906d 100644
--- a/lib/rb/spec/union_spec.rb
+++ b/lib/rb/spec/union_spec.rb
@@ -53,6 +53,11 @@ describe 'Union' do
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!")