arel 3.0.3 → 4.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.
- data/.travis.yml +2 -4
- data/Gemfile +2 -2
- data/History.txt +3 -54
- data/Manifest.txt +8 -2
- data/README.markdown +8 -4
- data/Rakefile +1 -1
- data/arel.gemspec +21 -29
- data/lib/arel/crud.rb +3 -3
- 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/nodes.rb +1 -0
- data/lib/arel/predications.rb +18 -2
- data/lib/arel/select_manager.rb +6 -2
- data/lib/arel/table.rb +14 -1
- data/lib/arel/tree_manager.rb +0 -2
- data/lib/arel/visitors/bind_visitor.rb +10 -0
- data/lib/arel/visitors/dot.rb +2 -2
- data/lib/arel/visitors/to_sql.rb +142 -31
- data/lib/arel.rb +1 -3
- 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/support/fake_record.rb +5 -1
- 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_to_sql.rb +78 -0
- metadata +84 -82
- data/lib/arel/nodes/ordering.rb +0 -6
- data/lib/arel/relation.rb +0 -6
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
|
|
@@ -31,6 +31,16 @@ module Arel
|
|
|
31
31
|
node = SqlLiteral.new('foo').eq(1)
|
|
32
32
|
@visitor.accept(node).must_be_like %{ foo = 1 }
|
|
33
33
|
end
|
|
34
|
+
|
|
35
|
+
it 'is equal with equal contents' do
|
|
36
|
+
array = [SqlLiteral.new('foo'), SqlLiteral.new('foo')]
|
|
37
|
+
assert_equal 1, array.uniq.size
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'is not equal with different contents' do
|
|
41
|
+
array = [SqlLiteral.new('foo'), SqlLiteral.new('bar')]
|
|
42
|
+
assert_equal 2, array.uniq.size
|
|
43
|
+
end
|
|
34
44
|
end
|
|
35
45
|
|
|
36
46
|
describe 'grouped "or" equality' do
|
data/test/nodes/test_sum.rb
CHANGED
|
@@ -9,4 +9,16 @@ describe Arel::Nodes::Sum do
|
|
|
9
9
|
}
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
describe 'equality' do
|
|
14
|
+
it 'is equal with equal ivars' do
|
|
15
|
+
array = [Arel::Nodes::Sum.new('foo'), Arel::Nodes::Sum.new('foo')]
|
|
16
|
+
assert_equal 1, array.uniq.size
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'is not equal with different ivars' do
|
|
20
|
+
array = [Arel::Nodes::Sum.new('foo'), Arel::Nodes::Sum.new('foo!')]
|
|
21
|
+
assert_equal 2, array.uniq.size
|
|
22
|
+
end
|
|
23
|
+
end
|
|
12
24
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
|
|
4
|
+
module Arel
|
|
5
|
+
module Nodes
|
|
6
|
+
describe 'table alias' do
|
|
7
|
+
it 'has an #engine which delegates to the relation' do
|
|
8
|
+
engine = 'vroom'
|
|
9
|
+
relation = Table.new(:users, engine)
|
|
10
|
+
|
|
11
|
+
node = TableAlias.new relation, :foo
|
|
12
|
+
node.engine.must_equal engine
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe 'equality' do
|
|
16
|
+
it 'is equal with equal ivars' do
|
|
17
|
+
relation1 = Table.new(:users, 'vroom')
|
|
18
|
+
node1 = TableAlias.new relation1, :foo
|
|
19
|
+
relation2 = Table.new(:users, 'vroom')
|
|
20
|
+
node2 = TableAlias.new relation2, :foo
|
|
21
|
+
array = [node1, node2]
|
|
22
|
+
assert_equal 1, array.uniq.size
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'is not equal with different ivars' do
|
|
26
|
+
relation1 = Table.new(:users, 'vroom')
|
|
27
|
+
node1 = TableAlias.new relation1, :foo
|
|
28
|
+
relation2 = Table.new(:users, 'vroom')
|
|
29
|
+
node2 = TableAlias.new relation2, :bar
|
|
30
|
+
array = [node1, node2]
|
|
31
|
+
assert_equal 2, array.uniq.size
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
|
|
3
|
+
module Arel
|
|
4
|
+
module Nodes
|
|
5
|
+
describe 'True' do
|
|
6
|
+
describe 'equality' do
|
|
7
|
+
it 'is equal to other true nodes' do
|
|
8
|
+
array = [True.new, True.new]
|
|
9
|
+
assert_equal 1, array.uniq.size
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'is not equal with other nodes' do
|
|
13
|
+
array = [True.new, Node.new]
|
|
14
|
+
assert_equal 2, array.uniq.size
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
@@ -15,4 +15,44 @@ describe Arel::Nodes::UpdateStatement 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::UpdateStatement.new
|
|
22
|
+
statement1.relation = 'zomg'
|
|
23
|
+
statement1.wheres = 2
|
|
24
|
+
statement1.values = false
|
|
25
|
+
statement1.orders = %w[x y z]
|
|
26
|
+
statement1.limit = 42
|
|
27
|
+
statement1.key = 'zomg'
|
|
28
|
+
statement2 = Arel::Nodes::UpdateStatement.new
|
|
29
|
+
statement2.relation = 'zomg'
|
|
30
|
+
statement2.wheres = 2
|
|
31
|
+
statement2.values = false
|
|
32
|
+
statement2.orders = %w[x y z]
|
|
33
|
+
statement2.limit = 42
|
|
34
|
+
statement2.key = 'zomg'
|
|
35
|
+
array = [statement1, statement2]
|
|
36
|
+
assert_equal 1, array.uniq.size
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'is not equal with different ivars' do
|
|
40
|
+
statement1 = Arel::Nodes::UpdateStatement.new
|
|
41
|
+
statement1.relation = 'zomg'
|
|
42
|
+
statement1.wheres = 2
|
|
43
|
+
statement1.values = false
|
|
44
|
+
statement1.orders = %w[x y z]
|
|
45
|
+
statement1.limit = 42
|
|
46
|
+
statement1.key = 'zomg'
|
|
47
|
+
statement2 = Arel::Nodes::UpdateStatement.new
|
|
48
|
+
statement2.relation = 'zomg'
|
|
49
|
+
statement2.wheres = 2
|
|
50
|
+
statement2.values = false
|
|
51
|
+
statement2.orders = %w[x y z]
|
|
52
|
+
statement2.limit = 42
|
|
53
|
+
statement2.key = 'wth'
|
|
54
|
+
array = [statement1, statement2]
|
|
55
|
+
assert_equal 2, array.uniq.size
|
|
56
|
+
end
|
|
57
|
+
end
|
|
18
58
|
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
|
|
3
|
+
module Arel
|
|
4
|
+
module Nodes
|
|
5
|
+
describe 'Window' do
|
|
6
|
+
describe 'equality' do
|
|
7
|
+
it 'is equal with equal ivars' do
|
|
8
|
+
window1 = Window.new
|
|
9
|
+
window1.orders = [1, 2]
|
|
10
|
+
window1.frame 3
|
|
11
|
+
window2 = Window.new
|
|
12
|
+
window2.orders = [1, 2]
|
|
13
|
+
window2.frame 3
|
|
14
|
+
array = [window1, window2]
|
|
15
|
+
assert_equal 1, array.uniq.size
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'is not equal with different ivars' do
|
|
19
|
+
window1 = Window.new
|
|
20
|
+
window1.orders = [1, 2]
|
|
21
|
+
window1.frame 3
|
|
22
|
+
window2 = Window.new
|
|
23
|
+
window2.orders = [1, 2]
|
|
24
|
+
window2.frame 4
|
|
25
|
+
array = [window1, window2]
|
|
26
|
+
assert_equal 2, array.uniq.size
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe 'NamedWindow' do
|
|
32
|
+
describe 'equality' do
|
|
33
|
+
it 'is equal with equal ivars' do
|
|
34
|
+
window1 = NamedWindow.new 'foo'
|
|
35
|
+
window1.orders = [1, 2]
|
|
36
|
+
window1.frame 3
|
|
37
|
+
window2 = NamedWindow.new 'foo'
|
|
38
|
+
window2.orders = [1, 2]
|
|
39
|
+
window2.frame 3
|
|
40
|
+
array = [window1, window2]
|
|
41
|
+
assert_equal 1, array.uniq.size
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'is not equal with different ivars' do
|
|
45
|
+
window1 = NamedWindow.new 'foo'
|
|
46
|
+
window1.orders = [1, 2]
|
|
47
|
+
window1.frame 3
|
|
48
|
+
window2 = NamedWindow.new 'bar'
|
|
49
|
+
window2.orders = [1, 2]
|
|
50
|
+
window2.frame 3
|
|
51
|
+
array = [window1, window2]
|
|
52
|
+
assert_equal 2, array.uniq.size
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe 'CurrentRow' do
|
|
58
|
+
describe 'equality' do
|
|
59
|
+
it 'is equal to other current row nodes' do
|
|
60
|
+
array = [CurrentRow.new, CurrentRow.new]
|
|
61
|
+
assert_equal 1, array.uniq.size
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'is not equal with other nodes' do
|
|
65
|
+
array = [CurrentRow.new, Node.new]
|
|
66
|
+
assert_equal 2, array.uniq.size
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
|
data/test/support/fake_record.rb
CHANGED
|
@@ -3,7 +3,7 @@ module FakeRecord
|
|
|
3
3
|
end
|
|
4
4
|
|
|
5
5
|
class Connection
|
|
6
|
-
attr_reader :tables
|
|
6
|
+
attr_reader :tables
|
|
7
7
|
attr_accessor :visitor
|
|
8
8
|
|
|
9
9
|
def initialize(visitor = nil)
|
|
@@ -31,6 +31,10 @@ module FakeRecord
|
|
|
31
31
|
@visitor = visitor
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
def columns_hash table_name
|
|
35
|
+
@columns_hash[table_name]
|
|
36
|
+
end
|
|
37
|
+
|
|
34
38
|
def primary_key name
|
|
35
39
|
@primary_keys[name.to_s]
|
|
36
40
|
end
|
data/test/test_attributes.rb
CHANGED
|
@@ -10,6 +10,18 @@ module Arel
|
|
|
10
10
|
assert_equal [attribute], node.expressions
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
describe 'equality' do
|
|
14
|
+
it 'is equal with equal ivars' do
|
|
15
|
+
array = [Attribute.new('foo', 'bar'), Attribute.new('foo', 'bar')]
|
|
16
|
+
assert_equal 1, array.uniq.size
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'is not equal with different ivars' do
|
|
20
|
+
array = [Attribute.new('foo', 'bar'), Attribute.new('foo', 'baz')]
|
|
21
|
+
assert_equal 2, array.uniq.size
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
13
25
|
describe 'for' do
|
|
14
26
|
it 'deals with unknown column types' do
|
|
15
27
|
column = Struct.new(:type).new :crazy
|
data/test/test_insert_manager.rb
CHANGED
|
@@ -10,7 +10,6 @@ module Arel
|
|
|
10
10
|
|
|
11
11
|
describe 'insert' do
|
|
12
12
|
it 'can create a Values node' do
|
|
13
|
-
table = Table.new(:users)
|
|
14
13
|
manager = Arel::InsertManager.new Table.engine
|
|
15
14
|
values = manager.create_values %w{ a b }, %w{ c d }
|
|
16
15
|
|
|
@@ -20,7 +19,6 @@ module Arel
|
|
|
20
19
|
end
|
|
21
20
|
|
|
22
21
|
it 'allows sql literals' do
|
|
23
|
-
table = Table.new(:users)
|
|
24
22
|
manager = Arel::InsertManager.new Table.engine
|
|
25
23
|
manager.values = manager.create_values [Arel.sql('*')], %w{ a }
|
|
26
24
|
manager.to_sql.must_be_like %{
|
data/test/test_select_manager.rb
CHANGED
|
@@ -119,7 +119,7 @@ module Arel
|
|
|
119
119
|
manager = Arel::SelectManager.new Table.engine
|
|
120
120
|
manager.project Arel.sql('name')
|
|
121
121
|
manager.from as
|
|
122
|
-
manager.to_sql.must_be_like "SELECT name FROM (SELECT * FROM zomg
|
|
122
|
+
manager.to_sql.must_be_like "SELECT name FROM (SELECT * FROM zomg) foo"
|
|
123
123
|
end
|
|
124
124
|
end
|
|
125
125
|
|
|
@@ -147,7 +147,7 @@ module Arel
|
|
|
147
147
|
manager1.from(as)
|
|
148
148
|
|
|
149
149
|
manager1.to_sql.must_be_like %{
|
|
150
|
-
SELECT lol FROM (SELECT * FROM "users"
|
|
150
|
+
SELECT lol FROM (SELECT * FROM "users") omg
|
|
151
151
|
}
|
|
152
152
|
end
|
|
153
153
|
end
|
|
@@ -672,7 +672,6 @@ module Arel
|
|
|
672
672
|
end
|
|
673
673
|
|
|
674
674
|
it 'returns string join sql' do
|
|
675
|
-
table = Table.new :users
|
|
676
675
|
manager = Arel::SelectManager.new Table.engine
|
|
677
676
|
manager.from Nodes::StringJoin.new('hello')
|
|
678
677
|
manager.join_sql.must_be_like %{ 'hello' }
|
|
@@ -1033,6 +1032,14 @@ module Arel
|
|
|
1033
1032
|
end
|
|
1034
1033
|
end
|
|
1035
1034
|
|
|
1035
|
+
describe 'projections' do
|
|
1036
|
+
it 'reads projections' do
|
|
1037
|
+
manager = Arel::SelectManager.new Table.engine
|
|
1038
|
+
manager.project Arel.sql('foo'), Arel.sql('bar')
|
|
1039
|
+
manager.projections.must_equal [Arel.sql('foo'), Arel.sql('bar')]
|
|
1040
|
+
end
|
|
1041
|
+
end
|
|
1042
|
+
|
|
1036
1043
|
describe 'projections=' do
|
|
1037
1044
|
it 'overwrites projections' do
|
|
1038
1045
|
manager = Arel::SelectManager.new Table.engine
|
|
@@ -1132,7 +1139,6 @@ module Arel
|
|
|
1132
1139
|
|
|
1133
1140
|
describe 'source' do
|
|
1134
1141
|
it 'returns the join source of the select core' do
|
|
1135
|
-
table = Table.new :users
|
|
1136
1142
|
manager = Arel::SelectManager.new Table.engine
|
|
1137
1143
|
manager.source.must_equal manager.ast.cores.last.source
|
|
1138
1144
|
end
|
|
@@ -1140,7 +1146,6 @@ module Arel
|
|
|
1140
1146
|
|
|
1141
1147
|
describe 'distinct' do
|
|
1142
1148
|
it 'sets the quantifier' do
|
|
1143
|
-
table = Table.new :users
|
|
1144
1149
|
manager = Arel::SelectManager.new Table.engine
|
|
1145
1150
|
|
|
1146
1151
|
manager.distinct
|
data/test/test_table.rb
CHANGED
|
@@ -180,5 +180,29 @@ module Arel
|
|
|
180
180
|
end
|
|
181
181
|
end
|
|
182
182
|
end
|
|
183
|
+
|
|
184
|
+
describe 'equality' do
|
|
185
|
+
it 'is equal with equal ivars' do
|
|
186
|
+
relation1 = Table.new(:users, 'vroom')
|
|
187
|
+
relation1.aliases = %w[a b c]
|
|
188
|
+
relation1.table_alias = 'zomg'
|
|
189
|
+
relation2 = Table.new(:users, 'vroom')
|
|
190
|
+
relation2.aliases = %w[a b c]
|
|
191
|
+
relation2.table_alias = 'zomg'
|
|
192
|
+
array = [relation1, relation2]
|
|
193
|
+
assert_equal 1, array.uniq.size
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it 'is not equal with different ivars' do
|
|
197
|
+
relation1 = Table.new(:users, 'vroom')
|
|
198
|
+
relation1.aliases = %w[a b c]
|
|
199
|
+
relation1.table_alias = 'zomg'
|
|
200
|
+
relation2 = Table.new(:users, 'vroom')
|
|
201
|
+
relation2.aliases = %w[x y z]
|
|
202
|
+
relation2.table_alias = 'zomg'
|
|
203
|
+
array = [relation1, relation2]
|
|
204
|
+
assert_equal 2, array.uniq.size
|
|
205
|
+
end
|
|
206
|
+
end
|
|
183
207
|
end
|
|
184
208
|
end
|
data/test/test_update_manager.rb
CHANGED
|
@@ -8,6 +8,14 @@ module Arel
|
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
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
|
+
|
|
11
19
|
it 'handles limit properly' do
|
|
12
20
|
table = Table.new(:users)
|
|
13
21
|
um = Arel::UpdateManager.new Table.engine
|