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:
parent
0e6c7e6de7
commit
0c99711a15
2 changed files with 27 additions and 1 deletions
|
@ -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
26
test/nodes/test_binary.rb
Normal 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
|
Loading…
Reference in a new issue