arel 6.0.0.beta2 → 6.0.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.
- checksums.yaml +4 -4
- data/History.txt +1 -1
- data/README.markdown +5 -5
- data/lib/arel.rb +1 -1
- data/lib/arel/collectors/sql_string.rb +7 -1
- data/lib/arel/expressions.rb +5 -4
- data/lib/arel/nodes.rb +1 -0
- data/lib/arel/nodes/bind_param.rb +6 -0
- data/lib/arel/nodes/sql_literal.rb +0 -3
- data/lib/arel/predications.rb +2 -2
- data/lib/arel/visitors/depth_first.rb +6 -0
- data/lib/arel/visitors/oracle.rb +4 -0
- data/lib/arel/visitors/postgresql.rb +4 -0
- data/lib/arel/visitors/reduce.rb +4 -4
- data/lib/arel/visitors/to_sql.rb +3 -2
- data/lib/arel/visitors/visitor.rb +15 -15
- metadata +26 -69
- data/.gitignore +0 -9
- data/.travis.yml +0 -18
- data/Gemfile +0 -5
- data/Rakefile +0 -15
- data/arel.gemspec +0 -24
- data/test/attributes/test_attribute.rb +0 -910
- data/test/collectors/test_bind_collector.rb +0 -70
- data/test/collectors/test_sql_string.rb +0 -38
- data/test/helper.rb +0 -22
- data/test/nodes/test_and.rb +0 -20
- data/test/nodes/test_as.rb +0 -34
- data/test/nodes/test_ascending.rb +0 -44
- data/test/nodes/test_bin.rb +0 -33
- data/test/nodes/test_binary.rb +0 -26
- data/test/nodes/test_count.rb +0 -33
- data/test/nodes/test_delete_statement.rb +0 -34
- data/test/nodes/test_descending.rb +0 -44
- data/test/nodes/test_distinct.rb +0 -20
- data/test/nodes/test_equality.rb +0 -84
- data/test/nodes/test_extract.rb +0 -41
- data/test/nodes/test_false.rb +0 -20
- data/test/nodes/test_grouping.rb +0 -25
- data/test/nodes/test_infix_operation.rb +0 -40
- data/test/nodes/test_insert_statement.rb +0 -42
- data/test/nodes/test_named_function.rb +0 -46
- data/test/nodes/test_node.rb +0 -39
- data/test/nodes/test_not.rb +0 -29
- data/test/nodes/test_or.rb +0 -34
- data/test/nodes/test_over.rb +0 -67
- data/test/nodes/test_select_core.rb +0 -69
- data/test/nodes/test_select_statement.rb +0 -49
- data/test/nodes/test_sql_literal.rb +0 -73
- data/test/nodes/test_sum.rb +0 -24
- data/test/nodes/test_table_alias.rb +0 -36
- data/test/nodes/test_true.rb +0 -21
- data/test/nodes/test_update_statement.rb +0 -58
- data/test/nodes/test_window.rb +0 -79
- data/test/support/fake_record.rb +0 -135
- data/test/test_attributes.rb +0 -66
- data/test/test_crud.rb +0 -63
- data/test/test_delete_manager.rb +0 -42
- data/test/test_factory_methods.rb +0 -44
- data/test/test_insert_manager.rb +0 -171
- data/test/test_select_manager.rb +0 -1181
- data/test/test_table.rb +0 -253
- data/test/test_update_manager.rb +0 -124
- data/test/visitors/test_bind_visitor.rb +0 -60
- data/test/visitors/test_depth_first.rb +0 -258
- data/test/visitors/test_dispatch_contamination.rb +0 -22
- data/test/visitors/test_dot.rb +0 -76
- data/test/visitors/test_ibm_db.rb +0 -33
- data/test/visitors/test_informix.rb +0 -58
- data/test/visitors/test_mssql.rb +0 -70
- data/test/visitors/test_mysql.rb +0 -60
- data/test/visitors/test_oracle.rb +0 -170
- data/test/visitors/test_postgres.rb +0 -122
- data/test/visitors/test_sqlite.rb +0 -23
- data/test/visitors/test_to_sql.rb +0 -598
data/test/test_table.rb
DELETED
@@ -1,253 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
describe Table do
|
5
|
-
before do
|
6
|
-
@relation = Table.new(:users)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should create join nodes' do
|
10
|
-
join = @relation.create_string_join 'foo'
|
11
|
-
assert_kind_of Arel::Nodes::StringJoin, join
|
12
|
-
assert_equal 'foo', join.left
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should create join nodes' do
|
16
|
-
join = @relation.create_join 'foo', 'bar'
|
17
|
-
assert_kind_of Arel::Nodes::InnerJoin, join
|
18
|
-
assert_equal 'foo', join.left
|
19
|
-
assert_equal 'bar', join.right
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should create join nodes with a klass' do
|
23
|
-
join = @relation.create_join 'foo', 'bar', Arel::Nodes::FullOuterJoin
|
24
|
-
assert_kind_of Arel::Nodes::FullOuterJoin, join
|
25
|
-
assert_equal 'foo', join.left
|
26
|
-
assert_equal 'bar', join.right
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should create join nodes with a klass' do
|
30
|
-
join = @relation.create_join 'foo', 'bar', Arel::Nodes::OuterJoin
|
31
|
-
assert_kind_of Arel::Nodes::OuterJoin, join
|
32
|
-
assert_equal 'foo', join.left
|
33
|
-
assert_equal 'bar', join.right
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should create join nodes with a klass' do
|
37
|
-
join = @relation.create_join 'foo', 'bar', Arel::Nodes::RightOuterJoin
|
38
|
-
assert_kind_of Arel::Nodes::RightOuterJoin, join
|
39
|
-
assert_equal 'foo', join.left
|
40
|
-
assert_equal 'bar', join.right
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should return an insert manager' do
|
44
|
-
im = @relation.compile_insert 'VALUES(NULL)'
|
45
|
-
assert_kind_of Arel::InsertManager, im
|
46
|
-
im.into Table.new(:users)
|
47
|
-
assert_equal "INSERT INTO \"users\" VALUES(NULL)", im.to_sql
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should return IM from insert_manager' do
|
51
|
-
im = @relation.insert_manager
|
52
|
-
assert_kind_of Arel::InsertManager, im
|
53
|
-
assert_equal im.engine, @relation.engine
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'skip' do
|
57
|
-
it 'should add an offset' do
|
58
|
-
sm = @relation.skip 2
|
59
|
-
sm.to_sql.must_be_like "SELECT FROM \"users\" OFFSET 2"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe 'select_manager' do
|
64
|
-
it 'should return an empty select manager' do
|
65
|
-
sm = @relation.select_manager
|
66
|
-
sm.to_sql.must_be_like 'SELECT'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'update_manager' do
|
71
|
-
it 'should return an update manager' do
|
72
|
-
um = @relation.update_manager
|
73
|
-
assert_kind_of Arel::UpdateManager, um
|
74
|
-
assert_equal um.engine, @relation.engine
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe 'delete_manager' do
|
79
|
-
it 'should return a delete manager' do
|
80
|
-
dm = @relation.delete_manager
|
81
|
-
assert_kind_of Arel::DeleteManager, dm
|
82
|
-
assert_equal dm.engine, @relation.engine
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe 'having' do
|
87
|
-
it 'adds a having clause' do
|
88
|
-
mgr = @relation.having @relation[:id].eq(10)
|
89
|
-
mgr.to_sql.must_be_like %{
|
90
|
-
SELECT FROM "users" HAVING "users"."id" = 10
|
91
|
-
}
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe 'backwards compat' do
|
96
|
-
describe 'join' do
|
97
|
-
it 'noops on nil' do
|
98
|
-
mgr = @relation.join nil
|
99
|
-
|
100
|
-
mgr.to_sql.must_be_like %{ SELECT FROM "users" }
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'takes a second argument for join type' do
|
104
|
-
right = @relation.alias
|
105
|
-
predicate = @relation[:id].eq(right[:id])
|
106
|
-
mgr = @relation.join(right, Nodes::OuterJoin).on(predicate)
|
107
|
-
|
108
|
-
mgr.to_sql.must_be_like %{
|
109
|
-
SELECT FROM "users"
|
110
|
-
LEFT OUTER JOIN "users" "users_2"
|
111
|
-
ON "users"."id" = "users_2"."id"
|
112
|
-
}
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe 'join' do
|
117
|
-
it 'creates an outer join' do
|
118
|
-
right = @relation.alias
|
119
|
-
predicate = @relation[:id].eq(right[:id])
|
120
|
-
mgr = @relation.outer_join(right).on(predicate)
|
121
|
-
|
122
|
-
mgr.to_sql.must_be_like %{
|
123
|
-
SELECT FROM "users"
|
124
|
-
LEFT OUTER JOIN "users" "users_2"
|
125
|
-
ON "users"."id" = "users_2"."id"
|
126
|
-
}
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe 'group' do
|
132
|
-
it 'should create a group' do
|
133
|
-
manager = @relation.group @relation[:id]
|
134
|
-
manager.to_sql.must_be_like %{
|
135
|
-
SELECT FROM "users" GROUP BY "users"."id"
|
136
|
-
}
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe 'alias' do
|
141
|
-
it 'should create a node that proxies to a table' do
|
142
|
-
@relation.aliases.must_equal []
|
143
|
-
|
144
|
-
node = @relation.alias
|
145
|
-
@relation.aliases.must_equal [node]
|
146
|
-
node.name.must_equal 'users_2'
|
147
|
-
node[:id].relation.must_equal node
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe 'new' do
|
152
|
-
it 'should accept an engine' do
|
153
|
-
rel = Table.new :users, 'foo'
|
154
|
-
rel.engine.must_equal 'foo'
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'should accept a hash' do
|
158
|
-
rel = Table.new :users, :engine => 'foo'
|
159
|
-
rel.engine.must_equal 'foo'
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'ignores as if it equals name' do
|
163
|
-
rel = Table.new :users, :as => 'users'
|
164
|
-
rel.table_alias.must_be_nil
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe 'order' do
|
169
|
-
it "should take an order" do
|
170
|
-
manager = @relation.order "foo"
|
171
|
-
manager.to_sql.must_be_like %{ SELECT FROM "users" ORDER BY foo }
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe 'take' do
|
176
|
-
it "should add a limit" do
|
177
|
-
manager = @relation.take 1
|
178
|
-
manager.project Nodes::SqlLiteral.new '*'
|
179
|
-
manager.to_sql.must_be_like %{ SELECT * FROM "users" LIMIT 1 }
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe 'project' do
|
184
|
-
it 'can project' do
|
185
|
-
manager = @relation.project Nodes::SqlLiteral.new '*'
|
186
|
-
manager.to_sql.must_be_like %{ SELECT * FROM "users" }
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'takes multiple parameters' do
|
190
|
-
manager = @relation.project Nodes::SqlLiteral.new('*'), Nodes::SqlLiteral.new('*')
|
191
|
-
manager.to_sql.must_be_like %{ SELECT *, * FROM "users" }
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe 'where' do
|
196
|
-
it "returns a tree manager" do
|
197
|
-
manager = @relation.where @relation[:id].eq 1
|
198
|
-
manager.project @relation[:id]
|
199
|
-
manager.must_be_kind_of TreeManager
|
200
|
-
manager.to_sql.must_be_like %{
|
201
|
-
SELECT "users"."id"
|
202
|
-
FROM "users"
|
203
|
-
WHERE "users"."id" = 1
|
204
|
-
}
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should have a name" do
|
209
|
-
@relation.name.must_equal 'users'
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should have a table name" do
|
213
|
-
@relation.table_name.must_equal 'users'
|
214
|
-
end
|
215
|
-
|
216
|
-
it "should have an engine" do
|
217
|
-
@relation.engine.must_equal Table.engine
|
218
|
-
end
|
219
|
-
|
220
|
-
describe '[]' do
|
221
|
-
describe 'when given a Symbol' do
|
222
|
-
it "manufactures an attribute if the symbol names an attribute within the relation" do
|
223
|
-
column = @relation[:id]
|
224
|
-
column.name.must_equal :id
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
describe 'equality' do
|
230
|
-
it 'is equal with equal ivars' do
|
231
|
-
relation1 = Table.new(:users, 'vroom')
|
232
|
-
relation1.aliases = %w[a b c]
|
233
|
-
relation1.table_alias = 'zomg'
|
234
|
-
relation2 = Table.new(:users, 'vroom')
|
235
|
-
relation2.aliases = %w[a b c]
|
236
|
-
relation2.table_alias = 'zomg'
|
237
|
-
array = [relation1, relation2]
|
238
|
-
assert_equal 1, array.uniq.size
|
239
|
-
end
|
240
|
-
|
241
|
-
it 'is not equal with different ivars' do
|
242
|
-
relation1 = Table.new(:users, 'vroom')
|
243
|
-
relation1.aliases = %w[a b c]
|
244
|
-
relation1.table_alias = 'zomg'
|
245
|
-
relation2 = Table.new(:users, 'vroom')
|
246
|
-
relation2.aliases = %w[x y z]
|
247
|
-
relation2.table_alias = 'zomg'
|
248
|
-
array = [relation1, relation2]
|
249
|
-
assert_equal 2, array.uniq.size
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
data/test/test_update_manager.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
describe 'update manager' do
|
5
|
-
describe 'new' do
|
6
|
-
it 'takes an engine' do
|
7
|
-
Arel::UpdateManager.new Table.engine
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should not quote sql literals" do
|
12
|
-
table = Table.new(:users)
|
13
|
-
um = Arel::UpdateManager.new Table.engine
|
14
|
-
um.table table
|
15
|
-
um.set [[table[:name], (Arel::Nodes::BindParam.new '?')]]
|
16
|
-
um.to_sql.must_be_like %{ UPDATE "users" SET "name" = ? }
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'handles limit properly' do
|
20
|
-
table = Table.new(:users)
|
21
|
-
um = Arel::UpdateManager.new Table.engine
|
22
|
-
um.key = 'id'
|
23
|
-
um.take 10
|
24
|
-
um.table table
|
25
|
-
um.set [[table[:name], nil]]
|
26
|
-
assert_match(/LIMIT 10/, um.to_sql)
|
27
|
-
end
|
28
|
-
|
29
|
-
describe 'set' do
|
30
|
-
it "updates with null" do
|
31
|
-
table = Table.new(:users)
|
32
|
-
um = Arel::UpdateManager.new Table.engine
|
33
|
-
um.table table
|
34
|
-
um.set [[table[:name], nil]]
|
35
|
-
um.to_sql.must_be_like %{ UPDATE "users" SET "name" = NULL }
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'takes a string' do
|
39
|
-
table = Table.new(:users)
|
40
|
-
um = Arel::UpdateManager.new Table.engine
|
41
|
-
um.table table
|
42
|
-
um.set Nodes::SqlLiteral.new "foo = bar"
|
43
|
-
um.to_sql.must_be_like %{ UPDATE "users" SET foo = bar }
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'takes a list of lists' do
|
47
|
-
table = Table.new(:users)
|
48
|
-
um = Arel::UpdateManager.new Table.engine
|
49
|
-
um.table table
|
50
|
-
um.set [[table[:id], 1], [table[:name], 'hello']]
|
51
|
-
um.to_sql.must_be_like %{
|
52
|
-
UPDATE "users" SET "id" = 1, "name" = 'hello'
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'chains' do
|
57
|
-
table = Table.new(:users)
|
58
|
-
um = Arel::UpdateManager.new Table.engine
|
59
|
-
um.set([[table[:id], 1], [table[:name], 'hello']]).must_equal um
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe 'table' do
|
64
|
-
it 'generates an update statement' do
|
65
|
-
um = Arel::UpdateManager.new Table.engine
|
66
|
-
um.table Table.new(:users)
|
67
|
-
um.to_sql.must_be_like %{ UPDATE "users" }
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'chains' do
|
71
|
-
um = Arel::UpdateManager.new Table.engine
|
72
|
-
um.table(Table.new(:users)).must_equal um
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'generates an update statement with joins' do
|
76
|
-
um = Arel::UpdateManager.new Table.engine
|
77
|
-
|
78
|
-
table = Table.new(:users)
|
79
|
-
join_source = Arel::Nodes::JoinSource.new(
|
80
|
-
table,
|
81
|
-
[table.create_join(Table.new(:posts))]
|
82
|
-
)
|
83
|
-
|
84
|
-
um.table join_source
|
85
|
-
um.to_sql.must_be_like %{ UPDATE "users" INNER JOIN "posts" }
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe 'where' do
|
90
|
-
it 'generates a where clause' do
|
91
|
-
table = Table.new :users
|
92
|
-
um = Arel::UpdateManager.new Table.engine
|
93
|
-
um.table table
|
94
|
-
um.where table[:id].eq(1)
|
95
|
-
um.to_sql.must_be_like %{
|
96
|
-
UPDATE "users" WHERE "users"."id" = 1
|
97
|
-
}
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'chains' do
|
101
|
-
table = Table.new :users
|
102
|
-
um = Arel::UpdateManager.new Table.engine
|
103
|
-
um.table table
|
104
|
-
um.where(table[:id].eq(1)).must_equal um
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe 'key' do
|
109
|
-
before do
|
110
|
-
@table = Table.new :users
|
111
|
-
@um = Arel::UpdateManager.new Table.engine
|
112
|
-
@um.key = @table[:foo]
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'can be set' do
|
116
|
-
@um.ast.key.must_equal @table[:foo]
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'can be accessed' do
|
120
|
-
@um.key.must_equal @table[:foo]
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'arel/visitors/bind_visitor'
|
3
|
-
require 'support/fake_record'
|
4
|
-
|
5
|
-
module Arel
|
6
|
-
module Visitors
|
7
|
-
class TestBindVisitor < Arel::Test
|
8
|
-
attr_reader :collector
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@collector = Collectors::SQLString.new
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
##
|
16
|
-
# Tests visit_Arel_Nodes_Assignment correctly
|
17
|
-
# substitutes binds with values from block
|
18
|
-
def test_assignment_binds_are_substituted
|
19
|
-
table = Table.new(:users)
|
20
|
-
um = Arel::UpdateManager.new Table.engine
|
21
|
-
bp = Nodes::BindParam.new '?'
|
22
|
-
um.set [[table[:name], bp]]
|
23
|
-
visitor = Class.new(Arel::Visitors::ToSql) {
|
24
|
-
include Arel::Visitors::BindVisitor
|
25
|
-
}.new Table.engine.connection
|
26
|
-
|
27
|
-
assignment = um.ast.values[0]
|
28
|
-
actual = visitor.accept(assignment, collector) {
|
29
|
-
"replace"
|
30
|
-
}
|
31
|
-
assert actual
|
32
|
-
value = actual.value
|
33
|
-
assert_like "\"name\" = replace", value
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_visitor_yields_on_binds
|
37
|
-
visitor = Class.new(Arel::Visitors::ToSql) {
|
38
|
-
include Arel::Visitors::BindVisitor
|
39
|
-
}.new nil
|
40
|
-
|
41
|
-
bp = Nodes::BindParam.new 'omg'
|
42
|
-
called = false
|
43
|
-
visitor.accept(bp, collector) { called = true }
|
44
|
-
assert called
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_visitor_only_yields_on_binds
|
48
|
-
visitor = Class.new(Arel::Visitors::ToSql) {
|
49
|
-
include Arel::Visitors::BindVisitor
|
50
|
-
}.new(nil)
|
51
|
-
|
52
|
-
bp = Arel.sql 'omg'
|
53
|
-
called = false
|
54
|
-
|
55
|
-
visitor.accept(bp, collector) { called = true }
|
56
|
-
refute called
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,258 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'set'
|
3
|
-
|
4
|
-
module Arel
|
5
|
-
module Visitors
|
6
|
-
class TestDepthFirst < Minitest::Test
|
7
|
-
Collector = Struct.new(:calls) do
|
8
|
-
def call object
|
9
|
-
calls << object
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def setup
|
14
|
-
@collector = Collector.new []
|
15
|
-
@visitor = Visitors::DepthFirst.new @collector
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_raises_with_object
|
19
|
-
assert_raises(TypeError) do
|
20
|
-
@visitor.accept(Object.new)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
# unary ops
|
26
|
-
[
|
27
|
-
Arel::Nodes::Not,
|
28
|
-
Arel::Nodes::Group,
|
29
|
-
Arel::Nodes::On,
|
30
|
-
Arel::Nodes::Grouping,
|
31
|
-
Arel::Nodes::Offset,
|
32
|
-
Arel::Nodes::Ordering,
|
33
|
-
Arel::Nodes::Having,
|
34
|
-
Arel::Nodes::StringJoin,
|
35
|
-
Arel::Nodes::UnqualifiedColumn,
|
36
|
-
Arel::Nodes::Top,
|
37
|
-
Arel::Nodes::Limit,
|
38
|
-
].each do |klass|
|
39
|
-
define_method("test_#{klass.name.gsub('::', '_')}") do
|
40
|
-
op = klass.new(:a)
|
41
|
-
@visitor.accept op
|
42
|
-
assert_equal [:a, op], @collector.calls
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# functions
|
47
|
-
[
|
48
|
-
Arel::Nodes::Exists,
|
49
|
-
Arel::Nodes::Avg,
|
50
|
-
Arel::Nodes::Min,
|
51
|
-
Arel::Nodes::Max,
|
52
|
-
Arel::Nodes::Sum,
|
53
|
-
].each do |klass|
|
54
|
-
define_method("test_#{klass.name.gsub('::', '_')}") do
|
55
|
-
func = klass.new(:a, "b")
|
56
|
-
@visitor.accept func
|
57
|
-
assert_equal [:a, "b", false, func], @collector.calls
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_named_function
|
62
|
-
func = Arel::Nodes::NamedFunction.new(:a, :b, "c")
|
63
|
-
@visitor.accept func
|
64
|
-
assert_equal [:a, :b, false, "c", func], @collector.calls
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_lock
|
68
|
-
lock = Nodes::Lock.new true
|
69
|
-
@visitor.accept lock
|
70
|
-
assert_equal [lock], @collector.calls
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_count
|
74
|
-
count = Nodes::Count.new :a, :b, "c"
|
75
|
-
@visitor.accept count
|
76
|
-
assert_equal [:a, "c", :b, count], @collector.calls
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_inner_join
|
80
|
-
join = Nodes::InnerJoin.new :a, :b
|
81
|
-
@visitor.accept join
|
82
|
-
assert_equal [:a, :b, join], @collector.calls
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_full_outer_join
|
86
|
-
join = Nodes::FullOuterJoin.new :a, :b
|
87
|
-
@visitor.accept join
|
88
|
-
assert_equal [:a, :b, join], @collector.calls
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_outer_join
|
92
|
-
join = Nodes::OuterJoin.new :a, :b
|
93
|
-
@visitor.accept join
|
94
|
-
assert_equal [:a, :b, join], @collector.calls
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_right_outer_join
|
98
|
-
join = Nodes::RightOuterJoin.new :a, :b
|
99
|
-
@visitor.accept join
|
100
|
-
assert_equal [:a, :b, join], @collector.calls
|
101
|
-
end
|
102
|
-
|
103
|
-
[
|
104
|
-
Arel::Nodes::Assignment,
|
105
|
-
Arel::Nodes::Between,
|
106
|
-
Arel::Nodes::DoesNotMatch,
|
107
|
-
Arel::Nodes::Equality,
|
108
|
-
Arel::Nodes::GreaterThan,
|
109
|
-
Arel::Nodes::GreaterThanOrEqual,
|
110
|
-
Arel::Nodes::In,
|
111
|
-
Arel::Nodes::LessThan,
|
112
|
-
Arel::Nodes::LessThanOrEqual,
|
113
|
-
Arel::Nodes::Matches,
|
114
|
-
Arel::Nodes::NotEqual,
|
115
|
-
Arel::Nodes::NotIn,
|
116
|
-
Arel::Nodes::Or,
|
117
|
-
Arel::Nodes::TableAlias,
|
118
|
-
Arel::Nodes::Values,
|
119
|
-
Arel::Nodes::As,
|
120
|
-
Arel::Nodes::DeleteStatement,
|
121
|
-
Arel::Nodes::JoinSource,
|
122
|
-
].each do |klass|
|
123
|
-
define_method("test_#{klass.name.gsub('::', '_')}") do
|
124
|
-
binary = klass.new(:a, :b)
|
125
|
-
@visitor.accept binary
|
126
|
-
assert_equal [:a, :b, binary], @collector.calls
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_Arel_Nodes_InfixOperation
|
131
|
-
binary = Arel::Nodes::InfixOperation.new(:o, :a, :b)
|
132
|
-
@visitor.accept binary
|
133
|
-
assert_equal [:a, :b, binary], @collector.calls
|
134
|
-
end
|
135
|
-
|
136
|
-
# N-ary
|
137
|
-
[
|
138
|
-
Arel::Nodes::And,
|
139
|
-
].each do |klass|
|
140
|
-
define_method("test_#{klass.name.gsub('::', '_')}") do
|
141
|
-
binary = klass.new([:a, :b, :c])
|
142
|
-
@visitor.accept binary
|
143
|
-
assert_equal [:a, :b, :c, binary], @collector.calls
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
[
|
148
|
-
Arel::Attributes::Integer,
|
149
|
-
Arel::Attributes::Float,
|
150
|
-
Arel::Attributes::String,
|
151
|
-
Arel::Attributes::Time,
|
152
|
-
Arel::Attributes::Boolean,
|
153
|
-
Arel::Attributes::Attribute
|
154
|
-
].each do |klass|
|
155
|
-
define_method("test_#{klass.name.gsub('::', '_')}") do
|
156
|
-
binary = klass.new(:a, :b)
|
157
|
-
@visitor.accept binary
|
158
|
-
assert_equal [:a, :b, binary], @collector.calls
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_table
|
163
|
-
relation = Arel::Table.new(:users)
|
164
|
-
@visitor.accept relation
|
165
|
-
assert_equal ['users', relation], @collector.calls
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_array
|
169
|
-
node = Nodes::Or.new(:a, :b)
|
170
|
-
list = [node]
|
171
|
-
@visitor.accept list
|
172
|
-
assert_equal [:a, :b, node, list], @collector.calls
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_set
|
176
|
-
node = Nodes::Or.new(:a, :b)
|
177
|
-
set = Set.new([node])
|
178
|
-
@visitor.accept set
|
179
|
-
assert_equal [:a, :b, node, set], @collector.calls
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_hash
|
183
|
-
node = Nodes::Or.new(:a, :b)
|
184
|
-
hash = { node => node }
|
185
|
-
@visitor.accept hash
|
186
|
-
assert_equal [:a, :b, node, :a, :b, node, hash], @collector.calls
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_update_statement
|
190
|
-
stmt = Nodes::UpdateStatement.new
|
191
|
-
stmt.relation = :a
|
192
|
-
stmt.values << :b
|
193
|
-
stmt.wheres << :c
|
194
|
-
stmt.orders << :d
|
195
|
-
stmt.limit = :e
|
196
|
-
|
197
|
-
@visitor.accept stmt
|
198
|
-
assert_equal [:a, :b, stmt.values, :c, stmt.wheres, :d, stmt.orders,
|
199
|
-
:e, stmt], @collector.calls
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_select_core
|
203
|
-
core = Nodes::SelectCore.new
|
204
|
-
core.projections << :a
|
205
|
-
core.froms = :b
|
206
|
-
core.wheres << :c
|
207
|
-
core.groups << :d
|
208
|
-
core.windows << :e
|
209
|
-
core.having = :f
|
210
|
-
|
211
|
-
@visitor.accept core
|
212
|
-
assert_equal [
|
213
|
-
:a, core.projections,
|
214
|
-
:b, [],
|
215
|
-
core.source,
|
216
|
-
:c, core.wheres,
|
217
|
-
:d, core.groups,
|
218
|
-
:e, core.windows,
|
219
|
-
:f,
|
220
|
-
core], @collector.calls
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_select_statement
|
224
|
-
ss = Nodes::SelectStatement.new
|
225
|
-
ss.cores.replace [:a]
|
226
|
-
ss.orders << :b
|
227
|
-
ss.limit = :c
|
228
|
-
ss.lock = :d
|
229
|
-
ss.offset = :e
|
230
|
-
|
231
|
-
@visitor.accept ss
|
232
|
-
assert_equal [
|
233
|
-
:a, ss.cores,
|
234
|
-
:b, ss.orders,
|
235
|
-
:c,
|
236
|
-
:d,
|
237
|
-
:e,
|
238
|
-
ss], @collector.calls
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_insert_statement
|
242
|
-
stmt = Nodes::InsertStatement.new
|
243
|
-
stmt.relation = :a
|
244
|
-
stmt.columns << :b
|
245
|
-
stmt.values = :c
|
246
|
-
|
247
|
-
@visitor.accept stmt
|
248
|
-
assert_equal [:a, :b, stmt.columns, :c, stmt], @collector.calls
|
249
|
-
end
|
250
|
-
|
251
|
-
def test_node
|
252
|
-
node = Nodes::Node.new
|
253
|
-
@visitor.accept node
|
254
|
-
assert_equal [node], @collector.calls
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|