arel 6.0.0.beta2 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/nodes/test_extract.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Arel::Nodes::Extract do
|
4
|
-
it "should extract field" do
|
5
|
-
table = Arel::Table.new :users
|
6
|
-
table[:timestamp].extract('date').to_sql.must_be_like %{
|
7
|
-
EXTRACT(DATE FROM "users"."timestamp")
|
8
|
-
}
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "as" do
|
12
|
-
it 'should alias the extract' do
|
13
|
-
table = Arel::Table.new :users
|
14
|
-
table[:timestamp].extract('date').as('foo').to_sql.must_be_like %{
|
15
|
-
EXTRACT(DATE FROM "users"."timestamp") AS foo
|
16
|
-
}
|
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
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'equality' do
|
29
|
-
it 'is equal with equal ivars' do
|
30
|
-
table = Arel::Table.new :users
|
31
|
-
array = [table[:attr].extract('foo'), table[:attr].extract('foo')]
|
32
|
-
assert_equal 1, array.uniq.size
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'is not equal with different ivars' do
|
36
|
-
table = Arel::Table.new :users
|
37
|
-
array = [table[:attr].extract('foo'), table[:attr].extract('bar')]
|
38
|
-
assert_equal 2, array.uniq.size
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/test/nodes/test_false.rb
DELETED
@@ -1,20 +0,0 @@
|
|
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
|
-
|
data/test/nodes/test_grouping.rb
DELETED
@@ -1,25 +0,0 @@
|
|
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(Nodes.build_quoted('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
|
-
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
class TestInfixOperation < Minitest::Test
|
6
|
-
def test_construct
|
7
|
-
operation = InfixOperation.new :+, 1, 2
|
8
|
-
assert_equal :+, operation.operator
|
9
|
-
assert_equal 1, operation.left
|
10
|
-
assert_equal 2, operation.right
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_operation_alias
|
14
|
-
operation = InfixOperation.new :+, 1, 2
|
15
|
-
aliaz = operation.as('zomg')
|
16
|
-
assert_kind_of As, aliaz
|
17
|
-
assert_equal operation, aliaz.left
|
18
|
-
assert_equal 'zomg', aliaz.right
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_operation_ordering
|
22
|
-
operation = InfixOperation.new :+, 1, 2
|
23
|
-
ordering = operation.desc
|
24
|
-
assert_kind_of Descending, ordering
|
25
|
-
assert_equal operation, ordering.expr
|
26
|
-
assert ordering.descending?
|
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
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Arel::Nodes::InsertStatement do
|
4
|
-
describe "#clone" do
|
5
|
-
it "clones columns and values" do
|
6
|
-
statement = Arel::Nodes::InsertStatement.new
|
7
|
-
statement.columns = %w[a b c]
|
8
|
-
statement.values = %w[x y z]
|
9
|
-
|
10
|
-
dolly = statement.clone
|
11
|
-
dolly.columns.must_equal statement.columns
|
12
|
-
dolly.values.must_equal statement.values
|
13
|
-
|
14
|
-
dolly.columns.wont_be_same_as statement.columns
|
15
|
-
dolly.values.wont_be_same_as statement.values
|
16
|
-
end
|
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
|
42
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
class TestNamedFunction < Minitest::Test
|
6
|
-
def test_construct
|
7
|
-
function = NamedFunction.new 'omg', 'zomg'
|
8
|
-
assert_equal 'omg', function.name
|
9
|
-
assert_equal 'zomg', function.expressions
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_function_alias
|
13
|
-
function = NamedFunction.new 'omg', 'zomg'
|
14
|
-
function = function.as('wth')
|
15
|
-
assert_equal 'omg', function.name
|
16
|
-
assert_equal 'zomg', function.expressions
|
17
|
-
assert_kind_of SqlLiteral, function.alias
|
18
|
-
assert_equal 'wth', function.alias
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_construct_with_alias
|
22
|
-
function = NamedFunction.new 'omg', 'zomg', 'wth'
|
23
|
-
assert_equal 'omg', function.name
|
24
|
-
assert_equal 'zomg', function.expressions
|
25
|
-
assert_kind_of SqlLiteral, function.alias
|
26
|
-
assert_equal 'wth', function.alias
|
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
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/test/nodes/test_node.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
class TestNode < Minitest::Test
|
5
|
-
def test_includes_factory_methods
|
6
|
-
assert Node.new.respond_to?(:create_join)
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_all_nodes_are_nodes
|
10
|
-
Nodes.constants.map { |k|
|
11
|
-
Nodes.const_get(k)
|
12
|
-
}.grep(Class).each do |klass|
|
13
|
-
next if Nodes::SqlLiteral == klass
|
14
|
-
next if Nodes::BindParam == klass
|
15
|
-
next if klass.name =~ /^Arel::Nodes::Test/
|
16
|
-
assert klass.ancestors.include?(Nodes::Node), klass.name
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_each
|
21
|
-
list = []
|
22
|
-
node = Nodes::Node.new
|
23
|
-
node.each { |n| list << n }
|
24
|
-
assert_equal [node], list
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_generator
|
28
|
-
list = []
|
29
|
-
node = Nodes::Node.new
|
30
|
-
node.each.each { |n| list << n }
|
31
|
-
assert_equal [node], list
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_enumerable
|
35
|
-
node = Nodes::Node.new
|
36
|
-
assert_kind_of Enumerable, node
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/test/nodes/test_not.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
describe 'not' do
|
6
|
-
describe '#not' do
|
7
|
-
it 'makes a NOT node' do
|
8
|
-
attr = Table.new(:users)[:id]
|
9
|
-
expr = attr.eq(10)
|
10
|
-
node = expr.not
|
11
|
-
node.must_be_kind_of Not
|
12
|
-
node.expr.must_equal expr
|
13
|
-
end
|
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
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/test/nodes/test_or.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
describe 'or' do
|
6
|
-
describe '#or' do
|
7
|
-
it 'makes an OR node' do
|
8
|
-
attr = Table.new(:users)[:id]
|
9
|
-
left = attr.eq(10)
|
10
|
-
right = attr.eq(11)
|
11
|
-
node = left.or right
|
12
|
-
node.expr.left.must_equal left
|
13
|
-
node.expr.right.must_equal right
|
14
|
-
|
15
|
-
oror = node.or(right)
|
16
|
-
oror.expr.left.must_equal node
|
17
|
-
oror.expr.right.must_equal right
|
18
|
-
end
|
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
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/test/nodes/test_over.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Arel::Nodes::Over do
|
4
|
-
describe 'as' do
|
5
|
-
it 'should alias the expression' do
|
6
|
-
table = Arel::Table.new :users
|
7
|
-
table[:id].count.over.as('foo').to_sql.must_be_like %{
|
8
|
-
COUNT("users"."id") OVER () AS foo
|
9
|
-
}
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe 'with literal' do
|
14
|
-
it 'should reference the window definition by name' do
|
15
|
-
table = Arel::Table.new :users
|
16
|
-
table[:id].count.over('foo').to_sql.must_be_like %{
|
17
|
-
COUNT("users"."id") OVER "foo"
|
18
|
-
}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'with SQL literal' do
|
23
|
-
it 'should reference the window definition by name' do
|
24
|
-
table = Arel::Table.new :users
|
25
|
-
table[:id].count.over(Arel.sql('foo')).to_sql.must_be_like %{
|
26
|
-
COUNT("users"."id") OVER foo
|
27
|
-
}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe 'with no expression' do
|
32
|
-
it 'should use empty definition' do
|
33
|
-
table = Arel::Table.new :users
|
34
|
-
table[:id].count.over.to_sql.must_be_like %{
|
35
|
-
COUNT("users"."id") OVER ()
|
36
|
-
}
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'with expression' do
|
41
|
-
it 'should use definition in sub-expression' do
|
42
|
-
table = Arel::Table.new :users
|
43
|
-
window = Arel::Nodes::Window.new.order(table['foo'])
|
44
|
-
table[:id].count.over(window).to_sql.must_be_like %{
|
45
|
-
COUNT("users"."id") OVER (ORDER BY \"users\".\"foo\")
|
46
|
-
}
|
47
|
-
end
|
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
|
67
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
class TestSelectCore < Minitest::Test
|
6
|
-
def test_clone
|
7
|
-
core = Arel::Nodes::SelectCore.new
|
8
|
-
core.froms = %w[a b c]
|
9
|
-
core.projections = %w[d e f]
|
10
|
-
core.wheres = %w[g h i]
|
11
|
-
|
12
|
-
dolly = core.clone
|
13
|
-
|
14
|
-
assert_equal core.froms, dolly.froms
|
15
|
-
assert_equal core.projections, dolly.projections
|
16
|
-
assert_equal core.wheres, dolly.wheres
|
17
|
-
|
18
|
-
refute_same core.froms, dolly.froms
|
19
|
-
refute_same core.projections, dolly.projections
|
20
|
-
refute_same core.wheres, dolly.wheres
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_set_quantifier
|
24
|
-
core = Arel::Nodes::SelectCore.new
|
25
|
-
core.set_quantifier = Arel::Nodes::Distinct.new
|
26
|
-
viz = Arel::Visitors::ToSql.new Table.engine.connection_pool
|
27
|
-
assert_match 'DISTINCT', viz.accept(core, Collectors::SQLString.new).value
|
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
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|