From 0c99711a1564bf1cb213b35142a3c05feddef0bd Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Thu, 23 Oct 2014 14:10:33 -0600 Subject: [PATCH] Binary nodes should not generate the same hash as nodes of other classes --- lib/arel/nodes/binary.rb | 2 +- test/nodes/test_binary.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/nodes/test_binary.rb diff --git a/lib/arel/nodes/binary.rb b/lib/arel/nodes/binary.rb index e35d2fd2e7..dddbde1431 100644 --- a/lib/arel/nodes/binary.rb +++ b/lib/arel/nodes/binary.rb @@ -16,7 +16,7 @@ module Arel end def hash - [@left, @right].hash + [self.class, @left, @right].hash end def eql? other diff --git a/test/nodes/test_binary.rb b/test/nodes/test_binary.rb new file mode 100644 index 0000000000..7e25a21151 --- /dev/null +++ b/test/nodes/test_binary.rb @@ -0,0 +1,26 @@ +require 'helper' +require 'set' + +module Arel + module Nodes + describe 'Binary' do + describe '#hash' do + it 'generates a hash based on its value' do + eq = Equality.new('foo', 'bar') + eq2 = Equality.new('foo', 'bar') + eq3 = Equality.new('bar', 'baz') + + assert_equal eq.hash, eq2.hash + refute_equal eq.hash, eq3.hash + end + + it 'generates a hash specific to its class' do + eq = Equality.new('foo', 'bar') + neq = NotEqual.new('foo', 'bar') + + refute_equal eq.hash, neq.hash + end + end + end + end +end