arel 6.0.0.beta1 → 6.0.0.beta2

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.
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+ require 'set'
3
+
4
+ module Arel
5
+ module Nodes
6
+ describe 'Binary' do
7
+ describe '#hash' do
8
+ it 'generates a hash based on its value' do
9
+ eq = Equality.new('foo', 'bar')
10
+ eq2 = Equality.new('foo', 'bar')
11
+ eq3 = Equality.new('bar', 'baz')
12
+
13
+ assert_equal eq.hash, eq2.hash
14
+ refute_equal eq.hash, eq3.hash
15
+ end
16
+
17
+ it 'generates a hash specific to its class' do
18
+ eq = Equality.new('foo', 'bar')
19
+ neq = NotEqual.new('foo', 'bar')
20
+
21
+ refute_equal eq.hash, neq.hash
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -15,6 +15,14 @@ describe Arel::Nodes::Extract do
15
15
  EXTRACT(DATE FROM "users"."timestamp") AS foo
16
16
  }
17
17
  end
18
+
19
+ it 'should not mutate the extract' do
20
+ table = Arel::Table.new :users
21
+ extract = table[:timestamp].extract('date')
22
+ before = extract.dup
23
+ extract.as('foo')
24
+ assert_equal extract, before
25
+ end
18
26
  end
19
27
 
20
28
  describe 'equality' do
@@ -307,13 +307,11 @@ module Arel
307
307
  table = Table.new :users
308
308
  @m1 = Arel::SelectManager.new Table.engine, table
309
309
  @m1.project Arel.star
310
- @m1.where(table[:age].in(18..60))
310
+ @m1.where(table[:age].between(18..60))
311
311
 
312
312
  @m2 = Arel::SelectManager.new Table.engine, table
313
313
  @m2.project Arel.star
314
- @m2.where(table[:age].in(40..99))
315
-
316
-
314
+ @m2.where(table[:age].between(40..99))
317
315
  end
318
316
 
319
317
  it 'should except two managers' do
@@ -1158,5 +1156,26 @@ module Arel
1158
1156
  manager.distinct(false).must_equal manager
1159
1157
  end
1160
1158
  end
1159
+
1160
+ describe 'distinct_on' do
1161
+ it 'sets the quantifier' do
1162
+ manager = Arel::SelectManager.new Table.engine
1163
+ table = Table.new :users
1164
+
1165
+ manager.distinct_on(table['id'])
1166
+ manager.ast.cores.last.set_quantifier.must_equal Arel::Nodes::DistinctOn.new(table['id'])
1167
+
1168
+ manager.distinct_on(false)
1169
+ manager.ast.cores.last.set_quantifier.must_equal nil
1170
+ end
1171
+
1172
+ it "chains" do
1173
+ manager = Arel::SelectManager.new Table.engine
1174
+ table = Table.new :users
1175
+
1176
+ manager.distinct_on(table['id']).must_equal manager
1177
+ manager.distinct_on(false).must_equal manager
1178
+ end
1179
+ end
1161
1180
  end
1162
1181
  end
@@ -35,9 +35,6 @@ module Arel
35
35
 
36
36
  def test_visitor_yields_on_binds
37
37
  visitor = Class.new(Arel::Visitors::ToSql) {
38
- def initialize omg
39
- end
40
-
41
38
  include Arel::Visitors::BindVisitor
42
39
  }.new nil
43
40
 
@@ -49,9 +46,6 @@ module Arel
49
46
 
50
47
  def test_visitor_only_yields_on_binds
51
48
  visitor = Class.new(Arel::Visitors::ToSql) {
52
- def initialize omg
53
- end
54
-
55
49
  include Arel::Visitors::BindVisitor
56
50
  }.new(nil)
57
51
 
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'set'
2
3
 
3
4
  module Arel
4
5
  module Visitors
@@ -171,6 +172,13 @@ module Arel
171
172
  assert_equal [:a, :b, node, list], @collector.calls
172
173
  end
173
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
+
174
182
  def test_hash
175
183
  node = Nodes::Or.new(:a, :b)
176
184
  hash = { node => node }
@@ -11,21 +11,21 @@ module Arel
11
11
  @visitor.accept(node, Collectors::SQLString.new).value
12
12
  end
13
13
 
14
- it 'uses LIMIT n to limit results' do
14
+ it 'uses FIRST n to limit results' do
15
15
  stmt = Nodes::SelectStatement.new
16
16
  stmt.limit = Nodes::Limit.new(1)
17
17
  sql = compile(stmt)
18
- sql.must_be_like "SELECT LIMIT 1"
18
+ sql.must_be_like "SELECT FIRST 1"
19
19
  end
20
20
 
21
- it 'uses LIMIT n in updates with a limit' do
21
+ it 'uses FIRST n in updates with a limit' do
22
22
  table = Table.new(:users)
