aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/arel.rb55
-rw-r--r--activerecord/lib/arel/alias_predication.rb5
-rw-r--r--activerecord/lib/arel/attributes.rb5
-rw-r--r--activerecord/lib/arel/attributes/attribute.rb1
-rw-r--r--activerecord/lib/arel/collectors/bind.rb4
-rw-r--r--activerecord/lib/arel/collectors/composite.rb6
-rw-r--r--activerecord/lib/arel/collectors/plain_string.rb5
-rw-r--r--activerecord/lib/arel/collectors/sql_string.rb6
-rw-r--r--activerecord/lib/arel/collectors/substitute_binds.rb7
-rw-r--r--activerecord/lib/arel/compatibility/wheres.rb3
-rw-r--r--activerecord/lib/arel/crud.rb6
-rw-r--r--activerecord/lib/arel/delete_manager.rb7
-rw-r--r--activerecord/lib/arel/errors.rb1
-rw-r--r--activerecord/lib/arel/expressions.rb6
-rw-r--r--activerecord/lib/arel/factory_methods.rb17
-rw-r--r--activerecord/lib/arel/insert_manager.rb11
-rw-r--r--activerecord/lib/arel/math.rb1
-rw-r--r--activerecord/lib/arel/nodes.rb87
-rw-r--r--activerecord/lib/arel/nodes/and.rb5
-rw-r--r--activerecord/lib/arel/nodes/ascending.rb3
-rw-r--r--activerecord/lib/arel/nodes/binary.rb7
-rw-r--r--activerecord/lib/arel/nodes/bind_param.rb1
-rw-r--r--activerecord/lib/arel/nodes/case.rb13
-rw-r--r--activerecord/lib/arel/nodes/casted.rb23
-rw-r--r--activerecord/lib/arel/nodes/count.rb3
-rw-r--r--activerecord/lib/arel/nodes/delete_statement.rb7
-rw-r--r--activerecord/lib/arel/nodes/descending.rb3
-rw-r--r--activerecord/lib/arel/nodes/equality.rb1
-rw-r--r--activerecord/lib/arel/nodes/extract.rb5
-rw-r--r--activerecord/lib/arel/nodes/false.rb3
-rw-r--r--activerecord/lib/arel/nodes/full_outer_join.rb1
-rw-r--r--activerecord/lib/arel/nodes/function.rb8
-rw-r--r--activerecord/lib/arel/nodes/grouping.rb1
-rw-r--r--activerecord/lib/arel/nodes/in.rb1
-rw-r--r--activerecord/lib/arel/nodes/infix_operation.rb26
-rw-r--r--activerecord/lib/arel/nodes/inner_join.rb1
-rw-r--r--activerecord/lib/arel/nodes/insert_statement.rb5
-rw-r--r--activerecord/lib/arel/nodes/join_source.rb3
-rw-r--r--activerecord/lib/arel/nodes/matches.rb1
-rw-r--r--activerecord/lib/arel/nodes/named_function.rb5
-rw-r--r--activerecord/lib/arel/nodes/node.rb9
-rw-r--r--activerecord/lib/arel/nodes/node_expression.rb2
-rw-r--r--activerecord/lib/arel/nodes/outer_join.rb1
-rw-r--r--activerecord/lib/arel/nodes/over.rb7
-rw-r--r--activerecord/lib/arel/nodes/regexp.rb1
-rw-r--r--activerecord/lib/arel/nodes/right_outer_join.rb1
-rw-r--r--activerecord/lib/arel/nodes/select_core.rb7
-rw-r--r--activerecord/lib/arel/nodes/select_statement.rb7
-rw-r--r--activerecord/lib/arel/nodes/sql_literal.rb1
-rw-r--r--activerecord/lib/arel/nodes/string_join.rb3
-rw-r--r--activerecord/lib/arel/nodes/table_alias.rb3
-rw-r--r--activerecord/lib/arel/nodes/terminal.rb3
-rw-r--r--activerecord/lib/arel/nodes/true.rb3
-rw-r--r--activerecord/lib/arel/nodes/unary.rb5
-rw-r--r--activerecord/lib/arel/nodes/unary_operation.rb6
-rw-r--r--activerecord/lib/arel/nodes/unqualified_column.rb1
-rw-r--r--activerecord/lib/arel/nodes/update_statement.rb5
-rw-r--r--activerecord/lib/arel/nodes/values.rb3
-rw-r--r--activerecord/lib/arel/nodes/values_list.rb3
-rw-r--r--activerecord/lib/arel/nodes/window.rb17
-rw-r--r--activerecord/lib/arel/nodes/with.rb2
-rw-r--r--activerecord/lib/arel/order_predications.rb3
-rw-r--r--activerecord/lib/arel/predications.rb117
-rw-r--r--activerecord/lib/arel/select_manager.rb81
-rw-r--r--activerecord/lib/arel/table.rb29
-rw-r--r--activerecord/lib/arel/tree_manager.rb7
-rw-r--r--activerecord/lib/arel/update_manager.rb17
-rw-r--r--activerecord/lib/arel/visitors.rb27
-rw-r--r--activerecord/lib/arel/visitors/depth_first.rb373
-rw-r--r--activerecord/lib/arel/visitors/dot.rb447
-rw-r--r--activerecord/lib/arel/visitors/ibm_db.rb12
-rw-r--r--activerecord/lib/arel/visitors/informix.rb82
-rw-r--r--activerecord/lib/arel/visitors/mssql.rb177
-rw-r--r--activerecord/lib/arel/visitors/mysql.rb127
-rw-r--r--activerecord/lib/arel/visitors/oracle.rb250
-rw-r--r--activerecord/lib/arel/visitors/oracle12.rb87
-rw-r--r--activerecord/lib/arel/visitors/postgresql.rb155
-rw-r--r--activerecord/lib/arel/visitors/sqlite.rb30
-rw-r--r--activerecord/lib/arel/visitors/to_sql.rb1239
-rw-r--r--activerecord/lib/arel/visitors/visitor.rb43
-rw-r--r--activerecord/lib/arel/visitors/where_sql.rb15
-rw-r--r--activerecord/lib/arel/window_predications.rb5
-rw-r--r--activerecord/test/cases/arel/attributes/attribute_test.rb445
-rw-r--r--activerecord/test/cases/arel/attributes_test.rb35
-rw-r--r--activerecord/test/cases/arel/collectors/bind_test.rb9
-rw-r--r--activerecord/test/cases/arel/collectors/composite_test.rb13
-rw-r--r--activerecord/test/cases/arel/collectors/sql_string_test.rb9
-rw-r--r--activerecord/test/cases/arel/collectors/substitute_bind_collector_test.rb7
-rw-r--r--activerecord/test/cases/arel/crud_test.rb27
-rw-r--r--activerecord/test/cases/arel/delete_manager_test.rb21
-rw-r--r--activerecord/test/cases/arel/factory_methods_test.rb5
-rw-r--r--activerecord/test/cases/arel/helper.rb19
-rw-r--r--activerecord/test/cases/arel/insert_manager_test.rb58
-rw-r--r--activerecord/test/cases/arel/nodes/and_test.rb16
-rw-r--r--activerecord/test/cases/arel/nodes/as_test.rb27
-rw-r--r--activerecord/test/cases/arel/nodes/ascending_test.rb19
-rw-r--r--activerecord/test/cases/arel/nodes/bin_test.rb17
-rw-r--r--activerecord/test/cases/arel/nodes/binary_test.rb21
-rw-r--r--activerecord/test/cases/arel/nodes/bind_param_test.rb11
-rw-r--r--activerecord/test/cases/arel/nodes/case_test.rb37
-rw-r--r--activerecord/test/cases/arel/nodes/casted_test.rb7
-rw-r--r--activerecord/test/cases/arel/nodes/count_test.rb21
-rw-r--r--activerecord/test/cases/arel/nodes/delete_statement_test.rb9
-rw-r--r--activerecord/test/cases/arel/nodes/descending_test.rb19
-rw-r--r--activerecord/test/cases/arel/nodes/distinct_test.rb12
-rw-r--r--activerecord/test/cases/arel/nodes/equality_test.rb41
-rw-r--r--activerecord/test/cases/arel/nodes/extract_test.rb25
-rw-r--r--activerecord/test/cases/arel/nodes/false_test.rb12
-rw-r--r--activerecord/test/cases/arel/nodes/grouping_test.rb20
-rw-r--r--activerecord/test/cases/arel/nodes/infix_operation_test.rb7
-rw-r--r--activerecord/test/cases/arel/nodes/insert_statement_test.rb9
-rw-r--r--activerecord/test/cases/arel/nodes/named_function_test.rb35
-rw-r--r--activerecord/test/cases/arel/nodes/node_test.rb3
-rw-r--r--activerecord/test/cases/arel/nodes/not_test.rb19
-rw-r--r--activerecord/test/cases/arel/nodes/or_test.rb19
-rw-r--r--activerecord/test/cases/arel/nodes/over_test.rb45
-rw-r--r--activerecord/test/cases/arel/nodes/select_core_test.rb5
-rw-r--r--activerecord/test/cases/arel/nodes/select_statement_test.rb17
-rw-r--r--activerecord/test/cases/arel/nodes/sql_literal_test.rb53
-rw-r--r--activerecord/test/cases/arel/nodes/sum_test.rb23
-rw-r--r--activerecord/test/cases/arel/nodes/table_alias_test.rb11
-rw-r--r--activerecord/test/cases/arel/nodes/true_test.rb13
-rw-r--r--activerecord/test/cases/arel/nodes/unary_operation_test.rb7
-rw-r--r--activerecord/test/cases/arel/nodes/update_statement_test.rb25
-rw-r--r--activerecord/test/cases/arel/nodes/window_test.rb35
-rw-r--r--activerecord/test/cases/arel/nodes_test.rb9
-rw-r--r--activerecord/test/cases/arel/select_manager_test.rb488
-rw-r--r--activerecord/test/cases/arel/support/fake_record.rb48
-rw-r--r--activerecord/test/cases/arel/table_test.rb129
-rw-r--r--activerecord/test/cases/arel/update_manager_test.rb43
-rw-r--r--activerecord/test/cases/arel/visitors/depth_first_test.rb7
-rw-r--r--activerecord/test/cases/arel/visitors/dispatch_contamination_test.rb14
-rw-r--r--activerecord/test/cases/arel/visitors/dot_test.rb5
-rw-r--r--activerecord/test/cases/arel/visitors/ibm_db_test.rb10
-rw-r--r--activerecord/test/cases/arel/visitors/informix_test.rb16
-rw-r--r--activerecord/test/cases/arel/visitors/mssql_test.rb30
-rw-r--r--activerecord/test/cases/arel/visitors/mysql_test.rb35
-rw-r--r--activerecord/test/cases/arel/visitors/oracle12_test.rb19
-rw-r--r--activerecord/test/cases/arel/visitors/oracle_test.rb61
-rw-r--r--activerecord/test/cases/arel/visitors/postgres_test.rb77
-rw-r--r--activerecord/test/cases/arel/visitors/sqlite_test.rb17
-rw-r--r--activerecord/test/cases/arel/visitors/to_sql_test.rb185
142 files changed, 3179 insertions, 3074 deletions
diff --git a/activerecord/lib/arel.rb b/activerecord/lib/arel.rb
index c327caeac0..2d5cfa4d5c 100644
--- a/activerecord/lib/arel.rb
+++ b/activerecord/lib/arel.rb
@@ -1,38 +1,39 @@
# frozen_string_literal: true
-require 'arel/errors'
-
-require 'arel/crud'
-require 'arel/factory_methods'
-
-require 'arel/expressions'
-require 'arel/predications'
-require 'arel/window_predications'
-require 'arel/math'
-require 'arel/alias_predication'
-require 'arel/order_predications'
-require 'arel/table'
-require 'arel/attributes'
-require 'arel/compatibility/wheres'
-
-require 'arel/visitors'
-require 'arel/collectors/sql_string'
-
-require 'arel/tree_manager'
-require 'arel/insert_manager'
-require 'arel/select_manager'
-require 'arel/update_manager'
-require 'arel/delete_manager'
-require 'arel/nodes'
+
+require "arel/errors"
+
+require "arel/crud"
+require "arel/factory_methods"
+
+require "arel/expressions"
+require "arel/predications"
+require "arel/window_predications"
+require "arel/math"
+require "arel/alias_predication"
+require "arel/order_predications"
+require "arel/table"
+require "arel/attributes"
+require "arel/compatibility/wheres"
+
+require "arel/visitors"
+require "arel/collectors/sql_string"
+
+require "arel/tree_manager"
+require "arel/insert_manager"
+require "arel/select_manager"
+require "arel/update_manager"
+require "arel/delete_manager"
+require "arel/nodes"
module Arel
- VERSION = '10.0.0'
+ VERSION = "10.0.0"
- def self.sql raw_sql
+ def self.sql(raw_sql)
Arel::Nodes::SqlLiteral.new raw_sql
end
def self.star
- sql '*'
+ sql "*"
end
## Convenience Alias
Node = Arel::Nodes::Node
diff --git a/activerecord/lib/arel/alias_predication.rb b/activerecord/lib/arel/alias_predication.rb
index cb50fb95be..ae44157b9a 100644
--- a/activerecord/lib/arel/alias_predication.rb
+++ b/activerecord/lib/arel/alias_predication.rb
@@ -1,8 +1,9 @@
# frozen_string_literal: true
+
module Arel
module AliasPredication
- def as other
+ def as(other)
Nodes::As.new self, Nodes::SqlLiteral.new(other)
end
end
-end \ No newline at end of file
+end
diff --git a/activerecord/lib/arel/attributes.rb b/activerecord/lib/arel/attributes.rb
index ed4739ebed..c81a7b941b 100644
--- a/activerecord/lib/arel/attributes.rb
+++ b/activerecord/lib/arel/attributes.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
-require 'arel/attributes/attribute'
+
+require "arel/attributes/attribute"
module Arel
module Attributes
###
# Factory method to wrap a raw database +column+ to an Arel Attribute.
- def self.for column
+ def self.for(column)
case column.type
when :string, :text, :binary then String
when :integer then Integer
diff --git a/activerecord/lib/arel/attributes/attribute.rb b/activerecord/lib/arel/attributes/attribute.rb
index 41bc0c32c7..71f839479a 100644
--- a/activerecord/lib/arel/attributes/attribute.rb
+++ b/activerecord/lib/arel/attributes/attribute.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Attributes
class Attribute < Struct.new :relation, :name
diff --git a/activerecord/lib/arel/collectors/bind.rb b/activerecord/lib/arel/collectors/bind.rb
index d816aed90d..8d19e7446d 100644
--- a/activerecord/lib/arel/collectors/bind.rb
+++ b/activerecord/lib/arel/collectors/bind.rb
@@ -7,11 +7,11 @@ module Arel
@binds = []
end
- def << str
+ def <<(str)
self
end
- def add_bind bind
+ def add_bind(bind)
@binds << bind
self
end
diff --git a/activerecord/lib/arel/collectors/composite.rb b/activerecord/lib/arel/collectors/composite.rb
index 4f6156fe27..675a819596 100644
--- a/activerecord/lib/arel/collectors/composite.rb
+++ b/activerecord/lib/arel/collectors/composite.rb
@@ -8,13 +8,13 @@ module Arel
@right = right
end
- def << str
+ def <<(str)
left << str
right << str
self
end
- def add_bind bind, &block
+ def add_bind(bind, &block)
left.add_bind bind, &block
right.add_bind bind, &block
self
@@ -26,7 +26,7 @@ module Arel
protected
- attr_reader :left, :right
+ attr_reader :left, :right
end
end
end
diff --git a/activerecord/lib/arel/collectors/plain_string.rb b/activerecord/lib/arel/collectors/plain_string.rb
index 1e8d2a2152..b98802c44a 100644
--- a/activerecord/lib/arel/collectors/plain_string.rb
+++ b/activerecord/lib/arel/collectors/plain_string.rb
@@ -1,16 +1,17 @@
# frozen_string_literal: true
+
module Arel
module Collectors
class PlainString
def initialize
- @str = ''.dup
+ @str = "".dup
end
def value
@str
end
- def << str
+ def <<(str)
@str << str
self
end
diff --git a/activerecord/lib/arel/collectors/sql_string.rb b/activerecord/lib/arel/collectors/sql_string.rb
index bcb941f6d4..78c9e48aab 100644
--- a/activerecord/lib/arel/collectors/sql_string.rb
+++ b/activerecord/lib/arel/collectors/sql_string.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'arel/collectors/plain_string'
+require "arel/collectors/plain_string"
module Arel
module Collectors
@@ -10,13 +10,13 @@ module Arel
@bind_index = 1
end
- def add_bind bind
+ def add_bind(bind)
self << yield(@bind_index)
@bind_index += 1
self
end
- def compile bvs
+ def compile(bvs)
value
end
end
diff --git a/activerecord/lib/arel/collectors/substitute_binds.rb b/activerecord/lib/arel/collectors/substitute_binds.rb
index 99d2215aaa..ee6635f914 100644
--- a/activerecord/lib/arel/collectors/substitute_binds.rb
+++ b/activerecord/lib/arel/collectors/substitute_binds.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Collectors
class SubstituteBinds
@@ -7,12 +8,12 @@ module Arel
@delegate = delegate_collector
end
- def << str
+ def <<(str)
delegate << str
self
end
- def add_bind bind
+ def add_bind(bind)
self << quoter.quote(bind)
end
@@ -22,7 +23,7 @@ module Arel
protected
- attr_reader :quoter, :delegate
+ attr_reader :quoter, :delegate
end
end
end
diff --git a/activerecord/lib/arel/compatibility/wheres.rb b/activerecord/lib/arel/compatibility/wheres.rb
index 3e60894bd8..2ffb2e0ad8 100644
--- a/activerecord/lib/arel/compatibility/wheres.rb
+++ b/activerecord/lib/arel/compatibility/wheres.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Compatibility # :nodoc:
class Wheres # :nodoc:
@@ -15,7 +16,7 @@ module Arel
end
end
- def initialize engine, collection
+ def initialize(engine, collection)
@engine = engine
@collection = collection
end
diff --git a/activerecord/lib/arel/crud.rb b/activerecord/lib/arel/crud.rb
index 2d10432205..e2427b730c 100644
--- a/activerecord/lib/arel/crud.rb
+++ b/activerecord/lib/arel/crud.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
module Arel
###
# FIXME hopefully we can remove this
module Crud
- def compile_update values, pk
+ def compile_update(values, pk)
um = UpdateManager.new
if Nodes::SqlLiteral === values
@@ -20,7 +21,7 @@ module Arel
um
end
- def compile_insert values
+ def compile_insert(values)
im = create_insert
im.insert values
im
@@ -37,6 +38,5 @@ module Arel
dm.from @ctx.froms
dm
end
-
end
end
diff --git a/activerecord/lib/arel/delete_manager.rb b/activerecord/lib/arel/delete_manager.rb
index aee4511249..df1f92bd23 100644
--- a/activerecord/lib/arel/delete_manager.rb
+++ b/activerecord/lib/arel/delete_manager.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
class DeleteManager < Arel::TreeManager
def initialize
@@ -7,17 +8,17 @@ module Arel
@ctx = @ast
end
- def from relation
+ def from(relation)
@ast.relation = relation
self
end
- def take limit
+ def take(limit)
@ast.limit = Nodes::Limit.new(Nodes.build_quoted(limit)) if limit
self
end
- def wheres= list
+ def wheres=(list)
@ast.wheres = list
end
end
diff --git a/activerecord/lib/arel/errors.rb b/activerecord/lib/arel/errors.rb
index 86fbb80461..8733b7ff5a 100644
--- a/activerecord/lib/arel/errors.rb
+++ b/activerecord/lib/arel/errors.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
class ArelError < StandardError
end
diff --git a/activerecord/lib/arel/expressions.rb b/activerecord/lib/arel/expressions.rb
index 612a0942f1..597b861b6c 100644
--- a/activerecord/lib/arel/expressions.rb
+++ b/activerecord/lib/arel/expressions.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+
module Arel
module Expressions
- def count distinct = false
+ def count(distinct = false)
Nodes::Count.new [self], distinct
end
@@ -21,9 +22,8 @@ module Arel
Nodes::Avg.new [self]
end
- def extract field
+ def extract(field)
Nodes::Extract.new [self], field
end
-
end
end
diff --git a/activerecord/lib/arel/factory_methods.rb b/activerecord/lib/arel/factory_methods.rb
index 6647c5ac44..55aea3ecd7 100644
--- a/activerecord/lib/arel/factory_methods.rb
+++ b/activerecord/lib/arel/factory_methods.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
###
# Methods for creating various nodes
@@ -11,34 +12,34 @@ module Arel
Arel::Nodes::False.new
end
- def create_table_alias relation, name
+ def create_table_alias(relation, name)
Nodes::TableAlias.new(relation, name)
end
- def create_join to, constraint = nil, klass = Nodes::InnerJoin
+ def create_join(to, constraint = nil, klass = Nodes::InnerJoin)
klass.new(to, constraint)
end
- def create_string_join to
+ def create_string_join(to)
create_join to, nil, Nodes::StringJoin
end
- def create_and clauses
+ def create_and(clauses)
Nodes::And.new clauses
end
- def create_on expr
+ def create_on(expr)
Nodes::On.new expr
end
- def grouping expr
+ def grouping(expr)
Nodes::Grouping.new expr
end
###
# Create a LOWER() function
- def lower column
- Nodes::NamedFunction.new 'LOWER', [Nodes.build_quoted(column)]
+ def lower(column)
+ Nodes::NamedFunction.new "LOWER", [Nodes.build_quoted(column)]
end
end
end
diff --git a/activerecord/lib/arel/insert_manager.rb b/activerecord/lib/arel/insert_manager.rb
index dcbac6cb43..47b52d6515 100644
--- a/activerecord/lib/arel/insert_manager.rb
+++ b/activerecord/lib/arel/insert_manager.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
class InsertManager < Arel::TreeManager
def initialize
@@ -6,19 +7,19 @@ module Arel
@ast = Nodes::InsertStatement.new
end
- def into table
+ def into(table)
@ast.relation = table
self
end
def columns; @ast.columns end
- def values= val; @ast.values = val; end
+ def values=(val); @ast.values = val; end
- def select select
+ def select(select)
@ast.select = select
end
- def insert fields
+ def insert(fields)
return if fields.empty?
if String === fields
@@ -37,7 +38,7 @@ module Arel
self
end
- def create_values values, columns
+ def create_values(values, columns)
Nodes::Values.new values, columns
end
diff --git a/activerecord/lib/arel/math.rb b/activerecord/lib/arel/math.rb
index 9e6549b58f..671457efff 100644
--- a/activerecord/lib/arel/math.rb
+++ b/activerecord/lib/arel/math.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Math
def *(other)
diff --git a/activerecord/lib/arel/nodes.rb b/activerecord/lib/arel/nodes.rb
index 8c6572dd6a..5af0e532e2 100644
--- a/activerecord/lib/arel/nodes.rb
+++ b/activerecord/lib/arel/nodes.rb
@@ -1,66 +1,67 @@
# frozen_string_literal: true
+
# node
-require 'arel/nodes/node'
-require 'arel/nodes/node_expression'
-require 'arel/nodes/select_statement'
-require 'arel/nodes/select_core'
-require 'arel/nodes/insert_statement'
-require 'arel/nodes/update_statement'
-require 'arel/nodes/bind_param'
+require "arel/nodes/node"
+require "arel/nodes/node_expression"
+require "arel/nodes/select_statement"
+require "arel/nodes/select_core"
+require "arel/nodes/insert_statement"
+require "arel/nodes/update_statement"
+require "arel/nodes/bind_param"
# terminal
-require 'arel/nodes/terminal'
-require 'arel/nodes/true'
-require 'arel/nodes/false'
+require "arel/nodes/terminal"
+require "arel/nodes/true"
+require "arel/nodes/false"
# unary
-require 'arel/nodes/unary'
-require 'arel/nodes/grouping'
-require 'arel/nodes/ascending'
-require 'arel/nodes/descending'
-require 'arel/nodes/unqualified_column'
-require 'arel/nodes/with'
+require "arel/nodes/unary"
+require "arel/nodes/grouping"
+require "arel/nodes/ascending"
+require "arel/nodes/descending"
+require "arel/nodes/unqualified_column"
+require "arel/nodes/with"
# binary
-require 'arel/nodes/binary'
-require 'arel/nodes/equality'
-require 'arel/nodes/in' # Why is this subclassed from equality?
-require 'arel/nodes/join_source'
-require 'arel/nodes/delete_statement'
-require 'arel/nodes/table_alias'
-require 'arel/nodes/infix_operation'
-require 'arel/nodes/unary_operation'
-require 'arel/nodes/over'
-require 'arel/nodes/matches'
-require 'arel/nodes/regexp'
+require "arel/nodes/binary"
+require "arel/nodes/equality"
+require "arel/nodes/in" # Why is this subclassed from equality?
+require "arel/nodes/join_source"
+require "arel/nodes/delete_statement"
+require "arel/nodes/table_alias"
+require "arel/nodes/infix_operation"
+require "arel/nodes/unary_operation"
+require "arel/nodes/over"
+require "arel/nodes/matches"
+require "arel/nodes/regexp"
# nary
-require 'arel/nodes/and'
+require "arel/nodes/and"
# function
# FIXME: Function + Alias can be rewritten as a Function and Alias node.
# We should make Function a Unary node and deprecate the use of "aliaz"
-require 'arel/nodes/function'
-require 'arel/nodes/count'
-require 'arel/nodes/extract'
-require 'arel/nodes/values'
-require 'arel/nodes/values_list'
-require 'arel/nodes/named_function'
+require "arel/nodes/function"
+require "arel/nodes/count"
+require "arel/nodes/extract"
+require "arel/nodes/values"
+require "arel/nodes/values_list"
+require "arel/nodes/named_function"
# windows
-require 'arel/nodes/window'
+require "arel/nodes/window"
# conditional expressions
-require 'arel/nodes/case'
+require "arel/nodes/case"
# joins
-require 'arel/nodes/full_outer_join'
-require 'arel/nodes/inner_join'
-require 'arel/nodes/outer_join'
-require 'arel/nodes/right_outer_join'
-require 'arel/nodes/string_join'
+require "arel/nodes/full_outer_join"
+require "arel/nodes/inner_join"
+require "arel/nodes/outer_join"
+require "arel/nodes/right_outer_join"
+require "arel/nodes/string_join"
-require 'arel/nodes/sql_literal'
+require "arel/nodes/sql_literal"
-require 'arel/nodes/casted'
+require "arel/nodes/casted"
diff --git a/activerecord/lib/arel/nodes/and.rb b/activerecord/lib/arel/nodes/and.rb
index 1e2f61cf43..e76d4f3933 100644
--- a/activerecord/lib/arel/nodes/and.rb
+++ b/activerecord/lib/arel/nodes/and.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class And < Arel::Nodes::Node
attr_reader :children
- def initialize children
+ def initialize(children)
super()
@children = children
end
@@ -21,7 +22,7 @@ module Arel
children.hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.children == other.children
end
diff --git a/activerecord/lib/arel/nodes/ascending.rb b/activerecord/lib/arel/nodes/ascending.rb
index adadab55e4..7ee531734f 100644
--- a/activerecord/lib/arel/nodes/ascending.rb
+++ b/activerecord/lib/arel/nodes/ascending.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Ascending < Ordering
-
def reverse
Descending.new(expr)
end
@@ -18,7 +18,6 @@ module Arel
def descending?
false
end
-
end
end
end
diff --git a/activerecord/lib/arel/nodes/binary.rb b/activerecord/lib/arel/nodes/binary.rb
index a86d4e4696..e6a5cb63df 100644
--- a/activerecord/lib/arel/nodes/binary.rb
+++ b/activerecord/lib/arel/nodes/binary.rb
@@ -1,16 +1,17 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Binary < Arel::Nodes::NodeExpression
attr_accessor :left, :right
- def initialize left, right
+ def initialize(left, right)
super()
@left = left
@right = right
end
- def initialize_copy other
+ def initialize_copy(other)
super
@left = @left.clone if @left
@right = @right.clone if @right
@@ -20,7 +21,7 @@ module Arel
[self.class, @left, @right].hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.left == other.left &&
self.right == other.right
diff --git a/activerecord/lib/arel/nodes/bind_param.rb b/activerecord/lib/arel/nodes/bind_param.rb
index efa4f452d4..1cc1886c2a 100644
--- a/activerecord/lib/arel/nodes/bind_param.rb
+++ b/activerecord/lib/arel/nodes/bind_param.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class BindParam < Node
diff --git a/activerecord/lib/arel/nodes/case.rb b/activerecord/lib/arel/nodes/case.rb
index 50ea1e0be2..22c2da98dd 100644
--- a/activerecord/lib/arel/nodes/case.rb
+++ b/activerecord/lib/arel/nodes/case.rb
@@ -1,31 +1,32 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Case < Arel::Nodes::Node
attr_accessor :case, :conditions, :default
- def initialize expression = nil, default = nil
+ def initialize(expression = nil, default = nil)
@case = expression
@conditions = []
@default = default
end
- def when condition, expression = nil
+ def when(condition, expression = nil)
@conditions << When.new(Nodes.build_quoted(condition), expression)
self
end
- def then expression
+ def then(expression)
@conditions.last.right = Nodes.build_quoted(expression)
self
end
- def else expression
+ def else(expression)
@default = Else.new Nodes.build_quoted(expression)
self
end
- def initialize_copy other
+ def initialize_copy(other)
super
@case = @case.clone if @case
@conditions = @conditions.map { |x| x.clone }
@@ -36,7 +37,7 @@ module Arel
[@case, @conditions, @default].hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.case == other.case &&
self.conditions == other.conditions &&
diff --git a/activerecord/lib/arel/nodes/casted.rb b/activerecord/lib/arel/nodes/casted.rb
index f945063dd2..c701e7ff41 100644
--- a/activerecord/lib/arel/nodes/casted.rb
+++ b/activerecord/lib/arel/nodes/casted.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Casted < Arel::Nodes::NodeExpression # :nodoc:
attr_reader :val, :attribute
- def initialize val, attribute
+ def initialize(val, attribute)
@val = val
@attribute = attribute
super()
@@ -15,7 +16,7 @@ module Arel
[self.class, val, attribute].hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.val == other.val &&
self.attribute == other.attribute
@@ -28,17 +29,17 @@ module Arel
def nil?; val.nil?; end
end
- def self.build_quoted other, attribute = nil
+ def self.build_quoted(other, attribute = nil)
case other
- when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager, Arel::Nodes::Quoted, Arel::Nodes::SqlLiteral
- other
+ when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Table, Arel::Nodes::BindParam, Arel::SelectManager, Arel::Nodes::Quoted, Arel::Nodes::SqlLiteral
+ other
+ else
+ case attribute
+ when Arel::Attributes::Attribute
+ Casted.new other, attribute
else
- case attribute
- when Arel::Attributes::Attribute
- Casted.new other, attribute
- else
- Quoted.new other
- end
+ Quoted.new other
+ end
end
end
end
diff --git a/activerecord/lib/arel/nodes/count.rb b/activerecord/lib/arel/nodes/count.rb
index 4dd9be453f..3f138738ef 100644
--- a/activerecord/lib/arel/nodes/count.rb
+++ b/activerecord/lib/arel/nodes/count.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Count < Arel::Nodes::Function
include Math
- def initialize expr, distinct = false, aliaz = nil
+ def initialize(expr, distinct = false, aliaz = nil)
super(expr, aliaz)
@distinct = distinct
end
diff --git a/activerecord/lib/arel/nodes/delete_statement.rb b/activerecord/lib/arel/nodes/delete_statement.rb
index 063a5341e5..1aad4199cd 100644
--- a/activerecord/lib/arel/nodes/delete_statement.rb
+++ b/activerecord/lib/arel/nodes/delete_statement.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class DeleteStatement < Arel::Nodes::Node
@@ -10,13 +11,13 @@ module Arel
alias :wheres :right
alias :wheres= :right=
- def initialize relation = nil, wheres = []
+ def initialize(relation = nil, wheres = [])
super()
@left = relation
@right = wheres
end
- def initialize_copy other
+ def initialize_copy(other)
super
@left = @left.clone if @left
@right = @right.clone if @right
@@ -26,7 +27,7 @@ module Arel
[self.class, @left, @right].hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.left == other.left &&
self.right == other.right
diff --git a/activerecord/lib/arel/nodes/descending.rb b/activerecord/lib/arel/nodes/descending.rb
index d7261ab583..afcb6b1b71 100644
--- a/activerecord/lib/arel/nodes/descending.rb
+++ b/activerecord/lib/arel/nodes/descending.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Descending < Ordering
-
def reverse
Ascending.new(expr)
end
@@ -18,7 +18,6 @@ module Arel
def descending?
true
end
-
end
end
end
diff --git a/activerecord/lib/arel/nodes/equality.rb b/activerecord/lib/arel/nodes/equality.rb
index ef44725e24..4ed545ae17 100644
--- a/activerecord/lib/arel/nodes/equality.rb
+++ b/activerecord/lib/arel/nodes/equality.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Equality < Arel::Nodes::Binary
diff --git a/activerecord/lib/arel/nodes/extract.rb b/activerecord/lib/arel/nodes/extract.rb
index fdf3004c6a..56069cd05a 100644
--- a/activerecord/lib/arel/nodes/extract.rb
+++ b/activerecord/lib/arel/nodes/extract.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Extract < Arel::Nodes::Unary
attr_accessor :field
- def initialize expr, field
+ def initialize(expr, field)
super(expr)
@field = field
end
@@ -13,7 +14,7 @@ module Arel
super ^ @field.hash
end
- def eql? other
+ def eql?(other)
super &&
self.field == other.field
end
diff --git a/activerecord/lib/arel/nodes/false.rb b/activerecord/lib/arel/nodes/false.rb
index 58132a2f90..1759a323e3 100644
--- a/activerecord/lib/arel/nodes/false.rb
+++ b/activerecord/lib/arel/nodes/false.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class False < Arel::Nodes::NodeExpression
@@ -6,7 +7,7 @@ module Arel
self.class.hash
end
- def eql? other
+ def eql?(other)
self.class == other.class
end
alias :== :eql?
diff --git a/activerecord/lib/arel/nodes/full_outer_join.rb b/activerecord/lib/arel/nodes/full_outer_join.rb
index 12a02d8cd9..3551855201 100644
--- a/activerecord/lib/arel/nodes/full_outer_join.rb
+++ b/activerecord/lib/arel/nodes/full_outer_join.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class FullOuterJoin < Arel::Nodes::Join
diff --git a/activerecord/lib/arel/nodes/function.rb b/activerecord/lib/arel/nodes/function.rb
index b3bf8f3e51..f3415da12b 100644
--- a/activerecord/lib/arel/nodes/function.rb
+++ b/activerecord/lib/arel/nodes/function.rb
@@ -1,18 +1,19 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Function < Arel::Nodes::NodeExpression
include Arel::WindowPredications
attr_accessor :expressions, :alias, :distinct
- def initialize expr, aliaz = nil
+ def initialize(expr, aliaz = nil)
super()
@expressions = expr
@alias = aliaz && SqlLiteral.new(aliaz)
@distinct = false
end
- def as aliaz
+ def as(aliaz)
self.alias = SqlLiteral.new(aliaz)
self
end
@@ -21,14 +22,13 @@ module Arel
[@expressions, @alias, @distinct].hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.expressions == other.expressions &&
self.alias == other.alias &&
self.distinct == other.distinct
end
alias :== :eql?
-
end
%w{
diff --git a/activerecord/lib/arel/nodes/grouping.rb b/activerecord/lib/arel/nodes/grouping.rb
index ffe66654ce..b371b01612 100644
--- a/activerecord/lib/arel/nodes/grouping.rb
+++ b/activerecord/lib/arel/nodes/grouping.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Grouping < Unary
diff --git a/activerecord/lib/arel/nodes/in.rb b/activerecord/lib/arel/nodes/in.rb
index 30cd771c40..5d24d34528 100644
--- a/activerecord/lib/arel/nodes/in.rb
+++ b/activerecord/lib/arel/nodes/in.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class In < Equality
diff --git a/activerecord/lib/arel/nodes/infix_operation.rb b/activerecord/lib/arel/nodes/infix_operation.rb
index 4eb7c5356f..501da11730 100644
--- a/activerecord/lib/arel/nodes/infix_operation.rb
+++ b/activerecord/lib/arel/nodes/infix_operation.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
+
module Arel
module Nodes
-
class InfixOperation < Binary
include Arel::Expressions
include Arel::Predications
@@ -11,68 +11,68 @@ module Arel
attr_reader :operator
- def initialize operator, left, right
+ def initialize(operator, left, right)
super(left, right)
@operator = operator
end
end
class Multiplication < InfixOperation
- def initialize left, right
+ def initialize(left, right)
super(:*, left, right)
end
end
class Division < InfixOperation
- def initialize left, right
+ def initialize(left, right)
super(:/, left, right)
end
end
class Addition < InfixOperation
- def initialize left, right
+ def initialize(left, right)
super(:+, left, right)
end
end
class Subtraction < InfixOperation
- def initialize left, right
+ def initialize(left, right)
super(:-, left, right)
end
end
class Concat < InfixOperation
- def initialize left, right
- super('||', left, right)
+ def initialize(left, right)
+ super("||", left, right)
end
end
class BitwiseAnd < InfixOperation
- def initialize left, right
+ def initialize(left, right)
super(:&, left, right)
end
end
class BitwiseOr < InfixOperation
- def initialize left, right
+ def initialize(left, right)
super(:|, left, right)
end
end
class BitwiseXor < InfixOperation
- def initialize left, right
+ def initialize(left, right)
super(:^, left, right)
end
end
class BitwiseShiftLeft < InfixOperation
- def initialize left, right
+ def initialize(left, right)
super(:<<, left, right)
end
end
class BitwiseShiftRight < InfixOperation
- def initialize left, right
+ def initialize(left, right)
super(:>>, left, right)
end
end
diff --git a/activerecord/lib/arel/nodes/inner_join.rb b/activerecord/lib/arel/nodes/inner_join.rb
index 4e398267c3..8af99c2dae 100644
--- a/activerecord/lib/arel/nodes/inner_join.rb
+++ b/activerecord/lib/arel/nodes/inner_join.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class InnerJoin < Arel::Nodes::Join
diff --git a/activerecord/lib/arel/nodes/insert_statement.rb b/activerecord/lib/arel/nodes/insert_statement.rb
index 72793bc1ad..206d05e74f 100644
--- a/activerecord/lib/arel/nodes/insert_statement.rb
+++ b/activerecord/lib/arel/nodes/insert_statement.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class InsertStatement < Arel::Nodes::Node
@@ -12,7 +13,7 @@ module Arel
@select = nil
end
- def initialize_copy other
+ def initialize_copy(other)
super
@columns = @columns.clone
@values = @values.clone if @values
@@ -23,7 +24,7 @@ module Arel
[@relation, @columns, @values, @select].hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.relation == other.relation &&
self.columns == other.columns &&
diff --git a/activerecord/lib/arel/nodes/join_source.rb b/activerecord/lib/arel/nodes/join_source.rb
index 428ce8183e..9d009e8081 100644
--- a/activerecord/lib/arel/nodes/join_source.rb
+++ b/activerecord/lib/arel/nodes/join_source.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
###
@@ -7,7 +8,7 @@ module Arel
# http://www.sqlite.org/syntaxdiagrams.html#join-source
class JoinSource < Arel::Nodes::Binary
- def initialize single_source, joinop = []
+ def initialize(single_source, joinop = [])
super
end
diff --git a/activerecord/lib/arel/nodes/matches.rb b/activerecord/lib/arel/nodes/matches.rb
index 3ad3850a8e..607efe86dc 100644
--- a/activerecord/lib/arel/nodes/matches.rb
+++ b/activerecord/lib/arel/nodes/matches.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Matches < Binary
diff --git a/activerecord/lib/arel/nodes/named_function.rb b/activerecord/lib/arel/nodes/named_function.rb
index 173838a7fd..1d0baf2885 100644
--- a/activerecord/lib/arel/nodes/named_function.rb
+++ b/activerecord/lib/arel/nodes/named_function.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class NamedFunction < Arel::Nodes::Function
attr_accessor :name
- def initialize name, expr, aliaz = nil
+ def initialize(name, expr, aliaz = nil)
super(expr, aliaz)
@name = name
end
@@ -13,7 +14,7 @@ module Arel
super ^ @name.hash
end
- def eql? other
+ def eql?(other)
super && self.name == other.name
end
alias :== :eql?
diff --git a/activerecord/lib/arel/nodes/node.rb b/activerecord/lib/arel/nodes/node.rb
index d2e6313dda..e2ce0a676d 100644
--- a/activerecord/lib/arel/nodes/node.rb
+++ b/activerecord/lib/arel/nodes/node.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
###
@@ -27,13 +28,13 @@ module Arel
###
# Factory method to create a Nodes::Grouping node that has an Nodes::Or
# node as a child.
- def or right
+ def or(right)
Nodes::Grouping.new Nodes::Or.new(self, right)
end
###
# Factory method to create an Nodes::And node.
- def and right
+ def and(right)
Nodes::And.new [self, right]
end
@@ -42,14 +43,14 @@ module Arel
# can find a node that has a "relation" member.
#
# Maybe we should just use `Table.engine`? :'(
- def to_sql engine = Table.engine
+ def to_sql(engine = Table.engine)
collector = Arel::Collectors::SQLString.new
collector = engine.connection.visitor.accept self, collector
collector.value
end
# Iterate through AST, nodes will be yielded depth-first
- def each &block
+ def each(&block)
return enum_for(:each) unless block_given?
::Arel::Visitors::DepthFirst.new(block).accept self
diff --git a/activerecord/lib/arel/nodes/node_expression.rb b/activerecord/lib/arel/nodes/node_expression.rb
index c4d4c8f428..e69e3262d5 100644
--- a/activerecord/lib/arel/nodes/node_expression.rb
+++ b/activerecord/lib/arel/nodes/node_expression.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Arel
module Nodes
class NodeExpression < Arel::Nodes::Node
diff --git a/activerecord/lib/arel/nodes/outer_join.rb b/activerecord/lib/arel/nodes/outer_join.rb
index c568655fe6..2440be1f03 100644
--- a/activerecord/lib/arel/nodes/outer_join.rb
+++ b/activerecord/lib/arel/nodes/outer_join.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class OuterJoin < Arel::Nodes::Join
diff --git a/activerecord/lib/arel/nodes/over.rb b/activerecord/lib/arel/nodes/over.rb
index 47a34e69ea..57baebe9b3 100644
--- a/activerecord/lib/arel/nodes/over.rb
+++ b/activerecord/lib/arel/nodes/over.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
+
module Arel
module Nodes
-
class Over < Binary
include Arel::AliasPredication
@@ -9,8 +9,7 @@ module Arel
super(left, right)
end
- def operator; 'OVER' end
+ def operator; "OVER" end
end
-
end
-end \ No newline at end of file
+end
diff --git a/activerecord/lib/arel/nodes/regexp.rb b/activerecord/lib/arel/nodes/regexp.rb
index 8a76185ef0..a2da51c135 100644
--- a/activerecord/lib/arel/nodes/regexp.rb
+++ b/activerecord/lib/arel/nodes/regexp.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Regexp < Binary
diff --git a/activerecord/lib/arel/nodes/right_outer_join.rb b/activerecord/lib/arel/nodes/right_outer_join.rb
index 04ab31ebf0..910eb0fa1f 100644
--- a/activerecord/lib/arel/nodes/right_outer_join.rb
+++ b/activerecord/lib/arel/nodes/right_outer_join.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class RightOuterJoin < Arel::Nodes::Join
diff --git a/activerecord/lib/arel/nodes/select_core.rb b/activerecord/lib/arel/nodes/select_core.rb
index fa1c026107..1686761bd5 100644
--- a/activerecord/lib/arel/nodes/select_core.rb
+++ b/activerecord/lib/arel/nodes/select_core.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class SelectCore < Arel::Nodes::Node
@@ -23,14 +24,14 @@ module Arel
@source.left
end
- def from= value
+ def from=(value)
@source.left = value
end
alias :froms= :from=
alias :froms :from
- def initialize_copy other
+ def initialize_copy(other)
super
@source = @source.clone if @source
@projections = @projections.clone
@@ -47,7 +48,7 @@ module Arel
].hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.source == other.source &&
self.top == other.top &&
diff --git a/activerecord/lib/arel/nodes/select_statement.rb b/activerecord/lib/arel/nodes/select_statement.rb
index 79176d4be5..d1c42dba3b 100644
--- a/activerecord/lib/arel/nodes/select_statement.rb
+++ b/activerecord/lib/arel/nodes/select_statement.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class SelectStatement < Arel::Nodes::NodeExpression
attr_reader :cores
attr_accessor :limit, :orders, :lock, :offset, :with
- def initialize cores = [SelectCore.new]
+ def initialize(cores = [SelectCore.new])
super()
@cores = cores
@orders = []
@@ -15,7 +16,7 @@ module Arel
@with = nil
end
- def initialize_copy other
+ def initialize_copy(other)
super
@cores = @cores.map { |x| x.clone }
@orders = @orders.map { |x| x.clone }
@@ -25,7 +26,7 @@ module Arel
[@cores, @orders, @limit, @lock, @offset, @with].hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.cores == other.cores &&
self.orders == other.orders &&
diff --git a/activerecord/lib/arel/nodes/sql_literal.rb b/activerecord/lib/arel/nodes/sql_literal.rb
index 73575a7d49..1ee496f285 100644
--- a/activerecord/lib/arel/nodes/sql_literal.rb
+++ b/activerecord/lib/arel/nodes/sql_literal.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class SqlLiteral < String
diff --git a/activerecord/lib/arel/nodes/string_join.rb b/activerecord/lib/arel/nodes/string_join.rb
index 21d6845c45..ba3f5f9535 100644
--- a/activerecord/lib/arel/nodes/string_join.rb
+++ b/activerecord/lib/arel/nodes/string_join.rb
@@ -1,8 +1,9 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class StringJoin < Arel::Nodes::Join
- def initialize left, right = nil
+ def initialize(left, right = nil)
super
end
end
diff --git a/activerecord/lib/arel/nodes/table_alias.rb b/activerecord/lib/arel/nodes/table_alias.rb
index 78deb175b6..37ad786d44 100644
--- a/activerecord/lib/arel/nodes/table_alias.rb
+++ b/activerecord/lib/arel/nodes/table_alias.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class TableAlias < Arel::Nodes::Binary
@@ -6,7 +7,7 @@ module Arel
alias :relation :left
alias :table_alias :name
- def [] name
+ def [](name)
Attribute.new(self, name)
end
diff --git a/activerecord/lib/arel/nodes/terminal.rb b/activerecord/lib/arel/nodes/terminal.rb
index 3a1cd7f0e1..7cfd2eba4b 100644
--- a/activerecord/lib/arel/nodes/terminal.rb
+++ b/activerecord/lib/arel/nodes/terminal.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Distinct < Arel::Nodes::NodeExpression
@@ -6,7 +7,7 @@ module Arel
self.class.hash
end
- def eql? other
+ def eql?(other)
self.class == other.class
end
alias :== :eql?
diff --git a/activerecord/lib/arel/nodes/true.rb b/activerecord/lib/arel/nodes/true.rb
index fdb8ed2095..8de1f7522f 100644
--- a/activerecord/lib/arel/nodes/true.rb
+++ b/activerecord/lib/arel/nodes/true.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class True < Arel::Nodes::NodeExpression
@@ -6,7 +7,7 @@ module Arel
self.class.hash
end
- def eql? other
+ def eql?(other)
self.class == other.class
end
alias :== :eql?
diff --git a/activerecord/lib/arel/nodes/unary.rb b/activerecord/lib/arel/nodes/unary.rb
index e458d87ab3..27dd2c1ddf 100644
--- a/activerecord/lib/arel/nodes/unary.rb
+++ b/activerecord/lib/arel/nodes/unary.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Unary < Arel::Nodes::NodeExpression
attr_accessor :expr
alias :value :expr
- def initialize expr
+ def initialize(expr)
super()
@expr = expr
end
@@ -14,7 +15,7 @@ module Arel
@expr.hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.expr == other.expr
end
diff --git a/activerecord/lib/arel/nodes/unary_operation.rb b/activerecord/lib/arel/nodes/unary_operation.rb
index be4e270e76..a64346d278 100644
--- a/activerecord/lib/arel/nodes/unary_operation.rb
+++ b/activerecord/lib/arel/nodes/unary_operation.rb
@@ -1,18 +1,18 @@
# frozen_string_literal: true
+
module Arel
module Nodes
-
class UnaryOperation < Unary
attr_reader :operator
- def initialize operator, operand
+ def initialize(operator, operand)
super(operand)
@operator = operator
end
end
class BitwiseNot < UnaryOperation
- def initialize operand
+ def initialize(operand)
super(:~, operand)
end
end
diff --git a/activerecord/lib/arel/nodes/unqualified_column.rb b/activerecord/lib/arel/nodes/unqualified_column.rb
index f9017238c8..216a35bc30 100644
--- a/activerecord/lib/arel/nodes/unqualified_column.rb
+++ b/activerecord/lib/arel/nodes/unqualified_column.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class UnqualifiedColumn < Arel::Nodes::Unary
diff --git a/activerecord/lib/arel/nodes/update_statement.rb b/activerecord/lib/arel/nodes/update_statement.rb
index 286f0bd3ce..5cce1e3615 100644
--- a/activerecord/lib/arel/nodes/update_statement.rb
+++ b/activerecord/lib/arel/nodes/update_statement.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class UpdateStatement < Arel::Nodes::Node
@@ -14,7 +15,7 @@ module Arel
@key = nil
end
- def initialize_copy other
+ def initialize_copy(other)
super
@wheres = @wheres.clone
@values = @values.clone
@@ -24,7 +25,7 @@ module Arel
[@relation, @wheres, @values, @orders, @limit, @key].hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.relation == other.relation &&
self.wheres == other.wheres &&
diff --git a/activerecord/lib/arel/nodes/values.rb b/activerecord/lib/arel/nodes/values.rb
index b32d5063a2..8554440be6 100644
--- a/activerecord/lib/arel/nodes/values.rb
+++ b/activerecord/lib/arel/nodes/values.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Values < Arel::Nodes::Binary
@@ -7,7 +8,7 @@ module Arel
alias :columns :right
alias :columns= :right=
- def initialize exprs, columns = []
+ def initialize(exprs, columns = [])
super
end
end
diff --git a/activerecord/lib/arel/nodes/values_list.rb b/activerecord/lib/arel/nodes/values_list.rb
index 89cea1790d..e68518d684 100644
--- a/activerecord/lib/arel/nodes/values_list.rb
+++ b/activerecord/lib/arel/nodes/values_list.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class ValuesList < Node
@@ -13,7 +14,7 @@ module Arel
@rows.hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.rows == other.rows
end
diff --git a/activerecord/lib/arel/nodes/window.rb b/activerecord/lib/arel/nodes/window.rb
index 23a005daba..1f14630c81 100644
--- a/activerecord/lib/arel/nodes/window.rb
+++ b/activerecord/lib/arel/nodes/window.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class Window < Arel::Nodes::Node
@@ -10,7 +11,7 @@ module Arel
@framing = nil
end
- def order *expr
+ def order(*expr)
# FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
@orders.concat expr.map { |x|
String === x || Symbol === x ? Nodes::SqlLiteral.new(x.to_s) : x
@@ -18,7 +19,7 @@ module Arel
self
end
- def partition *expr
+ def partition(*expr)
# FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
@partitions.concat expr.map { |x|
String === x || Symbol === x ? Nodes::SqlLiteral.new(x.to_s) : x
@@ -46,7 +47,7 @@ module Arel
end
end
- def initialize_copy other
+ def initialize_copy(other)
super
@orders = @orders.map { |x| x.clone }
end
@@ -55,7 +56,7 @@ module Arel
[@orders, @framing].hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.orders == other.orders &&
self.framing == other.framing &&
@@ -67,12 +68,12 @@ module Arel
class NamedWindow < Window
attr_accessor :name
- def initialize name
+ def initialize(name)
super()
@name = name
end
- def initialize_copy other
+ def initialize_copy(other)
super
@name = other.name.clone
end
@@ -81,7 +82,7 @@ module Arel
super ^ @name.hash
end
- def eql? other
+ def eql?(other)
super && self.name == other.name
end
alias :== :eql?
@@ -104,7 +105,7 @@ module Arel
self.class.hash
end
- def eql? other
+ def eql?(other)
self.class == other.class
end
alias :== :eql?
diff --git a/activerecord/lib/arel/nodes/with.rb b/activerecord/lib/arel/nodes/with.rb
index def7840ea3..a0fbf87e8e 100644
--- a/activerecord/lib/arel/nodes/with.rb
+++ b/activerecord/lib/arel/nodes/with.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Nodes
class With < Arel::Nodes::Unary
@@ -8,4 +9,3 @@ module Arel
class WithRecursive < With; end
end
end
-
diff --git a/activerecord/lib/arel/order_predications.rb b/activerecord/lib/arel/order_predications.rb
index d84be82bb6..a0f15cb4d6 100644
--- a/activerecord/lib/arel/order_predications.rb
+++ b/activerecord/lib/arel/order_predications.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
+
module Arel
module OrderPredications
-
def asc
Nodes::Ascending.new self
end
@@ -9,6 +9,5 @@ module Arel
def desc
Nodes::Descending.new self
end
-
end
end
diff --git a/activerecord/lib/arel/predications.rb b/activerecord/lib/arel/predications.rb
index 799c7c67b8..1e701586a4 100644
--- a/activerecord/lib/arel/predications.rb
+++ b/activerecord/lib/arel/predications.rb
@@ -1,31 +1,32 @@
# frozen_string_literal: true
+
module Arel
module Predications
- def not_eq other
+ def not_eq(other)
Nodes::NotEqual.new self, quoted_node(other)
end
- def not_eq_any others
+ def not_eq_any(others)
grouping_any :not_eq, others
end
- def not_eq_all others
+ def not_eq_all(others)
grouping_all :not_eq, others
end
- def eq other
+ def eq(other)
Nodes::Equality.new self, quoted_node(other)
end
- def eq_any others
+ def eq_any(others)
grouping_any :eq, others
end
- def eq_all others
+ def eq_all(others)
grouping_all :eq, quoted_array(others)
end
- def between other
+ def between(other)
if equals_quoted?(other.begin, -Float::INFINITY)
if equals_quoted?(other.end, Float::INFINITY)
not_in([])
@@ -45,7 +46,7 @@ module Arel
end
end
- def in other
+ def in(other)
case other
when Arel::SelectManager
Arel::Nodes::In.new(self, other.ast)
@@ -63,15 +64,15 @@ Passing a range to `#in` is deprecated. Call `#between`, instead.
end
end
- def in_any others
+ def in_any(others)
grouping_any :in, others
end
- def in_all others
+ def in_all(others)
grouping_all :in, others
end
- def not_between other
+ def not_between(other)
if equals_quoted?(other.begin, -Float::INFINITY)
if equals_quoted?(other.end, Float::INFINITY)
self.in([])
@@ -93,7 +94,7 @@ Passing a range to `#in` is deprecated. Call `#between`, instead.
end
end
- def not_in other
+ def not_in(other)
case other
when Arel::SelectManager
Arel::Nodes::NotIn.new(self, other.ast)
@@ -111,130 +112,130 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
end
end
- def not_in_any others
+ def not_in_any(others)
grouping_any :not_in, others
end
- def not_in_all others
+ def not_in_all(others)
grouping_all :not_in, others
end
- def matches other, escape = nil, case_sensitive = false
+ def matches(other, escape = nil, case_sensitive = false)
Nodes::Matches.new self, quoted_node(other), escape, case_sensitive
end
- def matches_regexp other, case_sensitive = true
+ def matches_regexp(other, case_sensitive = true)
Nodes::Regexp.new self, quoted_node(other), case_sensitive
end
- def matches_any others, escape = nil, case_sensitive = false
+ def matches_any(others, escape = nil, case_sensitive = false)
grouping_any :matches, others, escape, case_sensitive
end
- def matches_all others, escape = nil, case_sensitive = false
+ def matches_all(others, escape = nil, case_sensitive = false)
grouping_all :matches, others, escape, case_sensitive
end
- def does_not_match other, escape = nil, case_sensitive = false
+ def does_not_match(other, escape = nil, case_sensitive = false)
Nodes::DoesNotMatch.new self, quoted_node(other), escape, case_sensitive
end
- def does_not_match_regexp other, case_sensitive = true
+ def does_not_match_regexp(other, case_sensitive = true)
Nodes::NotRegexp.new self, quoted_node(other), case_sensitive
end
- def does_not_match_any others, escape = nil
+ def does_not_match_any(others, escape = nil)
grouping_any :does_not_match, others, escape
end
- def does_not_match_all others, escape = nil
+ def does_not_match_all(others, escape = nil)
grouping_all :does_not_match, others, escape
end
- def gteq right
+ def gteq(right)
Nodes::GreaterThanOrEqual.new self, quoted_node(right)
end
- def gteq_any others
+ def gteq_any(others)
grouping_any :gteq, others
end
- def gteq_all others
+ def gteq_all(others)
grouping_all :gteq, others
end
- def gt right
+ def gt(right)
Nodes::GreaterThan.new self, quoted_node(right)
end
- def gt_any others
+ def gt_any(others)
grouping_any :gt, others
end
- def gt_all others
+ def gt_all(others)
grouping_all :gt, others
end
- def lt right
+ def lt(right)
Nodes::LessThan.new self, quoted_node(right)
end
- def lt_any others
+ def lt_any(others)
grouping_any :lt, others
end
- def lt_all others
+ def lt_all(others)
grouping_all :lt, others
end
- def lteq right
+ def lteq(right)
Nodes::LessThanOrEqual.new self, quoted_node(right)
end
- def lteq_any others
+ def lteq_any(others)
grouping_any :lteq, others
end
- def lteq_all others
+ def lteq_all(others)
grouping_all :lteq, others
end
- def when right
+ def when(right)
Nodes::Case.new(self).when quoted_node(right)
end
- def concat other
+ def concat(other)
Nodes::Concat.new self, other
end
private
- def grouping_any method_id, others, *extras
- nodes = others.map {|expr| send(method_id, expr, *extras)}
- Nodes::Grouping.new nodes.inject { |memo,node|
- Nodes::Or.new(memo, node)
- }
- end
+ def grouping_any(method_id, others, *extras)
+ nodes = others.map { |expr| send(method_id, expr, *extras) }
+ Nodes::Grouping.new nodes.inject { |memo, node|
+ Nodes::Or.new(memo, node)
+ }
+ end
- def grouping_all method_id, others, *extras
- nodes = others.map {|expr| send(method_id, expr, *extras)}
- Nodes::Grouping.new Nodes::And.new(nodes)
- end
+ def grouping_all(method_id, others, *extras)
+ nodes = others.map { |expr| send(method_id, expr, *extras) }
+ Nodes::Grouping.new Nodes::And.new(nodes)
+ end
- def quoted_node(other)
- Nodes.build_quoted(other, self)
- end
+ def quoted_node(other)
+ Nodes.build_quoted(other, self)
+ end
- def quoted_array(others)
- others.map { |v| quoted_node(v) }
- end
+ def quoted_array(others)
+ others.map { |v| quoted_node(v) }
+ end
- def equals_quoted?(maybe_quoted, value)
- if maybe_quoted.is_a?(Nodes::Quoted)
- maybe_quoted.val == value
- else
- maybe_quoted == value
+ def equals_quoted?(maybe_quoted, value)
+ if maybe_quoted.is_a?(Nodes::Quoted)
+ maybe_quoted.val == value
+ else
+ maybe_quoted == value
+ end
end
- end
end
end
diff --git a/activerecord/lib/arel/select_manager.rb b/activerecord/lib/arel/select_manager.rb
index 0f3b0dc6a0..dc61447d01 100644
--- a/activerecord/lib/arel/select_manager.rb
+++ b/activerecord/lib/arel/select_manager.rb
@@ -1,18 +1,19 @@
# frozen_string_literal: true
+
module Arel
class SelectManager < Arel::TreeManager
include Arel::Crud
STRING_OR_SYMBOL_CLASS = [Symbol, String]
- def initialize table = nil
+ def initialize(table = nil)
super()
- @ast = Nodes::SelectStatement.new
- @ctx = @ast.cores.last
+ @ast = Nodes::SelectStatement.new
+ @ctx = @ast.cores.last
from table
end
- def initialize_copy other
+ def initialize_copy(other)
super
@ctx = @ast.cores.last
end
@@ -30,7 +31,7 @@ module Arel
@ast.offset && @ast.offset.expr
end
- def skip amount
+ def skip(amount)
if amount
@ast.offset = Nodes::Offset.new(amount)
else
@@ -46,14 +47,14 @@ module Arel
Arel::Nodes::Exists.new @ast
end
- def as other
+ def as(other)
create_table_alias grouping(@ast), Nodes::SqlLiteral.new(other)
end
- def lock locking = Arel.sql('FOR UPDATE')
+ def lock(locking = Arel.sql("FOR UPDATE"))
case locking
when true
- locking = Arel.sql('FOR UPDATE')
+ locking = Arel.sql("FOR UPDATE")
when Arel::Nodes::SqlLiteral
when String
locking = Arel.sql locking
@@ -67,12 +68,12 @@ module Arel
@ast.lock
end
- def on *exprs
+ def on(*exprs)
@ctx.source.right.last.right = Nodes::On.new(collapse(exprs))
self
end
- def group *columns
+ def group(*columns)
columns.each do |column|
# FIXME: backwards compat
column = Nodes::SqlLiteral.new(column) if String === column
@@ -83,7 +84,7 @@ module Arel
self
end
- def from table
+ def from(table)
table = Nodes::SqlLiteral.new(table) if String === table
case table
@@ -100,7 +101,7 @@ module Arel
@ast.cores.map { |x| x.from }.compact
end
- def join relation, klass = Nodes::InnerJoin
+ def join(relation, klass = Nodes::InnerJoin)
return self unless relation
case relation
@@ -113,22 +114,22 @@ module Arel
self
end
- def outer_join relation
+ def outer_join(relation)
join(relation, Nodes::OuterJoin)
end
- def having expr
+ def having(expr)
@ctx.havings << expr
self
end
- def window name
+ def window(name)
window = Nodes::NamedWindow.new(name)
@ctx.windows.push window
window
end
- def project *projections
+ def project(*projections)
# FIXME: converting these to SQLLiterals is probably not good, but
# rails tests require it.
@ctx.projections.concat projections.map { |x|
@@ -141,7 +142,7 @@ module Arel
@ctx.projections
end
- def projections= projections
+ def projections=(projections)
@ctx.projections = projections
end
@@ -163,7 +164,7 @@ module Arel
self
end
- def order *expr
+ def order(*expr)
# FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
@ast.orders.concat expr.map { |x|
STRING_OR_SYMBOL_CLASS.include?(x.class) ? Nodes::SqlLiteral.new(x.to_s) : x
@@ -175,14 +176,14 @@ module Arel
@ast.orders
end
- def where_sql engine = Table.engine
+ def where_sql(engine = Table.engine)
return if @ctx.wheres.empty?
viz = Visitors::WhereSql.new(engine.connection.visitor, engine.connection)
Nodes::SqlLiteral.new viz.accept(@ctx, Collectors::SQLString.new).value
end
- def union operation, other = nil
+ def union(operation, other = nil)
if other
node_class = Nodes.const_get("Union#{operation.to_s.capitalize}")
else
@@ -193,21 +194,21 @@ module Arel
node_class.new self.ast, other.ast
end
- def intersect other
+ def intersect(other)
Nodes::Intersect.new ast, other.ast
end
- def except other
+ def except(other)
Nodes::Except.new ast, other.ast
end
alias :minus :except
- def lateral table_name = nil
+ def lateral(table_name = nil)
base = table_name.nil? ? ast : as(table_name)
Nodes::Lateral.new(base)
end
- def with *subqueries
+ def with(*subqueries)
if subqueries.first.is_a? Symbol
node_class = Nodes.const_get("With#{subqueries.shift.to_s.capitalize}")
else
@@ -218,7 +219,7 @@ module Arel
self
end
- def take limit
+ def take(limit)
if limit
@ast.limit = Nodes::Limit.new(limit)
@ctx.top = Nodes::Top.new(limit)
@@ -240,7 +241,7 @@ module Arel
class Row < Struct.new(:data) # :nodoc:
def id
- data['id']
+ data["id"]
end
def method_missing(name, *args)
@@ -251,22 +252,22 @@ module Arel
end
private
- def collapse exprs, existing = nil
- exprs = exprs.unshift(existing.expr) if existing
- exprs = exprs.compact.map { |expr|
- if String === expr
- # FIXME: Don't do this automatically
- Arel.sql(expr)
+ def collapse(exprs, existing = nil)
+ exprs = exprs.unshift(existing.expr) if existing
+ exprs = exprs.compact.map { |expr|
+ if String === expr
+ # FIXME: Don't do this automatically
+ Arel.sql(expr)
+ else
+ expr
+ end
+ }
+
+ if exprs.length == 1
+ exprs.first
else
- expr
+ create_and exprs
end
- }
-
- if exprs.length == 1
- exprs.first
- else
- create_and exprs
end
- end
end
end
diff --git a/activerecord/lib/arel/table.rb b/activerecord/lib/arel/table.rb
index b3f2d79e5f..2df2c4c514 100644
--- a/activerecord/lib/arel/table.rb
+++ b/activerecord/lib/arel/table.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
class Table
include Arel::Crud
@@ -13,7 +14,7 @@ module Arel
alias :table_name :name
def initialize(name, as: nil, type_caster: nil)
- @name = name.to_s
+ @name = name.to_s
@type_caster = type_caster
# Sometime AR sends an :as parameter to table, to let the table know
@@ -25,7 +26,7 @@ module Arel
@table_alias = as
end
- def alias name = "#{self.name}_2"
+ def alias(name = "#{self.name}_2")
Nodes::TableAlias.new(self, name)
end
@@ -33,7 +34,7 @@ module Arel
SelectManager.new(self)
end
- def join relation, klass = Nodes::InnerJoin
+ def join(relation, klass = Nodes::InnerJoin)
return from unless relation
case relation
@@ -45,39 +46,39 @@ module Arel
from.join(relation, klass)
end
- def outer_join relation
+ def outer_join(relation)
join(relation, Nodes::OuterJoin)
end
- def group *columns
+ def group(*columns)
from.group(*columns)
end
- def order *expr
+ def order(*expr)
from.order(*expr)
end
- def where condition
+ def where(condition)
from.where condition
end
- def project *things
+ def project(*things)
from.project(*things)
end
- def take amount
+ def take(amount)
from.take amount
end
- def skip amount
+ def skip(amount)
from.skip amount
end
- def having expr
+ def having(expr)
from.having expr
end
- def [] name
+ def [](name)
::Arel::Attribute.new self, name
end
@@ -88,7 +89,7 @@ module Arel
@name.hash
end
- def eql? other
+ def eql?(other)
self.class == other.class &&
self.name == other.name &&
self.table_alias == other.table_alias
@@ -105,6 +106,6 @@ module Arel
protected
- attr_reader :type_caster
+ attr_reader :type_caster
end
end
diff --git a/activerecord/lib/arel/tree_manager.rb b/activerecord/lib/arel/tree_manager.rb
index b237bf368d..f6ec1415fa 100644
--- a/activerecord/lib/arel/tree_manager.rb
+++ b/activerecord/lib/arel/tree_manager.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
class TreeManager
include Arel::FactoryMethods
@@ -15,18 +16,18 @@ module Arel
collector.value
end
- def to_sql engine = Table.engine
+ def to_sql(engine = Table.engine)
collector = Arel::Collectors::SQLString.new
collector = engine.connection.visitor.accept @ast, collector
collector.value
end
- def initialize_copy other
+ def initialize_copy(other)
super
@ast = @ast.clone
end
- def where expr
+ def where(expr)
if Arel::TreeManager === expr
expr = expr.ast
end
diff --git a/activerecord/lib/arel/update_manager.rb b/activerecord/lib/arel/update_manager.rb
index eac414eafb..6e36e82cf9 100644
--- a/activerecord/lib/arel/update_manager.rb
+++ b/activerecord/lib/arel/update_manager.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
class UpdateManager < Arel::TreeManager
def initialize
@@ -7,12 +8,12 @@ module Arel
@ctx = @ast
end
- def take limit
+ def take(limit)
@ast.limit = Nodes::Limit.new(Nodes.build_quoted(limit)) if limit
self
end
- def key= key
+ def key=(key)
@ast.key = Nodes.build_quoted(key)
end
@@ -20,32 +21,32 @@ module Arel
@ast.key
end
- def order *expr
+ def order(*expr)
@ast.orders = expr
self
end
###
# UPDATE +table+
- def table table
+ def table(table)
@ast.relation = table
self
end
- def wheres= exprs
+ def wheres=(exprs)
@ast.wheres = exprs
end
- def where expr
+ def where(expr)
@ast.wheres << expr
self
end
- def set values
+ def set(values)
if String === values
@ast.values = [values]
else
- @ast.values = values.map { |column,value|
+ @ast.values = values.map { |column, value|
Nodes::Assignment.new(
Nodes::UnqualifiedColumn.new(column),
value
diff --git a/activerecord/lib/arel/visitors.rb b/activerecord/lib/arel/visitors.rb
index a3404cf992..fb44721117 100644
--- a/activerecord/lib/arel/visitors.rb
+++ b/activerecord/lib/arel/visitors.rb
@@ -1,17 +1,18 @@
# frozen_string_literal: true
-require 'arel/visitors/visitor'
-require 'arel/visitors/depth_first'
-require 'arel/visitors/to_sql'
-require 'arel/visitors/sqlite'
-require 'arel/visitors/postgresql'
-require 'arel/visitors/mysql'
-require 'arel/visitors/mssql'
-require 'arel/visitors/oracle'
-require 'arel/visitors/oracle12'
-require 'arel/visitors/where_sql'
-require 'arel/visitors/dot'
-require 'arel/visitors/ibm_db'
-require 'arel/visitors/informix'
+
+require "arel/visitors/visitor"
+require "arel/visitors/depth_first"
+require "arel/visitors/to_sql"
+require "arel/visitors/sqlite"
+require "arel/visitors/postgresql"
+require "arel/visitors/mysql"
+require "arel/visitors/mssql"
+require "arel/visitors/oracle"
+require "arel/visitors/oracle12"
+require "arel/visitors/where_sql"
+require "arel/visitors/dot"
+require "arel/visitors/ibm_db"
+require "arel/visitors/informix"
module Arel
module Visitors
diff --git a/activerecord/lib/arel/visitors/depth_first.rb b/activerecord/lib/arel/visitors/depth_first.rb
index b3bbc9bd40..fb32ef59ad 100644
--- a/activerecord/lib/arel/visitors/depth_first.rb
+++ b/activerecord/lib/arel/visitors/depth_first.rb
@@ -1,199 +1,200 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class DepthFirst < Arel::Visitors::Visitor
- def initialize block = nil
+ def initialize(block = nil)
@block = block || Proc.new
super()
end
private
- def visit o
- super
- @block.call o
- end
-
- def unary o
- visit o.expr
- end
- alias :visit_Arel_Nodes_Else :unary
- alias :visit_Arel_Nodes_Group :unary
- alias :visit_Arel_Nodes_Cube :unary
- alias :visit_Arel_Nodes_RollUp :unary
- alias :visit_Arel_Nodes_GroupingSet :unary
- alias :visit_Arel_Nodes_GroupingElement :unary
- alias :visit_Arel_Nodes_Grouping :unary
- alias :visit_Arel_Nodes_Having :unary
- alias :visit_Arel_Nodes_Lateral :unary
- alias :visit_Arel_Nodes_Limit :unary
- alias :visit_Arel_Nodes_Not :unary
- alias :visit_Arel_Nodes_Offset :unary
- alias :visit_Arel_Nodes_On :unary
- alias :visit_Arel_Nodes_Ordering :unary
- alias :visit_Arel_Nodes_Ascending :unary
- alias :visit_Arel_Nodes_Descending :unary
- alias :visit_Arel_Nodes_Top :unary
- alias :visit_Arel_Nodes_UnqualifiedColumn :unary
-
- def function o
- visit o.expressions
- visit o.alias
- visit o.distinct
- end
- alias :visit_Arel_Nodes_Avg :function
- alias :visit_Arel_Nodes_Exists :function
- alias :visit_Arel_Nodes_Max :function
- alias :visit_Arel_Nodes_Min :function
- alias :visit_Arel_Nodes_Sum :function
-
- def visit_Arel_Nodes_NamedFunction o
- visit o.name
- visit o.expressions
- visit o.distinct
- visit o.alias
- end
-
- def visit_Arel_Nodes_Count o
- visit o.expressions
- visit o.alias
- visit o.distinct
- end
-
- def visit_Arel_Nodes_Case o
- visit o.case
- visit o.conditions
- visit o.default
- end
-
- def nary o
- o.children.each { |child| visit child}
- end
- alias :visit_Arel_Nodes_And :nary
-
- def binary o
- visit o.left
- visit o.right
- end
- alias :visit_Arel_Nodes_As :binary
- alias :visit_Arel_Nodes_Assignment :binary
- alias :visit_Arel_Nodes_Between :binary
- alias :visit_Arel_Nodes_Concat :binary
- alias :visit_Arel_Nodes_DeleteStatement :binary
- alias :visit_Arel_Nodes_DoesNotMatch :binary
- alias :visit_Arel_Nodes_Equality :binary
- alias :visit_Arel_Nodes_FullOuterJoin :binary
- alias :visit_Arel_Nodes_GreaterThan :binary
- alias :visit_Arel_Nodes_GreaterThanOrEqual :binary
- alias :visit_Arel_Nodes_In :binary
- alias :visit_Arel_Nodes_InfixOperation :binary
- alias :visit_Arel_Nodes_JoinSource :binary
- alias :visit_Arel_Nodes_InnerJoin :binary
- alias :visit_Arel_Nodes_LessThan :binary
- alias :visit_Arel_Nodes_LessThanOrEqual :binary
- alias :visit_Arel_Nodes_Matches :binary
- alias :visit_Arel_Nodes_NotEqual :binary
- alias :visit_Arel_Nodes_NotIn :binary
- alias :visit_Arel_Nodes_NotRegexp :binary
- alias :visit_Arel_Nodes_Or :binary
- alias :visit_Arel_Nodes_OuterJoin :binary
- alias :visit_Arel_Nodes_Regexp :binary
- alias :visit_Arel_Nodes_RightOuterJoin :binary
- alias :visit_Arel_Nodes_TableAlias :binary
- alias :visit_Arel_Nodes_Values :binary
- alias :visit_Arel_Nodes_When :binary
-
- def visit_Arel_Nodes_StringJoin o
- visit o.left
- end
-
- def visit_Arel_Attribute o
- visit o.relation
- visit o.name
- end
- alias :visit_Arel_Attributes_Integer :visit_Arel_Attribute
- alias :visit_Arel_Attributes_Float :visit_Arel_Attribute
- alias :visit_Arel_Attributes_String :visit_Arel_Attribute
- alias :visit_Arel_Attributes_Time :visit_Arel_Attribute
- alias :visit_Arel_Attributes_Boolean :visit_Arel_Attribute
- alias :visit_Arel_Attributes_Attribute :visit_Arel_Attribute
- alias :visit_Arel_Attributes_Decimal :visit_Arel_Attribute
-
- def visit_Arel_Table o
- visit o.name
- end
-
- def terminal o
- end
- alias :visit_ActiveSupport_Multibyte_Chars :terminal
- alias :visit_ActiveSupport_StringInquirer :terminal
- alias :visit_Arel_Nodes_Lock :terminal
- alias :visit_Arel_Nodes_Node :terminal
- alias :visit_Arel_Nodes_SqlLiteral :terminal
- alias :visit_Arel_Nodes_BindParam :terminal
- alias :visit_Arel_Nodes_Window :terminal
- alias :visit_Arel_Nodes_True :terminal
- alias :visit_Arel_Nodes_False :terminal
- alias :visit_BigDecimal :terminal
- alias :visit_Bignum :terminal
- alias :visit_Class :terminal
- alias :visit_Date :terminal
- alias :visit_DateTime :terminal
- alias :visit_FalseClass :terminal
- alias :visit_Fixnum :terminal
- alias :visit_Float :terminal
- alias :visit_Integer :terminal
- alias :visit_NilClass :terminal
- alias :visit_String :terminal
- alias :visit_Symbol :terminal
- alias :visit_Time :terminal
- alias :visit_TrueClass :terminal
-
- def visit_Arel_Nodes_InsertStatement o
- visit o.relation
- visit o.columns
- visit o.values
- end
-
- def visit_Arel_Nodes_SelectCore o
- visit o.projections
- visit o.source
- visit o.wheres
- visit o.groups
- visit o.windows
- visit o.havings
- end
-
- def visit_Arel_Nodes_SelectStatement o
- visit o.cores
- visit o.orders
- visit o.limit
- visit o.lock
- visit o.offset
- end
-
- def visit_Arel_Nodes_UpdateStatement o
- visit o.relation
- visit o.values
- visit o.wheres
- visit o.orders
- visit o.limit
- end
-
- def visit_Array o
- o.each { |i| visit i }
- end
- alias :visit_Set :visit_Array
-
- def visit_Hash o
- o.each { |k,v| visit(k); visit(v) }
- end
-
- DISPATCH = dispatch_cache
-
- def get_dispatch_cache
- DISPATCH
- end
+ def visit(o)
+ super
+ @block.call o
+ end
+
+ def unary(o)
+ visit o.expr
+ end
+ alias :visit_Arel_Nodes_Else :unary
+ alias :visit_Arel_Nodes_Group :unary
+ alias :visit_Arel_Nodes_Cube :unary
+ alias :visit_Arel_Nodes_RollUp :unary
+ alias :visit_Arel_Nodes_GroupingSet :unary
+ alias :visit_Arel_Nodes_GroupingElement :unary
+ alias :visit_Arel_Nodes_Grouping :unary
+ alias :visit_Arel_Nodes_Having :unary
+ alias :visit_Arel_Nodes_Lateral :unary
+ alias :visit_Arel_Nodes_Limit :unary
+ alias :visit_Arel_Nodes_Not :unary
+ alias :visit_Arel_Nodes_Offset :unary
+ alias :visit_Arel_Nodes_On :unary
+ alias :visit_Arel_Nodes_Ordering :unary
+ alias :visit_Arel_Nodes_Ascending :unary
+ alias :visit_Arel_Nodes_Descending :unary
+ alias :visit_Arel_Nodes_Top :unary
+ alias :visit_Arel_Nodes_UnqualifiedColumn :unary
+
+ def function(o)
+ visit o.expressions
+ visit o.alias
+ visit o.distinct
+ end
+ alias :visit_Arel_Nodes_Avg :function
+ alias :visit_Arel_Nodes_Exists :function
+ alias :visit_Arel_Nodes_Max :function
+ alias :visit_Arel_Nodes_Min :function
+ alias :visit_Arel_Nodes_Sum :function
+
+ def visit_Arel_Nodes_NamedFunction(o)
+ visit o.name
+ visit o.expressions
+ visit o.distinct
+ visit o.alias
+ end
+
+ def visit_Arel_Nodes_Count(o)
+ visit o.expressions
+ visit o.alias
+ visit o.distinct
+ end
+
+ def visit_Arel_Nodes_Case(o)
+ visit o.case
+ visit o.conditions
+ visit o.default
+ end
+
+ def nary(o)
+ o.children.each { |child| visit child }
+ end
+ alias :visit_Arel_Nodes_And :nary
+
+ def binary(o)
+ visit o.left
+ visit o.right
+ end
+ alias :visit_Arel_Nodes_As :binary
+ alias :visit_Arel_Nodes_Assignment :binary
+ alias :visit_Arel_Nodes_Between :binary
+ alias :visit_Arel_Nodes_Concat :binary
+ alias :visit_Arel_Nodes_DeleteStatement :binary
+ alias :visit_Arel_Nodes_DoesNotMatch :binary
+ alias :visit_Arel_Nodes_Equality :binary
+ alias :visit_Arel_Nodes_FullOuterJoin :binary
+ alias :visit_Arel_Nodes_GreaterThan :binary
+ alias :visit_Arel_Nodes_GreaterThanOrEqual :binary
+ alias :visit_Arel_Nodes_In :binary
+ alias :visit_Arel_Nodes_InfixOperation :binary
+ alias :visit_Arel_Nodes_JoinSource :binary
+ alias :visit_Arel_Nodes_InnerJoin :binary
+ alias :visit_Arel_Nodes_LessThan :binary
+ alias :visit_Arel_Nodes_LessThanOrEqual :binary
+ alias :visit_Arel_Nodes_Matches :binary
+ alias :visit_Arel_Nodes_NotEqual :binary
+ alias :visit_Arel_Nodes_NotIn :binary
+ alias :visit_Arel_Nodes_NotRegexp :binary
+ alias :visit_Arel_Nodes_Or :binary
+ alias :visit_Arel_Nodes_OuterJoin :binary
+ alias :visit_Arel_Nodes_Regexp :binary
+ alias :visit_Arel_Nodes_RightOuterJoin :binary
+ alias :visit_Arel_Nodes_TableAlias :binary
+ alias :visit_Arel_Nodes_Values :binary
+ alias :visit_Arel_Nodes_When :binary
+
+ def visit_Arel_Nodes_StringJoin(o)
+ visit o.left
+ end
+
+ def visit_Arel_Attribute(o)
+ visit o.relation
+ visit o.name
+ end
+ alias :visit_Arel_Attributes_Integer :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_Float :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_String :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_Time :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_Boolean :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_Attribute :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_Decimal :visit_Arel_Attribute
+
+ def visit_Arel_Table(o)
+ visit o.name
+ end
+
+ def terminal(o)
+ end
+ alias :visit_ActiveSupport_Multibyte_Chars :terminal
+ alias :visit_ActiveSupport_StringInquirer :terminal
+ alias :visit_Arel_Nodes_Lock :terminal
+ alias :visit_Arel_Nodes_Node :terminal
+ alias :visit_Arel_Nodes_SqlLiteral :terminal
+ alias :visit_Arel_Nodes_BindParam :terminal
+ alias :visit_Arel_Nodes_Window :terminal
+ alias :visit_Arel_Nodes_True :terminal
+ alias :visit_Arel_Nodes_False :terminal
+ alias :visit_BigDecimal :terminal
+ alias :visit_Bignum :terminal
+ alias :visit_Class :terminal
+ alias :visit_Date :terminal
+ alias :visit_DateTime :terminal
+ alias :visit_FalseClass :terminal
+ alias :visit_Fixnum :terminal
+ alias :visit_Float :terminal
+ alias :visit_Integer :terminal
+ alias :visit_NilClass :terminal
+ alias :visit_String :terminal
+ alias :visit_Symbol :terminal
+ alias :visit_Time :terminal
+ alias :visit_TrueClass :terminal
+
+ def visit_Arel_Nodes_InsertStatement(o)
+ visit o.relation
+ visit o.columns
+ visit o.values
+ end
+
+ def visit_Arel_Nodes_SelectCore(o)
+ visit o.projections
+ visit o.source
+ visit o.wheres
+ visit o.groups
+ visit o.windows
+ visit o.havings
+ end
+
+ def visit_Arel_Nodes_SelectStatement(o)
+ visit o.cores
+ visit o.orders
+ visit o.limit
+ visit o.lock
+ visit o.offset
+ end
+
+ def visit_Arel_Nodes_UpdateStatement(o)
+ visit o.relation
+ visit o.values
+ visit o.wheres
+ visit o.orders
+ visit o.limit
+ end
+
+ def visit_Array(o)
+ o.each { |i| visit i }
+ end
+ alias :visit_Set :visit_Array
+
+ def visit_Hash(o)
+ o.each { |k, v| visit(k); visit(v) }
+ end
+
+ DISPATCH = dispatch_cache
+
+ def get_dispatch_cache
+ DISPATCH
+ end
end
end
end
diff --git a/activerecord/lib/arel/visitors/dot.rb b/activerecord/lib/arel/visitors/dot.rb
index 9aa22d33f6..2b285ac775 100644
--- a/activerecord/lib/arel/visitors/dot.rb
+++ b/activerecord/lib/arel/visitors/dot.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class Dot < Arel::Visitors::Visitor
class Node # :nodoc:
attr_accessor :name, :id, :fields
- def initialize name, id, fields = []
+ def initialize(name, id, fields = [])
@name = name
@id = id
@fields = fields
@@ -24,268 +25,268 @@ module Arel
@seen = {}
end
- def accept object, collector
+ def accept(object, collector)
visit object
collector << to_dot
end
private
- def visit_Arel_Nodes_Ordering o
- visit_edge o, "expr"
- end
-
- def visit_Arel_Nodes_TableAlias o
- visit_edge o, "name"
- visit_edge o, "relation"
- end
+ def visit_Arel_Nodes_Ordering(o)
+ visit_edge o, "expr"
+ end
- def visit_Arel_Nodes_Count o
- visit_edge o, "expressions"
- visit_edge o, "distinct"
- end
+ def visit_Arel_Nodes_TableAlias(o)
+ visit_edge o, "name"
+ visit_edge o, "relation"
+ end
- def visit_Arel_Nodes_Values o
- visit_edge o, "expressions"
- end
+ def visit_Arel_Nodes_Count(o)
+ visit_edge o, "expressions"
+ visit_edge o, "distinct"
+ end
- def visit_Arel_Nodes_StringJoin o
- visit_edge o, "left"
- end
+ def visit_Arel_Nodes_Values(o)
+ visit_edge o, "expressions"
+ end
- def visit_Arel_Nodes_InnerJoin o
- visit_edge o, "left"
- visit_edge o, "right"
- end
- alias :visit_Arel_Nodes_FullOuterJoin :visit_Arel_Nodes_InnerJoin
- alias :visit_Arel_Nodes_OuterJoin :visit_Arel_Nodes_InnerJoin
- alias :visit_Arel_Nodes_RightOuterJoin :visit_Arel_Nodes_InnerJoin
+ def visit_Arel_Nodes_StringJoin(o)
+ visit_edge o, "left"
+ end
- def visit_Arel_Nodes_DeleteStatement o
- visit_edge o, "relation"
- visit_edge o, "wheres"
- end
+ def visit_Arel_Nodes_InnerJoin(o)
+ visit_edge o, "left"
+ visit_edge o, "right"
+ end
+ alias :visit_Arel_Nodes_FullOuterJoin :visit_Arel_Nodes_InnerJoin
+ alias :visit_Arel_Nodes_OuterJoin :visit_Arel_Nodes_InnerJoin
+ alias :visit_Arel_Nodes_RightOuterJoin :visit_Arel_Nodes_InnerJoin
- def unary o
- visit_edge o, "expr"
- end
- alias :visit_Arel_Nodes_Group :unary
- alias :visit_Arel_Nodes_Cube :unary
- alias :visit_Arel_Nodes_RollUp :unary
- alias :visit_Arel_Nodes_GroupingSet :unary
- alias :visit_Arel_Nodes_GroupingElement :unary
- alias :visit_Arel_Nodes_Grouping :unary
- alias :visit_Arel_Nodes_Having :unary
- alias :visit_Arel_Nodes_Limit :unary
- alias :visit_Arel_Nodes_Not :unary
- alias :visit_Arel_Nodes_Offset :unary
- alias :visit_Arel_Nodes_On :unary
- alias :visit_Arel_Nodes_Top :unary
- alias :visit_Arel_Nodes_UnqualifiedColumn :unary
- alias :visit_Arel_Nodes_Preceding :unary
- alias :visit_Arel_Nodes_Following :unary
- alias :visit_Arel_Nodes_Rows :unary
- alias :visit_Arel_Nodes_Range :unary
-
- def window o
- visit_edge o, "partitions"
- visit_edge o, "orders"
- visit_edge o, "framing"
- end
- alias :visit_Arel_Nodes_Window :window
+ def visit_Arel_Nodes_DeleteStatement(o)
+ visit_edge o, "relation"
+ visit_edge o, "wheres"
+ end
- def named_window o
- visit_edge o, "partitions"
- visit_edge o, "orders"
- visit_edge o, "framing"
- visit_edge o, "name"
- end
- alias :visit_Arel_Nodes_NamedWindow :named_window
+ def unary(o)
+ visit_edge o, "expr"
+ end
+ alias :visit_Arel_Nodes_Group :unary
+ alias :visit_Arel_Nodes_Cube :unary
+ alias :visit_Arel_Nodes_RollUp :unary
+ alias :visit_Arel_Nodes_GroupingSet :unary
+ alias :visit_Arel_Nodes_GroupingElement :unary
+ alias :visit_Arel_Nodes_Grouping :unary
+ alias :visit_Arel_Nodes_Having :unary
+ alias :visit_Arel_Nodes_Limit :unary
+ alias :visit_Arel_Nodes_Not :unary
+ alias :visit_Arel_Nodes_Offset :unary
+ alias :visit_Arel_Nodes_On :unary
+ alias :visit_Arel_Nodes_Top :unary
+ alias :visit_Arel_Nodes_UnqualifiedColumn :unary
+ alias :visit_Arel_Nodes_Preceding :unary
+ alias :visit_Arel_Nodes_Following :unary
+ alias :visit_Arel_Nodes_Rows :unary
+ alias :visit_Arel_Nodes_Range :unary
+
+ def window(o)
+ visit_edge o, "partitions"
+ visit_edge o, "orders"
+ visit_edge o, "framing"
+ end
+ alias :visit_Arel_Nodes_Window :window
- def function o
- visit_edge o, "expressions"
- visit_edge o, "distinct"
- visit_edge o, "alias"
- end
- alias :visit_Arel_Nodes_Exists :function
- alias :visit_Arel_Nodes_Min :function
- alias :visit_Arel_Nodes_Max :function
- alias :visit_Arel_Nodes_Avg :function
- alias :visit_Arel_Nodes_Sum :function
-
- def extract o
- visit_edge o, "expressions"
- visit_edge o, "alias"
- end
- alias :visit_Arel_Nodes_Extract :extract
+ def named_window(o)
+ visit_edge o, "partitions"
+ visit_edge o, "orders"
+ visit_edge o, "framing"
+ visit_edge o, "name"
+ end
+ alias :visit_Arel_Nodes_NamedWindow :named_window
- def visit_Arel_Nodes_NamedFunction o
- visit_edge o, "name"
- visit_edge o, "expressions"
- visit_edge o, "distinct"
- visit_edge o, "alias"
- end
+ def function(o)
+ visit_edge o, "expressions"
+ visit_edge o, "distinct"
+ visit_edge o, "alias"
+ end
+ alias :visit_Arel_Nodes_Exists :function
+ alias :visit_Arel_Nodes_Min :function
+ alias :visit_Arel_Nodes_Max :function
+ alias :visit_Arel_Nodes_Avg :function
+ alias :visit_Arel_Nodes_Sum :function
+
+ def extract(o)
+ visit_edge o, "expressions"
+ visit_edge o, "alias"
+ end
+ alias :visit_Arel_Nodes_Extract :extract
- def visit_Arel_Nodes_InsertStatement o
- visit_edge o, "relation"
- visit_edge o, "columns"
- visit_edge o, "values"
- end
+ def visit_Arel_Nodes_NamedFunction(o)
+ visit_edge o, "name"
+ visit_edge o, "expressions"
+ visit_edge o, "distinct"
+ visit_edge o, "alias"
+ end
- def visit_Arel_Nodes_SelectCore o
- visit_edge o, "source"
- visit_edge o, "projections"
- visit_edge o, "wheres"
- visit_edge o, "windows"
- end
+ def visit_Arel_Nodes_InsertStatement(o)
+ visit_edge o, "relation"
+ visit_edge o, "columns"
+ visit_edge o, "values"
+ end
- def visit_Arel_Nodes_SelectStatement o
- visit_edge o, "cores"
- visit_edge o, "limit"
- visit_edge o, "orders"
- visit_edge o, "offset"
- end
+ def visit_Arel_Nodes_SelectCore(o)
+ visit_edge o, "source"
+ visit_edge o, "projections"
+ visit_edge o, "wheres"
+ visit_edge o, "windows"
+ end
- def visit_Arel_Nodes_UpdateStatement o
- visit_edge o, "relation"
- visit_edge o, "wheres"
- visit_edge o, "values"
- end
+ def visit_Arel_Nodes_SelectStatement(o)
+ visit_edge o, "cores"
+ visit_edge o, "limit"
+ visit_edge o, "orders"
+ visit_edge o, "offset"
+ end
- def visit_Arel_Table o
- visit_edge o, "name"
- end
+ def visit_Arel_Nodes_UpdateStatement(o)
+ visit_edge o, "relation"
+ visit_edge o, "wheres"
+ visit_edge o, "values"
+ end
- def visit_Arel_Nodes_Casted o
- visit_edge o, 'val'
- visit_edge o, 'attribute'
- end
+ def visit_Arel_Table(o)
+ visit_edge o, "name"
+ end
- def visit_Arel_Attribute o
- visit_edge o, "relation"
- visit_edge o, "name"
- end
- alias :visit_Arel_Attributes_Integer :visit_Arel_Attribute
- alias :visit_Arel_Attributes_Float :visit_Arel_Attribute
- alias :visit_Arel_Attributes_String :visit_Arel_Attribute
- alias :visit_Arel_Attributes_Time :visit_Arel_Attribute
- alias :visit_Arel_Attributes_Boolean :visit_Arel_Attribute
- alias :visit_Arel_Attributes_Attribute :visit_Arel_Attribute
+ def visit_Arel_Nodes_Casted(o)
+ visit_edge o, "val"
+ visit_edge o, "attribute"
+ end
- def nary o
- o.children.each_with_index do |x,i|
- edge(i) { visit x }
+ def visit_Arel_Attribute(o)
+ visit_edge o, "relation"
+ visit_edge o, "name"
end
- end
- alias :visit_Arel_Nodes_And :nary
+ alias :visit_Arel_Attributes_Integer :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_Float :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_String :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_Time :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_Boolean :visit_Arel_Attribute
+ alias :visit_Arel_Attributes_Attribute :visit_Arel_Attribute
+
+ def nary(o)
+ o.children.each_with_index do |x, i|
+ edge(i) { visit x }
+ end
+ end
+ alias :visit_Arel_Nodes_And :nary
- def binary o
- visit_edge o, "left"
- visit_edge o, "right"
- end
- alias :visit_Arel_Nodes_As :binary
- alias :visit_Arel_Nodes_Assignment :binary
- alias :visit_Arel_Nodes_Between :binary
- alias :visit_Arel_Nodes_Concat :binary
- alias :visit_Arel_Nodes_DoesNotMatch :binary
- alias :visit_Arel_Nodes_Equality :binary
- alias :visit_Arel_Nodes_GreaterThan :binary
- alias :visit_Arel_Nodes_GreaterThanOrEqual :binary
- alias :visit_Arel_Nodes_In :binary
- alias :visit_Arel_Nodes_JoinSource :binary
- alias :visit_Arel_Nodes_LessThan :binary
- alias :visit_Arel_Nodes_LessThanOrEqual :binary
- alias :visit_Arel_Nodes_Matches :binary
- alias :visit_Arel_Nodes_NotEqual :binary
- alias :visit_Arel_Nodes_NotIn :binary
- alias :visit_Arel_Nodes_Or :binary
- alias :visit_Arel_Nodes_Over :binary
-
- def visit_String o
- @node_stack.last.fields << o
- end
- alias :visit_Time :visit_String
- alias :visit_Date :visit_String
- alias :visit_DateTime :visit_String
- alias :visit_NilClass :visit_String
- alias :visit_TrueClass :visit_String
- alias :visit_FalseClass :visit_String
- alias :visit_Integer :visit_String
- alias :visit_Fixnum :visit_String
- alias :visit_BigDecimal :visit_String
- alias :visit_Float :visit_String
- alias :visit_Symbol :visit_String
- alias :visit_Arel_Nodes_SqlLiteral :visit_String
-
- def visit_Arel_Nodes_BindParam o; end
-
- def visit_Hash o
- o.each_with_index do |pair, i|
- edge("pair_#{i}") { visit pair }
+ def binary(o)
+ visit_edge o, "left"
+ visit_edge o, "right"
+ end
+ alias :visit_Arel_Nodes_As :binary
+ alias :visit_Arel_Nodes_Assignment :binary
+ alias :visit_Arel_Nodes_Between :binary
+ alias :visit_Arel_Nodes_Concat :binary
+ alias :visit_Arel_Nodes_DoesNotMatch :binary
+ alias :visit_Arel_Nodes_Equality :binary
+ alias :visit_Arel_Nodes_GreaterThan :binary
+ alias :visit_Arel_Nodes_GreaterThanOrEqual :binary
+ alias :visit_Arel_Nodes_In :binary
+ alias :visit_Arel_Nodes_JoinSource :binary
+ alias :visit_Arel_Nodes_LessThan :binary
+ alias :visit_Arel_Nodes_LessThanOrEqual :binary
+ alias :visit_Arel_Nodes_Matches :binary
+ alias :visit_Arel_Nodes_NotEqual :binary
+ alias :visit_Arel_Nodes_NotIn :binary
+ alias :visit_Arel_Nodes_Or :binary
+ alias :visit_Arel_Nodes_Over :binary
+
+ def visit_String(o)
+ @node_stack.last.fields << o
+ end
+ alias :visit_Time :visit_String
+ alias :visit_Date :visit_String
+ alias :visit_DateTime :visit_String
+ alias :visit_NilClass :visit_String
+ alias :visit_TrueClass :visit_String
+ alias :visit_FalseClass :visit_String
+ alias :visit_Integer :visit_String
+ alias :visit_Fixnum :visit_String
+ alias :visit_BigDecimal :visit_String
+ alias :visit_Float :visit_String
+ alias :visit_Symbol :visit_String
+ alias :visit_Arel_Nodes_SqlLiteral :visit_String
+
+ def visit_Arel_Nodes_BindParam(o); end
+
+ def visit_Hash(o)
+ o.each_with_index do |pair, i|
+ edge("pair_#{i}") { visit pair }
+ end
end
- end
- def visit_Array o
- o.each_with_index do |x,i|
- edge(i) { visit x }
+ def visit_Array(o)
+ o.each_with_index do |x, i|
+ edge(i) { visit x }
+ end
end
- end
- alias :visit_Set :visit_Array
+ alias :visit_Set :visit_Array
- def visit_edge o, method
- edge(method) { visit o.send(method) }
- end
+ def visit_edge(o, method)
+ edge(method) { visit o.send(method) }
+ end
- def visit o
- if node = @seen[o.object_id]
- @edge_stack.last.to = node
- return
+ def visit(o)
+ if node = @seen[o.object_id]
+ @edge_stack.last.to = node
+ return
+ end
+
+ node = Node.new(o.class.name, o.object_id)
+ @seen[node.id] = node
+ @nodes << node
+ with_node node do
+ super
+ end
end
- node = Node.new(o.class.name, o.object_id)
- @seen[node.id] = node
- @nodes << node
- with_node node do
- super
+ def edge(name)
+ edge = Edge.new(name, @node_stack.last)
+ @edge_stack.push edge
+ @edges << edge
+ yield
+ @edge_stack.pop
end
- end
- def edge name
- edge = Edge.new(name, @node_stack.last)
- @edge_stack.push edge
- @edges << edge
- yield
- @edge_stack.pop
- end
+ def with_node(node)
+ if edge = @edge_stack.last
+ edge.to = node
+ end
- def with_node node
- if edge = @edge_stack.last
- edge.to = node
+ @node_stack.push node
+ yield
+ @node_stack.pop
end
- @node_stack.push node
- yield
- @node_stack.pop
- end
-
- def quote string
- string.to_s.gsub('"', '\"')
- end
+ def quote(string)
+ string.to_s.gsub('"', '\"')
+ end
- def to_dot
- "digraph \"Arel\" {\nnode [width=0.375,height=0.25,shape=record];\n" +
- @nodes.map { |node|
- label = "<f0>#{node.name}"
+ def to_dot
+ "digraph \"Arel\" {\nnode [width=0.375,height=0.25,shape=record];\n" +
+ @nodes.map { |node|
+ label = "<f0>#{node.name}"
- node.fields.each_with_index do |field, i|
- label += "|<f#{i + 1}>#{quote field}"
- end
+ node.fields.each_with_index do |field, i|
+ label += "|<f#{i + 1}>#{quote field}"
+ end
- "#{node.id} [label=\"#{label}\"];"
- }.join("\n") + "\n" + @edges.map { |edge|
- "#{edge.from.id} -> #{edge.to.id} [label=\"#{edge.name}\"];"
- }.join("\n") + "\n}"
- end
+ "#{node.id} [label=\"#{label}\"];"
+ }.join("\n") + "\n" + @edges.map { |edge|
+ "#{edge.from.id} -> #{edge.to.id} [label=\"#{edge.name}\"];"
+ }.join("\n") + "\n}"
+ end
end
end
end
diff --git a/activerecord/lib/arel/visitors/ibm_db.rb b/activerecord/lib/arel/visitors/ibm_db.rb
index e85a5a08a7..0291e434c9 100644
--- a/activerecord/lib/arel/visitors/ibm_db.rb
+++ b/activerecord/lib/arel/visitors/ibm_db.rb
@@ -1,15 +1,15 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class IBM_DB < Arel::Visitors::ToSql
private
- def visit_Arel_Nodes_Limit o, collector
- collector << "FETCH FIRST "
- collector = visit o.expr, collector
- collector << " ROWS ONLY"
- end
-
+ def visit_Arel_Nodes_Limit(o, collector)
+ collector << "FETCH FIRST "
+ collector = visit o.expr, collector
+ collector << " ROWS ONLY"
+ end
end
end
end
diff --git a/activerecord/lib/arel/visitors/informix.rb b/activerecord/lib/arel/visitors/informix.rb
index 44b18b550e..9df5a60bc2 100644
--- a/activerecord/lib/arel/visitors/informix.rb
+++ b/activerecord/lib/arel/visitors/informix.rb
@@ -1,55 +1,55 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class Informix < Arel::Visitors::ToSql
private
- def visit_Arel_Nodes_SelectStatement o, collector
- collector << "SELECT "
- collector = maybe_visit o.offset, collector
- collector = maybe_visit o.limit, collector
- collector = o.cores.inject(collector) { |c,x|
- visit_Arel_Nodes_SelectCore x, c
- }
- if o.orders.any?
- collector << "ORDER BY "
- collector = inject_join o.orders, collector, ", "
- end
- collector = maybe_visit o.lock, collector
- end
- def visit_Arel_Nodes_SelectCore o, collector
- collector = inject_join o.projections, collector, ", "
- if o.source && !o.source.empty?
- collector << " FROM "
- collector = visit o.source, collector
+ def visit_Arel_Nodes_SelectStatement(o, collector)
+ collector << "SELECT "
+ collector = maybe_visit o.offset, collector
+ collector = maybe_visit o.limit, collector
+ collector = o.cores.inject(collector) { |c, x|
+ visit_Arel_Nodes_SelectCore x, c
+ }
+ if o.orders.any?
+ collector << "ORDER BY "
+ collector = inject_join o.orders, collector, ", "
+ end
+ collector = maybe_visit o.lock, collector
end
+ def visit_Arel_Nodes_SelectCore(o, collector)
+ collector = inject_join o.projections, collector, ", "
+ if o.source && !o.source.empty?
+ collector << " FROM "
+ collector = visit o.source, collector
+ end
- if o.wheres.any?
- collector << " WHERE "
- collector = inject_join o.wheres, collector, " AND "
- end
+ if o.wheres.any?
+ collector << " WHERE "
+ collector = inject_join o.wheres, collector, " AND "
+ end
- if o.groups.any?
- collector << "GROUP BY "
- collector = inject_join o.groups, collector, ", "
- end
+ if o.groups.any?
+ collector << "GROUP BY "
+ collector = inject_join o.groups, collector, ", "
+ end
- if o.havings.any?
- collector << " HAVING "
- collector = inject_join o.havings, collector, " AND "
+ if o.havings.any?
+ collector << " HAVING "
+ collector = inject_join o.havings, collector, " AND "
+ end
+ collector
end
- collector
- end
- def visit_Arel_Nodes_Offset o, collector
- collector << "SKIP "
- visit o.expr, collector
- end
- def visit_Arel_Nodes_Limit o, collector
- collector << "FIRST "
- visit o.expr, collector
- collector << " "
- end
+ def visit_Arel_Nodes_Offset(o, collector)
+ collector << "SKIP "
+ visit o.expr, collector
+ end
+ def visit_Arel_Nodes_Limit(o, collector)
+ collector << "FIRST "
+ visit o.expr, collector
+ collector << " "
+ end
end
end
end
-
diff --git a/activerecord/lib/arel/visitors/mssql.rb b/activerecord/lib/arel/visitors/mssql.rb
index 8347d05d06..4f2945e3a4 100644
--- a/activerecord/lib/arel/visitors/mssql.rb
+++ b/activerecord/lib/arel/visitors/mssql.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class MSSQL < Arel::Visitors::ToSql
@@ -11,114 +12,114 @@ module Arel
private
- # `top` wouldn't really work here. I.e. User.select("distinct first_name").limit(10) would generate
- # "select top 10 distinct first_name from users", which is invalid query! it should be
- # "select distinct top 10 first_name from users"
- def visit_Arel_Nodes_Top o
- ""
- end
-
- def visit_Arel_Visitors_MSSQL_RowNumber o, collector
- collector << "ROW_NUMBER() OVER (ORDER BY "
- inject_join(o.children, collector, ', ') << ") as _row_num"
- end
+ # `top` wouldn't really work here. I.e. User.select("distinct first_name").limit(10) would generate
+ # "select top 10 distinct first_name from users", which is invalid query! it should be
+ # "select distinct top 10 first_name from users"
+ def visit_Arel_Nodes_Top(o)
+ ""
+ end
- def visit_Arel_Nodes_SelectStatement o, collector
- if !o.limit && !o.offset
- return super
+ def visit_Arel_Visitors_MSSQL_RowNumber(o, collector)
+ collector << "ROW_NUMBER() OVER (ORDER BY "
+ inject_join(o.children, collector, ", ") << ") as _row_num"
end
- is_select_count = false
- o.cores.each { |x|
- core_order_by = row_num_literal determine_order_by(o.orders, x)
- if select_count? x
- x.projections = [core_order_by]
- is_select_count = true
- else
- x.projections << core_order_by
+ def visit_Arel_Nodes_SelectStatement(o, collector)
+ if !o.limit && !o.offset
+ return super
end
- }
- if is_select_count
- # fixme count distinct wouldn't work with limit or offset
- collector << "SELECT COUNT(1) as count_id FROM ("
- end
+ is_select_count = false
+ o.cores.each { |x|
+ core_order_by = row_num_literal determine_order_by(o.orders, x)
+ if select_count? x
+ x.projections = [core_order_by]
+ is_select_count = true
+ else
+ x.projections << core_order_by
+ end
+ }
+
+ if is_select_count
+ # fixme count distinct wouldn't work with limit or offset
+ collector << "SELECT COUNT(1) as count_id FROM ("
+ end
- collector << "SELECT _t.* FROM ("
- collector = o.cores.inject(collector) { |c,x|
- visit_Arel_Nodes_SelectCore x, c
- }
- collector << ") as _t WHERE #{get_offset_limit_clause(o)}"
+ collector << "SELECT _t.* FROM ("
+ collector = o.cores.inject(collector) { |c, x|
+ visit_Arel_Nodes_SelectCore x, c
+ }
+ collector << ") as _t WHERE #{get_offset_limit_clause(o)}"
- if is_select_count
- collector << ") AS subquery"
- else
- collector
+ if is_select_count
+ collector << ") AS subquery"
+ else
+ collector
+ end
end
- end
- def get_offset_limit_clause o
- first_row = o.offset ? o.offset.expr.to_i + 1 : 1
- last_row = o.limit ? o.limit.expr.to_i - 1 + first_row : nil
- if last_row
- " _row_num BETWEEN #{first_row} AND #{last_row}"
- else
- " _row_num >= #{first_row}"
+ def get_offset_limit_clause(o)
+ first_row = o.offset ? o.offset.expr.to_i + 1 : 1
+ last_row = o.limit ? o.limit.expr.to_i - 1 + first_row : nil
+ if last_row
+ " _row_num BETWEEN #{first_row} AND #{last_row}"
+ else
+ " _row_num >= #{first_row}"
+ end
end
- end
- def visit_Arel_Nodes_DeleteStatement o, collector
- collector << 'DELETE '
- if o.limit
- collector << 'TOP ('
- visit o.limit.expr, collector
- collector << ') '
- end
- collector << 'FROM '
- collector = visit o.relation, collector
- if o.wheres.any?
- collector << ' WHERE '
- inject_join o.wheres, collector, AND
- else
- collector
+ def visit_Arel_Nodes_DeleteStatement(o, collector)
+ collector << "DELETE "
+ if o.limit
+ collector << "TOP ("
+ visit o.limit.expr, collector
+ collector << ") "
+ end
+ collector << "FROM "
+ collector = visit o.relation, collector
+ if o.wheres.any?
+ collector << " WHERE "
+ inject_join o.wheres, collector, AND
+ else
+ collector
+ end
end
- end
- def determine_order_by orders, x
- if orders.any?
- orders
- elsif x.groups.any?
- x.groups
- else
- pk = find_left_table_pk(x.froms)
- pk ? [pk] : []
+ def determine_order_by(orders, x)
+ if orders.any?
+ orders
+ elsif x.groups.any?
+ x.groups
+ else
+ pk = find_left_table_pk(x.froms)
+ pk ? [pk] : []
+ end
end
- end
- def row_num_literal order_by
- RowNumber.new order_by
- end
+ def row_num_literal(order_by)
+ RowNumber.new order_by
+ end
- def select_count? x
- x.projections.length == 1 && Arel::Nodes::Count === x.projections.first
- end
+ def select_count?(x)
+ x.projections.length == 1 && Arel::Nodes::Count === x.projections.first
+ end
- # FIXME raise exception of there is no pk?
- def find_left_table_pk o
- if o.kind_of?(Arel::Nodes::Join)
- find_left_table_pk(o.left)
- elsif o.instance_of?(Arel::Table)
- find_primary_key(o)
+ # FIXME raise exception of there is no pk?
+ def find_left_table_pk(o)
+ if o.kind_of?(Arel::Nodes::Join)
+ find_left_table_pk(o.left)
+ elsif o.instance_of?(Arel::Table)
+ find_primary_key(o)
+ end
end
- end
- def find_primary_key(o)
- @primary_keys[o.name] ||= begin
- primary_key_name = @connection.primary_key(o.name)
- # some tables might be without primary key
- primary_key_name && o[primary_key_name]
+ def find_primary_key(o)
+ @primary_keys[o.name] ||= begin
+ primary_key_name = @connection.primary_key(o.name)
+ # some tables might be without primary key
+ primary_key_name && o[primary_key_name]
+ end
end
- end
end
end
end
diff --git a/activerecord/lib/arel/visitors/mysql.rb b/activerecord/lib/arel/visitors/mysql.rb
index 4c734f6292..7b32988be6 100644
--- a/activerecord/lib/arel/visitors/mysql.rb
+++ b/activerecord/lib/arel/visitors/mysql.rb
@@ -1,86 +1,87 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class MySQL < Arel::Visitors::ToSql
private
- def visit_Arel_Nodes_Union o, collector, suppress_parens = false
- unless suppress_parens
- collector << "( "
- end
+ def visit_Arel_Nodes_Union(o, collector, suppress_parens = false)
+ unless suppress_parens
+ collector << "( "
+ end
- collector = case o.left
- when Arel::Nodes::Union
- visit_Arel_Nodes_Union o.left, collector, true
- else
- visit o.left, collector
- end
+ collector = case o.left
+ when Arel::Nodes::Union
+ visit_Arel_Nodes_Union o.left, collector, true
+ else
+ visit o.left, collector
+ end
- collector << " UNION "
+ collector << " UNION "
- collector = case o.right
- when Arel::Nodes::Union
- visit_Arel_Nodes_Union o.right, collector, true
- else
- visit o.right, collector
- end
+ collector = case o.right
+ when Arel::Nodes::Union
+ visit_Arel_Nodes_Union o.right, collector, true
+ else
+ visit o.right, collector
+ end
- if suppress_parens
- collector
- else
- collector << " )"
+ if suppress_parens
+ collector
+ else
+ collector << " )"
+ end
end
- end
- def visit_Arel_Nodes_Bin o, collector
- collector << "BINARY "
- visit o.expr, collector
- end
+ def visit_Arel_Nodes_Bin(o, collector)
+ collector << "BINARY "
+ visit o.expr, collector
+ end
- ###
- # :'(
- # http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214
- def visit_Arel_Nodes_SelectStatement o, collector
- if o.offset && !o.limit
- o.limit = Arel::Nodes::Limit.new(18446744073709551615)
+ ###
+ # :'(
+ # http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214
+ def visit_Arel_Nodes_SelectStatement(o, collector)
+ if o.offset && !o.limit
+ o.limit = Arel::Nodes::Limit.new(18446744073709551615)
+ end
+ super
end
- super
- end
- def visit_Arel_Nodes_SelectCore o, collector
- o.froms ||= Arel.sql('DUAL')
- super
- end
+ def visit_Arel_Nodes_SelectCore(o, collector)
+ o.froms ||= Arel.sql("DUAL")
+ super
+ end
- def visit_Arel_Nodes_UpdateStatement o, collector
- collector << "UPDATE "
- collector = visit o.relation, collector
+ def visit_Arel_Nodes_UpdateStatement(o, collector)
+ collector << "UPDATE "
+ collector = visit o.relation, collector
- unless o.values.empty?
- collector << " SET "
- collector = inject_join o.values, collector, ', '
- end
+ unless o.values.empty?
+ collector << " SET "
+ collector = inject_join o.values, collector, ", "
+ end
- unless o.wheres.empty?
- collector << " WHERE "
- collector = inject_join o.wheres, collector, ' AND '
- end
+ unless o.wheres.empty?
+ collector << " WHERE "
+ collector = inject_join o.wheres, collector, " AND "
+ end
- unless o.orders.empty?
- collector << " ORDER BY "
- collector = inject_join o.orders, collector, ', '
- end
+ unless o.orders.empty?
+ collector << " ORDER BY "
+ collector = inject_join o.orders, collector, ", "
+ end
- maybe_visit o.limit, collector
- end
+ maybe_visit o.limit, collector
+ end
- def visit_Arel_Nodes_Concat o, collector
- collector << " CONCAT("
- visit o.left, collector
- collector << ", "
- visit o.right, collector
- collector << ") "
- collector
- end
+ def visit_Arel_Nodes_Concat(o, collector)
+ collector << " CONCAT("
+ visit o.left, collector
+ collector << ", "
+ visit o.right, collector
+ collector << ") "
+ collector
+ end
end
end
end
diff --git a/activerecord/lib/arel/visitors/oracle.rb b/activerecord/lib/arel/visitors/oracle.rb
index d4749bbae3..7811c18a8c 100644
--- a/activerecord/lib/arel/visitors/oracle.rb
+++ b/activerecord/lib/arel/visitors/oracle.rb
@@ -1,153 +1,153 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class Oracle < Arel::Visitors::ToSql
private
- def visit_Arel_Nodes_SelectStatement o, collector
- o = order_hacks(o)
+ def visit_Arel_Nodes_SelectStatement(o, collector)
+ o = order_hacks(o)
- # if need to select first records without ORDER BY and GROUP BY and without DISTINCT
- # then can use simple ROWNUM in WHERE clause
- if o.limit && o.orders.empty? && o.cores.first.groups.empty? && !o.offset && o.cores.first.set_quantifier.class.to_s !~ /Distinct/
- o.cores.last.wheres.push Nodes::LessThanOrEqual.new(
- Nodes::SqlLiteral.new('ROWNUM'), o.limit.expr
- )
- return super
- end
+ # if need to select first records without ORDER BY and GROUP BY and without DISTINCT
+ # then can use simple ROWNUM in WHERE clause
+ if o.limit && o.orders.empty? && o.cores.first.groups.empty? && !o.offset && o.cores.first.set_quantifier.class.to_s !~ /Distinct/
+ o.cores.last.wheres.push Nodes::LessThanOrEqual.new(
+ Nodes::SqlLiteral.new("ROWNUM"), o.limit.expr
+ )
+ return super
+ end
+
+ if o.limit && o.offset
+ o = o.dup
+ limit = o.limit.expr
+ offset = o.offset
+ o.offset = nil
+ collector << "
+ SELECT * FROM (
+ SELECT raw_sql_.*, rownum raw_rnum_
+ FROM ("
+
+ collector = super(o, collector)
+
+ if offset.expr.is_a? Nodes::BindParam
+ collector << ") raw_sql_ WHERE rownum <= ("
+ collector = visit offset.expr, collector
+ collector << " + "
+ collector = visit limit, collector
+ collector << ") ) WHERE raw_rnum_ > "
+ collector = visit offset.expr, collector
+ return collector
+ else
+ collector << ") raw_sql_
+ WHERE rownum <= #{offset.expr.to_i + limit}
+ )
+ WHERE "
+ return visit(offset, collector)
+ end
+ end
- if o.limit && o.offset
- o = o.dup
- limit = o.limit.expr
- offset = o.offset
- o.offset = nil
- collector << "
- SELECT * FROM (
- SELECT raw_sql_.*, rownum raw_rnum_
- FROM ("
-
- collector = super(o, collector)
-
- if offset.expr.is_a? Nodes::BindParam
- collector << ') raw_sql_ WHERE rownum <= ('
- collector = visit offset.expr, collector
- collector << ' + '
- collector = visit limit, collector
- collector << ") ) WHERE raw_rnum_ > "
- collector = visit offset.expr, collector
- return collector
- else
+ if o.limit
+ o = o.dup
+ limit = o.limit.expr
+ collector << "SELECT * FROM ("
+ collector = super(o, collector)
+ collector << ") WHERE ROWNUM <= "
+ return visit limit, collector
+ end
+
+ if o.offset
+ o = o.dup
+ offset = o.offset
+ o.offset = nil
+ collector << "SELECT * FROM (
+ SELECT raw_sql_.*, rownum raw_rnum_
+ FROM ("
+ collector = super(o, collector)
collector << ") raw_sql_
- WHERE rownum <= #{offset.expr.to_i + limit}
- )
- WHERE "
- return visit(offset, collector)
+ )
+ WHERE "
+ return visit offset, collector
end
- end
- if o.limit
- o = o.dup
- limit = o.limit.expr
- collector << "SELECT * FROM ("
- collector = super(o, collector)
- collector << ") WHERE ROWNUM <= "
- return visit limit, collector
+ super
end
- if o.offset
- o = o.dup
- offset = o.offset
- o.offset = nil
- collector << "SELECT * FROM (
- SELECT raw_sql_.*, rownum raw_rnum_
- FROM ("
- collector = super(o, collector)
- collector << ") raw_sql_
- )
- WHERE "
- return visit offset, collector
+ def visit_Arel_Nodes_Limit(o, collector)
+ collector
end
- super
- end
-
- def visit_Arel_Nodes_Limit o, collector
- collector
- end
-
- def visit_Arel_Nodes_Offset o, collector
- collector << "raw_rnum_ > "
- visit o.expr, collector
- end
-
- def visit_Arel_Nodes_Except o, collector
- collector << "( "
- collector = infix_value o, collector, " MINUS "
- collector << " )"
- end
-
- def visit_Arel_Nodes_UpdateStatement o, collector
- # Oracle does not allow ORDER BY/LIMIT in UPDATEs.
- if o.orders.any? && o.limit.nil?
- # However, there is no harm in silently eating the ORDER BY clause if no LIMIT has been provided,
- # otherwise let the user deal with the error
- o = o.dup
- o.orders = []
+ def visit_Arel_Nodes_Offset(o, collector)
+ collector << "raw_rnum_ > "
+ visit o.expr, collector
end
- super
- end
+ def visit_Arel_Nodes_Except(o, collector)
+ collector << "( "
+ collector = infix_value o, collector, " MINUS "
+ collector << " )"
+ end
- ###
- # Hacks for the order clauses specific to Oracle
- def order_hacks o
- return o if o.orders.empty?
- return o unless o.cores.any? do |core|
- core.projections.any? do |projection|
- /FIRST_VALUE/ === projection
+ def visit_Arel_Nodes_UpdateStatement(o, collector)
+ # Oracle does not allow ORDER BY/LIMIT in UPDATEs.
+ if o.orders.any? && o.limit.nil?
+ # However, there is no harm in silently eating the ORDER BY clause if no LIMIT has been provided,
+ # otherwise let the user deal with the error
+ o = o.dup
+ o.orders = []
end
+
+ super
end
- # Previous version with join and split broke ORDER BY clause
- # if it contained functions with several arguments (separated by ',').
- #
- # orders = o.orders.map { |x| visit x }.join(', ').split(',')
- orders = o.orders.map do |x|
- string = visit(x, Arel::Collectors::SQLString.new).value
- if string.include?(',')
- split_order_string(string)
- else
- string
+
+ ###
+ # Hacks for the order clauses specific to Oracle
+ def order_hacks(o)
+ return o if o.orders.empty?
+ return o unless o.cores.any? do |core|
+ core.projections.any? do |projection|
+ /FIRST_VALUE/ === projection
+ end
end
- end.flatten
- o.orders = []
- orders.each_with_index do |order, i|
- o.orders <<
- Nodes::SqlLiteral.new("alias_#{i}__#{' DESC' if /\bdesc$/i === order}")
- end
- o
- end
-
- # Split string by commas but count opening and closing brackets
- # and ignore commas inside brackets.
- def split_order_string(string)
- array = []
- i = 0
- string.split(',').each do |part|
- if array[i]
- array[i] << ',' << part
- else
- # to ensure that array[i] will be String and not Arel::Nodes::SqlLiteral
- array[i] = part.to_s
+ # Previous version with join and split broke ORDER BY clause
+ # if it contained functions with several arguments (separated by ',').
+ #
+ # orders = o.orders.map { |x| visit x }.join(', ').split(',')
+ orders = o.orders.map do |x|
+ string = visit(x, Arel::Collectors::SQLString.new).value
+ if string.include?(",")
+ split_order_string(string)
+ else
+ string
+ end
+ end.flatten
+ o.orders = []
+ orders.each_with_index do |order, i|
+ o.orders <<
+ Nodes::SqlLiteral.new("alias_#{i}__#{' DESC' if /\bdesc$/i === order}")
end
- i += 1 if array[i].count('(') == array[i].count(')')
+ o
end
- array
- end
- def visit_Arel_Nodes_BindParam o, collector
- collector.add_bind(o.value) { |i| ":a#{i}" }
- end
+ # Split string by commas but count opening and closing brackets
+ # and ignore commas inside brackets.
+ def split_order_string(string)
+ array = []
+ i = 0
+ string.split(",").each do |part|
+ if array[i]
+ array[i] << "," << part
+ else
+ # to ensure that array[i] will be String and not Arel::Nodes::SqlLiteral
+ array[i] = part.to_s
+ end
+ i += 1 if array[i].count("(") == array[i].count(")")
+ end
+ array
+ end
+ def visit_Arel_Nodes_BindParam(o, collector)
+ collector.add_bind(o.value) { |i| ":a#{i}" }
+ end
end
end
end
diff --git a/activerecord/lib/arel/visitors/oracle12.rb b/activerecord/lib/arel/visitors/oracle12.rb
index 648047ae61..e312ba96bb 100644
--- a/activerecord/lib/arel/visitors/oracle12.rb
+++ b/activerecord/lib/arel/visitors/oracle12.rb
@@ -1,60 +1,61 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class Oracle12 < Arel::Visitors::ToSql
private
- def visit_Arel_Nodes_SelectStatement o, collector
- # Oracle does not allow LIMIT clause with select for update
- if o.limit && o.lock
- raise ArgumentError, <<-MSG
+ def visit_Arel_Nodes_SelectStatement(o, collector)
+ # Oracle does not allow LIMIT clause with select for update
+ if o.limit && o.lock
+ raise ArgumentError, <<-MSG
'Combination of limit and lock is not supported.
because generated SQL statements
`SELECT FOR UPDATE and FETCH FIRST n ROWS` generates ORA-02014.`
MSG
+ end
+ super
+ end
+
+ def visit_Arel_Nodes_SelectOptions(o, collector)
+ collector = maybe_visit o.offset, collector
+ collector = maybe_visit o.limit, collector
+ collector = maybe_visit o.lock, collector
end
- super
- end
-
- def visit_Arel_Nodes_SelectOptions o, collector
- collector = maybe_visit o.offset, collector
- collector = maybe_visit o.limit, collector
- collector = maybe_visit o.lock, collector
- end
-
- def visit_Arel_Nodes_Limit o, collector
- collector << "FETCH FIRST "
- collector = visit o.expr, collector
- collector << " ROWS ONLY"
- end
-
- def visit_Arel_Nodes_Offset o, collector
- collector << "OFFSET "
- visit o.expr, collector
- collector << " ROWS"
- end
-
- def visit_Arel_Nodes_Except o, collector
- collector << "( "
- collector = infix_value o, collector, " MINUS "
- collector << " )"
- end
-
- def visit_Arel_Nodes_UpdateStatement o, collector
- # Oracle does not allow ORDER BY/LIMIT in UPDATEs.
- if o.orders.any? && o.limit.nil?
- # However, there is no harm in silently eating the ORDER BY clause if no LIMIT has been provided,
- # otherwise let the user deal with the error
- o = o.dup
- o.orders = []
+
+ def visit_Arel_Nodes_Limit(o, collector)
+ collector << "FETCH FIRST "
+ collector = visit o.expr, collector
+ collector << " ROWS ONLY"
end
- super
- end
+ def visit_Arel_Nodes_Offset(o, collector)
+ collector << "OFFSET "
+ visit o.expr, collector
+ collector << " ROWS"
+ end
- def visit_Arel_Nodes_BindParam o, collector
- collector.add_bind(o.value) { |i| ":a#{i}" }
- end
+ def visit_Arel_Nodes_Except(o, collector)
+ collector << "( "
+ collector = infix_value o, collector, " MINUS "
+ collector << " )"
+ end
+
+ def visit_Arel_Nodes_UpdateStatement(o, collector)
+ # Oracle does not allow ORDER BY/LIMIT in UPDATEs.
+ if o.orders.any? && o.limit.nil?
+ # However, there is no harm in silently eating the ORDER BY clause if no LIMIT has been provided,
+ # otherwise let the user deal with the error
+ o = o.dup
+ o.orders = []
+ end
+
+ super
+ end
+
+ def visit_Arel_Nodes_BindParam(o, collector)
+ collector.add_bind(o.value) { |i| ":a#{i}" }
+ end
end
end
end
diff --git a/activerecord/lib/arel/visitors/postgresql.rb b/activerecord/lib/arel/visitors/postgresql.rb
index 047f71aaa6..e7ed888ed8 100644
--- a/activerecord/lib/arel/visitors/postgresql.rb
+++ b/activerecord/lib/arel/visitors/postgresql.rb
@@ -1,103 +1,104 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class PostgreSQL < Arel::Visitors::ToSql
- CUBE = 'CUBE'
- ROLLUP = 'ROLLUP'
- GROUPING_SET = 'GROUPING SET'
- LATERAL = 'LATERAL'
+ CUBE = "CUBE"
+ ROLLUP = "ROLLUP"
+ GROUPING_SET = "GROUPING SET"
+ LATERAL = "LATERAL"
private
- def visit_Arel_Nodes_Matches o, collector
- op = o.case_sensitive ? ' LIKE ' : ' ILIKE '
- collector = infix_value o, collector, op
- if o.escape
- collector << ' ESCAPE '
- visit o.escape, collector
- else
- collector
+ def visit_Arel_Nodes_Matches(o, collector)
+ op = o.case_sensitive ? " LIKE " : " ILIKE "
+ collector = infix_value o, collector, op
+ if o.escape
+ collector << " ESCAPE "
+ visit o.escape, collector
+ else
+ collector
+ end
end
- end
- def visit_Arel_Nodes_DoesNotMatch o, collector
- op = o.case_sensitive ? ' NOT LIKE ' : ' NOT ILIKE '
- collector = infix_value o, collector, op
- if o.escape
- collector << ' ESCAPE '
- visit o.escape, collector
- else
- collector
+ def visit_Arel_Nodes_DoesNotMatch(o, collector)
+ op = o.case_sensitive ? " NOT LIKE " : " NOT ILIKE "
+ collector = infix_value o, collector, op
+ if o.escape
+ collector << " ESCAPE "
+ visit o.escape, collector
+ else
+ collector
+ end
end
- end
- def visit_Arel_Nodes_Regexp o, collector
- op = o.case_sensitive ? ' ~ ' : ' ~* '
- infix_value o, collector, op
- end
+ def visit_Arel_Nodes_Regexp(o, collector)
+ op = o.case_sensitive ? " ~ " : " ~* "
+ infix_value o, collector, op
+ end
- def visit_Arel_Nodes_NotRegexp o, collector
- op = o.case_sensitive ? ' !~ ' : ' !~* '
- infix_value o, collector, op
- end
+ def visit_Arel_Nodes_NotRegexp(o, collector)
+ op = o.case_sensitive ? " !~ " : " !~* "
+ infix_value o, collector, op
+ end
- def visit_Arel_Nodes_DistinctOn o, collector
- collector << "DISTINCT ON ( "
- visit(o.expr, collector) << " )"
- end
+ def visit_Arel_Nodes_DistinctOn(o, collector)
+ collector << "DISTINCT ON ( "
+ visit(o.expr, collector) << " )"
+ end
- def visit_Arel_Nodes_BindParam o, collector
- collector.add_bind(o.value) { |i| "$#{i}" }
- end
+ def visit_Arel_Nodes_BindParam(o, collector)
+ collector.add_bind(o.value) { |i| "$#{i}" }
+ end
- def visit_Arel_Nodes_GroupingElement o, collector
- collector << "( "
- visit(o.expr, collector) << " )"
- end
+ def visit_Arel_Nodes_GroupingElement(o, collector)
+ collector << "( "
+ visit(o.expr, collector) << " )"
+ end
- def visit_Arel_Nodes_Cube o, collector
- collector << CUBE
- grouping_array_or_grouping_element o, collector
- end
+ def visit_Arel_Nodes_Cube(o, collector)
+ collector << CUBE
+ grouping_array_or_grouping_element o, collector
+ end
- def visit_Arel_Nodes_RollUp o, collector
- collector << ROLLUP
- grouping_array_or_grouping_element o, collector
- end
+ def visit_Arel_Nodes_RollUp(o, collector)
+ collector << ROLLUP
+ grouping_array_or_grouping_element o, collector
+ end
- def visit_Arel_Nodes_GroupingSet o, collector
- collector << GROUPING_SET
- grouping_array_or_grouping_element o, collector
- end
+ def visit_Arel_Nodes_GroupingSet(o, collector)
+ collector << GROUPING_SET
+ grouping_array_or_grouping_element o, collector
+ end
- def visit_Arel_Nodes_Lateral o, collector
- collector << LATERAL
- collector << SPACE
- grouping_parentheses o, collector
- end
+ def visit_Arel_Nodes_Lateral(o, collector)
+ collector << LATERAL
+ collector << SPACE
+ grouping_parentheses o, collector
+ end
- # Used by Lateral visitor to enclose select queries in parentheses
- def grouping_parentheses o, collector
- if o.expr.is_a? Nodes::SelectStatement
- collector << "("
- visit o.expr, collector
- collector << ")"
- else
- visit o.expr, collector
+ # Used by Lateral visitor to enclose select queries in parentheses
+ def grouping_parentheses(o, collector)
+ if o.expr.is_a? Nodes::SelectStatement
+ collector << "("
+ visit o.expr, collector
+ collector << ")"
+ else
+ visit o.expr, collector
+ end
end
- end
- # Utilized by GroupingSet, Cube & RollUp visitors to
- # handle grouping aggregation semantics
- def grouping_array_or_grouping_element o, collector
- if o.expr.is_a? Array
- collector << "( "
- visit o.expr, collector
- collector << " )"
- else
- visit o.expr, collector
+ # Utilized by GroupingSet, Cube & RollUp visitors to
+ # handle grouping aggregation semantics
+ def grouping_array_or_grouping_element(o, collector)
+ if o.expr.is_a? Array
+ collector << "( "
+ visit o.expr, collector
+ collector << " )"
+ else
+ visit o.expr, collector
+ end
end
- end
end
end
end
diff --git a/activerecord/lib/arel/visitors/sqlite.rb b/activerecord/lib/arel/visitors/sqlite.rb
index 4ae093968b..8d4152c428 100644
--- a/activerecord/lib/arel/visitors/sqlite.rb
+++ b/activerecord/lib/arel/visitors/sqlite.rb
@@ -1,27 +1,27 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class SQLite < Arel::Visitors::ToSql
private
- # Locks are not supported in SQLite
- def visit_Arel_Nodes_Lock o, collector
- collector
- end
-
- def visit_Arel_Nodes_SelectStatement o, collector
- o.limit = Arel::Nodes::Limit.new(-1) if o.offset && !o.limit
- super
- end
+ # Locks are not supported in SQLite
+ def visit_Arel_Nodes_Lock(o, collector)
+ collector
+ end
- def visit_Arel_Nodes_True o, collector
- collector << "1"
- end
+ def visit_Arel_Nodes_SelectStatement(o, collector)
+ o.limit = Arel::Nodes::Limit.new(-1) if o.offset && !o.limit
+ super
+ end
- def visit_Arel_Nodes_False o, collector
- collector << "0"
- end
+ def visit_Arel_Nodes_True(o, collector)
+ collector << "1"
+ end
+ def visit_Arel_Nodes_False(o, collector)
+ collector << "0"
+ end
end
end
end
diff --git a/activerecord/lib/arel/visitors/to_sql.rb b/activerecord/lib/arel/visitors/to_sql.rb
index 2b5c43b173..24db04200a 100644
--- a/activerecord/lib/arel/visitors/to_sql.rb
+++ b/activerecord/lib/arel/visitors/to_sql.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class UnsupportedVisitError < StandardError
@@ -51,796 +52,796 @@ module Arel
# specialized for specific databases when necessary.
#
- WHERE = ' WHERE ' # :nodoc:
- SPACE = ' ' # :nodoc:
- COMMA = ', ' # :nodoc:
- GROUP_BY = ' GROUP BY ' # :nodoc:
- ORDER_BY = ' ORDER BY ' # :nodoc:
- WINDOW = ' WINDOW ' # :nodoc:
- AND = ' AND ' # :nodoc:
+ WHERE = " WHERE " # :nodoc:
+ SPACE = " " # :nodoc:
+ COMMA = ", " # :nodoc:
+ GROUP_BY = " GROUP BY " # :nodoc:
+ ORDER_BY = " ORDER BY " # :nodoc:
+ WINDOW = " WINDOW " # :nodoc:
+ AND = " AND " # :nodoc:
- DISTINCT = 'DISTINCT' # :nodoc:
+ DISTINCT = "DISTINCT" # :nodoc:
- def initialize connection
+ def initialize(connection)
super()
- @connection = connection
+ @connection = connection
end
- def compile node, &block
+ def compile(node, &block)
accept(node, Arel::Collectors::SQLString.new, &block).value
end
private
- def visit_Arel_Nodes_DeleteStatement o, collector
- collector << 'DELETE FROM '
- collector = visit o.relation, collector
- if o.wheres.any?
- collector << WHERE
- collector = inject_join o.wheres, collector, AND
+ def visit_Arel_Nodes_DeleteStatement(o, collector)
+ collector << "DELETE FROM "
+ collector = visit o.relation, collector
+ if o.wheres.any?
+ collector << WHERE
+ collector = inject_join o.wheres, collector, AND
+ end
+
+ maybe_visit o.limit, collector
end
- maybe_visit o.limit, collector
- end
+ # FIXME: we should probably have a 2-pass visitor for this
+ def build_subselect(key, o)
+ stmt = Nodes::SelectStatement.new
+ core = stmt.cores.first
+ core.froms = o.relation
+ core.wheres = o.wheres
+ core.projections = [key]
+ stmt.limit = o.limit
+ stmt.orders = o.orders
+ stmt
+ end
- # FIXME: we should probably have a 2-pass visitor for this
- def build_subselect key, o
- stmt = Nodes::SelectStatement.new
- core = stmt.cores.first
- core.froms = o.relation
- core.wheres = o.wheres
- core.projections = [key]
- stmt.limit = o.limit
- stmt.orders = o.orders
- stmt
- end
+ def visit_Arel_Nodes_UpdateStatement(o, collector)
+ if o.orders.empty? && o.limit.nil?
+ wheres = o.wheres
+ else
+ wheres = [Nodes::In.new(o.key, [build_subselect(o.key, o)])]
+ end
- def visit_Arel_Nodes_UpdateStatement o, collector
- if o.orders.empty? && o.limit.nil?
- wheres = o.wheres
- else
- wheres = [Nodes::In.new(o.key, [build_subselect(o.key, o)])]
- end
+ collector << "UPDATE "
+ collector = visit o.relation, collector
+ unless o.values.empty?
+ collector << " SET "
+ collector = inject_join o.values, collector, ", "
+ end
- collector << "UPDATE "
- collector = visit o.relation, collector
- unless o.values.empty?
- collector << " SET "
- collector = inject_join o.values, collector, ", "
- end
+ unless wheres.empty?
+ collector << " WHERE "
+ collector = inject_join wheres, collector, " AND "
+ end
- unless wheres.empty?
- collector << " WHERE "
- collector = inject_join wheres, collector, " AND "
+ collector
end
- collector
- end
+ def visit_Arel_Nodes_InsertStatement(o, collector)
+ collector << "INSERT INTO "
+ collector = visit o.relation, collector
+ if o.columns.any?
+ collector << " (#{o.columns.map { |x|
+ quote_column_name x.name
+ }.join ', '})"
+ end
- def visit_Arel_Nodes_InsertStatement o, collector
- collector << "INSERT INTO "
- collector = visit o.relation, collector
- if o.columns.any?
- collector << " (#{o.columns.map { |x|
- quote_column_name x.name
- }.join ', '})"
+ if o.values
+ maybe_visit o.values, collector
+ elsif o.select
+ maybe_visit o.select, collector
+ else
+ collector
+ end
end
- if o.values
- maybe_visit o.values, collector
- elsif o.select
- maybe_visit o.select, collector
- else
- collector
+ def visit_Arel_Nodes_Exists(o, collector)
+ collector << "EXISTS ("
+ collector = visit(o.expressions, collector) << ")"
+ if o.alias
+ collector << " AS "
+ visit o.alias, collector
+ else
+ collector
+ end
end
- end
- def visit_Arel_Nodes_Exists o, collector
- collector << "EXISTS ("
- collector = visit(o.expressions, collector) << ")"
- if o.alias
- collector << " AS "
- visit o.alias, collector
- else
- collector
+ def visit_Arel_Nodes_Casted(o, collector)
+ collector << quoted(o.val, o.attribute).to_s
end
- end
- def visit_Arel_Nodes_Casted o, collector
- collector << quoted(o.val, o.attribute).to_s
- end
+ def visit_Arel_Nodes_Quoted(o, collector)
+ collector << quoted(o.expr, nil).to_s
+ end
- def visit_Arel_Nodes_Quoted o, collector
- collector << quoted(o.expr, nil).to_s
- end
+ def visit_Arel_Nodes_True(o, collector)
+ collector << "TRUE"
+ end
- def visit_Arel_Nodes_True o, collector
- collector << "TRUE"
- end
+ def visit_Arel_Nodes_False(o, collector)
+ collector << "FALSE"
+ end
- def visit_Arel_Nodes_False o, collector
- collector << "FALSE"
- end
+ def visit_Arel_Nodes_ValuesList(o, collector)
+ collector << "VALUES "
- def visit_Arel_Nodes_ValuesList o, collector
- collector << "VALUES "
+ len = o.rows.length - 1
+ o.rows.each_with_index { |row, i|
+ collector << "("
+ row_len = row.length - 1
+ row.each_with_index do |value, k|
+ case value
+ when Nodes::SqlLiteral, Nodes::BindParam
+ collector = visit(value, collector)
+ else
+ collector << quote(value)
+ end
+ collector << COMMA unless k == row_len
+ end
+ collector << ")"
+ collector << COMMA unless i == len
+ }
+ collector
+ end
+
+ def visit_Arel_Nodes_Values(o, collector)
+ collector << "VALUES ("
- len = o.rows.length - 1
- o.rows.each_with_index { |row, i|
- collector << '('
- row_len = row.length - 1
- row.each_with_index do |value, k|
+ len = o.expressions.length - 1
+ o.expressions.each_with_index { |value, i|
case value
when Nodes::SqlLiteral, Nodes::BindParam
- collector = visit(value, collector)
+ collector = visit value, collector
else
- collector << quote(value)
+ collector << quote(value).to_s
end
- collector << COMMA unless k == row_len
- end
- collector << ')'
- collector << COMMA unless i == len
- }
- collector
- end
+ unless i == len
+ collector << COMMA
+ end
+ }
- def visit_Arel_Nodes_Values o, collector
- collector << "VALUES ("
+ collector << ")"
+ end
- len = o.expressions.length - 1
- o.expressions.each_with_index { |value, i|
- case value
- when Nodes::SqlLiteral, Nodes::BindParam
- collector = visit value, collector
- else
- collector << quote(value).to_s
+ def visit_Arel_Nodes_SelectStatement(o, collector)
+ if o.with
+ collector = visit o.with, collector
+ collector << SPACE
end
- unless i == len
- collector << COMMA
+
+ collector = o.cores.inject(collector) { |c, x|
+ visit_Arel_Nodes_SelectCore(x, c)
+ }
+
+ unless o.orders.empty?
+ collector << ORDER_BY
+ len = o.orders.length - 1
+ o.orders.each_with_index { |x, i|
+ collector = visit(x, collector)
+ collector << COMMA unless len == i
+ }
end
- }
- collector << ")"
- end
+ visit_Arel_Nodes_SelectOptions(o, collector)
- def visit_Arel_Nodes_SelectStatement o, collector
- if o.with
- collector = visit o.with, collector
- collector << SPACE
+ collector
end
- collector = o.cores.inject(collector) { |c,x|
- visit_Arel_Nodes_SelectCore(x, c)
- }
-
- unless o.orders.empty?
- collector << ORDER_BY
- len = o.orders.length - 1
- o.orders.each_with_index { |x, i|
- collector = visit(x, collector)
- collector << COMMA unless len == i
- }
+ def visit_Arel_Nodes_SelectOptions(o, collector)
+ collector = maybe_visit o.limit, collector
+ collector = maybe_visit o.offset, collector
+ collector = maybe_visit o.lock, collector
end
- visit_Arel_Nodes_SelectOptions(o, collector)
+ def visit_Arel_Nodes_SelectCore(o, collector)
+ collector << "SELECT"
- collector
- end
+ collector = maybe_visit o.top, collector
- def visit_Arel_Nodes_SelectOptions o, collector
- collector = maybe_visit o.limit, collector
- collector = maybe_visit o.offset, collector
- collector = maybe_visit o.lock, collector
- end
+ collector = maybe_visit o.set_quantifier, collector
- def visit_Arel_Nodes_SelectCore o, collector
- collector << "SELECT"
+ collect_nodes_for o.projections, collector, SPACE
- collector = maybe_visit o.top, collector
+ if o.source && !o.source.empty?
+ collector << " FROM "
+ collector = visit o.source, collector
+ end
- collector = maybe_visit o.set_quantifier, collector
+ collect_nodes_for o.wheres, collector, WHERE, AND
+ collect_nodes_for o.groups, collector, GROUP_BY
+ unless o.havings.empty?
+ collector << " HAVING "
+ inject_join o.havings, collector, AND
+ end
+ collect_nodes_for o.windows, collector, WINDOW
- collect_nodes_for o.projections, collector, SPACE
+ collector
+ end
- if o.source && !o.source.empty?
- collector << " FROM "
- collector = visit o.source, collector
+ def collect_nodes_for(nodes, collector, spacer, connector = COMMA)
+ unless nodes.empty?
+ collector << spacer
+ len = nodes.length - 1
+ nodes.each_with_index do |x, i|
+ collector = visit(x, collector)
+ collector << connector unless len == i
+ end
+ end
end
- collect_nodes_for o.wheres, collector, WHERE, AND
- collect_nodes_for o.groups, collector, GROUP_BY
- unless o.havings.empty?
- collector << " HAVING "
- inject_join o.havings, collector, AND
+ def visit_Arel_Nodes_Bin(o, collector)
+ visit o.expr, collector
end
- collect_nodes_for o.windows, collector, WINDOW
- collector
- end
+ def visit_Arel_Nodes_Distinct(o, collector)
+ collector << DISTINCT
+ end
- def collect_nodes_for nodes, collector, spacer, connector = COMMA
- unless nodes.empty?
- collector << spacer
- len = nodes.length - 1
- nodes.each_with_index do |x, i|
- collector = visit(x, collector)
- collector << connector unless len == i
- end
+ def visit_Arel_Nodes_DistinctOn(o, collector)
+ raise NotImplementedError, "DISTINCT ON not implemented for this db"
end
- end
- def visit_Arel_Nodes_Bin o, collector
- visit o.expr, collector
- end
+ def visit_Arel_Nodes_With(o, collector)
+ collector << "WITH "
+ inject_join o.children, collector, COMMA
+ end
- def visit_Arel_Nodes_Distinct o, collector
- collector << DISTINCT
- end
+ def visit_Arel_Nodes_WithRecursive(o, collector)
+ collector << "WITH RECURSIVE "
+ inject_join o.children, collector, COMMA
+ end
- def visit_Arel_Nodes_DistinctOn o, collector
- raise NotImplementedError, 'DISTINCT ON not implemented for this db'
- end
+ def visit_Arel_Nodes_Union(o, collector)
+ collector << "( "
+ infix_value(o, collector, " UNION ") << " )"
+ end
- def visit_Arel_Nodes_With o, collector
- collector << "WITH "
- inject_join o.children, collector, COMMA
- end
+ def visit_Arel_Nodes_UnionAll(o, collector)
+ collector << "( "
+ infix_value(o, collector, " UNION ALL ") << " )"
+ end
- def visit_Arel_Nodes_WithRecursive o, collector
- collector << "WITH RECURSIVE "
- inject_join o.children, collector, COMMA
- end
+ def visit_Arel_Nodes_Intersect(o, collector)
+ collector << "( "
+ infix_value(o, collector, " INTERSECT ") << " )"
+ end
- def visit_Arel_Nodes_Union o, collector
- collector << "( "
- infix_value(o, collector, " UNION ") << " )"
- end
+ def visit_Arel_Nodes_Except(o, collector)
+ collector << "( "
+ infix_value(o, collector, " EXCEPT ") << " )"
+ end
- def visit_Arel_Nodes_UnionAll o, collector
- collector << "( "
- infix_value(o, collector, " UNION ALL ") << " )"
- end
+ def visit_Arel_Nodes_NamedWindow(o, collector)
+ collector << quote_column_name(o.name)
+ collector << " AS "
+ visit_Arel_Nodes_Window o, collector
+ end
- def visit_Arel_Nodes_Intersect o, collector
- collector << "( "
- infix_value(o, collector, " INTERSECT ") << " )"
- end
+ def visit_Arel_Nodes_Window(o, collector)
+ collector << "("
- def visit_Arel_Nodes_Except o, collector
- collector << "( "
- infix_value(o, collector, " EXCEPT ") << " )"
- end
+ if o.partitions.any?
+ collector << "PARTITION BY "
+ collector = inject_join o.partitions, collector, ", "
+ end
- def visit_Arel_Nodes_NamedWindow o, collector
- collector << quote_column_name(o.name)
- collector << " AS "
- visit_Arel_Nodes_Window o, collector
- end
+ if o.orders.any?
+ collector << SPACE if o.partitions.any?
+ collector << "ORDER BY "
+ collector = inject_join o.orders, collector, ", "
+ end
- def visit_Arel_Nodes_Window o, collector
- collector << "("
+ if o.framing
+ collector << SPACE if o.partitions.any? || o.orders.any?
+ collector = visit o.framing, collector
+ end
- if o.partitions.any?
- collector << "PARTITION BY "
- collector = inject_join o.partitions, collector, ", "
+ collector << ")"
end
- if o.orders.any?
- collector << SPACE if o.partitions.any?
- collector << "ORDER BY "
- collector = inject_join o.orders, collector, ", "
+ def visit_Arel_Nodes_Rows(o, collector)
+ if o.expr
+ collector << "ROWS "
+ visit o.expr, collector
+ else
+ collector << "ROWS"
+ end
end
- if o.framing
- collector << SPACE if o.partitions.any? or o.orders.any?
- collector = visit o.framing, collector
+ def visit_Arel_Nodes_Range(o, collector)
+ if o.expr
+ collector << "RANGE "
+ visit o.expr, collector
+ else
+ collector << "RANGE"
+ end
end
- collector << ")"
- end
-
- def visit_Arel_Nodes_Rows o, collector
- if o.expr
- collector << "ROWS "
- visit o.expr, collector
- else
- collector << "ROWS"
- end
- end
+ def visit_Arel_Nodes_Preceding(o, collector)
+ collector = if o.expr
+ visit o.expr, collector
+ else
+ collector << "UNBOUNDED"
+ end
- def visit_Arel_Nodes_Range o, collector
- if o.expr
- collector << "RANGE "
- visit o.expr, collector
- else
- collector << "RANGE"
+ collector << " PRECEDING"
end
- end
- def visit_Arel_Nodes_Preceding o, collector
- collector = if o.expr
- visit o.expr, collector
- else
- collector << "UNBOUNDED"
- end
-
- collector << " PRECEDING"
- end
+ def visit_Arel_Nodes_Following(o, collector)
+ collector = if o.expr
+ visit o.expr, collector
+ else
+ collector << "UNBOUNDED"
+ end
- def visit_Arel_Nodes_Following o, collector
- collector = if o.expr
- visit o.expr, collector
- else
- collector << "UNBOUNDED"
- end
+ collector << " FOLLOWING"
+ end
- collector << " FOLLOWING"
- end
+ def visit_Arel_Nodes_CurrentRow(o, collector)
+ collector << "CURRENT ROW"
+ end
- def visit_Arel_Nodes_CurrentRow o, collector
- collector << "CURRENT ROW"
- end
+ def visit_Arel_Nodes_Over(o, collector)
+ case o.right
+ when nil
+ visit(o.left, collector) << " OVER ()"
+ when Arel::Nodes::SqlLiteral
+ infix_value o, collector, " OVER "
+ when String, Symbol
+ visit(o.left, collector) << " OVER #{quote_column_name o.right.to_s}"
+ else
+ infix_value o, collector, " OVER "
+ end
+ end
- def visit_Arel_Nodes_Over o, collector
- case o.right
- when nil
- visit(o.left, collector) << " OVER ()"
- when Arel::Nodes::SqlLiteral
- infix_value o, collector, " OVER "
- when String, Symbol
- visit(o.left, collector) << " OVER #{quote_column_name o.right.to_s}"
- else
- infix_value o, collector, " OVER "
+ def visit_Arel_Nodes_Offset(o, collector)
+ collector << "OFFSET "
+ visit o.expr, collector
end
- end
- def visit_Arel_Nodes_Offset o, collector
- collector << "OFFSET "
- visit o.expr, collector
- end
+ def visit_Arel_Nodes_Limit(o, collector)
+ collector << "LIMIT "
+ visit o.expr, collector
+ end
- def visit_Arel_Nodes_Limit o, collector
- collector << "LIMIT "
- visit o.expr, collector
- end
+ # FIXME: this does nothing on most databases, but does on MSSQL
+ def visit_Arel_Nodes_Top(o, collector)
+ collector
+ end
- # FIXME: this does nothing on most databases, but does on MSSQL
- def visit_Arel_Nodes_Top o, collector
- collector
- end
+ def visit_Arel_Nodes_Lock(o, collector)
+ visit o.expr, collector
+ end
- def visit_Arel_Nodes_Lock o, collector
- visit o.expr, collector
- end
+ def visit_Arel_Nodes_Grouping(o, collector)
+ if o.expr.is_a? Nodes::Grouping
+ visit(o.expr, collector)
+ else
+ collector << "("
+ visit(o.expr, collector) << ")"
+ end
+ end
- def visit_Arel_Nodes_Grouping o, collector
- if o.expr.is_a? Nodes::Grouping
- visit(o.expr, collector)
- else
+ def visit_Arel_SelectManager(o, collector)
collector << "("
- visit(o.expr, collector) << ")"
+ visit(o.ast, collector) << ")"
end
- end
-
- def visit_Arel_SelectManager o, collector
- collector << '('
- visit(o.ast, collector) << ')'
- end
-
- def visit_Arel_Nodes_Ascending o, collector
- visit(o.expr, collector) << " ASC"
- end
- def visit_Arel_Nodes_Descending o, collector
- visit(o.expr, collector) << " DESC"
- end
-
- def visit_Arel_Nodes_Group o, collector
- visit o.expr, collector
- end
+ def visit_Arel_Nodes_Ascending(o, collector)
+ visit(o.expr, collector) << " ASC"
+ end
- def visit_Arel_Nodes_NamedFunction o, collector
- collector << o.name
- collector << "("
- collector << "DISTINCT " if o.distinct
- collector = inject_join(o.expressions, collector, ", ") << ")"
- if o.alias
- collector << " AS "
- visit o.alias, collector
- else
- collector
+ def visit_Arel_Nodes_Descending(o, collector)
+ visit(o.expr, collector) << " DESC"
end
- end
- def visit_Arel_Nodes_Extract o, collector
- collector << "EXTRACT(#{o.field.to_s.upcase} FROM "
- visit(o.expr, collector) << ")"
- end
+ def visit_Arel_Nodes_Group(o, collector)
+ visit o.expr, collector
+ end
- def visit_Arel_Nodes_Count o, collector
- aggregate "COUNT", o, collector
- end
+ def visit_Arel_Nodes_NamedFunction(o, collector)
+ collector << o.name
+ collector << "("
+ collector << "DISTINCT " if o.distinct
+ collector = inject_join(o.expressions, collector, ", ") << ")"
+ if o.alias
+ collector << " AS "
+ visit o.alias, collector
+ else
+ collector
+ end
+ end
- def visit_Arel_Nodes_Sum o, collector
- aggregate "SUM", o, collector
- end
+ def visit_Arel_Nodes_Extract(o, collector)
+ collector << "EXTRACT(#{o.field.to_s.upcase} FROM "
+ visit(o.expr, collector) << ")"
+ end
- def visit_Arel_Nodes_Max o, collector
- aggregate "MAX", o, collector
- end
+ def visit_Arel_Nodes_Count(o, collector)
+ aggregate "COUNT", o, collector
+ end
- def visit_Arel_Nodes_Min o, collector
- aggregate "MIN", o, collector
- end
+ def visit_Arel_Nodes_Sum(o, collector)
+ aggregate "SUM", o, collector
+ end
- def visit_Arel_Nodes_Avg o, collector
- aggregate "AVG", o, collector
- end
+ def visit_Arel_Nodes_Max(o, collector)
+ aggregate "MAX", o, collector
+ end
- def visit_Arel_Nodes_TableAlias o, collector
- collector = visit o.relation, collector
- collector << " "
- collector << quote_table_name(o.name)
- end
+ def visit_Arel_Nodes_Min(o, collector)
+ aggregate "MIN", o, collector
+ end
- def visit_Arel_Nodes_Between o, collector
- collector = visit o.left, collector
- collector << " BETWEEN "
- visit o.right, collector
- end
+ def visit_Arel_Nodes_Avg(o, collector)
+ aggregate "AVG", o, collector
+ end
- def visit_Arel_Nodes_GreaterThanOrEqual o, collector
- collector = visit o.left, collector
- collector << " >= "
- visit o.right, collector
- end
+ def visit_Arel_Nodes_TableAlias(o, collector)
+ collector = visit o.relation, collector
+ collector << " "
+ collector << quote_table_name(o.name)
+ end
- def visit_Arel_Nodes_GreaterThan o, collector
- collector = visit o.left, collector
- collector << " > "
- visit o.right, collector
- end
+ def visit_Arel_Nodes_Between(o, collector)
+ collector = visit o.left, collector
+ collector << " BETWEEN "
+ visit o.right, collector
+ end
- def visit_Arel_Nodes_LessThanOrEqual o, collector
- collector = visit o.left, collector
- collector << " <= "
- visit o.right, collector
- end
+ def visit_Arel_Nodes_GreaterThanOrEqual(o, collector)
+ collector = visit o.left, collector
+ collector << " >= "
+ visit o.right, collector
+ end
- def visit_Arel_Nodes_LessThan o, collector
- collector = visit o.left, collector
- collector << " < "
- visit o.right, collector
- end
+ def visit_Arel_Nodes_GreaterThan(o, collector)
+ collector = visit o.left, collector
+ collector << " > "
+ visit o.right, collector
+ end
- def visit_Arel_Nodes_Matches o, collector
- collector = visit o.left, collector
- collector << " LIKE "
- collector = visit o.right, collector
- if o.escape
- collector << ' ESCAPE '
- visit o.escape, collector
- else
- collector
+ def visit_Arel_Nodes_LessThanOrEqual(o, collector)
+ collector = visit o.left, collector
+ collector << " <= "
+ visit o.right, collector
end
- end
- def visit_Arel_Nodes_DoesNotMatch o, collector
- collector = visit o.left, collector
- collector << " NOT LIKE "
- collector = visit o.right, collector
- if o.escape
- collector << ' ESCAPE '
- visit o.escape, collector
- else
- collector
+ def visit_Arel_Nodes_LessThan(o, collector)
+ collector = visit o.left, collector
+ collector << " < "
+ visit o.right, collector
end
- end
- def visit_Arel_Nodes_JoinSource o, collector
- if o.left
+ def visit_Arel_Nodes_Matches(o, collector)
collector = visit o.left, collector
+ collector << " LIKE "
+ collector = visit o.right, collector
+ if o.escape
+ collector << " ESCAPE "
+ visit o.escape, collector
+ else
+ collector
+ end
end
- if o.right.any?
- collector << SPACE if o.left
- collector = inject_join o.right, collector, SPACE
+
+ def visit_Arel_Nodes_DoesNotMatch(o, collector)
+ collector = visit o.left, collector
+ collector << " NOT LIKE "
+ collector = visit o.right, collector
+ if o.escape
+ collector << " ESCAPE "
+ visit o.escape, collector
+ else
+ collector
+ end
end
- collector
- end
- def visit_Arel_Nodes_Regexp o, collector
- raise NotImplementedError, '~ not implemented for this db'
- end
+ def visit_Arel_Nodes_JoinSource(o, collector)
+ if o.left
+ collector = visit o.left, collector
+ end
+ if o.right.any?
+ collector << SPACE if o.left
+ collector = inject_join o.right, collector, SPACE
+ end
+ collector
+ end
- def visit_Arel_Nodes_NotRegexp o, collector
- raise NotImplementedError, '!~ not implemented for this db'
- end
+ def visit_Arel_Nodes_Regexp(o, collector)
+ raise NotImplementedError, "~ not implemented for this db"
+ end
- def visit_Arel_Nodes_StringJoin o, collector
- visit o.left, collector
- end
+ def visit_Arel_Nodes_NotRegexp(o, collector)
+ raise NotImplementedError, "!~ not implemented for this db"
+ end
- def visit_Arel_Nodes_FullOuterJoin o, collector
- collector << "FULL OUTER JOIN "
- collector = visit o.left, collector
- collector << SPACE
- visit o.right, collector
- end
+ def visit_Arel_Nodes_StringJoin(o, collector)
+ visit o.left, collector
+ end
- def visit_Arel_Nodes_OuterJoin o, collector
- collector << "LEFT OUTER JOIN "
- collector = visit o.left, collector
- collector << " "
- visit o.right, collector
- end
+ def visit_Arel_Nodes_FullOuterJoin(o, collector)
+ collector << "FULL OUTER JOIN "
+ collector = visit o.left, collector
+ collector << SPACE
+ visit o.right, collector
+ end
- def visit_Arel_Nodes_RightOuterJoin o, collector
- collector << "RIGHT OUTER JOIN "
- collector = visit o.left, collector
- collector << SPACE
- visit o.right, collector
- end
+ def visit_Arel_Nodes_OuterJoin(o, collector)
+ collector << "LEFT OUTER JOIN "
+ collector = visit o.left, collector
+ collector << " "
+ visit o.right, collector
+ end
- def visit_Arel_Nodes_InnerJoin o, collector
- collector << "INNER JOIN "
- collector = visit o.left, collector
- if o.right
+ def visit_Arel_Nodes_RightOuterJoin(o, collector)
+ collector << "RIGHT OUTER JOIN "
+ collector = visit o.left, collector
collector << SPACE
- visit(o.right, collector)
- else
- collector
+ visit o.right, collector
end
- end
- def visit_Arel_Nodes_On o, collector
- collector << "ON "
- visit o.expr, collector
- end
+ def visit_Arel_Nodes_InnerJoin(o, collector)
+ collector << "INNER JOIN "
+ collector = visit o.left, collector
+ if o.right
+ collector << SPACE
+ visit(o.right, collector)
+ else
+ collector
+ end
+ end
- def visit_Arel_Nodes_Not o, collector
- collector << "NOT ("
- visit(o.expr, collector) << ")"
- end
+ def visit_Arel_Nodes_On(o, collector)
+ collector << "ON "
+ visit o.expr, collector
+ end
- def visit_Arel_Table o, collector
- if o.table_alias
- collector << "#{quote_table_name o.name} #{quote_table_name o.table_alias}"
- else
- collector << quote_table_name(o.name)
+ def visit_Arel_Nodes_Not(o, collector)
+ collector << "NOT ("
+ visit(o.expr, collector) << ")"
end
- end
- def visit_Arel_Nodes_In o, collector
- if Array === o.right && o.right.empty?
- collector << '1=0'
- else
- collector = visit o.left, collector
- collector << " IN ("
- visit(o.right, collector) << ")"
+ def visit_Arel_Table(o, collector)
+ if o.table_alias
+ collector << "#{quote_table_name o.name} #{quote_table_name o.table_alias}"
+ else
+ collector << quote_table_name(o.name)
+ end
end
- end
- def visit_Arel_Nodes_NotIn o, collector
- if Array === o.right && o.right.empty?
- collector << '1=1'
- else
- collector = visit o.left, collector
- collector << " NOT IN ("
- collector = visit o.right, collector
- collector << ")"
+ def visit_Arel_Nodes_In(o, collector)
+ if Array === o.right && o.right.empty?
+ collector << "1=0"
+ else
+ collector = visit o.left, collector
+ collector << " IN ("
+ visit(o.right, collector) << ")"
+ end
end
- end
- def visit_Arel_Nodes_And o, collector
- inject_join o.children, collector, " AND "
- end
+ def visit_Arel_Nodes_NotIn(o, collector)
+ if Array === o.right && o.right.empty?
+ collector << "1=1"
+ else
+ collector = visit o.left, collector
+ collector << " NOT IN ("
+ collector = visit o.right, collector
+ collector << ")"
+ end
+ end
- def visit_Arel_Nodes_Or o, collector
- collector = visit o.left, collector
- collector << " OR "
- visit o.right, collector
- end
+ def visit_Arel_Nodes_And(o, collector)
+ inject_join o.children, collector, " AND "
+ end
- def visit_Arel_Nodes_Assignment o, collector
- case o.right
- when Arel::Nodes::UnqualifiedColumn, Arel::Attributes::Attribute, Arel::Nodes::BindParam
+ def visit_Arel_Nodes_Or(o, collector)
collector = visit o.left, collector
- collector << " = "
+ collector << " OR "
visit o.right, collector
- else
- collector = visit o.left, collector
- collector << " = "
- collector << quote(o.right).to_s
end
- end
- def visit_Arel_Nodes_Equality o, collector
- right = o.right
+ def visit_Arel_Nodes_Assignment(o, collector)
+ case o.right
+ when Arel::Nodes::UnqualifiedColumn, Arel::Attributes::Attribute, Arel::Nodes::BindParam
+ collector = visit o.left, collector
+ collector << " = "
+ visit o.right, collector
+ else
+ collector = visit o.left, collector
+ collector << " = "
+ collector << quote(o.right).to_s
+ end
+ end
+
+ def visit_Arel_Nodes_Equality(o, collector)
+ right = o.right
- collector = visit o.left, collector
+ collector = visit o.left, collector
- if right.nil?
- collector << " IS NULL"
- else
- collector << " = "
- visit right, collector
+ if right.nil?
+ collector << " IS NULL"
+ else
+ collector << " = "
+ visit right, collector
+ end
end
- end
- def visit_Arel_Nodes_NotEqual o, collector
- right = o.right
+ def visit_Arel_Nodes_NotEqual(o, collector)
+ right = o.right
- collector = visit o.left, collector
+ collector = visit o.left, collector
- if right.nil?
- collector << " IS NOT NULL"
- else
- collector << " != "
- visit right, collector
+ if right.nil?
+ collector << " IS NOT NULL"
+ else
+ collector << " != "
+ visit right, collector
+ end
end
- end
- def visit_Arel_Nodes_As o, collector
- collector = visit o.left, collector
- collector << " AS "
- visit o.right, collector
- end
+ def visit_Arel_Nodes_As(o, collector)
+ collector = visit o.left, collector
+ collector << " AS "
+ visit o.right, collector
+ end
- def visit_Arel_Nodes_Case o, collector
- collector << "CASE "
- if o.case
- visit o.case, collector
- collector << " "
+ def visit_Arel_Nodes_Case(o, collector)
+ collector << "CASE "
+ if o.case
+ visit o.case, collector
+ collector << " "
+ end
+ o.conditions.each do |condition|
+ visit condition, collector
+ collector << " "
+ end
+ if o.default
+ visit o.default, collector
+ collector << " "
+ end
+ collector << "END"
end
- o.conditions.each do |condition|
- visit condition, collector
- collector << " "
+
+ def visit_Arel_Nodes_When(o, collector)
+ collector << "WHEN "
+ visit o.left, collector
+ collector << " THEN "
+ visit o.right, collector
end
- if o.default
- visit o.default, collector
- collector << " "
+
+ def visit_Arel_Nodes_Else(o, collector)
+ collector << "ELSE "
+ visit o.expr, collector
end
- collector << "END"
- end
- def visit_Arel_Nodes_When o, collector
- collector << "WHEN "
- visit o.left, collector
- collector << " THEN "
- visit o.right, collector
- end
+ def visit_Arel_Nodes_UnqualifiedColumn(o, collector)
+ collector << "#{quote_column_name o.name}"
+ collector
+ end
- def visit_Arel_Nodes_Else o, collector
- collector << "ELSE "
- visit o.expr, collector
- end
+ def visit_Arel_Attributes_Attribute(o, collector)
+ join_name = o.relation.table_alias || o.relation.name
+ collector << "#{quote_table_name join_name}.#{quote_column_name o.name}"
+ end
+ alias :visit_Arel_Attributes_Integer :visit_Arel_Attributes_Attribute
+ alias :visit_Arel_Attributes_Float :visit_Arel_Attributes_Attribute
+ alias :visit_Arel_Attributes_Decimal :visit_Arel_Attributes_Attribute
+ alias :visit_Arel_Attributes_String :visit_Arel_Attributes_Attribute
+ alias :visit_Arel_Attributes_Time :visit_Arel_Attributes_Attribute
+ alias :visit_Arel_Attributes_Boolean :visit_Arel_Attributes_Attribute
- def visit_Arel_Nodes_UnqualifiedColumn o, collector
- collector << "#{quote_column_name o.name}"
- collector
- end
+ def literal(o, collector); collector << o.to_s; end
- def visit_Arel_Attributes_Attribute o, collector
- join_name = o.relation.table_alias || o.relation.name
- collector << "#{quote_table_name join_name}.#{quote_column_name o.name}"
- end
- alias :visit_Arel_Attributes_Integer :visit_Arel_Attributes_Attribute
- alias :visit_Arel_Attributes_Float :visit_Arel_Attributes_Attribute
- alias :visit_Arel_Attributes_Decimal :visit_Arel_Attributes_Attribute
- alias :visit_Arel_Attributes_String :visit_Arel_Attributes_Attribute
- alias :visit_Arel_Attributes_Time :visit_Arel_Attributes_Attribute
- alias :visit_Arel_Attributes_Boolean :visit_Arel_Attributes_Attribute
+ def visit_Arel_Nodes_BindParam(o, collector)
+ collector.add_bind(o.value) { "?" }
+ end
- def literal o, collector; collector << o.to_s; end
+ alias :visit_Arel_Nodes_SqlLiteral :literal
+ alias :visit_Bignum :literal
+ alias :visit_Fixnum :literal
+ alias :visit_Integer :literal
- def visit_Arel_Nodes_BindParam o, collector
- collector.add_bind(o.value) { "?" }
- end
+ def quoted(o, a)
+ if a && a.able_to_type_cast?
+ quote(a.type_cast_for_database(o))
+ else
+ quote(o)
+ end
+ end
+
+ def unsupported(o, collector)
+ raise UnsupportedVisitError.new(o)
+ end
- alias :visit_Arel_Nodes_SqlLiteral :literal
- alias :visit_Bignum :literal
- alias :visit_Fixnum :literal
- alias :visit_Integer :literal
+ alias :visit_ActiveSupport_Multibyte_Chars :unsupported
+ alias :visit_ActiveSupport_StringInquirer :unsupported
+ alias :visit_BigDecimal :unsupported
+ alias :visit_Class :unsupported
+ alias :visit_Date :unsupported
+ alias :visit_DateTime :unsupported
+ alias :visit_FalseClass :unsupported
+ alias :visit_Float :unsupported
+ alias :visit_Hash :unsupported
+ alias :visit_NilClass :unsupported
+ alias :visit_String :unsupported
+ alias :visit_Symbol :unsupported
+ alias :visit_Time :unsupported
+ alias :visit_TrueClass :unsupported
- def quoted o, a
- if a && a.able_to_type_cast?
- quote(a.type_cast_for_database(o))
- else
- quote(o)
+ def visit_Arel_Nodes_InfixOperation(o, collector)
+ collector = visit o.left, collector
+ collector << " #{o.operator} "
+ visit o.right, collector
end
- end
- def unsupported o, collector
- raise UnsupportedVisitError.new(o)
- end
+ alias :visit_Arel_Nodes_Addition :visit_Arel_Nodes_InfixOperation
+ alias :visit_Arel_Nodes_Subtraction :visit_Arel_Nodes_InfixOperation
+ alias :visit_Arel_Nodes_Multiplication :visit_Arel_Nodes_InfixOperation
+ alias :visit_Arel_Nodes_Division :visit_Arel_Nodes_InfixOperation
- alias :visit_ActiveSupport_Multibyte_Chars :unsupported
- alias :visit_ActiveSupport_StringInquirer :unsupported
- alias :visit_BigDecimal :unsupported
- alias :visit_Class :unsupported
- alias :visit_Date :unsupported
- alias :visit_DateTime :unsupported
- alias :visit_FalseClass :unsupported
- alias :visit_Float :unsupported
- alias :visit_Hash :unsupported
- alias :visit_NilClass :unsupported
- alias :visit_String :unsupported
- alias :visit_Symbol :unsupported
- alias :visit_Time :unsupported
- alias :visit_TrueClass :unsupported
-
- def visit_Arel_Nodes_InfixOperation o, collector
- collector = visit o.left, collector
- collector << " #{o.operator} "
- visit o.right, collector
- end
+ def visit_Arel_Nodes_UnaryOperation(o, collector)
+ collector << " #{o.operator} "
+ visit o.expr, collector
+ end
- alias :visit_Arel_Nodes_Addition :visit_Arel_Nodes_InfixOperation
- alias :visit_Arel_Nodes_Subtraction :visit_Arel_Nodes_InfixOperation
- alias :visit_Arel_Nodes_Multiplication :visit_Arel_Nodes_InfixOperation
- alias :visit_Arel_Nodes_Division :visit_Arel_Nodes_InfixOperation
+ def visit_Array(o, collector)
+ inject_join o, collector, ", "
+ end
+ alias :visit_Set :visit_Array
- def visit_Arel_Nodes_UnaryOperation o, collector
- collector << " #{o.operator} "
- visit o.expr, collector
- end
+ def quote(value)
+ return value if Arel::Nodes::SqlLiteral === value
+ @connection.quote value
+ end
- def visit_Array o, collector
- inject_join o, collector, ", "
- end
- alias :visit_Set :visit_Array
+ def quote_table_name(name)
+ return name if Arel::Nodes::SqlLiteral === name
+ @connection.quote_table_name(name)
+ end
- def quote value
- return value if Arel::Nodes::SqlLiteral === value
- @connection.quote value
- end
+ def quote_column_name(name)
+ return name if Arel::Nodes::SqlLiteral === name
+ @connection.quote_column_name(name)
+ end
- def quote_table_name name
- return name if Arel::Nodes::SqlLiteral === name
- @connection.quote_table_name(name)
- end
+ def maybe_visit(thing, collector)
+ return collector unless thing
+ collector << " "
+ visit thing, collector
+ end
- def quote_column_name name
- return name if Arel::Nodes::SqlLiteral === name
- @connection.quote_column_name(name)
- end
+ def inject_join(list, collector, join_str)
+ len = list.length - 1
+ list.each_with_index.inject(collector) { |c, (x, i)|
+ if i == len
+ visit x, c
+ else
+ visit(x, c) << join_str
+ end
+ }
+ end
- def maybe_visit thing, collector
- return collector unless thing
- collector << " "
- visit thing, collector
- end
+ def infix_value(o, collector, value)
+ collector = visit o.left, collector
+ collector << value
+ visit o.right, collector
+ end
- def inject_join list, collector, join_str
- len = list.length - 1
- list.each_with_index.inject(collector) { |c, (x,i)|
- if i == len
- visit x, c
+ def aggregate(name, o, collector)
+ collector << "#{name}("
+ if o.distinct
+ collector << "DISTINCT "
+ end
+ collector = inject_join(o.expressions, collector, ", ") << ")"
+ if o.alias
+ collector << " AS "
+ visit o.alias, collector
else
- visit(x, c) << join_str
+ collector
end
- }
- end
-
- def infix_value o, collector, value
- collector = visit o.left, collector
- collector << value
- visit o.right, collector
- end
-
- def aggregate name, o, collector
- collector << "#{name}("
- if o.distinct
- collector << "DISTINCT "
end
- collector = inject_join(o.expressions, collector, ", ") << ")"
- if o.alias
- collector << " AS "
- visit o.alias, collector
- else
- collector
- end
- end
end
end
end
diff --git a/activerecord/lib/arel/visitors/visitor.rb b/activerecord/lib/arel/visitors/visitor.rb
index f156be9a0a..6cbe5caf8c 100644
--- a/activerecord/lib/arel/visitors/visitor.rb
+++ b/activerecord/lib/arel/visitors/visitor.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class Visitor
@@ -6,36 +7,36 @@ module Arel
@dispatch = get_dispatch_cache
end
- def accept object, *args
+ def accept(object, *args)
visit object, *args
end
private
- attr_reader :dispatch
+ attr_reader :dispatch
- def self.dispatch_cache
- Hash.new do |hash, klass|
- hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}"
+ def self.dispatch_cache
+ Hash.new do |hash, klass|
+ hash[klass] = "visit_#{(klass.name || '').gsub('::', '_')}"
+ end
end
- end
- def get_dispatch_cache
- self.class.dispatch_cache
- end
+ def get_dispatch_cache
+ self.class.dispatch_cache
+ end
- def visit object, *args
- dispatch_method = dispatch[object.class]
- send dispatch_method, object, *args
- rescue NoMethodError => e
- raise e if respond_to?(dispatch_method, true)
- superklass = object.class.ancestors.find { |klass|
- respond_to?(dispatch[klass], true)
- }
- raise(TypeError, "Cannot visit #{object.class}") unless superklass
- dispatch[object.class] = dispatch[superklass]
- retry
- end
+ def visit(object, *args)
+ dispatch_method = dispatch[object.class]
+ send dispatch_method, object, *args
+ rescue NoMethodError => e
+ raise e if respond_to?(dispatch_method, true)
+ superklass = object.class.ancestors.find { |klass|
+ respond_to?(dispatch[klass], true)
+ }
+ raise(TypeError, "Cannot visit #{object.class}") unless superklass
+ dispatch[object.class] = dispatch[superklass]
+ retry
+ end
end
end
end
diff --git a/activerecord/lib/arel/visitors/where_sql.rb b/activerecord/lib/arel/visitors/where_sql.rb
index 55e6ca9a21..d9c87f0130 100644
--- a/activerecord/lib/arel/visitors/where_sql.rb
+++ b/activerecord/lib/arel/visitors/where_sql.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Arel
module Visitors
class WhereSql < Arel::Visitors::ToSql
@@ -9,14 +10,14 @@ module Arel
private
- def visit_Arel_Nodes_SelectCore o, collector
- collector << "WHERE "
- wheres = o.wheres.map do |where|
- Nodes::SqlLiteral.new(@inner_visitor.accept(where, collector.class.new).value)
- end
+ def visit_Arel_Nodes_SelectCore(o, collector)
+ collector << "WHERE "
+ wheres = o.wheres.map do |where|
+ Nodes::SqlLiteral.new(@inner_visitor.accept(where, collector.class.new).value)
+ end
- inject_join wheres, collector, ' AND '
- end
+ inject_join wheres, collector, " AND "
+ end
end
end
end
diff --git a/activerecord/lib/arel/window_predications.rb b/activerecord/lib/arel/window_predications.rb
index f93dede036..60d8f05b3c 100644
--- a/activerecord/lib/arel/window_predications.rb
+++ b/activerecord/lib/arel/window_predications.rb
@@ -1,10 +1,9 @@
# frozen_string_literal: true
+
module Arel
module WindowPredications
-
def over(expr = nil)
Nodes::Over.new(self, expr)
end
-
end
-end \ No newline at end of file
+end
diff --git a/activerecord/test/cases/arel/attributes/attribute_test.rb b/activerecord/test/cases/arel/attributes/attribute_test.rb
index 802d6e743f..52573021a5 100644
--- a/activerecord/test/cases/arel/attributes/attribute_test.rb
+++ b/activerecord/test/cases/arel/attributes/attribute_test.rb
@@ -1,17 +1,18 @@
# frozen_string_literal: true
-require_relative '../helper'
-require 'ostruct'
+
+require_relative "../helper"
+require "ostruct"
module Arel
module Attributes
class AttributeTest < Arel::Spec
- describe '#not_eq' do
- it 'should create a NotEqual node' do
+ describe "#not_eq" do
+ it "should create a NotEqual node" do
relation = Table.new(:users)
relation[:id].not_eq(10).must_be_kind_of Nodes::NotEqual
end
- it 'should generate != in sql' do
+ it "should generate != in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_eq(10)
@@ -20,7 +21,7 @@ module Arel
}
end
- it 'should handle nil' do
+ it "should handle nil" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_eq(nil)
@@ -30,45 +31,45 @@ module Arel
end
end
- describe '#not_eq_any' do
- it 'should create a Grouping node' do
+ describe "#not_eq_any" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].not_eq_any([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].not_eq_any([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ORs in sql' do
+ it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].not_eq_any([1,2])
+ mgr.where relation[:id].not_eq_any([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" != 1 OR "users"."id" != 2)
}
end
end
- describe '#not_eq_all' do
- it 'should create a Grouping node' do
+ describe "#not_eq_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].not_eq_all([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].not_eq_all([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].not_eq_all([1,2])
+ mgr.where relation[:id].not_eq_all([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" != 1 AND "users"."id" != 2)
}
end
end
- describe '#gt' do
- it 'should create a GreaterThan node' do
+ describe "#gt" do
+ it "should create a GreaterThan node" do
relation = Table.new(:users)
relation[:id].gt(10).must_be_kind_of Nodes::GreaterThan
end
- it 'should generate > in sql' do
+ it "should generate > in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gt(10)
@@ -77,7 +78,7 @@ module Arel
}
end
- it 'should handle comparing with a subquery' do
+ it "should handle comparing with a subquery" do
users = Table.new(:users)
avg = users.project(users[:karma].average)
@@ -88,10 +89,10 @@ module Arel
}
end
- it 'should accept various data types.' do
+ it "should accept various data types." do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].gt('fake_name')
+ mgr.where relation[:name].gt("fake_name")
mgr.to_sql.must_match %{"users"."name" > 'fake_name'}
current_time = ::Time.now
@@ -100,45 +101,45 @@ module Arel
end
end
- describe '#gt_any' do
- it 'should create a Grouping node' do
+ describe "#gt_any" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].gt_any([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].gt_any([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ORs in sql' do
+ it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].gt_any([1,2])
+ mgr.where relation[:id].gt_any([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" > 1 OR "users"."id" > 2)
}
end
end
- describe '#gt_all' do
- it 'should create a Grouping node' do
+ describe "#gt_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].gt_all([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].gt_all([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].gt_all([1,2])
+ mgr.where relation[:id].gt_all([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" > 1 AND "users"."id" > 2)
}
end
end
- describe '#gteq' do
- it 'should create a GreaterThanOrEqual node' do
+ describe "#gteq" do
+ it "should create a GreaterThanOrEqual node" do
relation = Table.new(:users)
relation[:id].gteq(10).must_be_kind_of Nodes::GreaterThanOrEqual
end
- it 'should generate >= in sql' do
+ it "should generate >= in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gteq(10)
@@ -147,10 +148,10 @@ module Arel
}
end
- it 'should accept various data types.' do
+ it "should accept various data types." do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].gteq('fake_name')
+ mgr.where relation[:name].gteq("fake_name")
mgr.to_sql.must_match %{"users"."name" >= 'fake_name'}
current_time = ::Time.now
@@ -159,45 +160,45 @@ module Arel
end
end
- describe '#gteq_any' do
- it 'should create a Grouping node' do
+ describe "#gteq_any" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].gteq_any([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].gteq_any([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ORs in sql' do
+ it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].gteq_any([1,2])
+ mgr.where relation[:id].gteq_any([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" >= 1 OR "users"."id" >= 2)
}
end
end
- describe '#gteq_all' do
- it 'should create a Grouping node' do
+ describe "#gteq_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].gteq_all([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].gteq_all([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].gteq_all([1,2])
+ mgr.where relation[:id].gteq_all([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" >= 1 AND "users"."id" >= 2)
}
end
end
- describe '#lt' do
- it 'should create a LessThan node' do
+ describe "#lt" do
+ it "should create a LessThan node" do
relation = Table.new(:users)
relation[:id].lt(10).must_be_kind_of Nodes::LessThan
end
- it 'should generate < in sql' do
+ it "should generate < in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lt(10)
@@ -206,10 +207,10 @@ module Arel
}
end
- it 'should accept various data types.' do
+ it "should accept various data types." do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].lt('fake_name')
+ mgr.where relation[:name].lt("fake_name")
mgr.to_sql.must_match %{"users"."name" < 'fake_name'}
current_time = ::Time.now
@@ -218,45 +219,45 @@ module Arel
end
end
- describe '#lt_any' do
- it 'should create a Grouping node' do
+ describe "#lt_any" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].lt_any([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].lt_any([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ORs in sql' do
+ it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].lt_any([1,2])
+ mgr.where relation[:id].lt_any([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" < 1 OR "users"."id" < 2)
}
end
end
- describe '#lt_all' do
- it 'should create a Grouping node' do
+ describe "#lt_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].lt_all([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].lt_all([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].lt_all([1,2])
+ mgr.where relation[:id].lt_all([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" < 1 AND "users"."id" < 2)
}
end
end
- describe '#lteq' do
- it 'should create a LessThanOrEqual node' do
+ describe "#lteq" do
+ it "should create a LessThanOrEqual node" do
relation = Table.new(:users)
relation[:id].lteq(10).must_be_kind_of Nodes::LessThanOrEqual
end
- it 'should generate <= in sql' do
+ it "should generate <= in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lteq(10)
@@ -265,10 +266,10 @@ module Arel
}
end
- it 'should accept various data types.' do
+ it "should accept various data types." do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].lteq('fake_name')
+ mgr.where relation[:name].lteq("fake_name")
mgr.to_sql.must_match %{"users"."name" <= 'fake_name'}
current_time = ::Time.now
@@ -277,45 +278,45 @@ module Arel
end
end
- describe '#lteq_any' do
- it 'should create a Grouping node' do
+ describe "#lteq_any" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].lteq_any([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].lteq_any([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ORs in sql' do
+ it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].lteq_any([1,2])
+ mgr.where relation[:id].lteq_any([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" <= 1 OR "users"."id" <= 2)
}
end
end
- describe '#lteq_all' do
- it 'should create a Grouping node' do
+ describe "#lteq_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].lteq_all([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].lteq_all([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].lteq_all([1,2])
+ mgr.where relation[:id].lteq_all([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" <= 1 AND "users"."id" <= 2)
}
end
end
- describe '#average' do
- it 'should create a AVG node' do
+ describe "#average" do
+ it "should create a AVG node" do
relation = Table.new(:users)
relation[:id].average.must_be_kind_of Nodes::Avg
end
- it 'should generate the proper SQL' do
+ it "should generate the proper SQL" do
relation = Table.new(:users)
mgr = relation.project relation[:id].average
mgr.to_sql.must_be_like %{
@@ -325,13 +326,13 @@ module Arel
end
end
- describe '#maximum' do
- it 'should create a MAX node' do
+ describe "#maximum" do
+ it "should create a MAX node" do
relation = Table.new(:users)
relation[:id].maximum.must_be_kind_of Nodes::Max
end
- it 'should generate proper SQL' do
+ it "should generate proper SQL" do
relation = Table.new(:users)
mgr = relation.project relation[:id].maximum
mgr.to_sql.must_be_like %{
@@ -341,13 +342,13 @@ module Arel
end
end
- describe '#minimum' do
- it 'should create a Min node' do
+ describe "#minimum" do
+ it "should create a Min node" do
relation = Table.new(:users)
relation[:id].minimum.must_be_kind_of Nodes::Min
end
- it 'should generate proper SQL' do
+ it "should generate proper SQL" do
relation = Table.new(:users)
mgr = relation.project relation[:id].minimum
mgr.to_sql.must_be_like %{
@@ -357,13 +358,13 @@ module Arel
end
end
- describe '#sum' do
- it 'should create a SUM node' do
+ describe "#sum" do
+ it "should create a SUM node" do
relation = Table.new(:users)
relation[:id].sum.must_be_kind_of Nodes::Sum
end
- it 'should generate the proper SQL' do
+ it "should generate the proper SQL" do
relation = Table.new(:users)
mgr = relation.project relation[:id].sum
mgr.to_sql.must_be_like %{
@@ -373,13 +374,13 @@ module Arel
end
end
- describe '#count' do
- it 'should return a count node' do
+ describe "#count" do
+ it "should return a count node" do
relation = Table.new(:users)
relation[:id].count.must_be_kind_of Nodes::Count
end
- it 'should take a distinct param' do
+ it "should take a distinct param" do
relation = Table.new(:users)
count = relation[:id].count(nil)
count.must_be_kind_of Nodes::Count
@@ -387,8 +388,8 @@ module Arel
end
end
- describe '#eq' do
- it 'should return an equality node' do
+ describe "#eq" do
+ it "should return an equality node" do
attribute = Attribute.new nil, nil
equality = attribute.eq 1
equality.left.must_equal attribute
@@ -396,7 +397,7 @@ module Arel
equality.must_be_kind_of Nodes::Equality
end
- it 'should generate = in sql' do
+ it "should generate = in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq(10)
@@ -405,7 +406,7 @@ module Arel
}
end
- it 'should handle nil' do
+ it "should handle nil" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq(nil)
@@ -415,152 +416,152 @@ module Arel
end
end
- describe '#eq_any' do
- it 'should create a Grouping node' do
+ describe "#eq_any" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].eq_any([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].eq_any([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ORs in sql' do
+ it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].eq_any([1,2])
+ mgr.where relation[:id].eq_any([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 OR "users"."id" = 2)
}
end
- it 'should not eat input' do
+ it "should not eat input" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- values = [1,2]
+ values = [1, 2]
mgr.where relation[:id].eq_any(values)
- values.must_equal [1,2]
+ values.must_equal [1, 2]
end
end
- describe '#eq_all' do
- it 'should create a Grouping node' do
+ describe "#eq_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].eq_all([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].eq_all([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].eq_all([1,2])
+ mgr.where relation[:id].eq_all([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 AND "users"."id" = 2)
}
end
- it 'should not eat input' do
+ it "should not eat input" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- values = [1,2]
+ values = [1, 2]
mgr.where relation[:id].eq_all(values)
- values.must_equal [1,2]
+ values.must_equal [1, 2]
end
end
- describe '#matches' do
- it 'should create a Matches node' do
+ describe "#matches" do
+ it "should create a Matches node" do
relation = Table.new(:users)
- relation[:name].matches('%bacon%').must_be_kind_of Nodes::Matches
+ relation[:name].matches("%bacon%").must_be_kind_of Nodes::Matches
end
- it 'should generate LIKE in sql' do
+ it "should generate LIKE in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].matches('%bacon%')
+ mgr.where relation[:name].matches("%bacon%")
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."name" LIKE '%bacon%'
}
end
end
- describe '#matches_any' do
- it 'should create a Grouping node' do
+ describe "#matches_any" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:name].matches_any(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping
+ relation[:name].matches_any(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ORs in sql' do
+ it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].matches_any(['%chunky%','%bacon%'])
+ mgr.where relation[:name].matches_any(["%chunky%", "%bacon%"])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" LIKE '%chunky%' OR "users"."name" LIKE '%bacon%')
}
end
end
- describe '#matches_all' do
- it 'should create a Grouping node' do
+ describe "#matches_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:name].matches_all(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping
+ relation[:name].matches_all(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].matches_all(['%chunky%','%bacon%'])
+ mgr.where relation[:name].matches_all(["%chunky%", "%bacon%"])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" LIKE '%chunky%' AND "users"."name" LIKE '%bacon%')
}
end
end
- describe '#does_not_match' do
- it 'should create a DoesNotMatch node' do
+ describe "#does_not_match" do
+ it "should create a DoesNotMatch node" do
relation = Table.new(:users)
- relation[:name].does_not_match('%bacon%').must_be_kind_of Nodes::DoesNotMatch
+ relation[:name].does_not_match("%bacon%").must_be_kind_of Nodes::DoesNotMatch
end
- it 'should generate NOT LIKE in sql' do
+ it "should generate NOT LIKE in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].does_not_match('%bacon%')
+ mgr.where relation[:name].does_not_match("%bacon%")
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."name" NOT LIKE '%bacon%'
}
end
end
- describe '#does_not_match_any' do
- it 'should create a Grouping node' do
+ describe "#does_not_match_any" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:name].does_not_match_any(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping
+ relation[:name].does_not_match_any(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ORs in sql' do
+ it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].does_not_match_any(['%chunky%','%bacon%'])
+ mgr.where relation[:name].does_not_match_any(["%chunky%", "%bacon%"])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" NOT LIKE '%chunky%' OR "users"."name" NOT LIKE '%bacon%')
}
end
end
- describe '#does_not_match_all' do
- it 'should create a Grouping node' do
+ describe "#does_not_match_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:name].does_not_match_all(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping
+ relation[:name].does_not_match_all(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%'])
+ mgr.where relation[:name].does_not_match_all(["%chunky%", "%bacon%"])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" NOT LIKE '%chunky%' AND "users"."name" NOT LIKE '%bacon%')
}
end
end
- describe 'with a range' do
- it 'can be constructed with a standard range' do
+ describe "with a range" do
+ it "can be constructed with a standard range" do
attribute = Attribute.new nil, nil
node = attribute.between(1..3)
@@ -573,7 +574,7 @@ module Arel
)
end
- it 'can be constructed with a range starting from -Infinity' do
+ it "can be constructed with a range starting from -Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(-::Float::INFINITY..3)
@@ -583,7 +584,7 @@ module Arel
)
end
- it 'can be constructed with a quoted range starting from -Infinity' do
+ it "can be constructed with a quoted range starting from -Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(quoted_range(-::Float::INFINITY, 3, false))
@@ -593,7 +594,7 @@ module Arel
)
end
- it 'can be constructed with an exclusive range starting from -Infinity' do
+ it "can be constructed with an exclusive range starting from -Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(-::Float::INFINITY...3)
@@ -603,7 +604,7 @@ module Arel
)
end
- it 'can be constructed with a quoted exclusive range starting from -Infinity' do
+ it "can be constructed with a quoted exclusive range starting from -Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(quoted_range(-::Float::INFINITY, 3, true))
@@ -613,14 +614,14 @@ module Arel
)
end
- it 'can be constructed with an infinite range' do
+ it "can be constructed with an infinite range" do
attribute = Attribute.new nil, nil
node = attribute.between(-::Float::INFINITY..::Float::INFINITY)
node.must_equal Nodes::NotIn.new(attribute, [])
end
- it 'can be constructed with a quoted infinite range' do
+ it "can be constructed with a quoted infinite range" do
attribute = Attribute.new nil, nil
node = attribute.between(quoted_range(-::Float::INFINITY, ::Float::INFINITY, false))
@@ -628,7 +629,7 @@ module Arel
end
- it 'can be constructed with a range ending at Infinity' do
+ it "can be constructed with a range ending at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(0..::Float::INFINITY)
@@ -638,7 +639,7 @@ module Arel
)
end
- it 'can be constructed with a quoted range ending at Infinity' do
+ it "can be constructed with a quoted range ending at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.between(quoted_range(0, ::Float::INFINITY, false))
@@ -648,7 +649,7 @@ module Arel
)
end
- it 'can be constructed with an exclusive range' do
+ it "can be constructed with an exclusive range" do
attribute = Attribute.new nil, nil
node = attribute.between(0...3)
@@ -673,11 +674,11 @@ module Arel
end
end
- describe '#in' do
- it 'can be constructed with a subquery' do
+ describe "#in" do
+ it "can be constructed with a subquery" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%'])
+ mgr.where relation[:name].does_not_match_all(["%chunky%", "%bacon%"])
attribute = Attribute.new nil, nil
node = attribute.in(mgr)
@@ -685,7 +686,7 @@ module Arel
node.must_equal Nodes::In.new(attribute, mgr.ast)
end
- it 'can be constructed with a list' do
+ it "can be constructed with a list" do
attribute = Attribute.new nil, nil
node = attribute.in([1, 2, 3])
@@ -699,7 +700,7 @@ module Arel
)
end
- it 'can be constructed with a random object' do
+ it "can be constructed with a random object" do
attribute = Attribute.new nil, nil
random_object = Object.new
node = attribute.in(random_object)
@@ -710,58 +711,58 @@ module Arel
)
end
- it 'should generate IN in sql' do
+ it "should generate IN in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].in([1,2,3])
+ mgr.where relation[:id].in([1, 2, 3])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" IN (1, 2, 3)
}
end
end
- describe '#in_any' do
- it 'should create a Grouping node' do
+ describe "#in_any" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].in_any([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].in_any([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ORs in sql' do
+ it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].in_any([[1,2], [3,4]])
+ mgr.where relation[:id].in_any([[1, 2], [3, 4]])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" IN (1, 2) OR "users"."id" IN (3, 4))
}
end
end
- describe '#in_all' do
- it 'should create a Grouping node' do
+ describe "#in_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].in_all([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].in_all([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].in_all([[1,2], [3,4]])
+ mgr.where relation[:id].in_all([[1, 2], [3, 4]])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" IN (1, 2) AND "users"."id" IN (3, 4))
}
end
end
- describe 'with a range' do
- it 'can be constructed with a standard range' do
+ describe "with a range" do
+ it "can be constructed with a standard range" do
attribute = Attribute.new nil, nil
node = attribute.not_between(1..3)
node.must_equal Nodes::Grouping.new(Nodes::Or.new(
- Nodes::LessThan.new(
- attribute,
- Nodes::Casted.new(1, attribute)
- ),
+ Nodes::LessThan.new(
+ attribute,
+ Nodes::Casted.new(1, attribute)
+ ),
Nodes::GreaterThan.new(
attribute,
Nodes::Casted.new(3, attribute)
@@ -769,7 +770,7 @@ module Arel
))
end
- it 'can be constructed with a range starting from -Infinity' do
+ it "can be constructed with a range starting from -Infinity" do
attribute = Attribute.new nil, nil
node = attribute.not_between(-::Float::INFINITY..3)
@@ -779,7 +780,7 @@ module Arel
)
end
- it 'can be constructed with an exclusive range starting from -Infinity' do
+ it "can be constructed with an exclusive range starting from -Infinity" do
attribute = Attribute.new nil, nil
node = attribute.not_between(-::Float::INFINITY...3)
@@ -789,14 +790,14 @@ module Arel
)
end
- it 'can be constructed with an infinite range' do
+ it "can be constructed with an infinite range" do
attribute = Attribute.new nil, nil
node = attribute.not_between(-::Float::INFINITY..::Float::INFINITY)
node.must_equal Nodes::In.new(attribute, [])
end
- it 'can be constructed with a range ending at Infinity' do
+ it "can be constructed with a range ending at Infinity" do
attribute = Attribute.new nil, nil
node = attribute.not_between(0..::Float::INFINITY)
@@ -806,15 +807,15 @@ module Arel
)
end
- it 'can be constructed with an exclusive range' do
+ it "can be constructed with an exclusive range" do
attribute = Attribute.new nil, nil
node = attribute.not_between(0...3)
node.must_equal Nodes::Grouping.new(Nodes::Or.new(
- Nodes::LessThan.new(
- attribute,
- Nodes::Casted.new(0, attribute)
- ),
+ Nodes::LessThan.new(
+ attribute,
+ Nodes::Casted.new(0, attribute)
+ ),
Nodes::GreaterThanOrEqual.new(
attribute,
Nodes::Casted.new(3, attribute)
@@ -823,11 +824,11 @@ module Arel
end
end
- describe '#not_in' do
- it 'can be constructed with a subquery' do
+ describe "#not_in" do
+ it "can be constructed with a subquery" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%'])
+ mgr.where relation[:name].does_not_match_all(["%chunky%", "%bacon%"])
attribute = Attribute.new nil, nil
node = attribute.not_in(mgr)
@@ -835,7 +836,7 @@ module Arel
node.must_equal Nodes::NotIn.new(attribute, mgr.ast)
end
- it 'can be constructed with a Union' do
+ it "can be constructed with a Union" do
relation = Table.new(:users)
mgr1 = relation.project(relation[:id])
mgr2 = relation.project(relation[:id])
@@ -847,7 +848,7 @@ module Arel
}
end
- it 'can be constructed with a list' do
+ it "can be constructed with a list" do
attribute = Attribute.new nil, nil
node = attribute.not_in([1, 2, 3])
@@ -861,7 +862,7 @@ module Arel
)
end
- it 'can be constructed with a random object' do
+ it "can be constructed with a random object" do
attribute = Attribute.new nil, nil
random_object = Object.new
node = attribute.not_in(random_object)
@@ -872,71 +873,71 @@ module Arel
)
end
- it 'should generate NOT IN in sql' do
+ it "should generate NOT IN in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].not_in([1,2,3])
+ mgr.where relation[:id].not_in([1, 2, 3])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" NOT IN (1, 2, 3)
}
end
end
- describe '#not_in_any' do
- it 'should create a Grouping node' do
+ describe "#not_in_any" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].not_in_any([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].not_in_any([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ORs in sql' do
+ it "should generate ORs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].not_in_any([[1,2], [3,4]])
+ mgr.where relation[:id].not_in_any([[1, 2], [3, 4]])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" NOT IN (1, 2) OR "users"."id" NOT IN (3, 4))
}
end
end
- describe '#not_in_all' do
- it 'should create a Grouping node' do
+ describe "#not_in_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].not_in_all([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].not_in_all([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].not_in_all([[1,2], [3,4]])
+ mgr.where relation[:id].not_in_all([[1, 2], [3, 4]])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" NOT IN (1, 2) AND "users"."id" NOT IN (3, 4))
}
end
end
- describe '#eq_all' do
- it 'should create a Grouping node' do
+ describe "#eq_all" do
+ it "should create a Grouping node" do
relation = Table.new(:users)
- relation[:id].eq_all([1,2]).must_be_kind_of Nodes::Grouping
+ relation[:id].eq_all([1, 2]).must_be_kind_of Nodes::Grouping
end
- it 'should generate ANDs in sql' do
+ it "should generate ANDs in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
- mgr.where relation[:id].eq_all([1,2])
+ mgr.where relation[:id].eq_all([1, 2])
mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 AND "users"."id" = 2)
}
end
end
- describe '#asc' do
- it 'should create an Ascending node' do
+ describe "#asc" do
+ it "should create an Ascending node" do
relation = Table.new(:users)
relation[:id].asc.must_be_kind_of Nodes::Ascending
end
- it 'should generate ASC in sql' do
+ it "should generate ASC in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.order relation[:id].asc
@@ -946,13 +947,13 @@ module Arel
end
end
- describe '#desc' do
- it 'should create a Descending node' do
+ describe "#desc" do
+ it "should create a Descending node" do
relation = Table.new(:users)
relation[:id].desc.must_be_kind_of Nodes::Descending
end
- it 'should generate DESC in sql' do
+ it "should generate DESC in sql" do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.order relation[:id].desc
@@ -962,18 +963,18 @@ module Arel
end
end
- describe 'equality' do
- describe '#to_sql' do
- it 'should produce sql' do
+ describe "equality" do
+ describe "#to_sql" do
+ it "should produce sql" do
table = Table.new :users
- condition = table['id'].eq 1
+ condition = table["id"].eq 1
condition.to_sql.must_equal '"users"."id" = 1'
end
end
end
- describe 'type casting' do
- it 'does not type cast by default' do
+ describe "type casting" do
+ it "does not type cast by default" do
table = Table.new(:foo)
condition = table["id"].eq("1")
@@ -981,7 +982,7 @@ module Arel
condition.to_sql.must_equal %("foo"."id" = '1')
end
- it 'type casts when given an explicit caster' do
+ it "type casts when given an explicit caster" do
fake_caster = Object.new
def fake_caster.type_cast_for_database(attr_name, value)
if attr_name == "id"
@@ -997,7 +998,7 @@ module Arel
condition.to_sql.must_equal %("foo"."id" = 1 AND "foo"."other_id" = '2')
end
- it 'does not type cast SqlLiteral nodes' do
+ it "does not type cast SqlLiteral nodes" do
fake_caster = Object.new
def fake_caster.type_cast_for_database(attr_name, value)
value.to_i
diff --git a/activerecord/test/cases/arel/attributes_test.rb b/activerecord/test/cases/arel/attributes_test.rb
index e17a6f5fd2..b00af4bd29 100644
--- a/activerecord/test/cases/arel/attributes_test.rb
+++ b/activerecord/test/cases/arel/attributes_test.rb
@@ -1,62 +1,63 @@
# frozen_string_literal: true
-require_relative 'helper'
+
+require_relative "helper"
module Arel
- describe 'Attributes' do
- it 'responds to lower' do
+ describe "Attributes" do
+ it "responds to lower" do
relation = Table.new(:users)
attribute = relation[:foo]
node = attribute.lower
- assert_equal 'LOWER', node.name
+ assert_equal "LOWER", node.name
assert_equal [attribute], node.expressions
end
- describe 'equality' do
- it 'is equal with equal ivars' do
- array = [Attribute.new('foo', 'bar'), Attribute.new('foo', 'bar')]
+ describe "equality" do
+ it "is equal with equal ivars" do
+ array = [Attribute.new("foo", "bar"), Attribute.new("foo", "bar")]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- array = [Attribute.new('foo', 'bar'), Attribute.new('foo', 'baz')]
+ it "is not equal with different ivars" do
+ array = [Attribute.new("foo", "bar"), Attribute.new("foo", "baz")]
assert_equal 2, array.uniq.size
end
end
- describe 'for' do
- it 'deals with unknown column types' do
+ describe "for" do
+ it "deals with unknown column types" do
column = Struct.new(:type).new :crazy
Attributes.for(column).must_equal Attributes::Undefined
end
- it 'returns the correct constant for strings' do
+ it "returns the correct constant for strings" do
[:string, :text, :binary].each do |type|
column = Struct.new(:type).new type
Attributes.for(column).must_equal Attributes::String
end
end
- it 'returns the correct constant for ints' do
+ it "returns the correct constant for ints" do
column = Struct.new(:type).new :integer
Attributes.for(column).must_equal Attributes::Integer
end
- it 'returns the correct constant for floats' do
+ it "returns the correct constant for floats" do
column = Struct.new(:type).new :float
Attributes.for(column).must_equal Attributes::Float
end
- it 'returns the correct constant for decimals' do
+ it "returns the correct constant for decimals" do
column = Struct.new(:type).new :decimal
Attributes.for(column).must_equal Attributes::Decimal
end
- it 'returns the correct constant for boolean' do
+ it "returns the correct constant for boolean" do
column = Struct.new(:type).new :boolean
Attributes.for(column).must_equal Attributes::Boolean
end
- it 'returns the correct constant for time' do
+ it "returns the correct constant for time" do
[:date, :datetime, :timestamp, :time].each do |type|
column = Struct.new(:type).new type
Attributes.for(column).must_equal Attributes::Time
diff --git a/activerecord/test/cases/arel/collectors/bind_test.rb b/activerecord/test/cases/arel/collectors/bind_test.rb
index febc7290a7..9123a70c3e 100644
--- a/activerecord/test/cases/arel/collectors/bind_test.rb
+++ b/activerecord/test/cases/arel/collectors/bind_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Collectors
@@ -10,15 +11,15 @@ module Arel
super
end
- def collect node
+ def collect(node)
@visitor.accept(node, Collectors::Bind.new)
end
- def compile node
+ def compile(node)
collect(node).value
end
- def ast_with_binds bvs
+ def ast_with_binds(bvs)
table = Table.new(:users)
manager = Arel::SelectManager.new table
manager.where(table[:age].eq(Nodes::BindParam.new(bvs.shift)))
diff --git a/activerecord/test/cases/arel/collectors/composite_test.rb b/activerecord/test/cases/arel/collectors/composite_test.rb
index e330cae7a6..545637496f 100644
--- a/activerecord/test/cases/arel/collectors/composite_test.rb
+++ b/activerecord/test/cases/arel/collectors/composite_test.rb
@@ -1,8 +1,9 @@
# frozen_string_literal: true
-require_relative '../helper'
-require 'arel/collectors/bind'
-require 'arel/collectors/composite'
+require_relative "../helper"
+
+require "arel/collectors/bind"
+require "arel/collectors/composite"
module Arel
module Collectors
@@ -13,18 +14,18 @@ module Arel
super
end
- def collect node
+ def collect(node)
sql_collector = Collectors::SQLString.new
bind_collector = Collectors::Bind.new
collector = Collectors::Composite.new(sql_collector, bind_collector)
@visitor.accept(node, collector)
end
- def compile node
+ def compile(node)
collect(node).value
end
- def ast_with_binds bvs
+ def ast_with_binds(bvs)
table = Table.new(:users)
manager = Arel::SelectManager.new table
manager.where(table[:age].eq(Nodes::BindParam.new(bvs.shift)))
diff --git a/activerecord/test/cases/arel/collectors/sql_string_test.rb b/activerecord/test/cases/arel/collectors/sql_string_test.rb
index a8ed3eb625..380573494d 100644
--- a/activerecord/test/cases/arel/collectors/sql_string_test.rb
+++ b/activerecord/test/cases/arel/collectors/sql_string_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Collectors
@@ -10,15 +11,15 @@ module Arel
super
end
- def collect node
+ def collect(node)
@visitor.accept(node, Collectors::SQLString.new)
end
- def compile node
+ def compile(node)
collect(node).value
end
- def ast_with_binds bv
+ def ast_with_binds(bv)
table = Table.new(:users)
manager = Arel::SelectManager.new table
manager.where(table[:age].eq(bv))
diff --git a/activerecord/test/cases/arel/collectors/substitute_bind_collector_test.rb b/activerecord/test/cases/arel/collectors/substitute_bind_collector_test.rb
index 18f0ac14de..255c8e79e9 100644
--- a/activerecord/test/cases/arel/collectors/substitute_bind_collector_test.rb
+++ b/activerecord/test/cases/arel/collectors/substitute_bind_collector_test.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
-require_relative '../helper'
-require 'arel/collectors/substitute_binds'
-require 'arel/collectors/sql_string'
+
+require_relative "../helper"
+require "arel/collectors/substitute_binds"
+require "arel/collectors/sql_string"
module Arel
module Collectors
diff --git a/activerecord/test/cases/arel/crud_test.rb b/activerecord/test/cases/arel/crud_test.rb
index 38a956b9dd..f3cdd8927f 100644
--- a/activerecord/test/cases/arel/crud_test.rb
+++ b/activerecord/test/cases/arel/crud_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
+
+require_relative "helper"
module Arel
class FakeCrudder < SelectManager
@@ -10,12 +11,12 @@ module Arel
@calls = []
@connection_pool = self
@spec = self
- @config = { :adapter => 'sqlite3' }
+ @config = { adapter: "sqlite3" }
end
def connection; self end
- def method_missing name, *args
+ def method_missing(name, *args)
@calls << [name, args]
end
end
@@ -25,34 +26,34 @@ module Arel
attr_reader :engine
attr_accessor :ctx
- def initialize engine = FakeEngine.new
+ def initialize(engine = FakeEngine.new)
super
end
end
- describe 'crud' do
- describe 'insert' do
- it 'should call insert on the connection' do
+ describe "crud" do
+ describe "insert" do
+ it "should call insert on the connection" do
table = Table.new :users
fc = FakeCrudder.new
fc.from table
- im = fc.compile_insert [[table[:id], 'foo']]
+ im = fc.compile_insert [[table[:id], "foo"]]
assert_instance_of Arel::InsertManager, im
end
end
- describe 'update' do
- it 'should call update on the connection' do
+ describe "update" do
+ it "should call update on the connection" do
table = Table.new :users
fc = FakeCrudder.new
fc.from table
- stmt = fc.compile_update [[table[:id], 'foo']], Arel::Attributes::Attribute.new(table, 'id')
+ stmt = fc.compile_update [[table[:id], "foo"]], Arel::Attributes::Attribute.new(table, "id")
assert_instance_of Arel::UpdateManager, stmt
end
end
- describe 'delete' do
- it 'should call delete on the connection' do
+ describe "delete" do
+ it "should call delete on the connection" do
table = Table.new :users
fc = FakeCrudder.new
fc.from table
diff --git a/activerecord/test/cases/arel/delete_manager_test.rb b/activerecord/test/cases/arel/delete_manager_test.rb
index 36d482f10b..17a5271039 100644
--- a/activerecord/test/cases/arel/delete_manager_test.rb
+++ b/activerecord/test/cases/arel/delete_manager_test.rb
@@ -1,15 +1,16 @@
# frozen_string_literal: true
-require_relative 'helper'
+
+require_relative "helper"
module Arel
class DeleteManagerTest < Arel::Spec
- describe 'new' do
- it 'takes an engine' do
+ describe "new" do
+ it "takes an engine" do
Arel::DeleteManager.new
end
end
- it 'handles limit properly' do
+ it "handles limit properly" do
table = Table.new(:users)
dm = Arel::DeleteManager.new
dm.take 10
@@ -17,23 +18,23 @@ module Arel
assert_match(/LIMIT 10/, dm.to_sql)
end
- describe 'from' do
- it 'uses from' do
+ describe "from" do
+ it "uses from" do
table = Table.new(:users)
dm = Arel::DeleteManager.new
dm.from table
dm.to_sql.must_be_like %{ DELETE FROM "users" }
end
- it 'chains' do
+ it "chains" do
table = Table.new(:users)
dm = Arel::DeleteManager.new
dm.from(table).must_equal dm
end
end
- describe 'where' do
- it 'uses where values' do
+ describe "where" do
+ it "uses where values" do
table = Table.new(:users)
dm = Arel::DeleteManager.new
dm.from table
@@ -41,7 +42,7 @@ module Arel
dm.to_sql.must_be_like %{ DELETE FROM "users" WHERE "users"."id" = 10}
end
- it 'chains' do
+ it "chains" do
table = Table.new(:users)
dm = Arel::DeleteManager.new
dm.where(table[:id].eq(10)).must_equal dm
diff --git a/activerecord/test/cases/arel/factory_methods_test.rb b/activerecord/test/cases/arel/factory_methods_test.rb
index 2600b81e31..26d2cdd08d 100644
--- a/activerecord/test/cases/arel/factory_methods_test.rb
+++ b/activerecord/test/cases/arel/factory_methods_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
+
+require_relative "helper"
module Arel
module FactoryMethods
@@ -37,7 +38,7 @@ module Arel
def test_lower
lower = @factory.lower :one
assert_instance_of Nodes::NamedFunction, lower
- assert_equal 'LOWER', lower.name
+ assert_equal "LOWER", lower.name
assert_equal [:one], lower.expressions.map(&:expr)
end
end
diff --git a/activerecord/test/cases/arel/helper.rb b/activerecord/test/cases/arel/helper.rb
index b716ee833f..1f8612f799 100644
--- a/activerecord/test/cases/arel/helper.rb
+++ b/activerecord/test/cases/arel/helper.rb
@@ -1,13 +1,14 @@
# frozen_string_literal: true
-require 'rubygems'
-require 'minitest/autorun'
-require 'arel'
-require_relative 'support/fake_record'
+require "rubygems"
+require "minitest/autorun"
+require "arel"
+
+require_relative "support/fake_record"
class Object
- def must_be_like other
- gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip
+ def must_be_like(other)
+ gsub(/\s+/, " ").strip.must_equal other.gsub(/\s+/, " ").strip
end
end
@@ -24,9 +25,9 @@ module Arel
super
end
- def assert_like expected, actual
- assert_equal expected.gsub(/\s+/, ' ').strip,
- actual.gsub(/\s+/, ' ').strip
+ def assert_like(expected, actual)
+ assert_equal expected.gsub(/\s+/, " ").strip,
+ actual.gsub(/\s+/, " ").strip
end
end
diff --git a/activerecord/test/cases/arel/insert_manager_test.rb b/activerecord/test/cases/arel/insert_manager_test.rb
index 33fab63fbc..ae10ccf56c 100644
--- a/activerecord/test/cases/arel/insert_manager_test.rb
+++ b/activerecord/test/cases/arel/insert_manager_test.rb
@@ -1,16 +1,17 @@
# frozen_string_literal: true
-require_relative 'helper'
+
+require_relative "helper"
module Arel
class InsertManagerTest < Arel::Spec
- describe 'new' do
- it 'takes an engine' do
+ describe "new" do
+ it "takes an engine" do
Arel::InsertManager.new
end
end
- describe 'insert' do
- it 'can create a Values node' do
+ describe "insert" do
+ it "can create a Values node" do
manager = Arel::InsertManager.new
values = manager.create_values %w{ a b }, %w{ c d }
@@ -19,16 +20,16 @@ module Arel
assert_equal %w{ c d }, values.right
end
- it 'allows sql literals' do
- manager = Arel::InsertManager.new
+ it "allows sql literals" do
+ manager = Arel::InsertManager.new
manager.into Table.new(:users)
- manager.values = manager.create_values [Arel.sql('*')], %w{ a }
+ manager.values = manager.create_values [Arel.sql("*")], %w{ a }
manager.to_sql.must_be_like %{
INSERT INTO \"users\" VALUES (*)
}
end
- it 'works with multiple values' do
+ it "works with multiple values" do
table = Table.new(:users)
manager = Arel::InsertManager.new
manager.into table
@@ -39,7 +40,7 @@ module Arel
manager.values = manager.create_values_list([
%w{1 david},
%w{2 kir},
- ["3", Arel.sql('DEFAULT')],
+ ["3", Arel.sql("DEFAULT")],
])
manager.to_sql.must_be_like %{
@@ -47,7 +48,7 @@ module Arel
}
end
- it 'literals in multiple values are not escaped' do
+ it "literals in multiple values are not escaped" do
table = Table.new(:users)
manager = Arel::InsertManager.new
manager.into table
@@ -55,8 +56,8 @@ module Arel
manager.columns << table[:name]
manager.values = manager.create_values_list([
- [Arel.sql('*')],
- [Arel.sql('DEFAULT')],
+ [Arel.sql("*")],
+ [Arel.sql("DEFAULT")],
])
manager.to_sql.must_be_like %{
@@ -64,7 +65,7 @@ module Arel
}
end
- it 'works with multiple single values' do
+ it "works with multiple single values" do
table = Table.new(:users)
manager = Arel::InsertManager.new
manager.into table
@@ -74,7 +75,7 @@ module Arel
manager.values = manager.create_values_list([
%w{david},
%w{kir},
- [Arel.sql('DEFAULT')],
+ [Arel.sql("DEFAULT")],
])
manager.to_sql.must_be_like %{
@@ -114,26 +115,26 @@ module Arel
}
end
- it 'takes a list of lists' do
+ it "takes a list of lists" do
table = Table.new(:users)
manager = Arel::InsertManager.new
manager.into table
- manager.insert [[table[:id], 1], [table[:name], 'aaron']]
+ manager.insert [[table[:id], 1], [table[:name], "aaron"]]
manager.to_sql.must_be_like %{
INSERT INTO "users" ("id", "name") VALUES (1, 'aaron')
}
end
- it 'defaults the table' do
+ it "defaults the table" do
table = Table.new(:users)
manager = Arel::InsertManager.new
- manager.insert [[table[:id], 1], [table[:name], 'aaron']]
+ manager.insert [[table[:id], 1], [table[:name], "aaron"]]
manager.to_sql.must_be_like %{
INSERT INTO "users" ("id", "name") VALUES (1, 'aaron')
}
end
- it 'noop for empty list' do
+ it "noop for empty list" do
table = Table.new(:users)
manager = Arel::InsertManager.new
manager.insert [[table[:id], 1]]
@@ -143,21 +144,21 @@ module Arel
}
end
- it 'is chainable' do
+ it "is chainable" do
table = Table.new(:users)
manager = Arel::InsertManager.new
- insert_result = manager.insert [[table[:id],1]]
+ insert_result = manager.insert [[table[:id], 1]]
assert_equal manager, insert_result
end
end
- describe 'into' do
- it 'takes a Table and chains' do
+ describe "into" do
+ it "takes a Table and chains" do
manager = Arel::InsertManager.new
manager.into(Table.new(:users)).must_equal manager
end
- it 'converts to sql' do
+ it "converts to sql" do
table = Table.new :users
manager = Arel::InsertManager.new
manager.into table
@@ -167,7 +168,7 @@ module Arel
end
end
- describe 'columns' do
+ describe "columns" do
it "converts to sql" do
table = Table.new :users
manager = Arel::InsertManager.new
@@ -209,7 +210,7 @@ module Arel
manager = Arel::InsertManager.new
manager.into table
- manager.values = Nodes::Values.new [1, 'aaron']
+ manager.values = Nodes::Values.new [1, "aaron"]
manager.columns << table[:id]
manager.columns << table[:name]
manager.to_sql.must_be_like %{
@@ -227,7 +228,7 @@ module Arel
manager.into table
select = Arel::SelectManager.new
- select.project Arel.sql('1')
+ select.project Arel.sql("1")
select.project Arel.sql('"aaron"')
manager.select select
@@ -239,6 +240,5 @@ module Arel
end
end
-
end
end
diff --git a/activerecord/test/cases/arel/nodes/and_test.rb b/activerecord/test/cases/arel/nodes/and_test.rb
index de63e0bb31..eff54abd91 100644
--- a/activerecord/test/cases/arel/nodes/and_test.rb
+++ b/activerecord/test/cases/arel/nodes/and_test.rb
@@ -1,21 +1,21 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'And' do
- describe 'equality' do
- it 'is equal with equal ivars' do
- array = [And.new(['foo', 'bar']), And.new(['foo', 'bar'])]
+ describe "And" do
+ describe "equality" do
+ it "is equal with equal ivars" do
+ array = [And.new(["foo", "bar"]), And.new(["foo", "bar"])]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- array = [And.new(['foo', 'bar']), And.new(['foo', 'baz'])]
+ it "is not equal with different ivars" do
+ array = [And.new(["foo", "bar"]), And.new(["foo", "baz"])]
assert_equal 2, array.uniq.size
end
end
end
end
end
-
diff --git a/activerecord/test/cases/arel/nodes/as_test.rb b/activerecord/test/cases/arel/nodes/as_test.rb
index 09c8aa8d62..1169ea11c9 100644
--- a/activerecord/test/cases/arel/nodes/as_test.rb
+++ b/activerecord/test/cases/arel/nodes/as_test.rb
@@ -1,32 +1,33 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'As' do
- describe '#as' do
- it 'makes an AS node' do
+ describe "As" do
+ describe "#as" do
+ it "makes an AS node" do
attr = Table.new(:users)[:id]
- as = attr.as(Arel.sql('foo'))
+ as = attr.as(Arel.sql("foo"))
assert_equal attr, as.left
- assert_equal 'foo', as.right
+ assert_equal "foo", as.right
end
- it 'converts right to SqlLiteral if a string' do
+ it "converts right to SqlLiteral if a string" do
attr = Table.new(:users)[:id]
- as = attr.as('foo')
+ as = attr.as("foo")
assert_kind_of Arel::Nodes::SqlLiteral, as.right
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
- array = [As.new('foo', 'bar'), As.new('foo', 'bar')]
+ describe "equality" do
+ it "is equal with equal ivars" do
+ array = [As.new("foo", "bar"), As.new("foo", "bar")]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- array = [As.new('foo', 'bar'), As.new('foo', 'baz')]
+ it "is not equal with different ivars" do
+ array = [As.new("foo", "bar"), As.new("foo", "baz")]
assert_equal 2, array.uniq.size
end
end
diff --git a/activerecord/test/cases/arel/nodes/ascending_test.rb b/activerecord/test/cases/arel/nodes/ascending_test.rb
index 5c73e69fa5..1efb16222a 100644
--- a/activerecord/test/cases/arel/nodes/ascending_test.rb
+++ b/activerecord/test/cases/arel/nodes/ascending_test.rb
@@ -1,43 +1,44 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
class TestAscending < Arel::Test
def test_construct
- ascending = Ascending.new 'zomg'
- assert_equal 'zomg', ascending.expr
+ ascending = Ascending.new "zomg"
+ assert_equal "zomg", ascending.expr
end
def test_reverse
- ascending = Ascending.new 'zomg'
+ ascending = Ascending.new "zomg"
descending = ascending.reverse
assert_kind_of Descending, descending
assert_equal ascending.expr, descending.expr
end
def test_direction
- ascending = Ascending.new 'zomg'
+ ascending = Ascending.new "zomg"
assert_equal :asc, ascending.direction
end
def test_ascending?
- ascending = Ascending.new 'zomg'
+ ascending = Ascending.new "zomg"
assert ascending.ascending?
end
def test_descending?
- ascending = Ascending.new 'zomg'
+ ascending = Ascending.new "zomg"
assert !ascending.descending?
end
def test_equality_with_same_ivars
- array = [Ascending.new('zomg'), Ascending.new('zomg')]
+ array = [Ascending.new("zomg"), Ascending.new("zomg")]
assert_equal 1, array.uniq.size
end
def test_inequality_with_different_ivars
- array = [Ascending.new('zomg'), Ascending.new('zomg!')]
+ array = [Ascending.new("zomg"), Ascending.new("zomg!")]
assert_equal 2, array.uniq.size
end
end
diff --git a/activerecord/test/cases/arel/nodes/bin_test.rb b/activerecord/test/cases/arel/nodes/bin_test.rb
index 923a296adf..ee2ec3cf2f 100644
--- a/activerecord/test/cases/arel/nodes/bin_test.rb
+++ b/activerecord/test/cases/arel/nodes/bin_test.rb
@@ -1,32 +1,33 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
class TestBin < Arel::Test
def test_new
- assert Arel::Nodes::Bin.new('zomg')
+ assert Arel::Nodes::Bin.new("zomg")
end
def test_default_to_sql
viz = Arel::Visitors::ToSql.new Table.engine.connection_pool
- node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
- assert_equal 'zomg', viz.accept(node, Collectors::SQLString.new).value
+ node = Arel::Nodes::Bin.new(Arel.sql("zomg"))
+ assert_equal "zomg", viz.accept(node, Collectors::SQLString.new).value
end
def test_mysql_to_sql
viz = Arel::Visitors::MySQL.new Table.engine.connection_pool
- node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
- assert_equal 'BINARY zomg', viz.accept(node, Collectors::SQLString.new).value
+ node = Arel::Nodes::Bin.new(Arel.sql("zomg"))
+ assert_equal "BINARY zomg", viz.accept(node, Collectors::SQLString.new).value
end
def test_equality_with_same_ivars
- array = [Bin.new('zomg'), Bin.new('zomg')]
+ array = [Bin.new("zomg"), Bin.new("zomg")]
assert_equal 1, array.uniq.size
end
def test_inequality_with_different_ivars
- array = [Bin.new('zomg'), Bin.new('zomg!')]
+ array = [Bin.new("zomg"), Bin.new("zomg!")]
assert_equal 2, array.uniq.size
end
end
diff --git a/activerecord/test/cases/arel/nodes/binary_test.rb b/activerecord/test/cases/arel/nodes/binary_test.rb
index 0bea35f7dd..9bc55a155b 100644
--- a/activerecord/test/cases/arel/nodes/binary_test.rb
+++ b/activerecord/test/cases/arel/nodes/binary_test.rb
@@ -1,22 +1,23 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'Binary' do
- describe '#hash' do
- it 'generates a hash based on its value' do
- eq = Equality.new('foo', 'bar')
- eq2 = Equality.new('foo', 'bar')
- eq3 = Equality.new('bar', 'baz')
+ describe "Binary" do
+ describe "#hash" do
+ it "generates a hash based on its value" do
+ eq = Equality.new("foo", "bar")
+ eq2 = Equality.new("foo", "bar")
+ eq3 = Equality.new("bar", "baz")
assert_equal eq.hash, eq2.hash
refute_equal eq.hash, eq3.hash
end
- it 'generates a hash specific to its class' do
- eq = Equality.new('foo', 'bar')
- neq = NotEqual.new('foo', 'bar')
+ it "generates a hash specific to its class" do
+ eq = Equality.new("foo", "bar")
+ neq = NotEqual.new("foo", "bar")
refute_equal eq.hash, neq.hash
end
diff --git a/activerecord/test/cases/arel/nodes/bind_param_test.rb b/activerecord/test/cases/arel/nodes/bind_param_test.rb
index 665581edce..37a362ece4 100644
--- a/activerecord/test/cases/arel/nodes/bind_param_test.rb
+++ b/activerecord/test/cases/arel/nodes/bind_param_test.rb
@@ -1,19 +1,20 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'BindParam' do
- it 'is equal to other bind params with the same value' do
+ describe "BindParam" do
+ it "is equal to other bind params with the same value" do
BindParam.new(1).must_equal(BindParam.new(1))
BindParam.new("foo").must_equal(BindParam.new("foo"))
end
- it 'is not equal to other nodes' do
+ it "is not equal to other nodes" do
BindParam.new(nil).wont_equal(Node.new)
end
- it 'is not equal to bind params with different values' do
+ it "is not equal to bind params with different values" do
BindParam.new(1).wont_equal(BindParam.new(2))
end
end
diff --git a/activerecord/test/cases/arel/nodes/case_test.rb b/activerecord/test/cases/arel/nodes/case_test.rb
index 70364fe6ab..2c087e624e 100644
--- a/activerecord/test/cases/arel/nodes/case_test.rb
+++ b/activerecord/test/cases/arel/nodes/case_test.rb
@@ -1,26 +1,27 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'Case' do
- describe '#initialize' do
- it 'sets case expression from first argument' do
- node = Case.new 'foo'
+ describe "Case" do
+ describe "#initialize" do
+ it "sets case expression from first argument" do
+ node = Case.new "foo"
- assert_equal 'foo', node.case
+ assert_equal "foo", node.case
end
- it 'sets default case from second argument' do
- node = Case.new nil, 'bar'
+ it "sets default case from second argument" do
+ node = Case.new nil, "bar"
- assert_equal 'bar', node.default
+ assert_equal "bar", node.default
end
end
- describe '#clone' do
- it 'clones case, conditions and default' do
- foo = Nodes.build_quoted 'foo'
+ describe "#clone" do
+ it "clones case, conditions and default" do
+ foo = Nodes.build_quoted "foo"
node = Case.new
node.case = foo
@@ -40,9 +41,9 @@ module Arel
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
- foo = Nodes.build_quoted 'foo'
+ describe "equality" do
+ it "is equal with equal ivars" do
+ foo = Nodes.build_quoted "foo"
one = Nodes.build_quoted 1
zero = Nodes.build_quoted 0
@@ -59,9 +60,9 @@ module Arel
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- foo = Nodes.build_quoted 'foo'
- bar = Nodes.build_quoted 'bar'
+ it "is not equal with different ivars" do
+ foo = Nodes.build_quoted "foo"
+ bar = Nodes.build_quoted "bar"
one = Nodes.build_quoted 1
zero = Nodes.build_quoted 0
diff --git a/activerecord/test/cases/arel/nodes/casted_test.rb b/activerecord/test/cases/arel/nodes/casted_test.rb
index a6e2dd2294..e27f58a4e2 100644
--- a/activerecord/test/cases/arel/nodes/casted_test.rb
+++ b/activerecord/test/cases/arel/nodes/casted_test.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
describe Casted do
- describe '#hash' do
- it 'is equal when eql? returns true' do
+ describe "#hash" do
+ it "is equal when eql? returns true" do
one = Casted.new 1, 2
also_one = Casted.new 1, 2
diff --git a/activerecord/test/cases/arel/nodes/count_test.rb b/activerecord/test/cases/arel/nodes/count_test.rb
index 28d8481993..3107659e77 100644
--- a/activerecord/test/cases/arel/nodes/count_test.rb
+++ b/activerecord/test/cases/arel/nodes/count_test.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
class Arel::Nodes::CountTest < Arel::Spec
describe "as" do
- it 'should alias the count' do
+ it "should alias the count" do
table = Arel::Table.new :users
- table[:id].count.as('foo').to_sql.must_be_like %{
+ table[:id].count.as("foo").to_sql.must_be_like %{
COUNT("users"."id") AS foo
}
end
@@ -20,20 +21,20 @@ class Arel::Nodes::CountTest < Arel::Spec
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
- array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo')]
+ describe "equality" do
+ it "is equal with equal ivars" do
+ array = [Arel::Nodes::Count.new("foo"), Arel::Nodes::Count.new("foo")]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo!')]
+ it "is not equal with different ivars" do
+ array = [Arel::Nodes::Count.new("foo"), Arel::Nodes::Count.new("foo!")]
assert_equal 2, array.uniq.size
end
end
- describe 'math' do
- it 'allows mathematical functions' do
+ describe "math" do
+ it "allows mathematical functions" do
table = Arel::Table.new :users
(table[:id].count + 1).to_sql.must_be_like %{
(COUNT("users"."id") + 1)
diff --git a/activerecord/test/cases/arel/nodes/delete_statement_test.rb b/activerecord/test/cases/arel/nodes/delete_statement_test.rb
index ada8964646..3f078063a4 100644
--- a/activerecord/test/cases/arel/nodes/delete_statement_test.rb
+++ b/activerecord/test/cases/arel/nodes/delete_statement_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
describe Arel::Nodes::DeleteStatement do
describe "#clone" do
@@ -13,8 +14,8 @@ describe Arel::Nodes::DeleteStatement do
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
+ describe "equality" do
+ it "is equal with equal ivars" do
statement1 = Arel::Nodes::DeleteStatement.new
statement1.wheres = %w[a b c]
statement2 = Arel::Nodes::DeleteStatement.new
@@ -23,7 +24,7 @@ describe Arel::Nodes::DeleteStatement do
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
+ it "is not equal with different ivars" do
statement1 = Arel::Nodes::DeleteStatement.new
statement1.wheres = %w[a b c]
statement2 = Arel::Nodes::DeleteStatement.new
diff --git a/activerecord/test/cases/arel/nodes/descending_test.rb b/activerecord/test/cases/arel/nodes/descending_test.rb
index 5fe0ba62b0..45e22de17b 100644
--- a/activerecord/test/cases/arel/nodes/descending_test.rb
+++ b/activerecord/test/cases/arel/nodes/descending_test.rb
@@ -1,43 +1,44 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
class TestDescending < Arel::Test
def test_construct
- descending = Descending.new 'zomg'
- assert_equal 'zomg', descending.expr
+ descending = Descending.new "zomg"
+ assert_equal "zomg", descending.expr
end
def test_reverse
- descending = Descending.new 'zomg'
+ descending = Descending.new "zomg"
ascending = descending.reverse
assert_kind_of Ascending, ascending
assert_equal descending.expr, ascending.expr
end
def test_direction
- descending = Descending.new 'zomg'
+ descending = Descending.new "zomg"
assert_equal :desc, descending.direction
end
def test_ascending?
- descending = Descending.new 'zomg'
+ descending = Descending.new "zomg"
assert !descending.ascending?
end
def test_descending?
- descending = Descending.new 'zomg'
+ descending = Descending.new "zomg"
assert descending.descending?
end
def test_equality_with_same_ivars
- array = [Descending.new('zomg'), Descending.new('zomg')]
+ array = [Descending.new("zomg"), Descending.new("zomg")]
assert_equal 1, array.uniq.size
end
def test_inequality_with_different_ivars
- array = [Descending.new('zomg'), Descending.new('zomg!')]
+ array = [Descending.new("zomg"), Descending.new("zomg!")]
assert_equal 2, array.uniq.size
end
end
diff --git a/activerecord/test/cases/arel/nodes/distinct_test.rb b/activerecord/test/cases/arel/nodes/distinct_test.rb
index 465700118e..de5f0ee588 100644
--- a/activerecord/test/cases/arel/nodes/distinct_test.rb
+++ b/activerecord/test/cases/arel/nodes/distinct_test.rb
@@ -1,16 +1,17 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'Distinct' do
- describe 'equality' do
- it 'is equal to other distinct nodes' do
+ describe "Distinct" do
+ describe "equality" do
+ it "is equal to other distinct nodes" do
array = [Distinct.new, Distinct.new]
assert_equal 1, array.uniq.size
end
- it 'is not equal with other nodes' do
+ it "is not equal with other nodes" do
array = [Distinct.new, Node.new]
assert_equal 2, array.uniq.size
end
@@ -18,4 +19,3 @@ module Arel
end
end
end
-
diff --git a/activerecord/test/cases/arel/nodes/equality_test.rb b/activerecord/test/cases/arel/nodes/equality_test.rb
index 28a74de321..e173720e86 100644
--- a/activerecord/test/cases/arel/nodes/equality_test.rb
+++ b/activerecord/test/cases/arel/nodes/equality_test.rb
@@ -1,37 +1,38 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'equality' do
+ describe "equality" do
# FIXME: backwards compat
- describe 'backwards compat' do
- describe 'operator' do
- it 'returns :==' do
+ describe "backwards compat" do
+ describe "operator" do
+ it "returns :==" do
attr = Table.new(:users)[:id]
- left = attr.eq(10)
+ left = attr.eq(10)
left.operator.must_equal :==
end
end
- describe 'operand1' do
+ describe "operand1" do
it "should equal left" do
attr = Table.new(:users)[:id]
- left = attr.eq(10)
+ left = attr.eq(10)
left.left.must_equal left.operand1
end
end
- describe 'operand2' do
+ describe "operand2" do
it "should equal right" do
attr = Table.new(:users)[:id]
- left = attr.eq(10)
+ left = attr.eq(10)
left.right.must_equal left.operand2
end
end
- describe 'to_sql' do
- it 'takes an engine' do
+ describe "to_sql" do
+ it "takes an engine" do
engine = FakeRecord::Base.new
engine.connection.extend Module.new {
attr_accessor :quote_count
@@ -49,8 +50,8 @@ module Arel
end
end
- describe 'or' do
- it 'makes an OR node' do
+ describe "or" do
+ it "makes an OR node" do
attr = Table.new(:users)[:id]
left = attr.eq(10)
right = attr.eq(11)
@@ -60,8 +61,8 @@ module Arel
end
end
- describe 'and' do
- it 'makes and AND node' do
+ describe "and" do
+ it "makes and AND node" do
attr = Table.new(:users)[:id]
left = attr.eq(10)
right = attr.eq(11)
@@ -71,13 +72,13 @@ module Arel
end
end
- it 'is equal with equal ivars' do
- array = [Equality.new('foo', 'bar'), Equality.new('foo', 'bar')]
+ it "is equal with equal ivars" do
+ array = [Equality.new("foo", "bar"), Equality.new("foo", "bar")]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- array = [Equality.new('foo', 'bar'), Equality.new('foo', 'baz')]
+ it "is not equal with different ivars" do
+ array = [Equality.new("foo", "bar"), Equality.new("foo", "baz")]
assert_equal 2, array.uniq.size
end
end
diff --git a/activerecord/test/cases/arel/nodes/extract_test.rb b/activerecord/test/cases/arel/nodes/extract_test.rb
index f6dc1626a4..8fc1e04d67 100644
--- a/activerecord/test/cases/arel/nodes/extract_test.rb
+++ b/activerecord/test/cases/arel/nodes/extract_test.rb
@@ -1,41 +1,42 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
class Arel::Nodes::ExtractTest < Arel::Spec
it "should extract field" do
table = Arel::Table.new :users
- table[:timestamp].extract('date').to_sql.must_be_like %{
+ table[:timestamp].extract("date").to_sql.must_be_like %{
EXTRACT(DATE FROM "users"."timestamp")
}
end
describe "as" do
- it 'should alias the extract' do
+ it "should alias the extract" do
table = Arel::Table.new :users
- table[:timestamp].extract('date').as('foo').to_sql.must_be_like %{
+ table[:timestamp].extract("date").as("foo").to_sql.must_be_like %{
EXTRACT(DATE FROM "users"."timestamp") AS foo
}
end
- it 'should not mutate the extract' do
+ it "should not mutate the extract" do
table = Arel::Table.new :users
- extract = table[:timestamp].extract('date')
+ extract = table[:timestamp].extract("date")
before = extract.dup
- extract.as('foo')
+ extract.as("foo")
assert_equal extract, before
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
+ describe "equality" do
+ it "is equal with equal ivars" do
table = Arel::Table.new :users
- array = [table[:attr].extract('foo'), table[:attr].extract('foo')]
+ array = [table[:attr].extract("foo"), table[:attr].extract("foo")]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
+ it "is not equal with different ivars" do
table = Arel::Table.new :users
- array = [table[:attr].extract('foo'), table[:attr].extract('bar')]
+ array = [table[:attr].extract("foo"), table[:attr].extract("bar")]
assert_equal 2, array.uniq.size
end
end
diff --git a/activerecord/test/cases/arel/nodes/false_test.rb b/activerecord/test/cases/arel/nodes/false_test.rb
index 8b91dc227c..4ecf8e332e 100644
--- a/activerecord/test/cases/arel/nodes/false_test.rb
+++ b/activerecord/test/cases/arel/nodes/false_test.rb
@@ -1,16 +1,17 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'False' do
- describe 'equality' do
- it 'is equal to other false nodes' do
+ describe "False" do
+ describe "equality" do
+ it "is equal to other false nodes" do
array = [False.new, False.new]
assert_equal 1, array.uniq.size
end
- it 'is not equal with other nodes' do
+ it "is not equal with other nodes" do
array = [False.new, Node.new]
assert_equal 2, array.uniq.size
end
@@ -18,4 +19,3 @@ module Arel
end
end
end
-
diff --git a/activerecord/test/cases/arel/nodes/grouping_test.rb b/activerecord/test/cases/arel/nodes/grouping_test.rb
index 7ad1584f0f..03d5c142d5 100644
--- a/activerecord/test/cases/arel/nodes/grouping_test.rb
+++ b/activerecord/test/cases/arel/nodes/grouping_test.rb
@@ -1,26 +1,26 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
class GroupingTest < Arel::Spec
- it 'should create Equality nodes' do
- grouping = Grouping.new(Nodes.build_quoted('foo'))
- grouping.eq('foo').to_sql.must_be_like %q{('foo') = 'foo'}
+ it "should create Equality nodes" do
+ grouping = Grouping.new(Nodes.build_quoted("foo"))
+ grouping.eq("foo").to_sql.must_be_like "('foo') = 'foo'"
end
- describe 'equality' do
- it 'is equal with equal ivars' do
- array = [Grouping.new('foo'), Grouping.new('foo')]
+ describe "equality" do
+ it "is equal with equal ivars" do
+ array = [Grouping.new("foo"), Grouping.new("foo")]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- array = [Grouping.new('foo'), Grouping.new('bar')]
+ it "is not equal with different ivars" do
+ array = [Grouping.new("foo"), Grouping.new("bar")]
assert_equal 2, array.uniq.size
end
end
end
end
end
-
diff --git a/activerecord/test/cases/arel/nodes/infix_operation_test.rb b/activerecord/test/cases/arel/nodes/infix_operation_test.rb
index 28a4710dc0..dcf2200c12 100644
--- a/activerecord/test/cases/arel/nodes/infix_operation_test.rb
+++ b/activerecord/test/cases/arel/nodes/infix_operation_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
@@ -13,10 +14,10 @@ module Arel
def test_operation_alias
operation = InfixOperation.new :+, 1, 2
- aliaz = operation.as('zomg')
+ aliaz = operation.as("zomg")
assert_kind_of As, aliaz
assert_equal operation, aliaz.left
- assert_equal 'zomg', aliaz.right
+ assert_equal "zomg", aliaz.right
end
def test_operation_ordering
diff --git a/activerecord/test/cases/arel/nodes/insert_statement_test.rb b/activerecord/test/cases/arel/nodes/insert_statement_test.rb
index 87f9d83a32..252a0d0d0b 100644
--- a/activerecord/test/cases/arel/nodes/insert_statement_test.rb
+++ b/activerecord/test/cases/arel/nodes/insert_statement_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
describe Arel::Nodes::InsertStatement do
describe "#clone" do
@@ -17,8 +18,8 @@ describe Arel::Nodes::InsertStatement do
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
+ describe "equality" do
+ it "is equal with equal ivars" do
statement1 = Arel::Nodes::InsertStatement.new
statement1.columns = %w[a b c]
statement1.values = %w[x y z]
@@ -29,7 +30,7 @@ describe Arel::Nodes::InsertStatement do
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
+ it "is not equal with different ivars" do
statement1 = Arel::Nodes::InsertStatement.new
statement1.columns = %w[a b c]
statement1.values = %w[x y z]
diff --git a/activerecord/test/cases/arel/nodes/named_function_test.rb b/activerecord/test/cases/arel/nodes/named_function_test.rb
index 30f6dac595..dbd7ae43be 100644
--- a/activerecord/test/cases/arel/nodes/named_function_test.rb
+++ b/activerecord/test/cases/arel/nodes/named_function_test.rb
@@ -1,44 +1,45 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
class TestNamedFunction < Arel::Test
def test_construct
- function = NamedFunction.new 'omg', 'zomg'
- assert_equal 'omg', function.name
- assert_equal 'zomg', function.expressions
+ function = NamedFunction.new "omg", "zomg"
+ assert_equal "omg", function.name
+ assert_equal "zomg", function.expressions
end
def test_function_alias
- function = NamedFunction.new 'omg', 'zomg'
- function = function.as('wth')
- assert_equal 'omg', function.name
- assert_equal 'zomg', function.expressions
+ function = NamedFunction.new "omg", "zomg"
+ function = function.as("wth")
+ assert_equal "omg", function.name
+ assert_equal "zomg", function.expressions
assert_kind_of SqlLiteral, function.alias
- assert_equal 'wth', function.alias
+ assert_equal "wth", function.alias
end
def test_construct_with_alias
- function = NamedFunction.new 'omg', 'zomg', 'wth'
- assert_equal 'omg', function.name
- assert_equal 'zomg', function.expressions
+ function = NamedFunction.new "omg", "zomg", "wth"
+ assert_equal "omg", function.name
+ assert_equal "zomg", function.expressions
assert_kind_of SqlLiteral, function.alias
- assert_equal 'wth', function.alias
+ assert_equal "wth", function.alias
end
def test_equality_with_same_ivars
array = [
- NamedFunction.new('omg', 'zomg', 'wth'),
- NamedFunction.new('omg', 'zomg', 'wth')
+ NamedFunction.new("omg", "zomg", "wth"),
+ NamedFunction.new("omg", "zomg", "wth")
]
assert_equal 1, array.uniq.size
end
def test_inequality_with_different_ivars
array = [
- NamedFunction.new('omg', 'zomg', 'wth'),
- NamedFunction.new('zomg', 'zomg', 'wth')
+ NamedFunction.new("omg", "zomg", "wth"),
+ NamedFunction.new("zomg", "zomg", "wth")
]
assert_equal 2, array.uniq.size
end
diff --git a/activerecord/test/cases/arel/nodes/node_test.rb b/activerecord/test/cases/arel/nodes/node_test.rb
index c1d3a01d1c..f4f07ef2c5 100644
--- a/activerecord/test/cases/arel/nodes/node_test.rb
+++ b/activerecord/test/cases/arel/nodes/node_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
class TestNode < Arel::Test
diff --git a/activerecord/test/cases/arel/nodes/not_test.rb b/activerecord/test/cases/arel/nodes/not_test.rb
index 15f94a6f10..481e678700 100644
--- a/activerecord/test/cases/arel/nodes/not_test.rb
+++ b/activerecord/test/cases/arel/nodes/not_test.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'not' do
- describe '#not' do
- it 'makes a NOT node' do
+ describe "not" do
+ describe "#not" do
+ it "makes a NOT node" do
attr = Table.new(:users)[:id]
expr = attr.eq(10)
node = expr.not
@@ -14,14 +15,14 @@ module Arel
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
- array = [Not.new('foo'), Not.new('foo')]
+ describe "equality" do
+ it "is equal with equal ivars" do
+ array = [Not.new("foo"), Not.new("foo")]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- array = [Not.new('foo'), Not.new('baz')]
+ it "is not equal with different ivars" do
+ array = [Not.new("foo"), Not.new("baz")]
assert_equal 2, array.uniq.size
end
end
diff --git a/activerecord/test/cases/arel/nodes/or_test.rb b/activerecord/test/cases/arel/nodes/or_test.rb
index 4f8d56d165..93f826740d 100644
--- a/activerecord/test/cases/arel/nodes/or_test.rb
+++ b/activerecord/test/cases/arel/nodes/or_test.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'or' do
- describe '#or' do
- it 'makes an OR node' do
+ describe "or" do
+ describe "#or" do
+ it "makes an OR node" do
attr = Table.new(:users)[:id]
left = attr.eq(10)
right = attr.eq(11)
@@ -19,14 +20,14 @@ module Arel
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
- array = [Or.new('foo', 'bar'), Or.new('foo', 'bar')]
+ describe "equality" do
+ it "is equal with equal ivars" do
+ array = [Or.new("foo", "bar"), Or.new("foo", "bar")]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- array = [Or.new('foo', 'bar'), Or.new('foo', 'baz')]
+ it "is not equal with different ivars" do
+ array = [Or.new("foo", "bar"), Or.new("foo", "baz")]
assert_equal 2, array.uniq.size
end
end
diff --git a/activerecord/test/cases/arel/nodes/over_test.rb b/activerecord/test/cases/arel/nodes/over_test.rb
index c9804c395f..981ec2e34b 100644
--- a/activerecord/test/cases/arel/nodes/over_test.rb
+++ b/activerecord/test/cases/arel/nodes/over_test.rb
@@ -1,36 +1,37 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
class Arel::Nodes::OverTest < Arel::Spec
- describe 'as' do
- it 'should alias the expression' do
+ describe "as" do
+ it "should alias the expression" do
table = Arel::Table.new :users
- table[:id].count.over.as('foo').to_sql.must_be_like %{
+ table[:id].count.over.as("foo").to_sql.must_be_like %{
COUNT("users"."id") OVER () AS foo
}
end
end
- describe 'with literal' do
- it 'should reference the window definition by name' do
+ describe "with literal" do
+ it "should reference the window definition by name" do
table = Arel::Table.new :users
- table[:id].count.over('foo').to_sql.must_be_like %{
+ table[:id].count.over("foo").to_sql.must_be_like %{
COUNT("users"."id") OVER "foo"
}
end
end
- describe 'with SQL literal' do
- it 'should reference the window definition by name' do
+ describe "with SQL literal" do
+ it "should reference the window definition by name" do
table = Arel::Table.new :users
- table[:id].count.over(Arel.sql('foo')).to_sql.must_be_like %{
+ table[:id].count.over(Arel.sql("foo")).to_sql.must_be_like %{
COUNT("users"."id") OVER foo
}
end
end
- describe 'with no expression' do
- it 'should use empty definition' do
+ describe "with no expression" do
+ it "should use empty definition" do
table = Arel::Table.new :users
table[:id].count.over.to_sql.must_be_like %{
COUNT("users"."id") OVER ()
@@ -38,29 +39,29 @@ class Arel::Nodes::OverTest < Arel::Spec
end
end
- describe 'with expression' do
- it 'should use definition in sub-expression' do
+ describe "with expression" do
+ it "should use definition in sub-expression" do
table = Arel::Table.new :users
- window = Arel::Nodes::Window.new.order(table['foo'])
+ window = Arel::Nodes::Window.new.order(table["foo"])
table[:id].count.over(window).to_sql.must_be_like %{
COUNT("users"."id") OVER (ORDER BY \"users\".\"foo\")
}
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
+ describe "equality" do
+ it "is equal with equal ivars" do
array = [
- Arel::Nodes::Over.new('foo', 'bar'),
- Arel::Nodes::Over.new('foo', 'bar')
+ Arel::Nodes::Over.new("foo", "bar"),
+ Arel::Nodes::Over.new("foo", "bar")
]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
+ it "is not equal with different ivars" do
array = [
- Arel::Nodes::Over.new('foo', 'bar'),
- Arel::Nodes::Over.new('foo', 'baz')
+ Arel::Nodes::Over.new("foo", "bar"),
+ Arel::Nodes::Over.new("foo", "baz")
]
assert_equal 2, array.uniq.size
end
diff --git a/activerecord/test/cases/arel/nodes/select_core_test.rb b/activerecord/test/cases/arel/nodes/select_core_test.rb
index bbb06666b6..1cdc7a2360 100644
--- a/activerecord/test/cases/arel/nodes/select_core_test.rb
+++ b/activerecord/test/cases/arel/nodes/select_core_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
@@ -25,7 +26,7 @@ module Arel
core = Arel::Nodes::SelectCore.new
core.set_quantifier = Arel::Nodes::Distinct.new
viz = Arel::Visitors::ToSql.new Table.engine.connection_pool
- assert_match 'DISTINCT', viz.accept(core, Collectors::SQLString.new).value
+ assert_match "DISTINCT", viz.accept(core, Collectors::SQLString.new).value
end
def test_equality_with_same_ivars
diff --git a/activerecord/test/cases/arel/nodes/select_statement_test.rb b/activerecord/test/cases/arel/nodes/select_statement_test.rb
index 5e313e03fa..a91605de3e 100644
--- a/activerecord/test/cases/arel/nodes/select_statement_test.rb
+++ b/activerecord/test/cases/arel/nodes/select_statement_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
describe Arel::Nodes::SelectStatement do
describe "#clone" do
@@ -12,37 +13,37 @@ describe Arel::Nodes::SelectStatement do
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
+ describe "equality" do
+ it "is equal with equal ivars" do
statement1 = Arel::Nodes::SelectStatement.new %w[a b c]
statement1.offset = 1
statement1.limit = 2
statement1.lock = false
statement1.orders = %w[x y z]
- statement1.with = 'zomg'
+ statement1.with = "zomg"
statement2 = Arel::Nodes::SelectStatement.new %w[a b c]
statement2.offset = 1
statement2.limit = 2
statement2.lock = false
statement2.orders = %w[x y z]
- statement2.with = 'zomg'
+ statement2.with = "zomg"
array = [statement1, statement2]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
+ it "is not equal with different ivars" do
statement1 = Arel::Nodes::SelectStatement.new %w[a b c]
statement1.offset = 1
statement1.limit = 2
statement1.lock = false
statement1.orders = %w[x y z]
- statement1.with = 'zomg'
+ statement1.with = "zomg"
statement2 = Arel::Nodes::SelectStatement.new %w[a b c]
statement2.offset = 1
statement2.limit = 2
statement2.lock = false
statement2.orders = %w[x y z]
- statement2.with = 'wth'
+ statement2.with = "wth"
array = [statement1, statement2]
assert_equal 2, array.uniq.size
end
diff --git a/activerecord/test/cases/arel/nodes/sql_literal_test.rb b/activerecord/test/cases/arel/nodes/sql_literal_test.rb
index 0c4f23be78..3b95fed1f4 100644
--- a/activerecord/test/cases/arel/nodes/sql_literal_test.rb
+++ b/activerecord/test/cases/arel/nodes/sql_literal_test.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
-require_relative '../helper'
-require 'yaml'
+
+require_relative "../helper"
+require "yaml"
module Arel
module Nodes
@@ -9,64 +10,64 @@ module Arel
@visitor = Visitors::ToSql.new Table.engine.connection
end
- def compile node
+ def compile(node)
@visitor.accept(node, Collectors::SQLString.new).value
end
- describe 'sql' do
- it 'makes a sql literal node' do
- sql = Arel.sql 'foo'
+ describe "sql" do
+ it "makes a sql literal node" do
+ sql = Arel.sql "foo"
sql.must_be_kind_of Arel::Nodes::SqlLiteral
end
end
- describe 'count' do
- it 'makes a count node' do
- node = SqlLiteral.new('*').count
+ describe "count" do
+ it "makes a count node" do
+ node = SqlLiteral.new("*").count
compile(node).must_be_like %{ COUNT(*) }
end
- it 'makes a distinct node' do
- node = SqlLiteral.new('*').count true
+ it "makes a distinct node" do
+ node = SqlLiteral.new("*").count true
compile(node).must_be_like %{ COUNT(DISTINCT *) }
end
end
- describe 'equality' do
- it 'makes an equality node' do
- node = SqlLiteral.new('foo').eq(1)
+ describe "equality" do
+ it "makes an equality node" do
+ node = SqlLiteral.new("foo").eq(1)
compile(node).must_be_like %{ foo = 1 }
end
- it 'is equal with equal contents' do
- array = [SqlLiteral.new('foo'), SqlLiteral.new('foo')]
+ it "is equal with equal contents" do
+ array = [SqlLiteral.new("foo"), SqlLiteral.new("foo")]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different contents' do
- array = [SqlLiteral.new('foo'), SqlLiteral.new('bar')]
+ it "is not equal with different contents" do
+ array = [SqlLiteral.new("foo"), SqlLiteral.new("bar")]
assert_equal 2, array.uniq.size
end
end
describe 'grouped "or" equality' do
- it 'makes a grouping node with an or node' do
- node = SqlLiteral.new('foo').eq_any([1,2])
+ it "makes a grouping node with an or node" do
+ node = SqlLiteral.new("foo").eq_any([1, 2])
compile(node).must_be_like %{ (foo = 1 OR foo = 2) }
end
end
describe 'grouped "and" equality' do
- it 'makes a grouping node with an and node' do
- node = SqlLiteral.new('foo').eq_all([1,2])
+ it "makes a grouping node with an and node" do
+ node = SqlLiteral.new("foo").eq_all([1, 2])
compile(node).must_be_like %{ (foo = 1 AND foo = 2) }
end
end
- describe 'serialization' do
- it 'serializes into YAML' do
- yaml_literal = SqlLiteral.new('foo').to_yaml
- assert_equal('foo', YAML.load(yaml_literal))
+ describe "serialization" do
+ it "serializes into YAML" do
+ yaml_literal = SqlLiteral.new("foo").to_yaml
+ assert_equal("foo", YAML.load(yaml_literal))
end
end
end
diff --git a/activerecord/test/cases/arel/nodes/sum_test.rb b/activerecord/test/cases/arel/nodes/sum_test.rb
index 46c908d872..5015964951 100644
--- a/activerecord/test/cases/arel/nodes/sum_test.rb
+++ b/activerecord/test/cases/arel/nodes/sum_test.rb
@@ -1,30 +1,31 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
class Arel::Nodes::SumTest < Arel::Spec
describe "as" do
- it 'should alias the sum' do
+ it "should alias the sum" do
table = Arel::Table.new :users
- table[:id].sum.as('foo').to_sql.must_be_like %{
+ table[:id].sum.as("foo").to_sql.must_be_like %{
SUM("users"."id") AS foo
}
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
- array = [Arel::Nodes::Sum.new('foo'), Arel::Nodes::Sum.new('foo')]
+ describe "equality" do
+ it "is equal with equal ivars" do
+ array = [Arel::Nodes::Sum.new("foo"), Arel::Nodes::Sum.new("foo")]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- array = [Arel::Nodes::Sum.new('foo'), Arel::Nodes::Sum.new('foo!')]
+ it "is not equal with different ivars" do
+ array = [Arel::Nodes::Sum.new("foo"), Arel::Nodes::Sum.new("foo!")]
assert_equal 2, array.uniq.size
end
end
-
- describe 'order' do
- it 'should order the sum' do
+
+ describe "order" do
+ it "should order the sum" do
table = Arel::Table.new :users
table[:id].sum.desc.to_sql.must_be_like %{
SUM("users"."id") DESC
diff --git a/activerecord/test/cases/arel/nodes/table_alias_test.rb b/activerecord/test/cases/arel/nodes/table_alias_test.rb
index b1b49919d5..c661b6771e 100644
--- a/activerecord/test/cases/arel/nodes/table_alias_test.rb
+++ b/activerecord/test/cases/arel/nodes/table_alias_test.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'table alias' do
- describe 'equality' do
- it 'is equal with equal ivars' do
+ describe "table alias" do
+ describe "equality" do
+ it "is equal with equal ivars" do
relation1 = Table.new(:users)
node1 = TableAlias.new relation1, :foo
relation2 = Table.new(:users)
@@ -14,7 +15,7 @@ module Arel
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
+ it "is not equal with different ivars" do
relation1 = Table.new(:users)
node1 = TableAlias.new relation1, :foo
relation2 = Table.new(:users)
diff --git a/activerecord/test/cases/arel/nodes/true_test.rb b/activerecord/test/cases/arel/nodes/true_test.rb
index 198e7b1aa4..1e85fe7d48 100644
--- a/activerecord/test/cases/arel/nodes/true_test.rb
+++ b/activerecord/test/cases/arel/nodes/true_test.rb
@@ -1,16 +1,17 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'True' do
- describe 'equality' do
- it 'is equal to other true nodes' do
+ describe "True" do
+ describe "equality" do
+ it "is equal to other true nodes" do
array = [True.new, True.new]
assert_equal 1, array.uniq.size
end
- it 'is not equal with other nodes' do
+ it "is not equal with other nodes" do
array = [True.new, Node.new]
assert_equal 2, array.uniq.size
end
@@ -18,5 +19,3 @@ module Arel
end
end
end
-
-
diff --git a/activerecord/test/cases/arel/nodes/unary_operation_test.rb b/activerecord/test/cases/arel/nodes/unary_operation_test.rb
index e76b59c8e1..f0dd0c625c 100644
--- a/activerecord/test/cases/arel/nodes/unary_operation_test.rb
+++ b/activerecord/test/cases/arel/nodes/unary_operation_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
@@ -12,10 +13,10 @@ module Arel
def test_operation_alias
operation = UnaryOperation.new :-, 1
- aliaz = operation.as('zomg')
+ aliaz = operation.as("zomg")
assert_kind_of As, aliaz
assert_equal operation, aliaz.left
- assert_equal 'zomg', aliaz.right
+ assert_equal "zomg", aliaz.right
end
def test_operation_ordering
diff --git a/activerecord/test/cases/arel/nodes/update_statement_test.rb b/activerecord/test/cases/arel/nodes/update_statement_test.rb
index 3a635f75d6..a83ce32f68 100644
--- a/activerecord/test/cases/arel/nodes/update_statement_test.rb
+++ b/activerecord/test/cases/arel/nodes/update_statement_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
describe Arel::Nodes::UpdateStatement do
describe "#clone" do
@@ -17,41 +18,41 @@ describe Arel::Nodes::UpdateStatement do
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
+ describe "equality" do
+ it "is equal with equal ivars" do
statement1 = Arel::Nodes::UpdateStatement.new
- statement1.relation = 'zomg'
+ statement1.relation = "zomg"
statement1.wheres = 2
statement1.values = false
statement1.orders = %w[x y z]
statement1.limit = 42
- statement1.key = 'zomg'
+ statement1.key = "zomg"
statement2 = Arel::Nodes::UpdateStatement.new
- statement2.relation = 'zomg'
+ statement2.relation = "zomg"
statement2.wheres = 2
statement2.values = false
statement2.orders = %w[x y z]
statement2.limit = 42
- statement2.key = 'zomg'
+ statement2.key = "zomg"
array = [statement1, statement2]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
+ it "is not equal with different ivars" do
statement1 = Arel::Nodes::UpdateStatement.new
- statement1.relation = 'zomg'
+ statement1.relation = "zomg"
statement1.wheres = 2
statement1.values = false
statement1.orders = %w[x y z]
statement1.limit = 42
- statement1.key = 'zomg'
+ statement1.key = "zomg"
statement2 = Arel::Nodes::UpdateStatement.new
- statement2.relation = 'zomg'
+ statement2.relation = "zomg"
statement2.wheres = 2
statement2.values = false
statement2.orders = %w[x y z]
statement2.limit = 42
- statement2.key = 'wth'
+ statement2.key = "wth"
array = [statement1, statement2]
assert_equal 2, array.uniq.size
end
diff --git a/activerecord/test/cases/arel/nodes/window_test.rb b/activerecord/test/cases/arel/nodes/window_test.rb
index 81ecd5ced8..729b0556a4 100644
--- a/activerecord/test/cases/arel/nodes/window_test.rb
+++ b/activerecord/test/cases/arel/nodes/window_test.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Nodes
- describe 'Window' do
- describe 'equality' do
- it 'is equal with equal ivars' do
+ describe "Window" do
+ describe "equality" do
+ it "is equal with equal ivars" do
window1 = Window.new
window1.orders = [1, 2]
window1.partitions = [1]
@@ -18,7 +19,7 @@ module Arel
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
+ it "is not equal with different ivars" do
window1 = Window.new
window1.orders = [1, 2]
window1.partitions = [1]
@@ -33,14 +34,14 @@ module Arel
end
end
- describe 'NamedWindow' do
- describe 'equality' do
- it 'is equal with equal ivars' do
- window1 = NamedWindow.new 'foo'
+ describe "NamedWindow" do
+ describe "equality" do
+ it "is equal with equal ivars" do
+ window1 = NamedWindow.new "foo"
window1.orders = [1, 2]
window1.partitions = [1]
window1.frame 3
- window2 = NamedWindow.new 'foo'
+ window2 = NamedWindow.new "foo"
window2.orders = [1, 2]
window2.partitions = [1]
window2.frame 3
@@ -48,12 +49,12 @@ module Arel
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
- window1 = NamedWindow.new 'foo'
+ it "is not equal with different ivars" do
+ window1 = NamedWindow.new "foo"
window1.orders = [1, 2]
window1.partitions = [1]
window1.frame 3
- window2 = NamedWindow.new 'bar'
+ window2 = NamedWindow.new "bar"
window2.orders = [1, 2]
window2.partitions = [1]
window2.frame 3
@@ -63,14 +64,14 @@ module Arel
end
end
- describe 'CurrentRow' do
- describe 'equality' do
- it 'is equal to other current row nodes' do
+ describe "CurrentRow" do
+ describe "equality" do
+ it "is equal to other current row nodes" do
array = [CurrentRow.new, CurrentRow.new]
assert_equal 1, array.uniq.size
end
- it 'is not equal with other nodes' do
+ it "is not equal with other nodes" do
array = [CurrentRow.new, Node.new]
assert_equal 2, array.uniq.size
end
diff --git a/activerecord/test/cases/arel/nodes_test.rb b/activerecord/test/cases/arel/nodes_test.rb
index 1934ef4c3b..9021de0d20 100644
--- a/activerecord/test/cases/arel/nodes_test.rb
+++ b/activerecord/test/cases/arel/nodes_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
+
+require_relative "helper"
module Arel
module Nodes
@@ -24,12 +25,10 @@ module Arel
eqeq_owner == hash_owner
end
- problem_msg = 'Some subclasses of Arel::Nodes::Node do not have a' \
- ' #== or #eql? or #hash defined from the same class as the others'
+ problem_msg = "Some subclasses of Arel::Nodes::Node do not have a" \
+ " #== or #eql? or #hash defined from the same class as the others"
assert_empty bad_node_descendants, problem_msg
end
-
-
end
end
end
diff --git a/activerecord/test/cases/arel/select_manager_test.rb b/activerecord/test/cases/arel/select_manager_test.rb
index e9056953d8..1bc9f6abf2 100644
--- a/activerecord/test/cases/arel/select_manager_test.rb
+++ b/activerecord/test/cases/arel/select_manager_test.rb
@@ -1,18 +1,18 @@
# frozen_string_literal: true
-require_relative 'helper'
-module Arel
+require_relative "helper"
+module Arel
class SelectManagerTest < Arel::Spec
def test_join_sources
manager = Arel::SelectManager.new
- manager.join_sources << Arel::Nodes::StringJoin.new(Nodes.build_quoted('foo'))
+ manager.join_sources << Arel::Nodes::StringJoin.new(Nodes.build_quoted("foo"))
assert_equal "SELECT FROM 'foo'", manager.to_sql
end
- describe 'backwards compatibility' do
- describe 'project' do
- it 'accepts symbols as sql literals' do
+ describe "backwards compatibility" do
+ describe "project" do
+ it "accepts symbols as sql literals" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.project :id
@@ -23,19 +23,19 @@ module Arel
end
end
- describe 'order' do
- it 'accepts symbols' do
+ describe "order" do
+ it "accepts symbols" do
table = Table.new :users
manager = Arel::SelectManager.new
- manager.project Nodes::SqlLiteral.new '*'
+ manager.project Nodes::SqlLiteral.new "*"
manager.from table
manager.order :foo
manager.to_sql.must_be_like %{ SELECT * FROM "users" ORDER BY foo }
end
end
- describe 'group' do
- it 'takes a symbol' do
+ describe "group" do
+ it "takes a symbol" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
@@ -44,55 +44,55 @@ module Arel
end
end
- describe 'as' do
- it 'makes an AS node by grouping the AST' do
+ describe "as" do
+ it "makes an AS node by grouping the AST" do
manager = Arel::SelectManager.new
- as = manager.as(Arel.sql('foo'))
+ as = manager.as(Arel.sql("foo"))
assert_kind_of Arel::Nodes::Grouping, as.left
assert_equal manager.ast, as.left.expr
- assert_equal 'foo', as.right
+ assert_equal "foo", as.right
end
- it 'converts right to SqlLiteral if a string' do
+ it "converts right to SqlLiteral if a string" do
manager = Arel::SelectManager.new
- as = manager.as('foo')
+ as = manager.as("foo")
assert_kind_of Arel::Nodes::SqlLiteral, as.right
end
- it 'can make a subselect' do
+ it "can make a subselect" do
manager = Arel::SelectManager.new
manager.project Arel.star
- manager.from Arel.sql('zomg')
- as = manager.as(Arel.sql('foo'))
+ manager.from Arel.sql("zomg")
+ as = manager.as(Arel.sql("foo"))
manager = Arel::SelectManager.new
- manager.project Arel.sql('name')
+ manager.project Arel.sql("name")
manager.from as
manager.to_sql.must_be_like "SELECT name FROM (SELECT * FROM zomg) foo"
end
end
- describe 'from' do
- it 'ignores strings when table of same name exists' do
+ describe "from" do
+ it "ignores strings when table of same name exists" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.from 'users'
- manager.project table['id']
+ manager.from "users"
+ manager.project table["id"]
manager.to_sql.must_be_like 'SELECT "users"."id" FROM users'
end
- it 'should support any ast' do
- table = Table.new :users
+ it "should support any ast" do
+ table = Table.new :users
manager1 = Arel::SelectManager.new
manager2 = Arel::SelectManager.new
- manager2.project(Arel.sql('*'))
+ manager2.project(Arel.sql("*"))
manager2.from table
- manager1.project Arel.sql('lol')
- as = manager2.as Arel.sql('omg')
+ manager1.project Arel.sql("lol")
+ as = manager2.as Arel.sql("omg")
manager1.from(as)
manager1.to_sql.must_be_like %{
@@ -101,32 +101,32 @@ module Arel
end
end
- describe 'having' do
- it 'converts strings to SQLLiterals' do
- table = Table.new :users
+ describe "having" do
+ it "converts strings to SQLLiterals" do
+ table = Table.new :users
mgr = table.from
- mgr.having Arel.sql('foo')
+ mgr.having Arel.sql("foo")
mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo }
end
- it 'can have multiple items specified separately' do
+ it "can have multiple items specified separately" do
table = Table.new :users
mgr = table.from
- mgr.having Arel.sql('foo')
- mgr.having Arel.sql('bar')
+ mgr.having Arel.sql("foo")
+ mgr.having Arel.sql("bar")
mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo AND bar }
end
- it 'can receive any node' do
+ it "can receive any node" do
table = Table.new :users
mgr = table.from
- mgr.having Arel::Nodes::And.new([Arel.sql('foo'), Arel.sql('bar')])
+ mgr.having Arel::Nodes::And.new([Arel.sql("foo"), Arel.sql("bar")])
mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo AND bar }
end
end
- describe 'on' do
- it 'converts to sqlliterals' do
+ describe "on" do
+ it "converts to sqlliterals" do
table = Table.new :users
right = table.alias
mgr = table.from
@@ -134,7 +134,7 @@ module Arel
mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg }
end
- it 'converts to sqlliterals with multiple items' do
+ it "converts to sqlliterals with multiple items" do
table = Table.new :users
right = table.alias
mgr = table.from
@@ -144,17 +144,17 @@ module Arel
end
end
- describe 'clone' do
- it 'creates new cores' do
- table = Table.new :users, :as => 'foo'
+ describe "clone" do
+ it "creates new cores" do
+ table = Table.new :users, as: "foo"
mgr = table.from
m2 = mgr.clone
m2.project "foo"
mgr.to_sql.wont_equal m2.to_sql
end
- it 'makes updates to the correct copy' do
- table = Table.new :users, :as => 'foo'
+ it "makes updates to the correct copy" do
+ table = Table.new :users, as: "foo"
mgr = table.from
m2 = mgr.clone
m3 = m2.clone
@@ -164,40 +164,40 @@ module Arel
end
end
- describe 'initialize' do
- it 'uses alias in sql' do
- table = Table.new :users, :as => 'foo'
+ describe "initialize" do
+ it "uses alias in sql" do
+ table = Table.new :users, as: "foo"
mgr = table.from
mgr.skip 10
mgr.to_sql.must_be_like %{ SELECT FROM "users" "foo" OFFSET 10 }
end
end
- describe 'skip' do
- it 'should add an offset' do
- table = Table.new :users
+ describe "skip" do
+ it "should add an offset" do
+ table = Table.new :users
mgr = table.from
mgr.skip 10
mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 }
end
- it 'should chain' do
- table = Table.new :users
+ it "should chain" do
+ table = Table.new :users
mgr = table.from
mgr.skip(10).to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 }
end
end
- describe 'offset' do
- it 'should add an offset' do
- table = Table.new :users
+ describe "offset" do
+ it "should add an offset" do
+ table = Table.new :users
mgr = table.from
mgr.offset = 10
mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 }
end
- it 'should remove an offset' do
- table = Table.new :users
+ it "should remove an offset" do
+ table = Table.new :users
mgr = table.from
mgr.offset = 10
mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 }
@@ -206,35 +206,35 @@ module Arel
mgr.to_sql.must_be_like %{ SELECT FROM "users" }
end
- it 'should return the offset' do
- table = Table.new :users
+ it "should return the offset" do
+ table = Table.new :users
mgr = table.from
mgr.offset = 10
assert_equal 10, mgr.offset
end
end
- describe 'exists' do
- it 'should create an exists clause' do
+ describe "exists" do
+ it "should create an exists clause" do
table = Table.new(:users)
manager = Arel::SelectManager.new table
- manager.project Nodes::SqlLiteral.new '*'
+ manager.project Nodes::SqlLiteral.new "*"
m2 = Arel::SelectManager.new
m2.project manager.exists
m2.to_sql.must_be_like %{ SELECT EXISTS (#{manager.to_sql}) }
end
- it 'can be aliased' do
+ it "can be aliased" do
table = Table.new(:users)
manager = Arel::SelectManager.new table
- manager.project Nodes::SqlLiteral.new '*'
+ manager.project Nodes::SqlLiteral.new "*"
m2 = Arel::SelectManager.new
- m2.project manager.exists.as('foo')
+ m2.project manager.exists.as("foo")
m2.to_sql.must_be_like %{ SELECT EXISTS (#{manager.to_sql}) AS foo }
end
end
- describe 'union' do
+ describe "union" do
before do
table = Table.new :users
@m1 = Arel::SelectManager.new table
@@ -248,7 +248,7 @@ module Arel
end
- it 'should union two managers' do
+ it "should union two managers" do
# FIXME should this union "managers" or "statements" ?
# FIXME this probably shouldn't return a node
node = @m1.union @m2
@@ -259,7 +259,7 @@ module Arel
}
end
- it 'should union all' do
+ it "should union all" do
node = @m1.union :all, @m2
node.to_sql.must_be_like %{
@@ -269,7 +269,7 @@ module Arel
end
- describe 'intersect' do
+ describe "intersect" do
before do
table = Table.new :users
@m1 = Arel::SelectManager.new table
@@ -283,7 +283,7 @@ module Arel
end
- it 'should interect two managers' do
+ it "should interect two managers" do
# FIXME should this intersect "managers" or "statements" ?
# FIXME this probably shouldn't return a node
node = @m1.intersect @m2
@@ -296,7 +296,7 @@ module Arel
end
- describe 'except' do
+ describe "except" do
before do
table = Table.new :users
@m1 = Arel::SelectManager.new table
@@ -308,7 +308,7 @@ module Arel
@m2.where(table[:age].between(40..99))
end
- it 'should except two managers' do
+ it "should except two managers" do
# FIXME should this except "managers" or "statements" ?
# FIXME this probably shouldn't return a node
node = @m1.except @m2
@@ -321,8 +321,8 @@ module Arel
end
- describe 'with' do
- it 'should support basic WITH' do
+ describe "with" do
+ it "should support basic WITH" do
users = Table.new(:users)
users_top = Table.new(:users_top)
comments = Table.new(:comments)
@@ -370,43 +370,43 @@ module Arel
end
end
- describe 'ast' do
- it 'should return the ast' do
- table = Table.new :users
+ describe "ast" do
+ it "should return the ast" do
+ table = Table.new :users
mgr = table.from
assert mgr.ast
end
- it 'should allow orders to work when the ast is grepped' do
- table = Table.new :users
+ it "should allow orders to work when the ast is grepped" do
+ table = Table.new :users
mgr = table.from
- mgr.project Arel.sql '*'
+ mgr.project Arel.sql "*"
mgr.from table
- mgr.orders << Arel::Nodes::Ascending.new(Arel.sql('foo'))
+ mgr.orders << Arel::Nodes::Ascending.new(Arel.sql("foo"))
mgr.ast.grep(Arel::Nodes::OuterJoin)
mgr.to_sql.must_be_like %{ SELECT * FROM "users" ORDER BY foo ASC }
end
end
- describe 'taken' do
- it 'should return limit' do
+ describe "taken" do
+ it "should return limit" do
manager = Arel::SelectManager.new
manager.take 10
manager.taken.must_equal 10
end
end
- describe 'lock' do
+ describe "lock" do
# This should fail on other databases
- it 'adds a lock node' do
- table = Table.new :users
+ it "adds a lock node" do
+ table = Table.new :users
mgr = table.from
mgr.lock.to_sql.must_be_like %{ SELECT FROM "users" FOR UPDATE }
end
end
- describe 'orders' do
- it 'returns order clauses' do
+ describe "orders" do
+ it "returns order clauses" do
table = Table.new :users
manager = Arel::SelectManager.new
order = table[:id]
@@ -415,11 +415,11 @@ module Arel
end
end
- describe 'order' do
- it 'generates order clauses' do
+ describe "order" do
+ it "generates order clauses" do
table = Table.new :users
manager = Arel::SelectManager.new
- manager.project Nodes::SqlLiteral.new '*'
+ manager.project Nodes::SqlLiteral.new "*"
manager.from table
manager.order table[:id]
manager.to_sql.must_be_like %{
@@ -428,10 +428,10 @@ module Arel
end
# FIXME: I would like to deprecate this
- it 'takes *args' do
+ it "takes *args" do
table = Table.new :users
manager = Arel::SelectManager.new
- manager.project Nodes::SqlLiteral.new '*'
+ manager.project Nodes::SqlLiteral.new "*"
manager.from table
manager.order table[:id], table[:name]
manager.to_sql.must_be_like %{
@@ -439,16 +439,16 @@ module Arel
}
end
- it 'chains' do
+ it "chains" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.order(table[:id]).must_equal manager
end
- it 'has order attributes' do
+ it "has order attributes" do
table = Table.new :users
manager = Arel::SelectManager.new
- manager.project Nodes::SqlLiteral.new '*'
+ manager.project Nodes::SqlLiteral.new "*"
manager.from table
manager.order table[:id].desc
manager.to_sql.must_be_like %{
@@ -457,8 +457,8 @@ module Arel
end
end
- describe 'on' do
- it 'takes two params' do
+ describe "on" do
+ it "takes two params" do
left = Table.new :users
right = left.alias
predicate = left[:id].eq(right[:id])
@@ -474,7 +474,7 @@ module Arel
}
end
- it 'takes three params' do
+ it "takes three params" do
left = Table.new :users
right = left.alias
predicate = left[:id].eq(right[:id])
@@ -496,59 +496,59 @@ module Arel
end
end
- it 'should hand back froms' do
+ it "should hand back froms" do
relation = Arel::SelectManager.new
assert_equal [], relation.froms
end
- it 'should create and nodes' do
+ it "should create and nodes" do
relation = Arel::SelectManager.new
- children = ['foo', 'bar', 'baz']
+ children = ["foo", "bar", "baz"]
clause = relation.create_and children
assert_kind_of Arel::Nodes::And, clause
assert_equal children, clause.children
end
- it 'should create insert managers' do
+ it "should create insert managers" do
relation = Arel::SelectManager.new
insert = relation.create_insert
assert_kind_of Arel::InsertManager, insert
end
- it 'should create join nodes' do
+ it "should create join nodes" do
relation = Arel::SelectManager.new
- join = relation.create_join 'foo', 'bar'
+ join = relation.create_join "foo", "bar"
assert_kind_of Arel::Nodes::InnerJoin, join
- assert_equal 'foo', join.left
- assert_equal 'bar', join.right
+ assert_equal "foo", join.left
+ assert_equal "bar", join.right
end
- it 'should create join nodes with a full outer join klass' do
+ it "should create join nodes with a full outer join klass" do
relation = Arel::SelectManager.new
- join = relation.create_join 'foo', 'bar', Arel::Nodes::FullOuterJoin
+ join = relation.create_join "foo", "bar", Arel::Nodes::FullOuterJoin
assert_kind_of Arel::Nodes::FullOuterJoin, join
- assert_equal 'foo', join.left
- assert_equal 'bar', join.right
+ assert_equal "foo", join.left
+ assert_equal "bar", join.right
end
- it 'should create join nodes with a outer join klass' do
+ it "should create join nodes with a outer join klass" do
relation = Arel::SelectManager.new
- join = relation.create_join 'foo', 'bar', Arel::Nodes::OuterJoin
+ join = relation.create_join "foo", "bar", Arel::Nodes::OuterJoin
assert_kind_of Arel::Nodes::OuterJoin, join
- assert_equal 'foo', join.left
- assert_equal 'bar', join.right
+ assert_equal "foo", join.left
+ assert_equal "bar", join.right
end
- it 'should create join nodes with a right outer join klass' do
+ it "should create join nodes with a right outer join klass" do
relation = Arel::SelectManager.new
- join = relation.create_join 'foo', 'bar', Arel::Nodes::RightOuterJoin
+ join = relation.create_join "foo", "bar", Arel::Nodes::RightOuterJoin
assert_kind_of Arel::Nodes::RightOuterJoin, join
- assert_equal 'foo', join.left
- assert_equal 'bar', join.right
+ assert_equal "foo", join.left
+ assert_equal "bar", join.right
end
- describe 'join' do
- it 'responds to join' do
+ describe "join" do
+ it "responds to join" do
left = Table.new :users
right = left.alias
predicate = left[:id].eq(right[:id])
@@ -563,7 +563,7 @@ module Arel
}
end
- it 'takes a class' do
+ it "takes a class" do
left = Table.new :users
right = left.alias
predicate = left[:id].eq(right[:id])
@@ -578,7 +578,7 @@ module Arel
}
end
- it 'takes the full outer join class' do
+ it "takes the full outer join class" do
left = Table.new :users
right = left.alias
predicate = left[:id].eq(right[:id])
@@ -593,7 +593,7 @@ module Arel
}
end
- it 'takes the right outer join class' do
+ it "takes the right outer join class" do
left = Table.new :users
right = left.alias
predicate = left[:id].eq(right[:id])
@@ -608,12 +608,12 @@ module Arel
}
end
- it 'noops on nil' do
- manager = Arel::SelectManager.new
+ it "noops on nil" do
+ manager = Arel::SelectManager.new
manager.join(nil).must_equal manager
end
- it 'raises EmptyJoinError on empty' do
+ it "raises EmptyJoinError on empty" do
left = Table.new :users
manager = Arel::SelectManager.new
@@ -624,8 +624,8 @@ module Arel
end
end
- describe 'outer join' do
- it 'responds to join' do
+ describe "outer join" do
+ it "responds to join" do
left = Table.new :users
right = left.alias
predicate = left[:id].eq(right[:id])
@@ -640,15 +640,15 @@ module Arel
}
end
- it 'noops on nil' do
- manager = Arel::SelectManager.new
+ it "noops on nil" do
+ manager = Arel::SelectManager.new
manager.outer_join(nil).must_equal manager
end
end
- describe 'joins' do
+ describe "joins" do
- it 'returns inner join sql' do
+ it "returns inner join sql" do
table = Table.new :users
aliaz = table.alias
manager = Arel::SelectManager.new
@@ -657,7 +657,7 @@ module Arel
manager.to_sql
end
- it 'returns outer join sql' do
+ it "returns outer join sql" do
table = Table.new :users
aliaz = table.alias
manager = Arel::SelectManager.new
@@ -666,7 +666,7 @@ module Arel
manager.to_sql
end
- it 'can have a non-table alias as relation name' do
+ it "can have a non-table alias as relation name" do
users = Table.new :users
comments = Table.new :comments
@@ -678,7 +678,7 @@ module Arel
).as("counts")
joins = users.join(counts).on(counts[:user_id].eq(10))
- joins.to_sql.must_be_like %{
+ joins.to_sql.must_be_like %{
SELECT FROM "users" INNER JOIN (SELECT "comments"."user_id" AS user_id, COUNT("comments"."user_id") AS count FROM "comments" GROUP BY "comments"."user_id") counts ON counts."user_id" = 10
}
end
@@ -689,7 +689,7 @@ module Arel
predicate = left[:id].eq(right[:id])
mgr = left.join(right)
- mgr.project Nodes::SqlLiteral.new('*')
+ mgr.project Nodes::SqlLiteral.new("*")
mgr.on(predicate).must_equal mgr
mgr.to_sql.must_be_like %{
@@ -699,15 +699,15 @@ module Arel
}
end
- it 'returns string join sql' do
+ it "returns string join sql" do
manager = Arel::SelectManager.new
- manager.from Nodes::StringJoin.new(Nodes.build_quoted('hello'))
+ manager.from Nodes::StringJoin.new(Nodes.build_quoted("hello"))
assert_match "'hello'", manager.to_sql
end
end
- describe 'group' do
- it 'takes an attribute' do
+ describe "group" do
+ it "takes an attribute" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
@@ -717,13 +717,13 @@ module Arel
}
end
- it 'chains' do
+ it "chains" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.group(table[:id]).must_equal manager
end
- it 'takes multiple args' do
+ it "takes multiple args" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
@@ -734,132 +734,132 @@ module Arel
end
# FIXME: backwards compat
- it 'makes strings literals' do
+ it "makes strings literals" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.group 'foo'
+ manager.group "foo"
manager.to_sql.must_be_like %{ SELECT FROM "users" GROUP BY foo }
end
end
- describe 'window definition' do
- it 'can be empty' do
+ describe "window definition" do
+ it "can be empty" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window')
+ manager.window("a_window")
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS ()
}
end
- it 'takes an order' do
+ it "takes an order" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').order(table['foo'].asc)
+ manager.window("a_window").order(table["foo"].asc)
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ORDER BY "users"."foo" ASC)
}
end
- it 'takes an order with multiple columns' do
+ it "takes an order with multiple columns" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').order(table['foo'].asc, table['bar'].desc)
+ manager.window("a_window").order(table["foo"].asc, table["bar"].desc)
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ORDER BY "users"."foo" ASC, "users"."bar" DESC)
}
end
- it 'takes a partition' do
+ it "takes a partition" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').partition(table['bar'])
+ manager.window("a_window").partition(table["bar"])
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."bar")
}
end
- it 'takes a partition and an order' do
+ it "takes a partition and an order" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').partition(table['foo']).order(table['foo'].asc)
+ manager.window("a_window").partition(table["foo"]).order(table["foo"].asc)
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."foo"
ORDER BY "users"."foo" ASC)
}
end
- it 'takes a partition with multiple columns' do
+ it "takes a partition with multiple columns" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').partition(table['bar'], table['baz'])
+ manager.window("a_window").partition(table["bar"], table["baz"])
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."bar", "users"."baz")
}
end
- it 'takes a rows frame, unbounded preceding' do
+ it "takes a rows frame, unbounded preceding" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').rows(Arel::Nodes::Preceding.new)
+ manager.window("a_window").rows(Arel::Nodes::Preceding.new)
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS UNBOUNDED PRECEDING)
}
end
- it 'takes a rows frame, bounded preceding' do
+ it "takes a rows frame, bounded preceding" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').rows(Arel::Nodes::Preceding.new(5))
+ manager.window("a_window").rows(Arel::Nodes::Preceding.new(5))
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS 5 PRECEDING)
}
end
- it 'takes a rows frame, unbounded following' do
+ it "takes a rows frame, unbounded following" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').rows(Arel::Nodes::Following.new)
+ manager.window("a_window").rows(Arel::Nodes::Following.new)
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS UNBOUNDED FOLLOWING)
}
end
- it 'takes a rows frame, bounded following' do
+ it "takes a rows frame, bounded following" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').rows(Arel::Nodes::Following.new(5))
+ manager.window("a_window").rows(Arel::Nodes::Following.new(5))
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS 5 FOLLOWING)
}
end
- it 'takes a rows frame, current row' do
+ it "takes a rows frame, current row" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').rows(Arel::Nodes::CurrentRow.new)
+ manager.window("a_window").rows(Arel::Nodes::CurrentRow.new)
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (ROWS CURRENT ROW)
}
end
- it 'takes a rows frame, between two delimiters' do
+ it "takes a rows frame, between two delimiters" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- window = manager.window('a_window')
+ window = manager.window("a_window")
window.frame(
Arel::Nodes::Between.new(
window.rows,
@@ -872,61 +872,61 @@ module Arel
}
end
- it 'takes a range frame, unbounded preceding' do
+ it "takes a range frame, unbounded preceding" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').range(Arel::Nodes::Preceding.new)
+ manager.window("a_window").range(Arel::Nodes::Preceding.new)
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE UNBOUNDED PRECEDING)
}
end
- it 'takes a range frame, bounded preceding' do
+ it "takes a range frame, bounded preceding" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').range(Arel::Nodes::Preceding.new(5))
+ manager.window("a_window").range(Arel::Nodes::Preceding.new(5))
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE 5 PRECEDING)
}
end
- it 'takes a range frame, unbounded following' do
+ it "takes a range frame, unbounded following" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').range(Arel::Nodes::Following.new)
+ manager.window("a_window").range(Arel::Nodes::Following.new)
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE UNBOUNDED FOLLOWING)
}
end
- it 'takes a range frame, bounded following' do
+ it "takes a range frame, bounded following" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').range(Arel::Nodes::Following.new(5))
+ manager.window("a_window").range(Arel::Nodes::Following.new(5))
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE 5 FOLLOWING)
}
end
- it 'takes a range frame, current row' do
+ it "takes a range frame, current row" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.window('a_window').range(Arel::Nodes::CurrentRow.new)
+ manager.window("a_window").range(Arel::Nodes::CurrentRow.new)
manager.to_sql.must_be_like %{
SELECT FROM "users" WINDOW "a_window" AS (RANGE CURRENT ROW)
}
end
- it 'takes a range frame, between two delimiters' do
+ it "takes a range frame, between two delimiters" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- window = manager.window('a_window')
+ window = manager.window("a_window")
window.frame(
Arel::Nodes::Between.new(
window.range,
@@ -940,7 +940,7 @@ module Arel
end
end
- describe 'delete' do
+ describe "delete" do
it "copies from" do
table = Table.new :users
manager = Arel::SelectManager.new
@@ -963,8 +963,8 @@ module Arel
end
end
- describe 'where_sql' do
- it 'gives me back the where sql' do
+ describe "where_sql" do
+ it "gives me back the where sql" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
@@ -972,7 +972,7 @@ module Arel
manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 }
end
- it 'joins wheres with AND' do
+ it "joins wheres with AND" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
@@ -981,19 +981,19 @@ module Arel
manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 AND "users"."id" = 11}
end
- it 'handles database specific statements' do
+ it "handles database specific statements" do
old_visitor = Table.engine.connection.visitor
Table.engine.connection.visitor = Visitors::PostgreSQL.new Table.engine.connection
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
manager.where table[:id].eq 10
- manager.where table[:name].matches 'foo%'
+ manager.where table[:name].matches "foo%"
manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 AND "users"."name" ILIKE 'foo%' }
Table.engine.connection.visitor = old_visitor
end
- it 'returns nil when there are no wheres' do
+ it "returns nil when there are no wheres" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
@@ -1001,35 +1001,35 @@ module Arel
end
end
- describe 'update' do
+ describe "update" do
- it 'creates an update statement' do
+ it "creates an update statement" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- stmt = manager.compile_update({table[:id] => 1}, Arel::Attributes::Attribute.new(table, 'id'))
+ stmt = manager.compile_update({ table[:id] => 1 }, Arel::Attributes::Attribute.new(table, "id"))
stmt.to_sql.must_be_like %{
UPDATE "users" SET "id" = 1
}
end
- it 'takes a string' do
+ it "takes a string" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- stmt = manager.compile_update(Nodes::SqlLiteral.new('foo = bar'), Arel::Attributes::Attribute.new(table, 'id'))
+ stmt = manager.compile_update(Nodes::SqlLiteral.new("foo = bar"), Arel::Attributes::Attribute.new(table, "id"))
stmt.to_sql.must_be_like %{ UPDATE "users" SET foo = bar }
end
- it 'copies limits' do
+ it "copies limits" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
manager.take 1
- stmt = manager.compile_update(Nodes::SqlLiteral.new('foo = bar'), Arel::Attributes::Attribute.new(table, 'id'))
- stmt.key = table['id']
+ stmt = manager.compile_update(Nodes::SqlLiteral.new("foo = bar"), Arel::Attributes::Attribute.new(table, "id"))
+ stmt.key = table["id"]
stmt.to_sql.must_be_like %{
UPDATE "users" SET foo = bar
@@ -1037,13 +1037,13 @@ module Arel
}
end
- it 'copies order' do
+ it "copies order" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
manager.order :foo
- stmt = manager.compile_update(Nodes::SqlLiteral.new('foo = bar'), Arel::Attributes::Attribute.new(table, 'id'))
- stmt.key = table['id']
+ stmt = manager.compile_update(Nodes::SqlLiteral.new("foo = bar"), Arel::Attributes::Attribute.new(table, "id"))
+ stmt.key = table["id"]
stmt.to_sql.must_be_like %{
UPDATE "users" SET foo = bar
@@ -1051,25 +1051,25 @@ module Arel
}
end
- it 'copies where clauses' do
+ it "copies where clauses" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.where table[:id].eq 10
manager.from table
- stmt = manager.compile_update({table[:id] => 1}, Arel::Attributes::Attribute.new(table, 'id'))
+ stmt = manager.compile_update({ table[:id] => 1 }, Arel::Attributes::Attribute.new(table, "id"))
stmt.to_sql.must_be_like %{
UPDATE "users" SET "id" = 1 WHERE "users"."id" = 10
}
end
- it 'copies where clauses when nesting is triggered' do
+ it "copies where clauses when nesting is triggered" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.where table[:foo].eq 10
manager.take 42
manager.from table
- stmt = manager.compile_update({table[:id] => 1}, Arel::Attributes::Attribute.new(table, 'id'))
+ stmt = manager.compile_update({ table[:id] => 1 }, Arel::Attributes::Attribute.new(table, "id"))
stmt.to_sql.must_be_like %{
UPDATE "users" SET "id" = 1 WHERE "users"."id" IN (SELECT "users"."id" FROM "users" WHERE "users"."foo" = 10 LIMIT 42)
@@ -1078,51 +1078,51 @@ module Arel
end
- describe 'project' do
+ describe "project" do
it "takes sql literals" do
manager = Arel::SelectManager.new
- manager.project Nodes::SqlLiteral.new '*'
+ manager.project Nodes::SqlLiteral.new "*"
manager.to_sql.must_be_like %{ SELECT * }
end
- it 'takes multiple args' do
+ it "takes multiple args" do
manager = Arel::SelectManager.new
- manager.project Nodes::SqlLiteral.new('foo'),
- Nodes::SqlLiteral.new('bar')
+ manager.project Nodes::SqlLiteral.new("foo"),
+ Nodes::SqlLiteral.new("bar")
manager.to_sql.must_be_like %{ SELECT foo, bar }
end
- it 'takes strings' do
+ it "takes strings" do
manager = Arel::SelectManager.new
- manager.project '*'
+ manager.project "*"
manager.to_sql.must_be_like %{ SELECT * }
end
end
- describe 'projections' do
- it 'reads projections' do
+ describe "projections" do
+ it "reads projections" do
manager = Arel::SelectManager.new
- manager.project Arel.sql('foo'), Arel.sql('bar')
- manager.projections.must_equal [Arel.sql('foo'), Arel.sql('bar')]
+ manager.project Arel.sql("foo"), Arel.sql("bar")
+ manager.projections.must_equal [Arel.sql("foo"), Arel.sql("bar")]
end
end
- describe 'projections=' do
- it 'overwrites projections' do
+ describe "projections=" do
+ it "overwrites projections" do
manager = Arel::SelectManager.new
- manager.project Arel.sql('foo')
- manager.projections = [Arel.sql('bar')]
+ manager.project Arel.sql("foo")
+ manager.projections = [Arel.sql("bar")]
manager.to_sql.must_be_like %{ SELECT bar }
end
end
- describe 'take' do
+ describe "take" do
it "knows take" do
table = Table.new :users
manager = Arel::SelectManager.new
- manager.from(table).project(table['id'])
- manager.where(table['id'].eq(1))
+ manager.from(table).project(table["id"])
+ manager.where(table["id"].eq(1))
manager.take 1
manager.to_sql.must_be_like %{
@@ -1138,22 +1138,22 @@ module Arel
manager.take(1).must_equal manager
end
- it 'removes LIMIT when nil is passed' do
+ it "removes LIMIT when nil is passed" do
manager = Arel::SelectManager.new
manager.limit = 10
- assert_match('LIMIT', manager.to_sql)
+ assert_match("LIMIT", manager.to_sql)
manager.limit = nil
- refute_match('LIMIT', manager.to_sql)
+ refute_match("LIMIT", manager.to_sql)
end
end
- describe 'where' do
+ describe "where" do
it "knows where" do
table = Table.new :users
manager = Arel::SelectManager.new
- manager.from(table).project(table['id'])
- manager.where(table['id'].eq(1))
+ manager.from(table).project(table["id"])
+ manager.where(table["id"].eq(1))
manager.to_sql.must_be_like %{
SELECT "users"."id"
FROM "users"
@@ -1165,37 +1165,37 @@ module Arel
table = Table.new :users
manager = Arel::SelectManager.new
manager.from(table)
- manager.project(table['id']).where(table['id'].eq 1).must_equal manager
+ manager.project(table["id"]).where(table["id"].eq 1).must_equal manager
end
end
- describe 'from' do
+ describe "from" do
it "makes sql" do
table = Table.new :users
manager = Arel::SelectManager.new
manager.from table
- manager.project table['id']
+ manager.project table["id"]
manager.to_sql.must_be_like 'SELECT "users"."id" FROM "users"'
end
it "chains" do
table = Table.new :users
manager = Arel::SelectManager.new
- manager.from(table).project(table['id']).must_equal manager
+ manager.from(table).project(table["id"]).must_equal manager
manager.to_sql.must_be_like 'SELECT "users"."id" FROM "users"'
end
end
- describe 'source' do
- it 'returns the join source of the select core' do
+ describe "source" do
+ it "returns the join source of the select core" do
manager = Arel::SelectManager.new
manager.source.must_equal manager.ast.cores.last.source
end
end
- describe 'distinct' do
- it 'sets the quantifier' do
+ describe "distinct" do
+ it "sets the quantifier" do
manager = Arel::SelectManager.new
manager.distinct
@@ -1212,13 +1212,13 @@ module Arel
end
end
- describe 'distinct_on' do
- it 'sets the quantifier' do
+ describe "distinct_on" do
+ it "sets the quantifier" do
manager = Arel::SelectManager.new
table = Table.new :users
- manager.distinct_on(table['id'])
- manager.ast.cores.last.set_quantifier.must_equal Arel::Nodes::DistinctOn.new(table['id'])
+ manager.distinct_on(table["id"])
+ manager.ast.cores.last.set_quantifier.must_equal Arel::Nodes::DistinctOn.new(table["id"])
manager.distinct_on(false)
manager.ast.cores.last.set_quantifier.must_be_nil
@@ -1228,7 +1228,7 @@ module Arel
manager = Arel::SelectManager.new
table = Table.new :users
- manager.distinct_on(table['id']).must_equal manager
+ manager.distinct_on(table["id"]).must_equal manager
manager.distinct_on(false).must_equal manager
end
end
diff --git a/activerecord/test/cases/arel/support/fake_record.rb b/activerecord/test/cases/arel/support/fake_record.rb
index 75ac1e072f..8620d6fd34 100644
--- a/activerecord/test/cases/arel/support/fake_record.rb
+++ b/activerecord/test/cases/arel/support/fake_record.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'date'
+require "date"
module FakeRecord
class Column < Struct.new(:name, :type)
end
@@ -12,49 +12,49 @@ module FakeRecord
def initialize(visitor = nil)
@tables = %w{ users photos developers products}
@columns = {
- 'users' => [
- Column.new('id', :integer),
- Column.new('name', :string),
- Column.new('bool', :boolean),
- Column.new('created_at', :date)
+ "users" => [
+ Column.new("id", :integer),
+ Column.new("name", :string),
+ Column.new("bool", :boolean),
+ Column.new("created_at", :date)
],
- 'products' => [
- Column.new('id', :integer),
- Column.new('price', :decimal)
+ "products" => [
+ Column.new("id", :integer),
+ Column.new("price", :decimal)
]
}
@columns_hash = {
- 'users' => Hash[@columns['users'].map { |x| [x.name, x] }],
- 'products' => Hash[@columns['products'].map { |x| [x.name, x] }]
+ "users" => Hash[@columns["users"].map { |x| [x.name, x] }],
+ "products" => Hash[@columns["products"].map { |x| [x.name, x] }]
}
@primary_keys = {
- 'users' => 'id',
- 'products' => 'id'
+ "users" => "id",
+ "products" => "id"
}
@visitor = visitor
end
- def columns_hash table_name
+ def columns_hash(table_name)
@columns_hash[table_name]
end
- def primary_key name
+ def primary_key(name)
@primary_keys[name.to_s]
end
- def data_source_exists? name
+ def data_source_exists?(name)
@tables.include? name.to_s
end
- def columns name, message = nil
+ def columns(name, message = nil)
@columns[name.to_s]
end
- def quote_table_name name
+ def quote_table_name(name)
"\"#{name.to_s}\""
end
- def quote_column_name name
+ def quote_column_name(name)
"\"#{name.to_s}\""
end
@@ -62,7 +62,7 @@ module FakeRecord
self
end
- def quote thing
+ def quote(thing)
case thing
when DateTime
"'#{thing.strftime("%Y-%m-%d %H:%M:%S")}'"
@@ -73,7 +73,7 @@ module FakeRecord
when false
"'f'"
when nil
- 'NULL'
+ "NULL"
when Numeric
thing
else
@@ -89,7 +89,7 @@ module FakeRecord
attr_reader :spec, :connection
def initialize
- @spec = Spec.new(:adapter => 'america')
+ @spec = Spec.new(adapter: "america")
@connection = Connection.new
@connection.visitor = Arel::Visitors::ToSql.new(connection)
end
@@ -98,7 +98,7 @@ module FakeRecord
yield connection
end
- def table_exists? name
+ def table_exists?(name)
connection.tables.include? name.to_s
end
@@ -110,7 +110,7 @@ module FakeRecord
connection
end
- def quote thing
+ def quote(thing)
connection.quote thing
end
end
diff --git a/activerecord/test/cases/arel/table_test.rb b/activerecord/test/cases/arel/table_test.rb
index ccb3ab302f..91b7a5a480 100644
--- a/activerecord/test/cases/arel/table_test.rb
+++ b/activerecord/test/cases/arel/table_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative 'helper'
+
+require_relative "helper"
module Arel
class TableTest < Arel::Spec
@@ -7,56 +8,56 @@ module Arel
@relation = Table.new(:users)
end
- it 'should create join nodes' do
- join = @relation.create_string_join 'foo'
+ it "should create join nodes" do
+ join = @relation.create_string_join "foo"
assert_kind_of Arel::Nodes::StringJoin, join
- assert_equal 'foo', join.left
+ assert_equal "foo", join.left
end
- it 'should create join nodes' do
- join = @relation.create_join 'foo', 'bar'
+ it "should create join nodes" do
+ join = @relation.create_join "foo", "bar"
assert_kind_of Arel::Nodes::InnerJoin, join
- assert_equal 'foo', join.left
- assert_equal 'bar', join.right
+ assert_equal "foo", join.left
+ assert_equal "bar", join.right
end
- it 'should create join nodes with a klass' do
- join = @relation.create_join 'foo', 'bar', Arel::Nodes::FullOuterJoin
+ it "should create join nodes with a klass" do
+ join = @relation.create_join "foo", "bar", Arel::Nodes::FullOuterJoin
assert_kind_of Arel::Nodes::FullOuterJoin, join
- assert_equal 'foo', join.left
- assert_equal 'bar', join.right
+ assert_equal "foo", join.left
+ assert_equal "bar", join.right
end
- it 'should create join nodes with a klass' do
- join = @relation.create_join 'foo', 'bar', Arel::Nodes::OuterJoin
+ it "should create join nodes with a klass" do
+ join = @relation.create_join "foo", "bar", Arel::Nodes::OuterJoin
assert_kind_of Arel::Nodes::OuterJoin, join
- assert_equal 'foo', join.left
- assert_equal 'bar', join.right
+ assert_equal "foo", join.left
+ assert_equal "bar", join.right
end
- it 'should create join nodes with a klass' do
- join = @relation.create_join 'foo', 'bar', Arel::Nodes::RightOuterJoin
+ it "should create join nodes with a klass" do
+ join = @relation.create_join "foo", "bar", Arel::Nodes::RightOuterJoin
assert_kind_of Arel::Nodes::RightOuterJoin, join
- assert_equal 'foo', join.left
- assert_equal 'bar', join.right
+ assert_equal "foo", join.left
+ assert_equal "bar", join.right
end
- it 'should return an insert manager' do
- im = @relation.compile_insert 'VALUES(NULL)'
+ it "should return an insert manager" do
+ im = @relation.compile_insert "VALUES(NULL)"
assert_kind_of Arel::InsertManager, im
im.into Table.new(:users)
assert_equal "INSERT INTO \"users\" VALUES(NULL)", im.to_sql
end
- describe 'skip' do
- it 'should add an offset' do
+ describe "skip" do
+ it "should add an offset" do
sm = @relation.skip 2
sm.to_sql.must_be_like "SELECT FROM \"users\" OFFSET 2"
end
end
- describe 'having' do
- it 'adds a having clause' do
+ describe "having" do
+ it "adds a having clause" do
mgr = @relation.having @relation[:id].eq(10)
mgr.to_sql.must_be_like %{
SELECT FROM "users" HAVING "users"."id" = 10
@@ -64,21 +65,21 @@ module Arel
end
end
- describe 'backwards compat' do
- describe 'join' do
- it 'noops on nil' do
+ describe "backwards compat" do
+ describe "join" do
+ it "noops on nil" do
mgr = @relation.join nil
mgr.to_sql.must_be_like %{ SELECT FROM "users" }
end
- it 'raises EmptyJoinError on empty' do
+ it "raises EmptyJoinError on empty" do
assert_raises(EmptyJoinError) do
@relation.join ""
end
end
- it 'takes a second argument for join type' do
+ it "takes a second argument for join type" do
right = @relation.alias
predicate = @relation[:id].eq(right[:id])
mgr = @relation.join(right, Nodes::OuterJoin).on(predicate)
@@ -91,8 +92,8 @@ module Arel
end
end
- describe 'join' do
- it 'creates an outer join' do
+ describe "join" do
+ it "creates an outer join" do
right = @relation.alias
predicate = @relation[:id].eq(right[:id])
mgr = @relation.outer_join(right).on(predicate)
@@ -106,8 +107,8 @@ module Arel
end
end
- describe 'group' do
- it 'should create a group' do
+ describe "group" do
+ it "should create a group" do
manager = @relation.group @relation[:id]
manager.to_sql.must_be_like %{
SELECT FROM "users" GROUP BY "users"."id"
@@ -115,54 +116,54 @@ module Arel
end
end
- describe 'alias' do
- it 'should create a node that proxies to a table' do
+ describe "alias" do
+ it "should create a node that proxies to a table" do
node = @relation.alias
- node.name.must_equal 'users_2'
+ node.name.must_equal "users_2"
node[:id].relation.must_equal node
end
end
- describe 'new' do
- it 'should accept a hash' do
- rel = Table.new :users, :as => 'foo'
- rel.table_alias.must_equal 'foo'
+ describe "new" do
+ it "should accept a hash" do
+ rel = Table.new :users, as: "foo"
+ rel.table_alias.must_equal "foo"
end
- it 'ignores as if it equals name' do
- rel = Table.new :users, :as => 'users'
+ it "ignores as if it equals name" do
+ rel = Table.new :users, as: "users"
rel.table_alias.must_be_nil
end
end
- describe 'order' do
+ describe "order" do
it "should take an order" do
manager = @relation.order "foo"
manager.to_sql.must_be_like %{ SELECT FROM "users" ORDER BY foo }
end
end
- describe 'take' do
+ describe "take" do
it "should add a limit" do
manager = @relation.take 1
- manager.project Nodes::SqlLiteral.new '*'
+ manager.project Nodes::SqlLiteral.new "*"
manager.to_sql.must_be_like %{ SELECT * FROM "users" LIMIT 1 }
end
end
- describe 'project' do
- it 'can project' do
- manager = @relation.project Nodes::SqlLiteral.new '*'
+ describe "project" do
+ it "can project" do
+ manager = @relation.project Nodes::SqlLiteral.new "*"
manager.to_sql.must_be_like %{ SELECT * FROM "users" }
end
- it 'takes multiple parameters' do
- manager = @relation.project Nodes::SqlLiteral.new('*'), Nodes::SqlLiteral.new('*')
+ it "takes multiple parameters" do
+ manager = @relation.project Nodes::SqlLiteral.new("*"), Nodes::SqlLiteral.new("*")
manager.to_sql.must_be_like %{ SELECT *, * FROM "users" }
end
end
- describe 'where' do
+ describe "where" do
it "returns a tree manager" do
manager = @relation.where @relation[:id].eq 1
manager.project @relation[:id]
@@ -176,15 +177,15 @@ module Arel
end
it "should have a name" do
- @relation.name.must_equal 'users'
+ @relation.name.must_equal "users"
end
it "should have a table name" do
- @relation.table_name.must_equal 'users'
+ @relation.table_name.must_equal "users"
end
- describe '[]' do
- describe 'when given a Symbol' do
+ describe "[]" do
+ describe "when given a Symbol" do
it "manufactures an attribute if the symbol names an attribute within the relation" do
column = @relation[:id]
column.name.must_equal :id
@@ -192,21 +193,21 @@ module Arel
end
end
- describe 'equality' do
- it 'is equal with equal ivars' do
+ describe "equality" do
+ it "is equal with equal ivars" do
relation1 = Table.new(:users)
- relation1.table_alias = 'zomg'
+ relation1.table_alias = "zomg"
relation2 = Table.new(:users)
- relation2.table_alias = 'zomg'
+ relation2.table_alias = "zomg"
array = [relation1, relation2]
assert_equal 1, array.uniq.size
end
- it 'is not equal with different ivars' do
+ it "is not equal with different ivars" do
relation1 = Table.new(:users)
- relation1.table_alias = 'zomg'
+ relation1.table_alias = "zomg"
relation2 = Table.new(:users)
- relation2.table_alias = 'zomg2'
+ relation2.table_alias = "zomg2"
array = [relation1, relation2]
assert_equal 2, array.uniq.size
end
diff --git a/activerecord/test/cases/arel/update_manager_test.rb b/activerecord/test/cases/arel/update_manager_test.rb
index 91118c5e9f..cc1b9ac5b3 100644
--- a/activerecord/test/cases/arel/update_manager_test.rb
+++ b/activerecord/test/cases/arel/update_manager_test.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
-require_relative 'helper'
+
+require_relative "helper"
module Arel
class UpdateManagerTest < Arel::Spec
- describe 'new' do
- it 'takes an engine' do
+ describe "new" do
+ it "takes an engine" do
Arel::UpdateManager.new
end
end
@@ -17,17 +18,17 @@ module Arel
um.to_sql.must_be_like %{ UPDATE "users" SET "name" = ? }
end
- it 'handles limit properly' do
+ it "handles limit properly" do
table = Table.new(:users)
um = Arel::UpdateManager.new
- um.key = 'id'
+ um.key = "id"
um.take 10
um.table table
um.set [[table[:name], nil]]
assert_match(/LIMIT 10/, um.to_sql)
end
- describe 'set' do
+ describe "set" do
it "updates with null" do
table = Table.new(:users)
um = Arel::UpdateManager.new
@@ -36,7 +37,7 @@ module Arel
um.to_sql.must_be_like %{ UPDATE "users" SET "name" = NULL }
end
- it 'takes a string' do
+ it "takes a string" do
table = Table.new(:users)
um = Arel::UpdateManager.new
um.table table
@@ -44,36 +45,36 @@ module Arel
um.to_sql.must_be_like %{ UPDATE "users" SET foo = bar }
end
- it 'takes a list of lists' do
+ it "takes a list of lists" do
table = Table.new(:users)
um = Arel::UpdateManager.new
um.table table
- um.set [[table[:id], 1], [table[:name], 'hello']]
+ um.set [[table[:id], 1], [table[:name], "hello"]]
um.to_sql.must_be_like %{
UPDATE "users" SET "id" = 1, "name" = 'hello'
}
end
- it 'chains' do
+ it "chains" do
table = Table.new(:users)
um = Arel::UpdateManager.new
- um.set([[table[:id], 1], [table[:name], 'hello']]).must_equal um
+ um.set([[table[:id], 1], [table[:name], "hello"]]).must_equal um
end
end
- describe 'table' do
- it 'generates an update statement' do
+ describe "table" do
+ it "generates an update statement" do
um = Arel::UpdateManager.new
um.table Table.new(:users)
um.to_sql.must_be_like %{ UPDATE "users" }
end
- it 'chains' do
+ it "chains" do
um = Arel::UpdateManager.new
um.table(Table.new(:users)).must_equal um
end
- it 'generates an update statement with joins' do
+ it "generates an update statement with joins" do
um = Arel::UpdateManager.new
table = Table.new(:users)
@@ -87,8 +88,8 @@ module Arel
end
end
- describe 'where' do
- it 'generates a where clause' do
+ describe "where" do
+ it "generates a where clause" do
table = Table.new :users
um = Arel::UpdateManager.new
um.table table
@@ -98,7 +99,7 @@ module Arel
}
end
- it 'chains' do
+ it "chains" do
table = Table.new :users
um = Arel::UpdateManager.new
um.table table
@@ -106,18 +107,18 @@ module Arel
end
end
- describe 'key' do
+ describe "key" do
before do
@table = Table.new :users
@um = Arel::UpdateManager.new
@um.key = @table[:foo]
end
- it 'can be set' do
+ it "can be set" do
@um.ast.key.must_equal @table[:foo]
end
- it 'can be accessed' do
+ it "can be accessed" do
@um.key.must_equal @table[:foo]
end
end
diff --git a/activerecord/test/cases/arel/visitors/depth_first_test.rb b/activerecord/test/cases/arel/visitors/depth_first_test.rb
index b841d119d2..3baccc7316 100644
--- a/activerecord/test/cases/arel/visitors/depth_first_test.rb
+++ b/activerecord/test/cases/arel/visitors/depth_first_test.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Visitors
class TestDepthFirst < Arel::Test
Collector = Struct.new(:calls) do
- def call object
+ def call(object)
calls << object
end
end
@@ -164,7 +165,7 @@ module Arel
def test_table
relation = Arel::Table.new(:users)
@visitor.accept relation
- assert_equal ['users', relation], @collector.calls
+ assert_equal ["users", relation], @collector.calls
end
def test_array
diff --git a/activerecord/test/cases/arel/visitors/dispatch_contamination_test.rb b/activerecord/test/cases/arel/visitors/dispatch_contamination_test.rb
index eb278cde4c..a07a1a050a 100644
--- a/activerecord/test/cases/arel/visitors/dispatch_contamination_test.rb
+++ b/activerecord/test/cases/arel/visitors/dispatch_contamination_test.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
-require_relative '../helper'
-require 'concurrent'
+
+require_relative "../helper"
+require "concurrent"
module Arel
module Visitors
@@ -10,14 +11,14 @@ module Arel
@barrier = Concurrent::CyclicBarrier.new(2)
end
- def visit_Arel_Visitors_DummySuperNode node
+ def visit_Arel_Visitors_DummySuperNode(node)
42
end
# This is terrible, but it's the only way to reliably reproduce
# the possible race where two threads attempt to correct the
# dispatch hash at the same time.
- def send *args
+ def send(*args)
super
rescue
# Both threads try (and fail) to dispatch to the subclass's name
@@ -43,7 +44,7 @@ module Arel
@table = Table.new(:users)
end
- it 'dispatches properly after failing upwards' do
+ 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
@@ -52,7 +53,7 @@ module Arel
assert_equal "( TRUE UNION FALSE )", node.to_sql
end
- it 'is threadsafe when implementing superclass fallback' do
+ it "is threadsafe when implementing superclass fallback" do
visitor = DummyVisitor.new
main_thread_finished = Concurrent::Event.new
@@ -69,4 +70,3 @@ module Arel
end
end
end
-
diff --git a/activerecord/test/cases/arel/visitors/dot_test.rb b/activerecord/test/cases/arel/visitors/dot_test.rb
index 048482c3ca..98f3bab620 100644
--- a/activerecord/test/cases/arel/visitors/dot_test.rb
+++ b/activerecord/test/cases/arel/visitors/dot_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Visitors
@@ -23,7 +24,7 @@ module Arel
end
def test_named_function
- func = Nodes::NamedFunction.new 'omg', 'omg'
+ func = Nodes::NamedFunction.new "omg", "omg"
@visitor.accept func, Collectors::PlainString.new
end
diff --git a/activerecord/test/cases/arel/visitors/ibm_db_test.rb b/activerecord/test/cases/arel/visitors/ibm_db_test.rb
index d7569eedc3..7163cb34d3 100644
--- a/activerecord/test/cases/arel/visitors/ibm_db_test.rb
+++ b/activerecord/test/cases/arel/visitors/ibm_db_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Visitors
@@ -8,18 +9,18 @@ module Arel
@visitor = IBM_DB.new Table.engine.connection
end
- def compile node
+ def compile(node)
@visitor.accept(node, Collectors::SQLString.new).value
end
- it 'uses FETCH FIRST n ROWS to limit results' do
+ it "uses FETCH FIRST n ROWS to limit results" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(1)
sql = compile(stmt)
sql.must_be_like "SELECT FETCH FIRST 1 ROWS ONLY"
end
- it 'uses FETCH FIRST n ROWS in updates with a limit' do
+ it "uses FETCH FIRST n ROWS in updates with a limit" do
table = Table.new(:users)
stmt = Nodes::UpdateStatement.new
stmt.relation = table
@@ -28,7 +29,6 @@ module Arel
sql = compile(stmt)
sql.must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT \"users\".\"id\" FROM \"users\" FETCH FIRST 1 ROWS ONLY)"
end
-
end
end
end
diff --git a/activerecord/test/cases/arel/visitors/informix_test.rb b/activerecord/test/cases/arel/visitors/informix_test.rb
index bb6ff42f05..b0b031cca3 100644
--- a/activerecord/test/cases/arel/visitors/informix_test.rb
+++ b/activerecord/test/cases/arel/visitors/informix_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Visitors
@@ -8,18 +9,18 @@ module Arel
@visitor = Informix.new Table.engine.connection
end
- def compile node
+ def compile(node)
@visitor.accept(node, Collectors::SQLString.new).value
end
- it 'uses FIRST n to limit results' do
+ it "uses FIRST n to limit results" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(1)
sql = compile(stmt)
sql.must_be_like "SELECT FIRST 1"
end
- it 'uses FIRST n in updates with a limit' do
+ it "uses FIRST n in updates with a limit" do
table = Table.new(:users)
stmt = Nodes::UpdateStatement.new
stmt.relation = table
@@ -29,14 +30,14 @@ module Arel
sql.must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT FIRST 1 \"users\".\"id\" FROM \"users\")"
end
- it 'uses SKIP n to jump results' do
+ it "uses SKIP n to jump results" do
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(10)
sql = compile(stmt)
sql.must_be_like "SELECT SKIP 10"
end
- it 'uses SKIP before FIRST' do
+ it "uses SKIP before FIRST" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(1)
stmt.offset = Nodes::Offset.new(1)
@@ -44,7 +45,7 @@ module Arel
sql.must_be_like "SELECT SKIP 1 FIRST 1"
end
- it 'uses INNER JOIN to perform joins' do
+ it "uses INNER JOIN to perform joins" do
core = Nodes::SelectCore.new
table = Table.new(:posts)
core.source = Nodes::JoinSource.new(table, [table.create_join(Table.new(:comments))])
@@ -53,7 +54,6 @@ module Arel
sql = compile(stmt)
sql.must_be_like 'SELECT FROM "posts" INNER JOIN "comments"'
end
-
end
end
end
diff --git a/activerecord/test/cases/arel/visitors/mssql_test.rb b/activerecord/test/cases/arel/visitors/mssql_test.rb
index 4e81678813..340376c3d6 100644
--- a/activerecord/test/cases/arel/visitors/mssql_test.rb
+++ b/activerecord/test/cases/arel/visitors/mssql_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Visitors
@@ -9,17 +10,17 @@ module Arel
@table = Arel::Table.new "users"
end
- def compile node
+ def compile(node)
@visitor.accept(node, Collectors::SQLString.new).value
end
- it 'should not modify query if no offset or limit' do
+ it "should not modify query if no offset or limit" do
stmt = Nodes::SelectStatement.new
sql = compile(stmt)
sql.must_be_like "SELECT"
end
- it 'should go over table PK if no .order() or .group()' do
+ it "should go over table PK if no .order() or .group()" do
stmt = Nodes::SelectStatement.new
stmt.cores.first.from = @table
stmt.limit = Nodes::Limit.new(10)
@@ -27,7 +28,7 @@ module Arel
sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY \"users\".\"id\") as _row_num FROM \"users\") as _t WHERE _row_num BETWEEN 1 AND 10"
end
- it 'caches the PK lookup for order' do
+ it "caches the PK lookup for order" do
connection = Minitest::Mock.new
connection.expect(:primary_key, ["id"], ["users"])
@@ -46,7 +47,7 @@ module Arel
connection.verify
end
- it 'should use TOP for limited deletes' do
+ it "should use TOP for limited deletes" do
stmt = Nodes::DeleteStatement.new
stmt.relation = @table
stmt.limit = Nodes::Limit.new(10)
@@ -55,23 +56,23 @@ module Arel
sql.must_be_like "DELETE TOP (10) FROM \"users\""
end
- it 'should go over query ORDER BY if .order()' do
+ it "should go over query ORDER BY if .order()" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(10)
- stmt.orders << Nodes::SqlLiteral.new('order_by')
+ stmt.orders << Nodes::SqlLiteral.new("order_by")
sql = compile(stmt)
sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY order_by) as _row_num) as _t WHERE _row_num BETWEEN 1 AND 10"
end
- it 'should go over query GROUP BY if no .order() and there is .group()' do
+ it "should go over query GROUP BY if no .order() and there is .group()" do
stmt = Nodes::SelectStatement.new
- stmt.cores.first.groups << Nodes::SqlLiteral.new('group_by')
+ stmt.cores.first.groups << Nodes::SqlLiteral.new("group_by")
stmt.limit = Nodes::Limit.new(10)
sql = compile(stmt)
sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY group_by) as _row_num GROUP BY group_by) as _t WHERE _row_num BETWEEN 1 AND 10"
end
- it 'should use BETWEEN if both .limit() and .offset' do
+ it "should use BETWEEN if both .limit() and .offset" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(10)
stmt.offset = Nodes::Offset.new(20)
@@ -79,21 +80,20 @@ module Arel
sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num BETWEEN 21 AND 30"
end
- it 'should use >= if only .offset' do
+ it "should use >= if only .offset" do
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(20)
sql = compile(stmt)
sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num >= 21"
end
- it 'should generate subquery for .count' do
+ it "should generate subquery for .count" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(10)
- stmt.cores.first.projections << Nodes::Count.new('*')
+ stmt.cores.first.projections << Nodes::Count.new("*")
sql = compile(stmt)
sql.must_be_like "SELECT COUNT(1) as count_id FROM (SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num BETWEEN 1 AND 10) AS subquery"
end
-
end
end
end
diff --git a/activerecord/test/cases/arel/visitors/mysql_test.rb b/activerecord/test/cases/arel/visitors/mysql_test.rb
index f9b468b1d2..9d3bad8516 100644
--- a/activerecord/test/cases/arel/visitors/mysql_test.rb
+++ b/activerecord/test/cases/arel/visitors/mysql_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Visitors
@@ -8,24 +9,24 @@ module Arel
@visitor = MySQL.new Table.engine.connection
end
- def compile node
+ def compile(node)
@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
+ 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
+ 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
- it 'defaults limit to 18446744073709551615' do
+ it "defaults limit to 18446744073709551615" do
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(1)
sql = compile(stmt)
@@ -39,20 +40,20 @@ module Arel
assert_equal("UPDATE \"users\" LIMIT 'omg'", compile(sc))
end
- it 'uses DUAL for empty from' do
+ it "uses DUAL for empty from" do
stmt = Nodes::SelectStatement.new
sql = compile(stmt)
sql.must_be_like "SELECT FROM DUAL"
end
- describe 'locking' do
- it 'defaults to FOR UPDATE when locking' do
- node = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
+ describe "locking" do
+ it "defaults to FOR UPDATE when locking" do
+ node = Nodes::Lock.new(Arel.sql("FOR UPDATE"))
compile(node).must_be_like "FOR UPDATE"
end
- it 'allows a custom string to be used as a lock' do
- node = Nodes::Lock.new(Arel.sql('LOCK IN SHARE MODE'))
+ it "allows a custom string to be used as a lock" do
+ node = Nodes::Lock.new(Arel.sql("LOCK IN SHARE MODE"))
compile(node).must_be_like "LOCK IN SHARE MODE"
end
end
@@ -68,7 +69,7 @@ module Arel
it "concats a string" do
@table = Table.new(:users)
- query = @table[:name].concat(Nodes.build_quoted('abc'))
+ query = @table[:name].concat(Nodes.build_quoted("abc"))
compile(query).must_be_like %{
CONCAT("users"."name", 'abc')
}
diff --git a/activerecord/test/cases/arel/visitors/oracle12_test.rb b/activerecord/test/cases/arel/visitors/oracle12_test.rb
index ef2050b7c9..83a2ee36ca 100644
--- a/activerecord/test/cases/arel/visitors/oracle12_test.rb
+++ b/activerecord/test/cases/arel/visitors/oracle12_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Visitors
@@ -9,11 +10,11 @@ module Arel
@table = Table.new(:users)
end
- def compile node
+ def compile(node)
@visitor.accept(node, Collectors::SQLString.new).value
end
- it 'modified except to be minus' do
+ it "modified except to be minus" do
left = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 10")
right = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 20")
sql = compile Nodes::Except.new(left, right)
@@ -22,7 +23,7 @@ module Arel
}
end
- it 'generates select options offset then limit' do
+ it "generates select options offset then limit" do
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(1)
stmt.limit = Nodes::Limit.new(10)
@@ -30,18 +31,18 @@ module Arel
sql.must_be_like "SELECT OFFSET 1 ROWS FETCH FIRST 10 ROWS ONLY"
end
- describe 'locking' do
- it 'generates ArgumentError if limit and lock are used' do
+ describe "locking" do
+ it "generates ArgumentError if limit and lock are used" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(10)
- stmt.lock = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
+ stmt.lock = Nodes::Lock.new(Arel.sql("FOR UPDATE"))
assert_raises ArgumentError do
compile(stmt)
end
end
- it 'defaults to FOR UPDATE when locking' do
- node = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
+ it "defaults to FOR UPDATE when locking" do
+ node = Nodes::Lock.new(Arel.sql("FOR UPDATE"))
compile(node).must_be_like "FOR UPDATE"
end
end
diff --git a/activerecord/test/cases/arel/visitors/oracle_test.rb b/activerecord/test/cases/arel/visitors/oracle_test.rb
index 0737774fbf..e1dfe40cf9 100644
--- a/activerecord/test/cases/arel/visitors/oracle_test.rb
+++ b/activerecord/test/cases/arel/visitors/oracle_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Visitors
@@ -9,79 +10,79 @@ module Arel
@table = Table.new(:users)
end
- def compile node
+ def compile(node)
@visitor.accept(node, Collectors::SQLString.new).value
end
- it 'modifies order when there is distinct and first value' do
+ it "modifies order when there is distinct and first value" do
# *sigh*
select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__"
stmt = Nodes::SelectStatement.new
stmt.cores.first.projections << Nodes::SqlLiteral.new(select)
- stmt.orders << Nodes::SqlLiteral.new('foo')
+ stmt.orders << Nodes::SqlLiteral.new("foo")
sql = compile(stmt)
sql.must_be_like %{
SELECT #{select} ORDER BY alias_0__
}
end
- it 'is idempotent with crazy query' do
+ it "is idempotent with crazy query" do
# *sigh*
select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__"
stmt = Nodes::SelectStatement.new
stmt.cores.first.projections << Nodes::SqlLiteral.new(select)
- stmt.orders << Nodes::SqlLiteral.new('foo')
+ stmt.orders << Nodes::SqlLiteral.new("foo")
sql = compile(stmt)
sql2 = compile(stmt)
sql.must_equal sql2
end
- it 'splits orders with commas' do
+ it "splits orders with commas" do
# *sigh*
select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__"
stmt = Nodes::SelectStatement.new
stmt.cores.first.projections << Nodes::SqlLiteral.new(select)
- stmt.orders << Nodes::SqlLiteral.new('foo, bar')
+ stmt.orders << Nodes::SqlLiteral.new("foo, bar")
sql = compile(stmt)
sql.must_be_like %{
SELECT #{select} ORDER BY alias_0__, alias_1__
}
end
- it 'splits orders with commas and function calls' do
+ it "splits orders with commas and function calls" do
# *sigh*
select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__"
stmt = Nodes::SelectStatement.new
stmt.cores.first.projections << Nodes::SqlLiteral.new(select)
- stmt.orders << Nodes::SqlLiteral.new('NVL(LOWER(bar, foo), foo) DESC, UPPER(baz)')
+ stmt.orders << Nodes::SqlLiteral.new("NVL(LOWER(bar, foo), foo) DESC, UPPER(baz)")
sql = compile(stmt)
sql.must_be_like %{
SELECT #{select} ORDER BY alias_0__ DESC, alias_1__
}
end
- describe 'Nodes::SelectStatement' do
- describe 'limit' do
- it 'adds a rownum clause' do
+ describe "Nodes::SelectStatement" do
+ describe "limit" do
+ it "adds a rownum clause" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(10)
sql = compile stmt
sql.must_be_like %{ SELECT WHERE ROWNUM <= 10 }
end
- it 'is idempotent' do
+ it "is idempotent" do
stmt = Nodes::SelectStatement.new
- stmt.orders << Nodes::SqlLiteral.new('foo')
+ stmt.orders << Nodes::SqlLiteral.new("foo")
stmt.limit = Nodes::Limit.new(10)
sql = compile stmt
sql2 = compile stmt
sql.must_equal sql2
end
- it 'creates a subquery when there is order_by' do
+ it "creates a subquery when there is order_by" do
stmt = Nodes::SelectStatement.new
- stmt.orders << Nodes::SqlLiteral.new('foo')
+ stmt.orders << Nodes::SqlLiteral.new("foo")
stmt.limit = Nodes::Limit.new(10)
sql = compile stmt
sql.must_be_like %{
@@ -89,9 +90,9 @@ module Arel
}
end
- it 'creates a subquery when there is group by' do
+ it "creates a subquery when there is group by" do
stmt = Nodes::SelectStatement.new
- stmt.cores.first.groups << Nodes::SqlLiteral.new('foo')
+ stmt.cores.first.groups << Nodes::SqlLiteral.new("foo")
stmt.limit = Nodes::Limit.new(10)
sql = compile stmt
sql.must_be_like %{
@@ -99,10 +100,10 @@ module Arel
}
end
- it 'creates a subquery when there is DISTINCT' do
+ it "creates a subquery when there is DISTINCT" do
stmt = Nodes::SelectStatement.new
stmt.cores.first.set_quantifier = Arel::Nodes::Distinct.new
- stmt.cores.first.projections << Nodes::SqlLiteral.new('id')
+ stmt.cores.first.projections << Nodes::SqlLiteral.new("id")
stmt.limit = Arel::Nodes::Limit.new(10)
sql = compile stmt
sql.must_be_like %{
@@ -110,7 +111,7 @@ module Arel
}
end
- it 'creates a different subquery when there is an offset' do
+ it "creates a different subquery when there is an offset" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(10)
stmt.offset = Nodes::Offset.new(10)
@@ -125,7 +126,7 @@ module Arel
}
end
- it 'creates a subquery when there is limit and offset with BindParams' do
+ it "creates a subquery when there is limit and offset with BindParams" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(Nodes::BindParam.new(1))
stmt.offset = Nodes::Offset.new(Nodes::BindParam.new(1))
@@ -140,7 +141,7 @@ module Arel
}
end
- it 'is idempotent with different subquery' do
+ it "is idempotent with different subquery" do
stmt = Nodes::SelectStatement.new
stmt.limit = Nodes::Limit.new(10)
stmt.offset = Nodes::Offset.new(10)
@@ -150,8 +151,8 @@ module Arel
end
end
- describe 'only offset' do
- it 'creates a select from subquery with rownum condition' do
+ describe "only offset" do
+ it "creates a select from subquery with rownum condition" do
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(10)
sql = compile stmt
@@ -166,7 +167,7 @@ module Arel
end
end
- it 'modified except to be minus' do
+ it "modified except to be minus" do
left = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 10")
right = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 20")
sql = compile Nodes::Except.new(left, right)
@@ -175,9 +176,9 @@ module Arel
}
end
- describe 'locking' do
- it 'defaults to FOR UPDATE when locking' do
- node = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
+ describe "locking" do
+ it "defaults to FOR UPDATE when locking" do
+ node = Nodes::Lock.new(Arel.sql("FOR UPDATE"))
compile(node).must_be_like "FOR UPDATE"
end
end
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.*')
diff --git a/activerecord/test/cases/arel/visitors/sqlite_test.rb b/activerecord/test/cases/arel/visitors/sqlite_test.rb
index 23f66ee096..6650b6ff3a 100644
--- a/activerecord/test/cases/arel/visitors/sqlite_test.rb
+++ b/activerecord/test/cases/arel/visitors/sqlite_test.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-require_relative '../helper'
+
+require_relative "../helper"
module Arel
module Visitors
@@ -8,23 +9,23 @@ module Arel
@visitor = SQLite.new Table.engine.connection_pool
end
- it 'defaults limit to -1' do
+ it "defaults limit to -1" do
stmt = Nodes::SelectStatement.new
stmt.offset = Nodes::Offset.new(1)
sql = @visitor.accept(stmt, Collectors::SQLString.new).value
sql.must_be_like "SELECT LIMIT -1 OFFSET 1"
end
- it 'does not support locking' do
- node = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
- assert_equal '', @visitor.accept(node, Collectors::SQLString.new).value
+ it "does not support locking" do
+ node = Nodes::Lock.new(Arel.sql("FOR UPDATE"))
+ assert_equal "", @visitor.accept(node, Collectors::SQLString.new).value
end
- it 'does not support boolean' do
+ it "does not support boolean" do
node = Nodes::True.new()
- assert_equal '1', @visitor.accept(node, Collectors::SQLString.new).value
+ assert_equal "1", @visitor.accept(node, Collectors::SQLString.new).value
node = Nodes::False.new()
- assert_equal '0', @visitor.accept(node, Collectors::SQLString.new).value
+ assert_equal "0", @visitor.accept(node, Collectors::SQLString.new).value
end
end
end
diff --git a/activerecord/test/cases/arel/visitors/to_sql_test.rb b/activerecord/test/cases/arel/visitors/to_sql_test.rb
index 1503bcd578..ce836eded7 100644
--- a/activerecord/test/cases/arel/visitors/to_sql_test.rb
+++ b/activerecord/test/cases/arel/visitors/to_sql_test.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
-require_relative '../helper'
-require 'bigdecimal'
+
+require_relative "../helper"
+require "bigdecimal"
module Arel
module Visitors
- describe 'the to_sql visitor' do
+ describe "the to_sql visitor" do
before do
@conn = FakeRecord::Base.new
@visitor = ToSql.new @conn.connection
@@ -12,24 +13,24 @@ module Arel
@attr = @table[:id]
end
- def compile node
+ def compile(node)
@visitor.accept(node, Collectors::SQLString.new).value
end
- it 'works with BindParams' do
+ it "works with BindParams" do
node = Nodes::BindParam.new(1)
sql = compile node
- sql.must_be_like '?'
+ sql.must_be_like "?"
end
- it 'does not quote BindParams used as part of a Values' do
+ it "does not quote BindParams used as part of a Values" do
bp = Nodes::BindParam.new(1)
values = Nodes::Values.new([bp])
sql = compile values
- sql.must_be_like 'VALUES (?)'
+ sql.must_be_like "VALUES (?)"
end
- it 'can define a dispatch method' do
+ it "can define a dispatch method" do
visited = false
viz = Class.new(Arel::Visitors::Visitor) {
define_method(:hello) do |node, c|
@@ -37,117 +38,117 @@ module Arel
end
def dispatch
- { Arel::Table => 'hello' }
+ { Arel::Table => "hello" }
end
}.new
viz.accept(@table, Collectors::SQLString.new)
- assert visited, 'hello method was called'
+ assert visited, "hello method was called"
end
- it 'should not quote sql literals' do
+ it "should not quote sql literals" do
node = @table[Arel.star]
sql = compile node
sql.must_be_like '"users".*'
end
- it 'should visit named functions' do
- function = Nodes::NamedFunction.new('omg', [Arel.star])
- assert_equal 'omg(*)', compile(function)
+ it "should visit named functions" do
+ function = Nodes::NamedFunction.new("omg", [Arel.star])
+ assert_equal "omg(*)", compile(function)
end
- it 'should chain predications on named functions' do
- function = Nodes::NamedFunction.new('omg', [Arel.star])
+ it "should chain predications on named functions" do
+ function = Nodes::NamedFunction.new("omg", [Arel.star])
sql = compile(function.eq(2))
sql.must_be_like %{ omg(*) = 2 }
end
- it 'should handle nil with named functions' do
- function = Nodes::NamedFunction.new('omg', [Arel.star])
+ it "should handle nil with named functions" do
+ function = Nodes::NamedFunction.new("omg", [Arel.star])
sql = compile(function.eq(nil))
sql.must_be_like %{ omg(*) IS NULL }
end
- it 'should visit built-in functions' do
+ it "should visit built-in functions" do
function = Nodes::Count.new([Arel.star])
- assert_equal 'COUNT(*)', compile(function)
+ assert_equal "COUNT(*)", compile(function)
function = Nodes::Sum.new([Arel.star])
- assert_equal 'SUM(*)', compile(function)
+ assert_equal "SUM(*)", compile(function)
function = Nodes::Max.new([Arel.star])
- assert_equal 'MAX(*)', compile(function)
+ assert_equal "MAX(*)", compile(function)
function = Nodes::Min.new([Arel.star])
- assert_equal 'MIN(*)', compile(function)
+ assert_equal "MIN(*)", compile(function)
function = Nodes::Avg.new([Arel.star])
- assert_equal 'AVG(*)', compile(function)
+ assert_equal "AVG(*)", compile(function)
end
- it 'should visit built-in functions operating on distinct values' do
+ it "should visit built-in functions operating on distinct values" do
function = Nodes::Count.new([Arel.star])
function.distinct = true
- assert_equal 'COUNT(DISTINCT *)', compile(function)
+ assert_equal "COUNT(DISTINCT *)", compile(function)
function = Nodes::Sum.new([Arel.star])
function.distinct = true
- assert_equal 'SUM(DISTINCT *)', compile(function)
+ assert_equal "SUM(DISTINCT *)", compile(function)
function = Nodes::Max.new([Arel.star])
function.distinct = true
- assert_equal 'MAX(DISTINCT *)', compile(function)
+ assert_equal "MAX(DISTINCT *)", compile(function)
function = Nodes::Min.new([Arel.star])
function.distinct = true
- assert_equal 'MIN(DISTINCT *)', compile(function)
+ assert_equal "MIN(DISTINCT *)", compile(function)
function = Nodes::Avg.new([Arel.star])
function.distinct = true
- assert_equal 'AVG(DISTINCT *)', compile(function)
+ assert_equal "AVG(DISTINCT *)", compile(function)
end
- it 'works with lists' do
- function = Nodes::NamedFunction.new('omg', [Arel.star, Arel.star])
- assert_equal 'omg(*, *)', compile(function)
+ it "works with lists" do
+ function = Nodes::NamedFunction.new("omg", [Arel.star, Arel.star])
+ assert_equal "omg(*, *)", compile(function)
end
- describe 'Nodes::Equality' do
+ describe "Nodes::Equality" do
it "should escape strings" do
- test = Table.new(:users)[:name].eq 'Aaron Patterson'
+ test = Table.new(:users)[:name].eq "Aaron Patterson"
compile(test).must_be_like %{
"users"."name" = 'Aaron Patterson'
}
end
- it 'should handle false' do
+ it "should handle false" do
table = Table.new(:users)
val = Nodes.build_quoted(false, table[:active])
sql = compile Nodes::Equality.new(val, val)
sql.must_be_like %{ 'f' = 'f' }
end
- it 'should handle nil' do
+ it "should handle nil" do
sql = compile Nodes::Equality.new(@table[:name], nil)
sql.must_be_like %{ "users"."name" IS NULL }
end
end
- describe 'Nodes::Grouping' do
- it 'wraps nested groupings in brackets only once' do
- sql = compile Nodes::Grouping.new(Nodes::Grouping.new(Nodes.build_quoted('foo')))
+ describe "Nodes::Grouping" do
+ it "wraps nested groupings in brackets only once" do
+ sql = compile Nodes::Grouping.new(Nodes::Grouping.new(Nodes.build_quoted("foo")))
sql.must_equal "('foo')"
end
end
- describe 'Nodes::NotEqual' do
- it 'should handle false' do
+ describe "Nodes::NotEqual" do
+ it "should handle false" do
val = Nodes.build_quoted(false, @table[:active])
sql = compile Nodes::NotEqual.new(@table[:active], val)
sql.must_be_like %{ "users"."active" != 'f' }
end
- it 'should handle nil' do
+ it "should handle nil" do
val = Nodes.build_quoted(nil, @table[:active])
sql = compile Nodes::NotEqual.new(@table[:name], val)
sql.must_be_like %{ "users"."name" IS NOT NULL }
@@ -225,7 +226,7 @@ module Arel
end
it "should visit_Hash" do
- compile(Nodes.build_quoted({:a => 1}))
+ compile(Nodes.build_quoted(a: 1))
end
it "should visit_Set" do
@@ -233,7 +234,7 @@ module Arel
end
it "should visit_BigDecimal" do
- compile Nodes.build_quoted(BigDecimal('2.14'))
+ compile Nodes.build_quoted(BigDecimal("2.14"))
end
it "should visit_Date" do
@@ -296,21 +297,21 @@ module Arel
describe "Nodes::Matches" do
it "should know how to visit" do
- node = @table[:name].matches('foo%')
+ node = @table[:name].matches("foo%")
compile(node).must_be_like %{
"users"."name" LIKE 'foo%'
}
end
it "can handle ESCAPE" do
- node = @table[:name].matches('foo!%', '!')
+ node = @table[:name].matches("foo!%", "!")
compile(node).must_be_like %{
"users"."name" LIKE '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" LIKE 'foo%')
@@ -320,21 +321,21 @@ 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%")
compile(node).must_be_like %{
"users"."name" NOT LIKE 'foo%'
}
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 LIKE '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 LIKE 'foo%')
@@ -361,24 +362,24 @@ module Arel
it "should return 1=0 when empty right which is always false" do
node = @attr.in []
- compile(node).must_equal '1=0'
+ compile(node).must_equal "1=0"
end
- it 'can handle two dot ranges' do
+ it "can handle two dot ranges" do
node = @attr.between 1..3
compile(node).must_be_like %{
"users"."id" BETWEEN 1 AND 3
}
end
- it 'can handle three dot ranges' do
+ it "can handle three dot ranges" do
node = @attr.between 1...3
compile(node).must_be_like %{
"users"."id" >= 1 AND "users"."id" < 3
}
end
- it 'can handle ranges bounded by infinity' do
+ it "can handle ranges bounded by infinity" do
node = @attr.between 1..Float::INFINITY
compile(node).must_be_like %{
"users"."id" >= 1
@@ -395,9 +396,9 @@ module Arel
compile(node).must_be_like %{1=1}
end
- it 'can handle subqueries' do
+ it "can handle subqueries" do
table = Table.new(:users)
- subquery = table.project(:id).where(table[:name].eq('Aaron'))
+ subquery = table.project(:id).where(table[:name].eq("Aaron"))
node = @attr.in subquery
compile(node).must_be_like %{
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" = 'Aaron')
@@ -459,7 +460,7 @@ module Arel
it "should handle arbitrary operators" do
node = Arel::Nodes::InfixOperation.new(
- '&&',
+ "&&",
Arel::Attributes::String.new(Table.new(:products), :name),
Arel::Attributes::String.new(Table.new(:products), :name)
)
@@ -474,7 +475,7 @@ module Arel
end
it "should handle arbitrary operators" do
- node = Arel::Nodes::UnaryOperation.new('!', Arel::Attributes::String.new(Table.new(:products), :active))
+ node = Arel::Nodes::UnaryOperation.new("!", Arel::Attributes::String.new(Table.new(:products), :active))
compile(node).must_equal %( ! "products"."active")
end
end
@@ -489,24 +490,24 @@ module Arel
it "should return 1=1 when empty right which is always true" do
node = @attr.not_in []
- compile(node).must_equal '1=1'
+ compile(node).must_equal "1=1"
end
- it 'can handle two dot ranges' do
+ it "can handle two dot ranges" do
node = @attr.not_between 1..3
compile(node).must_equal(
%{("users"."id" < 1 OR "users"."id" > 3)}
)
end
- it 'can handle three dot ranges' do
+ it "can handle three dot ranges" do
node = @attr.not_between 1...3
compile(node).must_equal(
%{("users"."id" < 1 OR "users"."id" >= 3)}
)
end
- it 'can handle ranges bounded by infinity' do
+ it "can handle ranges bounded by infinity" do
node = @attr.not_between 1..Float::INFINITY
compile(node).must_be_like %{
"users"."id" < 1
@@ -523,9 +524,9 @@ module Arel
compile(node).must_be_like %{1=0}
end
- it 'can handle subqueries' do
+ it "can handle subqueries" do
table = Table.new(:users)
- subquery = table.project(:id).where(table[:name].eq('Aaron'))
+ subquery = table.project(:id).where(table[:name].eq("Aaron"))
node = @attr.not_in subquery
compile(node).must_be_like %{
"users"."id" NOT IN (SELECT id FROM "users" WHERE "users"."name" = 'Aaron')
@@ -533,7 +534,7 @@ module Arel
end
end
- describe 'Constants' do
+ describe "Constants" do
it "should handle true" do
test = Table.new(:users).create_true
compile(test).must_be_like %{
@@ -549,19 +550,19 @@ module Arel
end
end
- describe 'TableAlias' do
+ describe "TableAlias" do
it "should use the underlying table for checking columns" do
- test = Table.new(:users).alias('zomgusers')[:id].eq '3'
+ test = Table.new(:users).alias("zomgusers")[:id].eq "3"
compile(test).must_be_like %{
"zomgusers"."id" = '3'
}
end
end
- describe 'distinct on' do
- it 'raises not implemented error' do
+ describe "distinct on" do
+ it "raises not implemented error" do
core = Arel::Nodes::SelectCore.new
- core.set_quantifier = Arel::Nodes::DistinctOn.new(Arel.sql('aaron'))
+ core.set_quantifier = Arel::Nodes::DistinctOn.new(Arel.sql("aaron"))
assert_raises(NotImplementedError) do
compile(core)
@@ -569,9 +570,9 @@ module Arel
end
end
- describe 'Nodes::Regexp' do
- it 'raises not implemented error' do
- node = Arel::Nodes::Regexp.new(@table[:name], Nodes.build_quoted('foo%'))
+ describe "Nodes::Regexp" do
+ it "raises not implemented error" do
+ node = Arel::Nodes::Regexp.new(@table[:name], Nodes.build_quoted("foo%"))
assert_raises(NotImplementedError) do
compile(node)
@@ -579,9 +580,9 @@ module Arel
end
end
- describe 'Nodes::NotRegexp' do
- it 'raises not implemented error' do
- node = Arel::Nodes::NotRegexp.new(@table[:name], Nodes.build_quoted('foo%'))
+ describe "Nodes::NotRegexp" do
+ it "raises not implemented error" do
+ node = Arel::Nodes::NotRegexp.new(@table[:name], Nodes.build_quoted("foo%"))
assert_raises(NotImplementedError) do
compile(node)
@@ -589,10 +590,10 @@ module Arel
end
end
- describe 'Nodes::Case' do
- it 'supports simple case expressions' do
+ describe "Nodes::Case" do
+ it "supports simple case expressions" do
node = Arel::Nodes::Case.new(@table[:name])
- .when('foo').then(1)
+ .when("foo").then(1)
.else(0)
compile(node).must_be_like %{
@@ -600,7 +601,7 @@ module Arel
}
end
- it 'supports extended case expressions' do
+ it "supports extended case expressions" do
node = Arel::Nodes::Case.new
.when(@table[:name].in(%w(foo bar))).then(1)
.else(0)
@@ -610,19 +611,19 @@ module Arel
}
end
- it 'works without default branch' do
+ it "works without default branch" do
node = Arel::Nodes::Case.new(@table[:name])
- .when('foo').then(1)
+ .when("foo").then(1)
compile(node).must_be_like %{
CASE "users"."name" WHEN 'foo' THEN 1 END
}
end
- it 'allows chaining multiple conditions' do
+ it "allows chaining multiple conditions" do
node = Arel::Nodes::Case.new(@table[:name])
- .when('foo').then(1)
- .when('bar').then(2)
+ .when("foo").then(1)
+ .when("bar").then(2)
.else(0)
compile(node).must_be_like %{
@@ -630,7 +631,7 @@ module Arel
}
end
- it 'supports #when with two arguments and no #then' do
+ it "supports #when with two arguments and no #then" do
node = Arel::Nodes::Case.new @table[:name]
{ foo: 1, bar: 0 }.reduce(node) { |_node, pair| _node.when(*pair) }
@@ -640,8 +641,8 @@ module Arel
}
end
- it 'can be chained as a predicate' do
- node = @table[:name].when('foo').then('bar').else('baz')
+ it "can be chained as a predicate" do
+ node = @table[:name].when("foo").then("bar").else("baz")
compile(node).must_be_like %{
CASE "users"."name" WHEN 'foo' THEN 'bar' ELSE 'baz' END