1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Binary nodes should not generate the same hash as nodes of other classes

This commit is contained in:
Sean Griffin 2014-10-23 14:10:33 -06:00
parent 0e6c7e6de7
commit 0c99711a15
2 changed files with 27 additions and 1 deletions

View file

@ -16,7 +16,7 @@ module Arel
end
def hash
[@left, @right].hash
[self.class, @left, @right].hash
end
def eql? other

26
test/nodes/test_binary.rb Normal file
View file

@ -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