23
23
  stmt = Nodes::UpdateStatement.new
24
24
  stmt.relation = table
25
25
  stmt.limit = Nodes::Limit.new(Nodes.build_quoted(1))
26
26
  stmt.key = table[:id]
27
27
  sql = compile(stmt)
28
- sql.must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT LIMIT 1 \"users\".\"id\" FROM \"users\")"
28
+ sql.must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT FIRST 1 \"users\".\"id\" FROM \"users\")"
29
29
  end
30
30
 
31
31
  it 'uses SKIP n to jump results' do
@@ -35,12 +35,12 @@ module Arel
35
35
  sql.must_be_like "SELECT SKIP 10"
36
36
  end
37
37
 
38
- it 'uses SKIP before LIMIT' do
38
+ it 'uses SKIP before FIRST' do
39
39
  stmt = Nodes::SelectStatement.new
40
40
  stmt.limit = Nodes::Limit.new(1)
41
41
  stmt.offset = Nodes::Offset.new(1)
42
42
  sql = compile(stmt)
43
- sql.must_be_like "SELECT SKIP 1 LIMIT 1"
43
+ sql.must_be_like "SELECT SKIP 1 FIRST 1"
44
44
  end
45
45
 
46
46
  it 'uses INNER JOIN to perform joins' do
@@ -87,6 +87,16 @@ module Arel
87
87
  }
88
88
  end
89
89
 
90
+ it 'creates a subquery when there is group by' do
91
+ stmt = Nodes::SelectStatement.new
92
+ stmt.cores.first.groups << Nodes::SqlLiteral.new('foo')
93
+ stmt.limit = Nodes::Limit.new(10)
94
+ sql = compile stmt
95
+ sql.must_be_like %{
96
+ SELECT * FROM (SELECT GROUP BY foo ) WHERE ROWNUM <= 10
97
+ }
98
+ end
99
+
90
100
  it 'creates a subquery when there is DISTINCT' do
91
101
  stmt = Nodes::SelectStatement.new
92
102
  stmt.cores.first.set_quantifier = Arel::Nodes::Distinct.new
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'set'
2
3
 
3
4
  module Arel
4
5
  module Visitors
@@ -28,7 +29,7 @@ module Arel
28
29
  end
29
30
 
30
31
  def dispatch
31
- { Arel::Table => 'hello' }
32
+ { Arel::Table.name => 'hello' }
32
33
  end
33
34
  }.new
34
35
 
@@ -131,6 +132,13 @@ module Arel
131
132
  end
132
133
  end
133
134
 
135
+ describe 'Nodes::Grouping' do
136
+ it 'wraps nested groupings in brackets only once' do
137
+ sql = compile Nodes::Grouping.new(Nodes::Grouping.new(Nodes.build_quoted('foo')))
138
+ sql.must_equal "('foo')"
139
+ end
140
+ end
141
+
134
142
  describe 'Nodes::NotEqual' do
135
143
  it 'should handle false' do
136
144
  val = Nodes.build_quoted(false, @table[:active])
@@ -221,6 +229,10 @@ module Arel
221
229
  compile(Nodes.build_quoted({:a => 1}))
222
230
  end
223
231
 
232
+ it "should visit_Set" do
233
+ compile Nodes.build_quoted(Set.new([1, 2]))
234
+ end
235
+
224
236
  it "should visit_BigDecimal" do
225
237
  compile Nodes.build_quoted(BigDecimal.new('2.14'))
226
238
  end
@@ -300,6 +312,13 @@ module Arel
300
312
  }
301
313
  end
302
314
 
315
+ it "can handle ESCAPE" do
316
+ node = @table[:name].matches('foo!%', '!')
317
+ compile(node).must_be_like %{
318
+ "users"."name" LIKE 'foo!%' ESCAPE '!'
319
+ }
320
+ end
321
+
303
322
  it 'can handle subqueries' do
304
323
  subquery = @table.project(:id).where(@table[:name].matches('foo%'))
305
324
  node = @attr.in subquery
@@ -317,6 +336,13 @@ module Arel
317
336
  }
318
337
  end
319
338
 
339
+ it "can handle ESCAPE" do
340
+ node = @table[:name].does_not_match('foo!%', '!')
341
+ compile(node).must_be_like %{
342
+ "users"."name" NOT LIKE 'foo!%' ESCAPE '!'
343
+ }
344
+ end
345
+
320
346
  it 'can handle subqueries' do
321
347
  subquery = @table.project(:id).where(@table[:name].does_not_match('foo%'))
322
348
  node = @attr.in subquery
@@ -349,33 +375,33 @@ module Arel
349
375
  end
350
376
 
351
377
  it 'can handle two dot ranges' do
