aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/visitors/visitor.rb9
-rw-r--r--test/visitors/test_dispatch_contamination.rb22
2 files changed, 28 insertions, 3 deletions
diff --git a/lib/arel/visitors/visitor.rb b/lib/arel/visitors/visitor.rb
index 204657883f..33ec5eafb4 100644
--- a/lib/arel/visitors/visitor.rb
+++ b/lib/arel/visitors/visitor.rb
@@ -7,12 +7,15 @@ module Arel
private
- DISPATCH = Hash.new do |hash, klass|
- hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}"
+ DISPATCH = Hash.new do |hash, visitor_class|
+ hash[visitor_class] =
+ Hash.new do |hash, node_class|
+ hash[node_class] = "visit_#{(node_class.name || '').gsub('::', '_')}"
+ end
end
def dispatch
- DISPATCH
+ DISPATCH[self.class]
end
def visit object, attribute = nil
diff --git a/test/visitors/test_dispatch_contamination.rb b/test/visitors/test_dispatch_contamination.rb
new file mode 100644
index 0000000000..d3c9e8af2e
--- /dev/null
+++ b/test/visitors/test_dispatch_contamination.rb
@@ -0,0 +1,22 @@
+require 'helper'
+
+module Arel
+ module Visitors
+ describe 'avoiding contamination between visitor dispatch tables' do
+ before do
+ @connection = Table.engine.connection
+ @table = Table.new(:users)
+ end
+
+ it 'dispatches properly after failing upwards' do
+ node = Nodes::Union.new(Nodes::True.new, Nodes::False.new)
+ assert_equal "( TRUE UNION FALSE )", node.to_sql
+
+ node.first # from Nodes::Node's Enumerable mixin
+
+ assert_equal "( TRUE UNION FALSE )", node.to_sql
+ end
+ end
+ end
+end
+