arel 2.1.4 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/History.txt +8 -0
- data/Manifest.txt +3 -0
- data/arel.gemspec +14 -18
- data/lib/arel.rb +1 -1
- data/lib/arel/factory_methods.rb +8 -0
- data/lib/arel/nodes.rb +2 -0
- data/lib/arel/nodes/false.rb +6 -0
- data/lib/arel/nodes/join_source.rb +4 -0
- data/lib/arel/nodes/node.rb +1 -2
- data/lib/arel/nodes/true.rb +6 -0
- data/lib/arel/predications.rb +0 -1
- data/lib/arel/select_manager.rb +5 -4
- data/lib/arel/tree_manager.rb +7 -5
- data/lib/arel/visitors/oracle.rb +12 -0
- data/lib/arel/visitors/to_sql.rb +11 -8
- data/test/nodes/test_bin.rb +2 -2
- data/test/nodes/test_select_core.rb +1 -1
- data/test/nodes/test_sql_literal.rb +9 -10
- data/test/support/fake_record.rb +4 -3
- data/test/test_factory_methods.rb +10 -0
- data/test/test_select_manager.rb +4 -0
- data/test/test_update_manager.rb +13 -0
- data/test/visitors/test_ibm_db.rb +1 -1
- data/test/visitors/test_informix.rb +1 -1
- data/test/visitors/test_join_sql.rb +1 -1
- data/test/visitors/test_mssql.rb +1 -1
- data/test/visitors/test_mysql.rb +1 -1
- data/test/visitors/test_oracle.rb +1 -1
- data/test/visitors/test_postgres.rb +1 -1
- data/test/visitors/test_sqlite.rb +1 -1
- data/test/visitors/test_to_sql.rb +19 -3
- metadata +7 -4
data/Gemfile
ADDED
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 2.2.0 / 2011-08-09
|
2
|
+
|
3
|
+
* Bug Fixes
|
4
|
+
|
5
|
+
* The database connection caches visitors for generating SQL.
|
6
|
+
* FALSE and TRUE nodes can be constructed.
|
7
|
+
* Fixed ORDER BY / LIMIT clauses for UPDATE statements in Oracle.
|
8
|
+
|
1
9
|
== 2.1.4 / 2011-07-25
|
2
10
|
|
3
11
|
* Bug Fixes
|
data/Manifest.txt
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
.autotest
|
2
2
|
.gemtest
|
3
|
+
Gemfile
|
3
4
|
History.txt
|
4
5
|
MIT-LICENSE.txt
|
5
6
|
Manifest.txt
|
@@ -27,6 +28,7 @@ lib/arel/nodes/count.rb
|
|
27
28
|
lib/arel/nodes/delete_statement.rb
|
28
29
|
lib/arel/nodes/descending.rb
|
29
30
|
lib/arel/nodes/equality.rb
|
31
|
+
lib/arel/nodes/false.rb
|
30
32
|
lib/arel/nodes/function.rb
|
31
33
|
lib/arel/nodes/in.rb
|
32
34
|
lib/arel/nodes/infix_operation.rb
|
@@ -43,6 +45,7 @@ lib/arel/nodes/sql_literal.rb
|
|
43
45
|
lib/arel/nodes/string_join.rb
|
44
46
|
lib/arel/nodes/table_alias.rb
|
45
47
|
lib/arel/nodes/terminal.rb
|
48
|
+
lib/arel/nodes/true.rb
|
46
49
|
lib/arel/nodes/unary.rb
|
47
50
|
lib/arel/nodes/unqualified_column.rb
|
48
51
|
lib/arel/nodes/update_statement.rb
|
data/arel.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{arel}
|
5
|
-
s.version = "2.
|
5
|
+
s.version = "2.2.0.20110809140134"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date = %q{2011-
|
8
|
+
s.authors = [%q{Aaron Patterson}, %q{Bryan Halmkamp}, %q{Emilio Tagua}, %q{Nick Kallen}]
|
9
|
+
s.date = %q{2011-08-09}
|
10
10
|
s.description = %q{Arel is a SQL AST manager for Ruby. It
|
11
11
|
|
12
12
|
1. Simplifies the generation complex of SQL queries
|
@@ -15,30 +15,26 @@ Gem::Specification.new do |s|
|
|
15
15
|
It is intended to be a framework framework; that is, you can build your own ORM
|
16
16
|
with it, focusing on innovative object and collection modeling as opposed to
|
17
17
|
database compatibility and query generation.}
|
18
|
-
s.email = [
|
19
|
-
s.extra_rdoc_files = [
|
20
|
-
s.files = [
|
18
|
+
s.email = [%q{aaron@tenderlovemaking.com}, %q{bryan@brynary.com}, %q{miloops@gmail.com}, %q{nick@example.org}]
|
19
|
+
s.extra_rdoc_files = [%q{History.txt}, %q{MIT-LICENSE.txt}, %q{Manifest.txt}, %q{README.markdown}]
|
20
|
+
s.files = [%q{.autotest}, %q{.gemtest}, %q{Gemfile}, %q{History.txt}, %q{MIT-LICENSE.txt}, %q{Manifest.txt}, %q{README.markdown}, %q{Rakefile}, %q{arel.gemspec}, %q{lib/arel.rb}, %q{lib/arel/alias_predication.rb}, %q{lib/arel/attributes.rb}, %q{lib/arel/attributes/attribute.rb}, %q{lib/arel/compatibility/wheres.rb}, %q{lib/arel/crud.rb}, %q{lib/arel/delete_manager.rb}, %q{lib/arel/deprecated.rb}, %q{lib/arel/expression.rb}, %q{lib/arel/expressions.rb}, %q{lib/arel/factory_methods.rb}, %q{lib/arel/insert_manager.rb}, %q{lib/arel/math.rb}, %q{lib/arel/nodes.rb}, %q{lib/arel/nodes/and.rb}, %q{lib/arel/nodes/ascending.rb}, %q{lib/arel/nodes/binary.rb}, %q{lib/arel/nodes/count.rb}, %q{lib/arel/nodes/delete_statement.rb}, %q{lib/arel/nodes/descending.rb}, %q{lib/arel/nodes/equality.rb}, %q{lib/arel/nodes/false.rb}, %q{lib/arel/nodes/function.rb}, %q{lib/arel/nodes/in.rb}, %q{lib/arel/nodes/infix_operation.rb}, %q{lib/arel/nodes/inner_join.rb}, %q{lib/arel/nodes/insert_statement.rb}, %q{lib/arel/nodes/join_source.rb}, %q{lib/arel/nodes/named_function.rb}, %q{lib/arel/nodes/node.rb}, %q{lib/arel/nodes/ordering.rb}, %q{lib/arel/nodes/outer_join.rb}, %q{lib/arel/nodes/select_core.rb}, %q{lib/arel/nodes/select_statement.rb}, %q{lib/arel/nodes/sql_literal.rb}, %q{lib/arel/nodes/string_join.rb}, %q{lib/arel/nodes/table_alias.rb}, %q{lib/arel/nodes/terminal.rb}, %q{lib/arel/nodes/true.rb}, %q{lib/arel/nodes/unary.rb}, %q{lib/arel/nodes/unqualified_column.rb}, %q{lib/arel/nodes/update_statement.rb}, %q{lib/arel/nodes/values.rb}, %q{lib/arel/nodes/with.rb}, %q{lib/arel/order_predications.rb}, %q{lib/arel/predications.rb}, %q{lib/arel/relation.rb}, %q{lib/arel/select_manager.rb}, %q{lib/arel/sql/engine.rb}, %q{lib/arel/sql_literal.rb}, %q{lib/arel/table.rb}, %q{lib/arel/tree_manager.rb}, %q{lib/arel/update_manager.rb}, %q{lib/arel/visitors.rb}, %q{lib/arel/visitors/depth_first.rb}, %q{lib/arel/visitors/dot.rb}, %q{lib/arel/visitors/ibm_db.rb}, %q{lib/arel/visitors/informix.rb}, %q{lib/arel/visitors/join_sql.rb}, %q{lib/arel/visitors/mssql.rb}, %q{lib/arel/visitors/mysql.rb}, %q{lib/arel/visitors/oracle.rb}, %q{lib/arel/visitors/order_clauses.rb}, %q{lib/arel/visitors/postgresql.rb}, %q{lib/arel/visitors/sqlite.rb}, %q{lib/arel/visitors/to_sql.rb}, %q{lib/arel/visitors/visitor.rb}, %q{lib/arel/visitors/where_sql.rb}, %q{test/attributes/test_attribute.rb}, %q{test/helper.rb}, %q{test/nodes/test_as.rb}, %q{test/nodes/test_ascending.rb}, %q{test/nodes/test_bin.rb}, %q{test/nodes/test_count.rb}, %q{test/nodes/test_delete_statement.rb}, %q{test/nodes/test_descending.rb}, %q{test/nodes/test_equality.rb}, %q{test/nodes/test_infix_operation.rb}, %q{test/nodes/test_insert_statement.rb}, %q{test/nodes/test_named_function.rb}, %q{test/nodes/test_node.rb}, %q{test/nodes/test_not.rb}, %q{test/nodes/test_or.rb}, %q{test/nodes/test_select_core.rb}, %q{test/nodes/test_select_statement.rb}, %q{test/nodes/test_sql_literal.rb}, %q{test/nodes/test_sum.rb}, %q{test/nodes/test_update_statement.rb}, %q{test/support/fake_record.rb}, %q{test/test_activerecord_compat.rb}, %q{test/test_attributes.rb}, %q{test/test_crud.rb}, %q{test/test_delete_manager.rb}, %q{test/test_factory_methods.rb}, %q{test/test_insert_manager.rb}, %q{test/test_select_manager.rb}, %q{test/test_table.rb}, %q{test/test_update_manager.rb}, %q{test/visitors/test_depth_first.rb}, %q{test/visitors/test_dot.rb}, %q{test/visitors/test_ibm_db.rb}, %q{test/visitors/test_informix.rb}, %q{test/visitors/test_join_sql.rb}, %q{test/visitors/test_mssql.rb}, %q{test/visitors/test_mysql.rb}, %q{test/visitors/test_oracle.rb}, %q{test/visitors/test_postgres.rb}, %q{test/visitors/test_sqlite.rb}, %q{test/visitors/test_to_sql.rb}]
|
21
21
|
s.homepage = %q{http://github.com/rails/arel}
|
22
|
-
s.rdoc_options = [
|
23
|
-
s.require_paths = [
|
22
|
+
s.rdoc_options = [%q{--main}, %q{README.markdown}]
|
23
|
+
s.require_paths = [%q{lib}]
|
24
24
|
s.rubyforge_project = %q{arel}
|
25
|
-
s.rubygems_version = %q{1.
|
25
|
+
s.rubygems_version = %q{1.8.6.1}
|
26
26
|
s.summary = %q{Arel is a SQL AST manager for Ruby}
|
27
|
-
s.test_files = [
|
27
|
+
s.test_files = [%q{test/attributes/test_attribute.rb}, %q{test/nodes/test_as.rb}, %q{test/nodes/test_ascending.rb}, %q{test/nodes/test_bin.rb}, %q{test/nodes/test_count.rb}, %q{test/nodes/test_delete_statement.rb}, %q{test/nodes/test_descending.rb}, %q{test/nodes/test_equality.rb}, %q{test/nodes/test_infix_operation.rb}, %q{test/nodes/test_insert_statement.rb}, %q{test/nodes/test_named_function.rb}, %q{test/nodes/test_node.rb}, %q{test/nodes/test_not.rb}, %q{test/nodes/test_or.rb}, %q{test/nodes/test_select_core.rb}, %q{test/nodes/test_select_statement.rb}, %q{test/nodes/test_sql_literal.rb}, %q{test/nodes/test_sum.rb}, %q{test/nodes/test_update_statement.rb}, %q{test/test_activerecord_compat.rb}, %q{test/test_attributes.rb}, %q{test/test_crud.rb}, %q{test/test_delete_manager.rb}, %q{test/test_factory_methods.rb}, %q{test/test_insert_manager.rb}, %q{test/test_select_manager.rb}, %q{test/test_table.rb}, %q{test/test_update_manager.rb}, %q{test/visitors/test_depth_first.rb}, %q{test/visitors/test_dot.rb}, %q{test/visitors/test_ibm_db.rb}, %q{test/visitors/test_informix.rb}, %q{test/visitors/test_join_sql.rb}, %q{test/visitors/test_mssql.rb}, %q{test/visitors/test_mysql.rb}, %q{test/visitors/test_oracle.rb}, %q{test/visitors/test_postgres.rb}, %q{test/visitors/test_sqlite.rb}, %q{test/visitors/test_to_sql.rb}]
|
28
28
|
|
29
29
|
if s.respond_to? :specification_version then
|
30
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
31
30
|
s.specification_version = 3
|
32
31
|
|
33
|
-
if Gem::Version.new(Gem::
|
34
|
-
s.add_development_dependency(%q<
|
35
|
-
s.add_development_dependency(%q<hoe>, ["~> 2.9"])
|
32
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
33
|
+
s.add_development_dependency(%q<hoe>, ["~> 2.10"])
|
36
34
|
else
|
37
|
-
s.add_dependency(%q<
|
38
|
-
s.add_dependency(%q<hoe>, ["~> 2.9"])
|
35
|
+
s.add_dependency(%q<hoe>, ["~> 2.10"])
|
39
36
|
end
|
40
37
|
else
|
41
|
-
s.add_dependency(%q<
|
42
|
-
s.add_dependency(%q<hoe>, ["~> 2.9"])
|
38
|
+
s.add_dependency(%q<hoe>, ["~> 2.10"])
|
43
39
|
end
|
44
40
|
end
|
data/lib/arel.rb
CHANGED
data/lib/arel/factory_methods.rb
CHANGED
@@ -2,6 +2,14 @@ module Arel
|
|
2
2
|
###
|
3
3
|
# Methods for creating various nodes
|
4
4
|
module FactoryMethods
|
5
|
+
def create_true
|
6
|
+
Arel::Nodes::True.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_false
|
10
|
+
Arel::Nodes::False.new
|
11
|
+
end
|
12
|
+
|
5
13
|
def create_table_alias relation, name
|
6
14
|
Nodes::TableAlias.new(relation, name)
|
7
15
|
end
|
data/lib/arel/nodes.rb
CHANGED
data/lib/arel/nodes/node.rb
CHANGED
@@ -32,8 +32,7 @@ module Arel
|
|
32
32
|
#
|
33
33
|
# Maybe we should just use `Table.engine`? :'(
|
34
34
|
def to_sql engine = Table.engine
|
35
|
-
|
36
|
-
viz.accept self
|
35
|
+
engine.connection.visitor.accept self
|
37
36
|
end
|
38
37
|
|
39
38
|
# Iterate through AST, nodes will be yielded depth-first
|
data/lib/arel/predications.rb
CHANGED
data/lib/arel/select_manager.rb
CHANGED
@@ -149,13 +149,13 @@ module Arel
|
|
149
149
|
|
150
150
|
def wheres
|
151
151
|
warn "#{caller[0]}: SelectManager#wheres is deprecated and will be removed in ARel 3.0.0 with no replacement"
|
152
|
-
Compatibility::Wheres.new @engine, @ctx.wheres
|
152
|
+
Compatibility::Wheres.new @engine.connection_pool, @ctx.wheres
|
153
153
|
end
|
154
154
|
|
155
155
|
def where_sql
|
156
156
|
return if @ctx.wheres.empty?
|
157
157
|
|
158
|
-
viz = Visitors::WhereSql.new @engine
|
158
|
+
viz = Visitors::WhereSql.new @engine.connection_pool
|
159
159
|
Nodes::SqlLiteral.new viz.accept @ctx
|
160
160
|
end
|
161
161
|
|
@@ -205,12 +205,13 @@ module Arel
|
|
205
205
|
def join_sql
|
206
206
|
return nil if @ctx.source.right.empty?
|
207
207
|
|
208
|
-
sql =
|
208
|
+
sql = visitor.dup.extend(Visitors::JoinSql).accept @ctx
|
209
209
|
Nodes::SqlLiteral.new sql
|
210
210
|
end
|
211
211
|
|
212
212
|
def order_clauses
|
213
|
-
Visitors::OrderClauses.new(@engine
|
213
|
+
visitor = Visitors::OrderClauses.new(@engine.connection_pool)
|
214
|
+
visitor.accept(@ast).map { |x|
|
214
215
|
Nodes::SqlLiteral.new x
|
215
216
|
}
|
216
217
|
end
|
data/lib/arel/tree_manager.rb
CHANGED
@@ -4,21 +4,23 @@ module Arel
|
|
4
4
|
include Arel::Relation
|
5
5
|
include Arel::FactoryMethods
|
6
6
|
|
7
|
-
attr_accessor :visitor
|
8
7
|
attr_reader :ast, :engine
|
9
8
|
|
10
9
|
def initialize engine
|
11
|
-
@engine
|
12
|
-
@
|
13
|
-
@ctx = nil
|
10
|
+
@engine = engine
|
11
|
+
@ctx = nil
|
14
12
|
end
|
15
13
|
|
16
14
|
def to_dot
|
17
15
|
Visitors::Dot.new.accept @ast
|
18
16
|
end
|
19
17
|
|
18
|
+
def visitor
|
19
|
+
engine.connection.visitor
|
20
|
+
end
|
21
|
+
|
20
22
|
def to_sql
|
21
|
-
|
23
|
+
visitor.accept @ast
|
22
24
|
end
|
23
25
|
|
24
26
|
def initialize_copy other
|
data/lib/arel/visitors/oracle.rb
CHANGED
@@ -65,6 +65,18 @@ module Arel
|
|
65
65
|
"( #{visit o.left} MINUS #{visit o.right} )"
|
66
66
|
end
|
67
67
|
|
68
|
+
def visit_Arel_Nodes_UpdateStatement o
|
69
|
+
# Oracle does not allow ORDER BY/LIMIT in UPDATEs.
|
70
|
+
if o.orders.any? && o.limit.nil?
|
71
|
+
# However, there is no harm in silently eating the ORDER BY clause if no LIMIT has been provided,
|
72
|
+
# otherwise let the user deal with the error
|
73
|
+
o = o.dup
|
74
|
+
o.orders = []
|
75
|
+
end
|
76
|
+
|
77
|
+
super
|
78
|
+
end
|
79
|
+
|
68
80
|
###
|
69
81
|
# Hacks for the order clauses specific to Oracle
|
70
82
|
def order_hacks o
|
data/lib/arel/visitors/to_sql.rb
CHANGED
@@ -4,17 +4,15 @@ require 'date'
|
|
4
4
|
module Arel
|
5
5
|
module Visitors
|
6
6
|
class ToSql < Arel::Visitors::Visitor
|
7
|
-
def initialize
|
8
|
-
@
|
7
|
+
def initialize pool
|
8
|
+
@pool = pool
|
9
9
|
@connection = nil
|
10
|
-
@pool = nil
|
11
10
|
@quoted_tables = {}
|
12
11
|
@quoted_columns = {}
|
13
12
|
end
|
14
13
|
|
15
14
|
def accept object
|
16
15
|
self.last_column = nil
|
17
|
-
@pool = @engine.connection_pool
|
18
16
|
@pool.with_connection do |conn|
|
19
17
|
@connection = conn
|
20
18
|
super
|
@@ -90,6 +88,14 @@ key on UpdateManager using UpdateManager#key=
|
|
90
88
|
o.alias ? " AS #{visit o.alias}" : ''}"
|
91
89
|
end
|
92
90
|
|
91
|
+
def visit_Arel_Nodes_True o
|
92
|
+
"TRUE"
|
93
|
+
end
|
94
|
+
|
95
|
+
def visit_Arel_Nodes_False o
|
96
|
+
"FALSE"
|
97
|
+
end
|
98
|
+
|
93
99
|
def table_exists? name
|
94
100
|
@pool.table_exists? name
|
95
101
|
end
|
@@ -134,7 +140,7 @@ key on UpdateManager using UpdateManager#key=
|
|
134
140
|
(visit(o.top) if o.top),
|
135
141
|
(visit(o.set_quantifier) if o.set_quantifier),
|
136
142
|
("#{o.projections.map { |x| visit x }.join ', '}" unless o.projections.empty?),
|
137
|
-
(visit(o.source) if o.source),
|
143
|
+
("FROM #{visit(o.source)}" if o.source && !o.source.empty?),
|
138
144
|
("WHERE #{o.wheres.map { |x| visit x }.join ' AND ' }" unless o.wheres.empty?),
|
139
145
|
("GROUP BY #{o.groups.map { |x| visit x }.join ', ' }" unless o.groups.empty?),
|
140
146
|
(visit(o.having) if o.having),
|
@@ -280,10 +286,7 @@ key on UpdateManager using UpdateManager#key=
|
|
280
286
|
end
|
281
287
|
|
282
288
|
def visit_Arel_Nodes_JoinSource o
|
283
|
-
return unless o.left || !o.right.empty?
|
284
|
-
|
285
289
|
[
|
286
|
-
"FROM",
|
287
290
|
(visit(o.left) if o.left),
|
288
291
|
o.right.map { |j| visit j }.join(' ')
|
289
292
|
].compact.join ' '
|
data/test/nodes/test_bin.rb
CHANGED
@@ -8,13 +8,13 @@ module Arel
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_default_to_sql
|
11
|
-
viz = Arel::Visitors::ToSql.new Table.engine
|
11
|
+
viz = Arel::Visitors::ToSql.new Table.engine.connection_pool
|
12
12
|
node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
|
13
13
|
assert_equal 'zomg', viz.accept(node)
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_mysql_to_sql
|
17
|
-
viz = Arel::Visitors::MySQL.new Table.engine
|
17
|
+
viz = Arel::Visitors::MySQL.new Table.engine.connection_pool
|
18
18
|
node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
|
19
19
|
assert_equal 'BINARY zomg', viz.accept(node)
|
20
20
|
end
|
@@ -23,7 +23,7 @@ module Arel
|
|
23
23
|
def test_set_quantifier
|
24
24
|
core = Arel::Nodes::SelectCore.new
|
25
25
|
core.set_quantifier = Arel::Nodes::Distinct.new
|
26
|
-
viz = Arel::Visitors::ToSql.new Table.engine
|
26
|
+
viz = Arel::Visitors::ToSql.new Table.engine.connection_pool
|
27
27
|
assert_match 'DISTINCT', viz.accept(core)
|
28
28
|
end
|
29
29
|
end
|
@@ -3,6 +3,10 @@ require 'helper'
|
|
3
3
|
module Arel
|
4
4
|
module Nodes
|
5
5
|
describe 'sql literal' do
|
6
|
+
before do
|
7
|
+
@visitor = Visitors::ToSql.new Table.engine.connection_pool
|
8
|
+
end
|
9
|
+
|
6
10
|
describe 'sql' do
|
7
11
|
it 'makes a sql literal node' do
|
8
12
|
sql = Arel.sql 'foo'
|
@@ -13,38 +17,33 @@ module Arel
|
|
13
17
|
describe 'count' do
|
14
18
|
it 'makes a count node' do
|
15
19
|
node = SqlLiteral.new('*').count
|
16
|
-
|
17
|
-
viz.accept(node).must_be_like %{ COUNT(*) }
|
20
|
+
@visitor.accept(node).must_be_like %{ COUNT(*) }
|
18
21
|
end
|
19
22
|
|
20
23
|
it 'makes a distinct node' do
|
21
24
|
node = SqlLiteral.new('*').count true
|
22
|
-
|
23
|
-
viz.accept(node).must_be_like %{ COUNT(DISTINCT *) }
|
25
|
+
@visitor.accept(node).must_be_like %{ COUNT(DISTINCT *) }
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
29
|
describe 'equality' do
|
28
30
|
it 'makes an equality node' do
|
29
31
|
node = SqlLiteral.new('foo').eq(1)
|
30
|
-
|
31
|
-
viz.accept(node).must_be_like %{ foo = 1 }
|
32
|
+
@visitor.accept(node).must_be_like %{ foo = 1 }
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
36
|
describe 'grouped "or" equality' do
|
36
37
|
it 'makes a grouping node with an or node' do
|
37
38
|
node = SqlLiteral.new('foo').eq_any([1,2])
|
38
|
-
|
39
|
-
viz.accept(node).must_be_like %{ (foo = 1 OR foo = 2) }
|
39
|
+
@visitor.accept(node).must_be_like %{ (foo = 1 OR foo = 2) }
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe 'grouped "and" equality' do
|
44
44
|
it 'makes a grouping node with an or node' do
|
45
45
|
node = SqlLiteral.new('foo').eq_all([1,2])
|
46
|
-
|
47
|
-
viz.accept(node).must_be_like %{ (foo = 1 AND foo = 2) }
|
46
|
+
@visitor.accept(node).must_be_like %{ (foo = 1 AND foo = 2) }
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
data/test/support/fake_record.rb
CHANGED
@@ -3,9 +3,9 @@ module FakeRecord
|
|
3
3
|
end
|
4
4
|
|
5
5
|
class Connection
|
6
|
-
attr_reader :tables, :columns_hash
|
6
|
+
attr_reader :tables, :columns_hash, :visitor
|
7
7
|
|
8
|
-
def initialize
|
8
|
+
def initialize(visitor)
|
9
9
|
@tables = %w{ users photos developers products}
|
10
10
|
@columns = {
|
11
11
|
'users' => [
|
@@ -27,6 +27,7 @@ module FakeRecord
|
|
27
27
|
'users' => 'id',
|
28
28
|
'products' => 'id'
|
29
29
|
}
|
30
|
+
@visitor = visitor
|
30
31
|
end
|
31
32
|
|
32
33
|
def primary_key name
|
@@ -78,7 +79,7 @@ module FakeRecord
|
|
78
79
|
|
79
80
|
def initialize
|
80
81
|
@spec = Spec.new(:adapter => 'america')
|
81
|
-
@connection = Connection.new
|
82
|
+
@connection = Connection.new(Arel::Visitors::ToSql.new(self))
|
82
83
|
end
|
83
84
|
|
84
85
|
def with_connection
|
@@ -23,6 +23,16 @@ module Arel
|
|
23
23
|
assert_equal :one, on.expr
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_create_true
|
27
|
+
true_node = @factory.create_true
|
28
|
+
assert_instance_of Nodes::True, true_node
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create_false
|
32
|
+
false_node = @factory.create_false
|
33
|
+
assert_instance_of Nodes::False, false_node
|
34
|
+
end
|
35
|
+
|
26
36
|
def test_lower
|
27
37
|
lower = @factory.lower :one
|
28
38
|
assert_instance_of Nodes::NamedFunction, lower
|
data/test/test_select_manager.rb
CHANGED
data/test/test_update_manager.rb
CHANGED
@@ -62,6 +62,19 @@ module Arel
|
|
62
62
|
um = Arel::UpdateManager.new Table.engine
|
63
63
|
um.table(Table.new(:users)).must_equal um
|
64
64
|
end
|
65
|
+
|
66
|
+
it 'generates an update statement with joins' do
|
67
|
+
um = Arel::UpdateManager.new Table.engine
|
68
|
+
|
69
|
+
table = Table.new(:users)
|
70
|
+
join_source = Arel::Nodes::JoinSource.new(
|
71
|
+
table,
|
72
|
+
[table.create_join(Table.new(:posts))]
|
73
|
+
)
|
74
|
+
|
75
|
+
um.table join_source
|
76
|
+
um.to_sql.must_be_like %{ UPDATE "users" INNER JOIN "posts" }
|
77
|
+
end
|
65
78
|
end
|
66
79
|
|
67
80
|
describe 'where' do
|
data/test/visitors/test_mssql.rb
CHANGED
data/test/visitors/test_mysql.rb
CHANGED
@@ -8,7 +8,7 @@ module Arel
|
|
8
8
|
module Visitors
|
9
9
|
describe 'the to_sql visitor' do
|
10
10
|
before do
|
11
|
-
@visitor = ToSql.new Table.engine
|
11
|
+
@visitor = ToSql.new Table.engine.connection_pool
|
12
12
|
@table = Table.new(:users)
|
13
13
|
@attr = @table[:id]
|
14
14
|
end
|
@@ -220,7 +220,7 @@ module Arel
|
|
220
220
|
end
|
221
221
|
end
|
222
222
|
in_node = Nodes::In.new @attr, %w{ a b c }
|
223
|
-
visitor = visitor.new(Table.engine)
|
223
|
+
visitor = visitor.new(Table.engine.connection_pool)
|
224
224
|
visitor.expected = Table.engine.connection.columns(:users).find { |x|
|
225
225
|
x.name == 'name'
|
226
226
|
}
|
@@ -308,7 +308,7 @@ module Arel
|
|
308
308
|
end
|
309
309
|
end
|
310
310
|
in_node = Nodes::NotIn.new @attr, %w{ a b c }
|
311
|
-
visitor = visitor.new(Table.engine)
|
311
|
+
visitor = visitor.new(Table.engine.connection_pool)
|
312
312
|
visitor.expected = Table.engine.connection.columns(:users).find { |x|
|
313
313
|
x.name == 'name'
|
314
314
|
}
|
@@ -325,6 +325,22 @@ module Arel
|
|
325
325
|
end
|
326
326
|
end
|
327
327
|
|
328
|
+
describe 'Constants' do
|
329
|
+
it "should handle true" do
|
330
|
+
test = Table.new(:users).create_true
|
331
|
+
@visitor.accept(test).must_be_like %{
|
332
|
+
TRUE
|
333
|
+
}
|
334
|
+
end
|
335
|
+
|
336
|
+
it "should handle false" do
|
337
|
+
test = Table.new(:users).create_false
|
338
|
+
@visitor.accept(test).must_be_like %{
|
339
|
+
FALSE
|
340
|
+
}
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
328
344
|
describe 'TableAlias' do
|
329
345
|
it "should use the underlying table for checking columns" do
|
330
346
|
test = Table.new(:users).alias('zomgusers')[:id].eq '3'
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 2.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 2.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Aaron Patterson
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-
|
20
|
+
date: 2011-08-09 00:00:00 -07:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -72,6 +72,7 @@ extra_rdoc_files:
|
|
72
72
|
files:
|
73
73
|
- .autotest
|
74
74
|
- .gemtest
|
75
|
+
- Gemfile
|
75
76
|
- History.txt
|
76
77
|
- MIT-LICENSE.txt
|
77
78
|
- Manifest.txt
|
@@ -99,6 +100,7 @@ files:
|
|
99
100
|
- lib/arel/nodes/delete_statement.rb
|
100
101
|
- lib/arel/nodes/descending.rb
|
101
102
|
- lib/arel/nodes/equality.rb
|
103
|
+
- lib/arel/nodes/false.rb
|
102
104
|
- lib/arel/nodes/function.rb
|
103
105
|
- lib/arel/nodes/in.rb
|
104
106
|
- lib/arel/nodes/infix_operation.rb
|
@@ -115,6 +117,7 @@ files:
|
|
115
117
|
- lib/arel/nodes/string_join.rb
|
116
118
|
- lib/arel/nodes/table_alias.rb
|
117
119
|
- lib/arel/nodes/terminal.rb
|
120
|
+
- lib/arel/nodes/true.rb
|
118
121
|
- lib/arel/nodes/unary.rb
|
119
122
|
- lib/arel/nodes/unqualified_column.rb
|
120
123
|
- lib/arel/nodes/update_statement.rb
|