diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-07-21 08:33:09 -0400 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2017-07-21 08:33:09 -0400 |
commit | db1bb4e9a728a437d16f8bdb48c3b772c3e4edb0 (patch) | |
tree | f0f7623e9b730679adcb0dfe97f9c8415a91328f /test/collectors | |
parent | f031a3b9aa6a8093802e0188abce58e0b997078e (diff) | |
download | rails-db1bb4e9a728a437d16f8bdb48c3b772c3e4edb0.tar.gz rails-db1bb4e9a728a437d16f8bdb48c3b772c3e4edb0.tar.bz2 rails-db1bb4e9a728a437d16f8bdb48c3b772c3e4edb0.zip |
Add a value field `Nodes::BindParam`
This is part of a greater refactoring to have the `BindParam` nodes hold
onto their values. We want to generally keep the AST decoupled from what
you're actually doing with those values, but ultimately the usage of
`BindParam` is almost identical to how you'd use `Casted` or `Quoted`.
Forcing consumers of Arel's API to maintain the bind values separately
from the AST makes manipulating the AST essentially impossible, as you
would need to perform a full walk of the AST to determine whether a
given node contains bind parameters, and which value it maps to.
By storing the value on the bind parameter directly, we can collect them
in another AST pass (realistically it'll be part of the same pass that
performs SQL construction for performance reasons). This will
dramatically simplify AST manipulation for Rails or any other consumers
that work with bind params.
As part of this change I've removed the `BindVisitor`, which appears to
be dead code, and had tests break from this change.
Diffstat (limited to 'test/collectors')
-rw-r--r-- | test/collectors/test_sql_string.rb | 2 | ||||
-rw-r--r-- | test/collectors/test_substitute_bind_collector.rb (renamed from test/collectors/test_bind_collector.rb) | 10 |
2 files changed, 6 insertions, 6 deletions
diff --git a/test/collectors/test_sql_string.rb b/test/collectors/test_sql_string.rb index 769c2e6d53..8651296ff8 100644 --- a/test/collectors/test_sql_string.rb +++ b/test/collectors/test_sql_string.rb @@ -27,7 +27,7 @@ module Arel end def test_compile - bv = Nodes::BindParam.new + bv = Nodes::BindParam.new(nil) collector = collect ast_with_binds bv sql = collector.compile ["hello", "world"] diff --git a/test/collectors/test_bind_collector.rb b/test/collectors/test_substitute_bind_collector.rb index fef157782b..adcaf98319 100644 --- a/test/collectors/test_bind_collector.rb +++ b/test/collectors/test_substitute_bind_collector.rb @@ -4,7 +4,7 @@ require 'arel/collectors/substitute_binds' module Arel module Collectors - class TestBindCollector < Arel::Test + class TestSubstituteBindCollector < Arel::Test def setup @conn = FakeRecord::Base.new @visitor = Visitors::ToSql.new @conn.connection @@ -28,14 +28,14 @@ module Arel end def test_leaves_binds - node = Nodes::BindParam.new + node = Nodes::BindParam.new(nil) list = compile node assert_equal node, list.first assert_equal node.class, list.first.class end def test_adds_strings - bv = Nodes::BindParam.new + bv = Nodes::BindParam.new(nil) list = compile ast_with_binds bv assert_operator list.length, :>, 0 assert_equal bv, list.grep(Nodes::BindParam).first @@ -43,7 +43,7 @@ module Arel end def test_substitute_binds - bv = Nodes::BindParam.new + bv = Nodes::BindParam.new(nil) collector = collect ast_with_binds bv values = collector.value @@ -60,7 +60,7 @@ module Arel end def test_compile - bv = Nodes::BindParam.new + bv = Nodes::BindParam.new(nil) collector = collect ast_with_binds bv sql = collector.compile ["hello", "world"] |