diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-09 15:20:39 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-09 15:20:39 -0700 |
commit | 03e560b0943f90155a13934c27abfe3827579d8b (patch) | |
tree | cad08608843c92e43122a634cedb3de98c4d9be5 | |
parent | e33c568f5e07e8caf7d36e8a8ca1a793b1781dc4 (diff) | |
download | rails-03e560b0943f90155a13934c27abfe3827579d8b.tar.gz rails-03e560b0943f90155a13934c27abfe3827579d8b.tar.bz2 rails-03e560b0943f90155a13934c27abfe3827579d8b.zip |
add test for sql string collector
-rw-r--r-- | test/collectors/test_sql_string.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/collectors/test_sql_string.rb b/test/collectors/test_sql_string.rb new file mode 100644 index 0000000000..6d2e23151b --- /dev/null +++ b/test/collectors/test_sql_string.rb @@ -0,0 +1,38 @@ +require 'helper' +require 'arel/collectors/bind' + +module Arel + module Collectors + class TestSqlString < Arel::Test + def setup + @conn = FakeRecord::Base.new + @visitor = Visitors::ToSql.new @conn.connection + super + end + + def collect node + @visitor.accept(node, Collectors::SQLString.new) + end + + def compile node + collect(node).value + end + + def ast_with_binds bv + table = Table.new(:users) + manager = Arel::SelectManager.new Table.engine, table + manager.where(table[:age].eq(bv)) + manager.where(table[:name].eq(bv)) + manager.ast + end + + def test_compile + bv = Nodes::BindParam.new('?') + collector = collect ast_with_binds bv + + sql = collector.compile ["hello", "world"] + assert_equal 'SELECT FROM "users" WHERE "users"."age" = ? AND "users"."name" = ?', sql + end + end + end +end |