diff options
author | Matthew Draper <matthew@trebex.net> | 2018-02-24 17:15:50 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2018-02-24 17:16:13 +1030 |
commit | 4c0a3d48804a363c7e9272519665a21f601b5248 (patch) | |
tree | 6b1f6e28f85cfd69a0ce534856ef939c7079d5cf /activerecord/test/cases/arel/visitors/postgres_test.rb | |
parent | 17ca17072dcdff11b3702a6b45f2fb0c8f8fe9a4 (diff) | |
download | rails-4c0a3d48804a363c7e9272519665a21f601b5248.tar.gz rails-4c0a3d48804a363c7e9272519665a21f601b5248.tar.bz2 rails-4c0a3d48804a363c7e9272519665a21f601b5248.zip |
Arel: rubocop -a
Diffstat (limited to 'activerecord/test/cases/arel/visitors/postgres_test.rb')
-rw-r--r-- | activerecord/test/cases/arel/visitors/postgres_test.rb | 77 |
1 files changed, 39 insertions, 38 deletions
diff --git a/activerecord/test/cases/arel/visitors/postgres_test.rb b/activerecord/test/cases/arel/visitors/postgres_test.rb index 6aa786b14f..ba37afecfb 100644 --- a/activerecord/test/cases/arel/visitors/postgres_test.rb +++ b/activerecord/test/cases/arel/visitors/postgres_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors @@ -10,19 +11,19 @@ module Arel @attr = @table[:id] end - def compile node + def compile(node) @visitor.accept(node, Collectors::SQLString.new).value end - describe 'locking' do - it 'defaults to FOR UPDATE' do - compile(Nodes::Lock.new(Arel.sql('FOR UPDATE'))).must_be_like %{ + describe "locking" do + it "defaults to FOR UPDATE" do + compile(Nodes::Lock.new(Arel.sql("FOR UPDATE"))).must_be_like %{ FOR UPDATE } end - it 'allows a custom string to be used as a lock' do - node = Nodes::Lock.new(Arel.sql('FOR SHARE')) + it "allows a custom string to be used as a lock" do + node = Nodes::Lock.new(Arel.sql("FOR SHARE")) compile(node).must_be_like %{ FOR SHARE } @@ -32,42 +33,42 @@ module Arel it "should escape LIMIT" do sc = Arel::Nodes::SelectStatement.new sc.limit = Nodes::Limit.new(Nodes.build_quoted("omg")) - sc.cores.first.projections << Arel.sql('DISTINCT ON') + sc.cores.first.projections << Arel.sql("DISTINCT ON") sc.orders << Arel.sql("xyz") - sql = compile(sc) + sql = compile(sc) assert_match(/LIMIT 'omg'/, sql) - assert_equal 1, sql.scan(/LIMIT/).length, 'should have one limit' + assert_equal 1, sql.scan(/LIMIT/).length, "should have one limit" end - it 'should support DISTINCT ON' do + it "should support DISTINCT ON" do core = Arel::Nodes::SelectCore.new - core.set_quantifier = Arel::Nodes::DistinctOn.new(Arel.sql('aaron')) - assert_match 'DISTINCT ON ( aaron )', compile(core) + core.set_quantifier = Arel::Nodes::DistinctOn.new(Arel.sql("aaron")) + assert_match "DISTINCT ON ( aaron )", compile(core) end - it 'should support DISTINCT' do + it "should support DISTINCT" do core = Arel::Nodes::SelectCore.new core.set_quantifier = Arel::Nodes::Distinct.new - assert_equal 'SELECT DISTINCT', compile(core) + assert_equal "SELECT DISTINCT", compile(core) end - it 'encloses LATERAL queries in parens' do - subquery = @table.project(:id).where(@table[:name].matches('foo%')) + it "encloses LATERAL queries in parens" do + subquery = @table.project(:id).where(@table[:name].matches("foo%")) compile(subquery.lateral).must_be_like %{ LATERAL (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') } end - it 'produces LATERAL queries with alias' do - subquery = @table.project(:id).where(@table[:name].matches('foo%')) - compile(subquery.lateral('bar')).must_be_like %{ + it "produces LATERAL queries with alias" do + subquery = @table.project(:id).where(@table[:name].matches("foo%")) + compile(subquery.lateral("bar")).must_be_like %{ LATERAL (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') bar } end describe "Nodes::Matches" do it "should know how to visit" do - node = @table[:name].matches('foo%') + node = @table[:name].matches("foo%") node.must_be_kind_of Nodes::Matches node.case_sensitive.must_equal(false) compile(node).must_be_like %{ @@ -76,7 +77,7 @@ module Arel end it "should know how to visit case sensitive" do - node = @table[:name].matches('foo%', nil, true) + node = @table[:name].matches("foo%", nil, true) node.case_sensitive.must_equal(true) compile(node).must_be_like %{ "users"."name" LIKE 'foo%' @@ -84,14 +85,14 @@ module Arel end it "can handle ESCAPE" do - node = @table[:name].matches('foo!%', '!') + node = @table[:name].matches("foo!%", "!") compile(node).must_be_like %{ "users"."name" ILIKE 'foo!%' ESCAPE '!' } end - it 'can handle subqueries' do - subquery = @table.project(:id).where(@table[:name].matches('foo%')) + it "can handle subqueries" do + subquery = @table.project(:id).where(@table[:name].matches("foo%")) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') @@ -101,7 +102,7 @@ module Arel describe "Nodes::DoesNotMatch" do it "should know how to visit" do - node = @table[:name].does_not_match('foo%') + node = @table[:name].does_not_match("foo%") node.must_be_kind_of Nodes::DoesNotMatch node.case_sensitive.must_equal(false) compile(node).must_be_like %{ @@ -110,7 +111,7 @@ module Arel end it "should know how to visit case sensitive" do - node = @table[:name].does_not_match('foo%', nil, true) + node = @table[:name].does_not_match("foo%", nil, true) node.case_sensitive.must_equal(true) compile(node).must_be_like %{ "users"."name" NOT LIKE 'foo%' @@ -118,14 +119,14 @@ module Arel end it "can handle ESCAPE" do - node = @table[:name].does_not_match('foo!%', '!') + node = @table[:name].does_not_match("foo!%", "!") compile(node).must_be_like %{ "users"."name" NOT ILIKE 'foo!%' ESCAPE '!' } end - it 'can handle subqueries' do - subquery = @table.project(:id).where(@table[:name].does_not_match('foo%')) + it "can handle subqueries" do + subquery = @table.project(:id).where(@table[:name].does_not_match("foo%")) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT ILIKE 'foo%') @@ -135,7 +136,7 @@ module Arel describe "Nodes::Regexp" do it "should know how to visit" do - node = @table[:name].matches_regexp('foo.*') + node = @table[:name].matches_regexp("foo.*") node.must_be_kind_of Nodes::Regexp node.case_sensitive.must_equal(true) compile(node).must_be_like %{ @@ -144,7 +145,7 @@ module Arel end it "can handle case insensitive" do - node = @table[:name].matches_regexp('foo.*', false) + node = @table[:name].matches_regexp("foo.*", false) node.must_be_kind_of Nodes::Regexp node.case_sensitive.must_equal(false) compile(node).must_be_like %{ @@ -152,8 +153,8 @@ module Arel } end - it 'can handle subqueries' do - subquery = @table.project(:id).where(@table[:name].matches_regexp('foo.*')) + it "can handle subqueries" do + subquery = @table.project(:id).where(@table[:name].matches_regexp("foo.*")) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ~ 'foo.*') @@ -163,7 +164,7 @@ module Arel describe "Nodes::NotRegexp" do it "should know how to visit" do - node = @table[:name].does_not_match_regexp('foo.*') + node = @table[:name].does_not_match_regexp("foo.*") node.must_be_kind_of Nodes::NotRegexp node.case_sensitive.must_equal(true) compile(node).must_be_like %{ @@ -172,15 +173,15 @@ module Arel end it "can handle case insensitive" do - node = @table[:name].does_not_match_regexp('foo.*', false) + node = @table[:name].does_not_match_regexp("foo.*", false) node.case_sensitive.must_equal(false) compile(node).must_be_like %{ "users"."name" !~* 'foo.*' } end - it 'can handle subqueries' do - subquery = @table.project(:id).where(@table[:name].does_not_match_regexp('foo.*')) + it "can handle subqueries" do + subquery = @table.project(:id).where(@table[:name].does_not_match_regexp("foo.*")) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" !~ 'foo.*') |