aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/arel/nodes_test.rb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2018-04-25 08:18:02 +0930
committerGitHub <noreply@github.com>2018-04-25 08:18:02 +0930
commit989b1cb4a326632a686d61df42695b27e4ef6b2e (patch)
tree026a41714b44dba185f084f8f21bb81eb01db681 /activerecord/test/cases/arel/nodes_test.rb
parent7e815415edbe42f1df64d786a8f923a171778d64 (diff)
parent354f1c28e81d9846fb9e5346fcca50cf303c12c1 (diff)
downloadrails-989b1cb4a326632a686d61df42695b27e4ef6b2e.tar.gz
rails-989b1cb4a326632a686d61df42695b27e4ef6b2e.tar.bz2
rails-989b1cb4a326632a686d61df42695b27e4ef6b2e.zip
Merge pull request #32097 from matthewd/arel
Merge Arel
Diffstat (limited to 'activerecord/test/cases/arel/nodes_test.rb')
-rw-r--r--activerecord/test/cases/arel/nodes_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/cases/arel/nodes_test.rb b/activerecord/test/cases/arel/nodes_test.rb
new file mode 100644
index 0000000000..9021de0d20
--- /dev/null
+++ b/activerecord/test/cases/arel/nodes_test.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require_relative "helper"
+
+module Arel
+ module Nodes
+ class TestNodes < Arel::Test
+ def test_every_arel_nodes_have_hash_eql_eqeq_from_same_class
+ # #descendants code from activesupport
+ node_descendants = []
+ ObjectSpace.each_object(Arel::Nodes::Node.singleton_class) do |k|
+ next if k.respond_to?(:singleton_class?) && k.singleton_class?
+ node_descendants.unshift k unless k == self
+ end
+ node_descendants.delete(Arel::Nodes::Node)
+ node_descendants.delete(Arel::Nodes::NodeExpression)
+
+ bad_node_descendants = node_descendants.reject do |subnode|
+ eqeq_owner = subnode.instance_method(:==).owner
+ eql_owner = subnode.instance_method(:eql?).owner
+ hash_owner = subnode.instance_method(:hash).owner
+
+ eqeq_owner < Arel::Nodes::Node &&
+ eqeq_owner == eql_owner &&
+ eqeq_owner == hash_owner
+ end
+
+ problem_msg = "Some subclasses of Arel::Nodes::Node do not have a" \
+ " #== or #eql? or #hash defined from the same class as the others"
+ assert_empty bad_node_descendants, problem_msg
+ end
+ end
+ end
+end