diff options
author | Keenan Brock <keenan@thebrocks.net> | 2018-11-13 15:22:08 -0500 |
---|---|---|
committer | Keenan Brock <keenan@thebrocks.net> | 2018-11-13 17:05:45 -0500 |
commit | 63dd8d8e12edb25d8d5bac324aacb1caf05bbe22 (patch) | |
tree | 17be93d6389f6723309979ca2bdb39ac9f9349b7 /activerecord/test | |
parent | 7a954211e6ffe9b482fbd65711edadbb265bf1a7 (diff) | |
download | rails-63dd8d8e12edb25d8d5bac324aacb1caf05bbe22.tar.gz rails-63dd8d8e12edb25d8d5bac324aacb1caf05bbe22.tar.bz2 rails-63dd8d8e12edb25d8d5bac324aacb1caf05bbe22.zip |
Emit single pair of parens for UNION and UNION ALL
mysql has a great implementation to suppress multiple parens for union
sql statements.
This moves that functionality to the generic implementation
This also introduces that functionality for UNION ALL
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/arel/visitors/mysql_test.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/arel/visitors/to_sql_test.rb | 22 |
2 files changed, 22 insertions, 10 deletions
diff --git a/activerecord/test/cases/arel/visitors/mysql_test.rb b/activerecord/test/cases/arel/visitors/mysql_test.rb index 9d3bad8516..dae98b0583 100644 --- a/activerecord/test/cases/arel/visitors/mysql_test.rb +++ b/activerecord/test/cases/arel/visitors/mysql_test.rb @@ -13,16 +13,6 @@ module Arel @visitor.accept(node, Collectors::SQLString.new).value end - it "squashes parenthesis on multiple unions" do - subnode = Nodes::Union.new Arel.sql("left"), Arel.sql("right") - node = Nodes::Union.new subnode, Arel.sql("topright") - assert_equal 1, compile(node).scan("(").length - - subnode = Nodes::Union.new Arel.sql("left"), Arel.sql("right") - node = Nodes::Union.new Arel.sql("topleft"), subnode - assert_equal 1, compile(node).scan("(").length - end - ### # :'( # http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214 diff --git a/activerecord/test/cases/arel/visitors/to_sql_test.rb b/activerecord/test/cases/arel/visitors/to_sql_test.rb index b6426a211e..680c26a9ab 100644 --- a/activerecord/test/cases/arel/visitors/to_sql_test.rb +++ b/activerecord/test/cases/arel/visitors/to_sql_test.rb @@ -480,6 +480,28 @@ module Arel end end + describe "Nodes::Union" do + it "squashes parenthesis on multiple unions" do + subnode = Nodes::Union.new Arel.sql("left"), Arel.sql("right") + node = Nodes::Union.new subnode, Arel.sql("topright") + assert_equal("( left UNION right UNION topright )", compile(node)) + subnode = Nodes::Union.new Arel.sql("left"), Arel.sql("right") + node = Nodes::Union.new Arel.sql("topleft"), subnode + assert_equal("( topleft UNION left UNION right )", compile(node)) + end + end + + describe "Nodes::UnionAll" do + it "squashes parenthesis on multiple union alls" do + subnode = Nodes::UnionAll.new Arel.sql("left"), Arel.sql("right") + node = Nodes::UnionAll.new subnode, Arel.sql("topright") + assert_equal("( left UNION ALL right UNION ALL topright )", compile(node)) + subnode = Nodes::UnionAll.new Arel.sql("left"), Arel.sql("right") + node = Nodes::UnionAll.new Arel.sql("topleft"), subnode + assert_equal("( topleft UNION ALL left UNION ALL right )", compile(node)) + end + end + describe "Nodes::NotIn" do it "should know how to visit" do node = @attr.not_in [1, 2, 3] |