Repository: thrift Updated Branches: refs/heads/master 401d399ed -> 56d38fb91
THRIFT-3176 ruby: Union incorrectly implements == Patch: István Karaszi Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/56d38fb9 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/56d38fb9 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/56d38fb9 Branch: refs/heads/master Commit: 56d38fb913791f7df476471d3c0294849140964a Parents: 401d399 Author: Roger Meier <[email protected]> Authored: Mon Jun 1 22:01:09 2015 +0200 Committer: Roger Meier <[email protected]> Committed: Mon Jun 1 22:01:09 2015 +0200 ---------------------------------------------------------------------- lib/rb/lib/thrift/union.rb | 9 +++------ lib/rb/spec/union_spec.rb | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/56d38fb9/lib/rb/lib/thrift/union.rb ---------------------------------------------------------------------- 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 @@ 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 http://git-wip-us.apache.org/repos/asf/thrift/blob/56d38fb9/lib/rb/spec/union_spec.rb ---------------------------------------------------------------------- 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 @@ 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!")
