From df9dd77ee5cf2610599942555e49dedd678a8e8b Mon Sep 17 00:00:00 2001 From: Bert Bruynooghe Date: Wed, 17 Feb 2016 22:30:10 +0100 Subject: [PATCH] added Casted#hash --- lib/arel/nodes/casted.rb | 4 ++++ test/nodes/test_casted.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/nodes/test_casted.rb diff --git a/lib/arel/nodes/casted.rb b/lib/arel/nodes/casted.rb index 9fa02955ef..543374d695 100644 --- a/lib/arel/nodes/casted.rb +++ b/lib/arel/nodes/casted.rb @@ -10,6 +10,10 @@ module Arel def nil?; @val.nil?; end + def hash + [@class, @val, @attribute].hash + end + def eql? other self.class == other.class && self.val == other.val && diff --git a/test/nodes/test_casted.rb b/test/nodes/test_casted.rb new file mode 100644 index 0000000000..6d775e17ec --- /dev/null +++ b/test/nodes/test_casted.rb @@ -0,0 +1,16 @@ +require 'helper' + +module Arel + module Nodes + describe Casted do + describe '#hash' do + it 'is equal when eql? returns true' do + one = Casted.new 1, 2 + also_one = Casted.new 1, 2 + + assert_equal one.hash, also_one.hash + end + end + end + end +end