352
- node = @attr.in 1..3
378
+ node = @attr.between 1..3
353
379
  compile(node).must_be_like %{
354
380
  "users"."id" BETWEEN 1 AND 3
355
381
  }
356
382
  end
357
383
 
358
384
  it 'can handle three dot ranges' do
359
- node = @attr.in 1...3
385
+ node = @attr.between 1...3
360
386
  compile(node).must_be_like %{
361
387
  "users"."id" >= 1 AND "users"."id" < 3
362
388
  }
363
389
  end
364
390
 
365
391
  it 'can handle ranges bounded by infinity' do
366
- node = @attr.in 1..Float::INFINITY
392
+ node = @attr.between 1..Float::INFINITY
367
393
  compile(node).must_be_like %{
368
394
  "users"."id" >= 1
369
395
  }
370
- node = @attr.in(-Float::INFINITY..3)
396
+ node = @attr.between(-Float::INFINITY..3)
371
397
  compile(node).must_be_like %{
372
398
  "users"."id" <= 3
373
399
  }
374
- node = @attr.in(-Float::INFINITY...3)
400
+ node = @attr.between(-Float::INFINITY...3)
375
401
  compile(node).must_be_like %{
376
402
  "users"."id" < 3
377
403
  }
378
- node = @attr.in(-Float::INFINITY..Float::INFINITY)
404
+ node = @attr.between(-Float::INFINITY..Float::INFINITY)
379
405
  compile(node).must_be_like %{1=1}
380
406
  end
381
407
 
@@ -453,33 +479,33 @@ module Arel
453
479
  end
454
480
 
455
481
  it 'can handle two dot ranges' do
456
- node = @attr.not_in 1..3
457
- compile(node).must_be_like %{
458
- "users"."id" < 1 OR "users"."id" > 3
459
- }
482
+ node = @attr.not_between 1..3
483
+ compile(node).must_equal(
484
+ %{("users"."id" < 1 OR "users"."id" > 3)}
485
+ )
460
486
  end
461
487
 
462
488
  it 'can handle three dot ranges' do
463
- node = @attr.not_in 1...3
464
- compile(node).must_be_like %{
465
- "users"."id" < 1 OR "users"."id" >= 3
466
- }
489
+ node = @attr.not_between 1...3
490
+ compile(node).must_equal(
491
+ %{("users"."id" < 1 OR "users"."id" >= 3)}
492
+ )
467
493
  end
468
494
 
469
495
  it 'can handle ranges bounded by infinity' do
470
- node = @attr.not_in 1..Float::INFINITY
496
+ node = @attr.not_between 1..Float::INFINITY
471
497
  compile(node).must_be_like %{
472
498
  "users"."id" < 1
473
499
  }
474
- node = @attr.not_in(-Float::INFINITY..3)
500
+ node = @attr.not_between(-Float::INFINITY..3)
475
501
  compile(node).must_be_like %{
476
502
  "users"."id" > 3
477
503
  }
478
- node = @attr.not_in(-Float::INFINITY...3)
504
+ node = @attr.not_between(-Float::INFINITY...3)
479
505
  compile(node).must_be_like %{
480
506
  "users"."id" >= 3
481
507
  }
482
- node = @attr.not_in(-Float::INFINITY..Float::INFINITY)
508
+ node = @attr.not_between(-Float::INFINITY..Float::INFINITY)
483
509
  compile(node).must_be_like %{1=0}
484
510
  end
485
511
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.beta1
4
+ version: 6.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -11,50 +11,36 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-08-18 00:00:00.000000000 Z
14
+ date: 2014-10-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: minitest
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
- - - "~>"
20
+ - - ~>
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5.4'
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '5.4'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rdoc
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - "~>"
34
+ - - ~>
35
35
  - !ruby/object:Gem::Version
36
36
  version: '4.0'
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - "~>"
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
43
  version: '4.0'
44
- - !ruby/object:Gem::Dependency
45
- name: hoe
46
- requirement: !ruby/object:Gem::Requirement
47
- requirements:
48
- - - "~>"
49
- - !ruby/object:Gem::Version
50
- version: '3.12'
51
- type: :development
52
- prerelease: false
53
- version_requirements: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '3.12'
58
44
  description: |-
59
45
  Arel Really Exasperates Logicians
60
46
 
@@ -70,22 +56,18 @@ email:
70
56
  - aaron@tenderlovemaking.com
71
57
  - bryan@brynary.com
72
58
  - miloops@gmail.com
73
- - nick@example.org
74
59
  executables: []
75
60
  extensions: []
76
61
  extra_rdoc_files:
77
62
  - History.txt
78
63
  - MIT-LICENSE.txt
79
- - Manifest.txt
80
64
  - README.markdown
81
65
  files:
82
- - ".autotest"
83
- - ".gemtest"
84
- - ".travis.yml"
66
+ - .gitignore
67
+ - .travis.yml
85
68
  - Gemfile
