arel 3.0.3 → 4.0.0.beta1
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 +7 -0
- data/.travis.yml +2 -2
- data/Gemfile +3 -4
- data/History.txt +0 -51
- data/Manifest.txt +8 -2
- data/README.markdown +1 -1
- data/Rakefile +1 -1
- data/arel.gemspec +21 -29
- data/lib/arel.rb +1 -3
- data/lib/arel/nodes.rb +1 -0
- data/lib/arel/nodes/and.rb +10 -0
- data/lib/arel/nodes/binary.rb +11 -0
- data/lib/arel/nodes/extract.rb +11 -0
- data/lib/arel/nodes/false.rb +7 -0
- data/lib/arel/nodes/function.rb +11 -0
- data/lib/arel/nodes/grouping.rb +7 -0
- data/lib/arel/nodes/insert_statement.rb +12 -0
- data/lib/arel/nodes/named_function.rb +9 -0
- data/lib/arel/nodes/select_core.rb +20 -0
- data/lib/arel/nodes/select_statement.rb +15 -1
- data/lib/arel/nodes/table_alias.rb +4 -0
- data/lib/arel/nodes/terminal.rb +7 -0
- data/lib/arel/nodes/true.rb +7 -0
- data/lib/arel/nodes/unary.rb +10 -1
- data/lib/arel/nodes/update_statement.rb +15 -0
- data/lib/arel/nodes/window.rb +30 -3
- data/lib/arel/select_manager.rb +4 -0
- data/lib/arel/table.rb +13 -0
- data/lib/arel/tree_manager.rb +0 -2
- data/lib/arel/visitors/bind_visitor.rb +10 -0
- data/lib/arel/visitors/dot.rb +1 -1
- data/lib/arel/visitors/oracle.rb +1 -2
- data/lib/arel/visitors/to_sql.rb +138 -27
- data/test/nodes/test_and.rb +20 -0
- data/test/nodes/test_as.rb +12 -0
- data/test/nodes/test_ascending.rb +10 -0
- data/test/nodes/test_bin.rb +10 -0
- data/test/nodes/test_count.rb +12 -0
- data/test/nodes/test_delete_statement.rb +20 -0
- data/test/nodes/test_descending.rb +10 -0
- data/test/nodes/test_distinct.rb +20 -0
- data/test/nodes/test_equality.rb +10 -0
- data/test/nodes/test_extract.rb +14 -0
- data/test/nodes/test_false.rb +20 -0
- data/test/nodes/test_grouping.rb +25 -0
- data/test/nodes/test_infix_operation.rb +10 -0
- data/test/nodes/test_insert_statement.rb +24 -0
- data/test/nodes/test_named_function.rb +16 -0
- data/test/nodes/test_not.rb +12 -0
- data/test/nodes/test_or.rb +12 -0
- data/test/nodes/test_over.rb +18 -0
- data/test/nodes/test_select_core.rb +38 -0
- data/test/nodes/test_select_statement.rb +36 -0
- data/test/nodes/test_sql_literal.rb +10 -0
- data/test/nodes/test_sum.rb +12 -0
- data/test/nodes/test_table_alias.rb +36 -0
- data/test/nodes/test_true.rb +21 -0
- data/test/nodes/test_update_statement.rb +40 -0
- data/test/nodes/test_window.rb +73 -0
- data/test/test_attributes.rb +12 -0
- data/test/test_insert_manager.rb +0 -2
- data/test/test_select_manager.rb +10 -5
- data/test/test_table.rb +24 -0
- data/test/test_update_manager.rb +8 -0
- data/test/visitors/test_bind_visitor.rb +20 -1
- data/test/visitors/test_oracle.rb +1 -2
- data/test/visitors/test_to_sql.rb +44 -0
- metadata +76 -86
- data/lib/arel/nodes/ordering.rb +0 -6
- data/lib/arel/relation.rb +0 -6
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
module Nodes
|
5
|
+
describe 'And' do
|
6
|
+
describe 'equality' do
|
7
|
+
it 'is equal with equal ivars' do
|
8
|
+
array = [And.new(['foo', 'bar']), And.new(['foo', 'bar'])]
|
9
|
+
assert_equal 1, array.uniq.size
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'is not equal with different ivars' do
|
13
|
+
array = [And.new(['foo', 'bar']), And.new(['foo', 'baz'])]
|
14
|
+
assert_equal 2, array.uniq.size
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/test/nodes/test_as.rb
CHANGED
@@ -17,6 +17,18 @@ module Arel
|
|
17
17
|
assert_kind_of Arel::Nodes::SqlLiteral, as.right
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
describe 'equality' do
|
22
|
+
it 'is equal with equal ivars' do
|
23
|
+
array = [As.new('foo', 'bar'), As.new('foo', 'bar')]
|
24
|
+
assert_equal 1, array.uniq.size
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is not equal with different ivars' do
|
28
|
+
array = [As.new('foo', 'bar'), As.new('foo', 'baz')]
|
29
|
+
assert_equal 2, array.uniq.size
|
30
|
+
end
|
31
|
+
end
|
20
32
|
end
|
21
33
|
end
|
22
34
|
end
|
@@ -29,6 +29,16 @@ module Arel
|
|
29
29
|
ascending = Ascending.new 'zomg'
|
30
30
|
assert !ascending.descending?
|
31
31
|
end
|
32
|
+
|
33
|
+
def test_equality_with_same_ivars
|
34
|
+
array = [Ascending.new('zomg'), Ascending.new('zomg')]
|
35
|
+
assert_equal 1, array.uniq.size
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_inequality_with_different_ivars
|
39
|
+
array = [Ascending.new('zomg'), Ascending.new('zomg!')]
|
40
|
+
assert_equal 2, array.uniq.size
|
41
|
+
end
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
data/test/nodes/test_bin.rb
CHANGED
@@ -18,6 +18,16 @@ module Arel
|
|
18
18
|
node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
|
19
19
|
assert_equal 'BINARY zomg', viz.accept(node)
|
20
20
|
end
|
21
|
+
|
22
|
+
def test_equality_with_same_ivars
|
23
|
+
array = [Bin.new('zomg'), Bin.new('zomg')]
|
24
|
+
assert_equal 1, array.uniq.size
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_inequality_with_different_ivars
|
28
|
+
array = [Bin.new('zomg'), Bin.new('zomg!')]
|
29
|
+
assert_equal 2, array.uniq.size
|
30
|
+
end
|
21
31
|
end
|
22
32
|
end
|
23
33
|
end
|
data/test/nodes/test_count.rb
CHANGED
@@ -24,4 +24,16 @@ describe Arel::Nodes::Count do
|
|
24
24
|
}
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
describe 'equality' do
|
29
|
+
it 'is equal with equal ivars' do
|
30
|
+
array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo')]
|
31
|
+
assert_equal 1, array.uniq.size
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'is not equal with different ivars' do
|
35
|
+
array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo!')]
|
36
|
+
assert_equal 2, array.uniq.size
|
37
|
+
end
|
38
|
+
end
|
27
39
|
end
|
@@ -11,4 +11,24 @@ describe Arel::Nodes::DeleteStatement do
|
|
11
11
|
dolly.wheres.wont_be_same_as statement.wheres
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
describe 'equality' do
|
16
|
+
it 'is equal with equal ivars' do
|
17
|
+
statement1 = Arel::Nodes::DeleteStatement.new
|
18
|
+
statement1.wheres = %w[a b c]
|
19
|
+
statement2 = Arel::Nodes::DeleteStatement.new
|
20
|
+
statement2.wheres = %w[a b c]
|
21
|
+
array = [statement1, statement2]
|
22
|
+
assert_equal 1, array.uniq.size
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'is not equal with different ivars' do
|
26
|
+
statement1 = Arel::Nodes::DeleteStatement.new
|
27
|
+
statement1.wheres = %w[a b c]
|
28
|
+
statement2 = Arel::Nodes::DeleteStatement.new
|
29
|
+
statement2.wheres = %w[1 2 3]
|
30
|
+
array = [statement1, statement2]
|
31
|
+
assert_equal 2, array.uniq.size
|
32
|
+
end
|
33
|
+
end
|
14
34
|
end
|
@@ -29,6 +29,16 @@ module Arel
|
|
29
29
|
descending = Descending.new 'zomg'
|
30
30
|
assert descending.descending?
|
31
31
|
end
|
32
|
+
|
33
|
+
def test_equality_with_same_ivars
|
34
|
+
array = [Descending.new('zomg'), Descending.new('zomg')]
|
35
|
+
assert_equal 1, array.uniq.size
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_inequality_with_different_ivars
|
39
|
+
array = [Descending.new('zomg'), Descending.new('zomg!')]
|
40
|
+
assert_equal 2, array.uniq.size
|
41
|
+
end
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
module Nodes
|
5
|
+
describe 'Distinct' do
|
6
|
+
describe 'equality' do
|
7
|
+
it 'is equal to other distinct nodes' do
|
8
|
+
array = [Distinct.new, Distinct.new]
|
9
|
+
assert_equal 1, array.uniq.size
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'is not equal with other nodes' do
|
13
|
+
array = [Distinct.new, Node.new]
|
14
|
+
assert_equal 2, array.uniq.size
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/test/nodes/test_equality.rb
CHANGED
@@ -69,6 +69,16 @@ module Arel
|
|
69
69
|
node.right.must_equal right
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
it 'is equal with equal ivars' do
|
74
|
+
array = [Equality.new('foo', 'bar'), Equality.new('foo', 'bar')]
|
75
|
+
assert_equal 1, array.uniq.size
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'is not equal with different ivars' do
|
79
|
+
array = [Equality.new('foo', 'bar'), Equality.new('foo', 'baz')]
|
80
|
+
assert_equal 2, array.uniq.size
|
81
|
+
end
|
72
82
|
end
|
73
83
|
end
|
74
84
|
end
|
data/test/nodes/test_extract.rb
CHANGED
@@ -16,4 +16,18 @@ describe Arel::Nodes::Extract do
|
|
16
16
|
}
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
describe 'equality' do
|
21
|
+
it 'is equal with equal ivars' do
|
22
|
+
table = Arel::Table.new :users
|
23
|
+
array = [table[:attr].extract('foo'), table[:attr].extract('foo')]
|
24
|
+
assert_equal 1, array.uniq.size
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is not equal with different ivars' do
|
28
|
+
table = Arel::Table.new :users
|
29
|
+
array = [table[:attr].extract('foo'), table[:attr].extract('bar')]
|
30
|
+
assert_equal 2, array.uniq.size
|
31
|
+
end
|
32
|
+
end
|
19
33
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
module Nodes
|
5
|
+
describe 'False' do
|
6
|
+
describe 'equality' do
|
7
|
+
it 'is equal to other false nodes' do
|
8
|
+
array = [False.new, False.new]
|
9
|
+
assert_equal 1, array.uniq.size
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'is not equal with other nodes' do
|
13
|
+
array = [False.new, Node.new]
|
14
|
+
assert_equal 2, array.uniq.size
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Arel
|
4
|
+
module Nodes
|
5
|
+
describe 'Grouping' do
|
6
|
+
it 'should create Equality nodes' do
|
7
|
+
grouping = Grouping.new('foo')
|
8
|
+
grouping.eq('foo').to_sql.must_be_like %q{('foo') = 'foo'}
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'equality' do
|
12
|
+
it 'is equal with equal ivars' do
|
13
|
+
array = [Grouping.new('foo'), Grouping.new('foo')]
|
14
|
+
assert_equal 1, array.uniq.size
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'is not equal with different ivars' do
|
18
|
+
array = [Grouping.new('foo'), Grouping.new('bar')]
|
19
|
+
assert_equal 2, array.uniq.size
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -25,6 +25,16 @@ module Arel
|
|
25
25
|
assert_equal operation, ordering.expr
|
26
26
|
assert ordering.descending?
|
27
27
|
end
|
28
|
+
|
29
|
+
def test_equality_with_same_ivars
|
30
|
+
array = [InfixOperation.new(:+, 1, 2), InfixOperation.new(:+, 1, 2)]
|
31
|
+
assert_equal 1, array.uniq.size
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_inequality_with_different_ivars
|
35
|
+
array = [InfixOperation.new(:+, 1, 2), InfixOperation.new(:+, 1, 3)]
|
36
|
+
assert_equal 2, array.uniq.size
|
37
|
+
end
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
@@ -15,4 +15,28 @@ describe Arel::Nodes::InsertStatement do
|
|
15
15
|
dolly.values.wont_be_same_as statement.values
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
describe 'equality' do
|
20
|
+
it 'is equal with equal ivars' do
|
21
|
+
statement1 = Arel::Nodes::InsertStatement.new
|
22
|
+
statement1.columns = %w[a b c]
|
23
|
+
statement1.values = %w[x y z]
|
24
|
+
statement2 = Arel::Nodes::InsertStatement.new
|
25
|
+
statement2.columns = %w[a b c]
|
26
|
+
statement2.values = %w[x y z]
|
27
|
+
array = [statement1, statement2]
|
28
|
+
assert_equal 1, array.uniq.size
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'is not equal with different ivars' do
|
32
|
+
statement1 = Arel::Nodes::InsertStatement.new
|
33
|
+
statement1.columns = %w[a b c]
|
34
|
+
statement1.values = %w[x y z]
|
35
|
+
statement2 = Arel::Nodes::InsertStatement.new
|
36
|
+
statement2.columns = %w[a b c]
|
37
|
+
statement2.values = %w[1 2 3]
|
38
|
+
array = [statement1, statement2]
|
39
|
+
assert_equal 2, array.uniq.size
|
40
|
+
end
|
41
|
+
end
|
18
42
|
end
|
@@ -25,6 +25,22 @@ module Arel
|
|
25
25
|
assert_kind_of SqlLiteral, function.alias
|
26
26
|
assert_equal 'wth', function.alias
|
27
27
|
end
|
28
|
+
|
29
|
+
def test_equality_with_same_ivars
|
30
|
+
array = [
|
31
|
+
NamedFunction.new('omg', 'zomg', 'wth'),
|
32
|
+
NamedFunction.new('omg', 'zomg', 'wth')
|
33
|
+
]
|
34
|
+
assert_equal 1, array.uniq.size
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_inequality_with_different_ivars
|
38
|
+
array = [
|
39
|
+
NamedFunction.new('omg', 'zomg', 'wth'),
|
40
|
+
NamedFunction.new('zomg', 'zomg', 'wth')
|
41
|
+
]
|
42
|
+
assert_equal 2, array.uniq.size
|
43
|
+
end
|
28
44
|
end
|
29
45
|
end
|
30
46
|
end
|
data/test/nodes/test_not.rb
CHANGED
@@ -12,6 +12,18 @@ module Arel
|
|
12
12
|
node.expr.must_equal expr
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
describe 'equality' do
|
17
|
+
it 'is equal with equal ivars' do
|
18
|
+
array = [Not.new('foo'), Not.new('foo')]
|
19
|
+
assert_equal 1, array.uniq.size
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'is not equal with different ivars' do
|
23
|
+
array = [Not.new('foo'), Not.new('baz')]
|
24
|
+
assert_equal 2, array.uniq.size
|
25
|
+
end
|
26
|
+
end
|
15
27
|
end
|
16
28
|
end
|
17
29
|
end
|
data/test/nodes/test_or.rb
CHANGED
@@ -17,6 +17,18 @@ module Arel
|
|
17
17
|
oror.expr.right.must_equal right
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
describe 'equality' do
|
22
|
+
it 'is equal with equal ivars' do
|
23
|
+
array = [Or.new('foo', 'bar'), Or.new('foo', 'bar')]
|
24
|
+
assert_equal 1, array.uniq.size
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is not equal with different ivars' do
|
28
|
+
array = [Or.new('foo', 'bar'), Or.new('foo', 'baz')]
|
29
|
+
assert_equal 2, array.uniq.size
|
30
|
+
end
|
31
|
+
end
|
20
32
|
end
|
21
33
|
end
|
22
34
|
end
|
data/test/nodes/test_over.rb
CHANGED
@@ -46,4 +46,22 @@ describe Arel::Nodes::Over do
|
|
46
46
|
}
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
describe 'equality' do
|
51
|
+
it 'is equal with equal ivars' do
|
52
|
+
array = [
|
53
|
+
Arel::Nodes::Over.new('foo', 'bar'),
|
54
|
+
Arel::Nodes::Over.new('foo', 'bar')
|
55
|
+
]
|
56
|
+
assert_equal 1, array.uniq.size
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'is not equal with different ivars' do
|
60
|
+
array = [
|
61
|
+
Arel::Nodes::Over.new('foo', 'bar'),
|
62
|
+
Arel::Nodes::Over.new('foo', 'baz')
|
63
|
+
]
|
64
|
+
assert_equal 2, array.uniq.size
|
65
|
+
end
|
66
|
+
end
|
49
67
|
end
|
@@ -26,6 +26,44 @@ module Arel
|
|
26
26
|
viz = Arel::Visitors::ToSql.new Table.engine.connection_pool
|
27
27
|
assert_match 'DISTINCT', viz.accept(core)
|
28
28
|
end
|
29
|
+
|
30
|
+
def test_equality_with_same_ivars
|
31
|
+
core1 = SelectCore.new
|
32
|
+
core1.froms = %w[a b c]
|
33
|
+
core1.projections = %w[d e f]
|
34
|
+
core1.wheres = %w[g h i]
|
35
|
+
core1.groups = %w[j k l]
|
36
|
+
core1.windows = %w[m n o]
|
37
|
+
core1.having = %w[p q r]
|
38
|
+
core2 = SelectCore.new
|
39
|
+
core2.froms = %w[a b c]
|
40
|
+
core2.projections = %w[d e f]
|
41
|
+
core2.wheres = %w[g h i]
|
42
|
+
core2.groups = %w[j k l]
|
43
|
+
core2.windows = %w[m n o]
|
44
|
+
core2.having = %w[p q r]
|
45
|
+
array = [core1, core2]
|
46
|
+
assert_equal 1, array.uniq.size
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_inequality_with_different_ivars
|
50
|
+
core1 = SelectCore.new
|
51
|
+
core1.froms = %w[a b c]
|
52
|
+
core1.projections = %w[d e f]
|
53
|
+
core1.wheres = %w[g h i]
|
54
|
+
core1.groups = %w[j k l]
|
55
|
+
core1.windows = %w[m n o]
|
56
|
+
core1.having = %w[p q r]
|
57
|
+
core2 = SelectCore.new
|
58
|
+
core2.froms = %w[a b c]
|
59
|
+
core2.projections = %w[d e f]
|
60
|
+
core2.wheres = %w[g h i]
|
61
|
+
core2.groups = %w[j k l]
|
62
|
+
core2.windows = %w[m n o]
|
63
|
+
core2.having = %w[l o l]
|
64
|
+
array = [core1, core2]
|
65
|
+
assert_equal 2, array.uniq.size
|
66
|
+
end
|
29
67
|
end
|
30
68
|
end
|
31
69
|
end
|
@@ -10,4 +10,40 @@ describe Arel::Nodes::SelectStatement do
|
|
10
10
|
dolly.cores.wont_be_same_as statement.cores
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
describe 'equality' do
|
15
|
+
it 'is equal with equal ivars' do
|
16
|
+
statement1 = Arel::Nodes::SelectStatement.new %w[a b c]
|
17
|
+
statement1.offset = 1
|
18
|
+
statement1.limit = 2
|
19
|
+
statement1.lock = false
|
20
|
+
statement1.orders = %w[x y z]
|
21
|
+
statement1.with = 'zomg'
|
22
|
+
statement2 = Arel::Nodes::SelectStatement.new %w[a b c]
|
23
|
+
statement2.offset = 1
|
24
|
+
statement2.limit = 2
|
25
|
+
statement2.lock = false
|
26
|
+
statement2.orders = %w[x y z]
|
27
|
+
statement2.with = 'zomg'
|
28
|
+
array = [statement1, statement2]
|
29
|
+
assert_equal 1, array.uniq.size
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'is not equal with different ivars' do
|
33
|
+
statement1 = Arel::Nodes::SelectStatement.new %w[a b c]
|
34
|
+
statement1.offset = 1
|
35
|
+
statement1.limit = 2
|
36
|
+
statement1.lock = false
|
37
|
+
statement1.orders = %w[x y z]
|
38
|
+
statement1.with = 'zomg'
|
39
|
+
statement2 = Arel::Nodes::SelectStatement.new %w[a b c]
|
40
|
+
statement2.offset = 1
|
41
|
+
statement2.limit = 2
|
42
|
+
statement2.lock = false
|
43
|
+
statement2.orders = %w[x y z]
|
44
|
+
statement2.with = 'wth'
|
45
|
+
array = [statement1, statement2]
|
46
|
+
assert_equal 2, array.uniq.size
|
47
|
+
end
|
48
|
+
end
|
13
49
|
end
|