86
69
  - History.txt
87
70
  - MIT-LICENSE.txt
88
- - Manifest.txt
89
71
  - README.markdown
90
72
  - Rakefile
91
73
  - arel.gemspec
@@ -121,6 +103,7 @@ files:
121
103
  - lib/arel/nodes/inner_join.rb
122
104
  - lib/arel/nodes/insert_statement.rb
123
105
  - lib/arel/nodes/join_source.rb
106
+ - lib/arel/nodes/matches.rb
124
107
  - lib/arel/nodes/named_function.rb
125
108
  - lib/arel/nodes/node.rb
126
109
  - lib/arel/nodes/outer_join.rb
@@ -170,6 +153,7 @@ files:
170
153
  - test/nodes/test_as.rb
171
154
  - test/nodes/test_ascending.rb
172
155
  - test/nodes/test_bin.rb
156
+ - test/nodes/test_binary.rb
173
157
  - test/nodes/test_count.rb
174
158
  - test/nodes/test_delete_statement.rb
175
159
  - test/nodes/test_descending.rb
@@ -214,80 +198,30 @@ files:
214
198
  - test/visitors/test_postgres.rb
215
199
  - test/visitors/test_sqlite.rb
216
200
  - test/visitors/test_to_sql.rb
217
- homepage: http://github.com/rails/arel
201
+ homepage: https://github.com/rails/arel
218
202
  licenses:
219
203
  - MIT
220
204
  metadata: {}
221
205
  post_install_message:
222
206
  rdoc_options:
223
- - "--main"
207
+ - --main
224
208
  - README.markdown
225
209
  require_paths:
226
210
  - lib
227
211
  required_ruby_version: !ruby/object:Gem::Requirement
228
212
  requirements:
229
- - - ">="
213
+ - - '>='
230
214
  - !ruby/object:Gem::Version
231
215
  version: '0'
232
216
  required_rubygems_version: !ruby/object:Gem::Requirement
233
217
  requirements:
234
- - - ">"
218
+ - - '>'
235
219
  - !ruby/object:Gem::Version
236
220
  version: 1.3.1
237
221
  requirements: []
238
222
  rubyforge_project:
239
- rubygems_version: 2.2.2
223
+ rubygems_version: 2.2.1
240
224
  signing_key:
241
225
  specification_version: 4
242
226
  summary: Arel Really Exasperates Logicians Arel is a SQL AST manager for Ruby
243
- test_files:
244
- - test/attributes/test_attribute.rb
245
- - test/collectors/test_bind_collector.rb
246
- - test/collectors/test_sql_string.rb
247
- - test/nodes/test_and.rb
248
- - test/nodes/test_as.rb
249
- - test/nodes/test_ascending.rb
250
- - test/nodes/test_bin.rb
251
- - test/nodes/test_count.rb
252
- - test/nodes/test_delete_statement.rb
253
- - test/nodes/test_descending.rb
254
- - test/nodes/test_distinct.rb
255
- - test/nodes/test_equality.rb
256
- - test/nodes/test_extract.rb
257
- - test/nodes/test_false.rb
258
- - test/nodes/test_grouping.rb
259
- - test/nodes/test_infix_operation.rb
260
- - test/nodes/test_insert_statement.rb
261
- - test/nodes/test_named_function.rb
262
- - test/nodes/test_node.rb
263
- - test/nodes/test_not.rb
264
- - test/nodes/test_or.rb
265
- - test/nodes/test_over.rb
266
- - test/nodes/test_select_core.rb
267
- - test/nodes/test_select_statement.rb
268
- - test/nodes/test_sql_literal.rb
269
- - test/nodes/test_sum.rb
270
- - test/nodes/test_table_alias.rb
271
- - test/nodes/test_true.rb
272
- - test/nodes/test_update_statement.rb
273
- - test/nodes/test_window.rb
274
- - test/test_attributes.rb
275
- - test/test_crud.rb
276
- - test/test_delete_manager.rb
277
- - test/test_factory_methods.rb
278
- - test/test_insert_manager.rb
279
- - test/test_select_manager.rb
280
- - test/test_table.rb
281
- - test/test_update_manager.rb
282
- - test/visitors/test_bind_visitor.rb
283
- - test/visitors/test_depth_first.rb
284
- - test/visitors/test_dispatch_contamination.rb
285
- - test/visitors/test_dot.rb
286
- - test/visitors/test_ibm_db.rb
287
- - test/visitors/test_informix.rb
288
- - test/visitors/test_mssql.rb
289
- - test/visitors/test_mysql.rb
290
- - test/visitors/test_oracle.rb
291
- - test/visitors/test_postgres.rb
292
- - test/visitors/test_sqlite.rb
293
- - test/visitors/test_to_sql.rb
227
+ test_files: []