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
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'arel/collectors/bind'
|
3
|
-
|
4
|
-
module Arel
|
5
|
-
module Collectors
|
6
|
-
class TestBindCollector < Arel::Test
|
7
|
-
def setup
|
8
|
-
@conn = FakeRecord::Base.new
|
9
|
-
@visitor = Visitors::ToSql.new @conn.connection
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
def collect node
|
14
|
-
@visitor.accept(node, Collectors::Bind.new)
|
15
|
-
end
|
16
|
-
|
17
|
-
def compile node
|
18
|
-
collect(node).value
|
19
|
-
end
|
20
|
-
|
21
|
-
def ast_with_binds bv
|
22
|
-
table = Table.new(:users)
|
23
|
-
manager = Arel::SelectManager.new Table.engine, table
|
24
|
-
manager.where(table[:age].eq(bv))
|
25
|
-
manager.where(table[:name].eq(bv))
|
26
|
-
manager.ast
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_leaves_binds
|
30
|
-
node = Nodes::BindParam.new 'omg'
|
31
|
-
list = compile node
|
32
|
-
assert_equal node, list.first
|
33
|
-
assert_equal node.class, list.first.class
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_adds_strings
|
37
|
-
bv = Nodes::BindParam.new('?')
|
38
|
-
list = compile ast_with_binds bv
|
39
|
-
assert_operator list.length, :>, 0
|
40
|
-
assert_equal bv, list.grep(Nodes::BindParam).first
|
41
|
-
assert_equal bv.class, list.grep(Nodes::BindParam).first.class
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_substitute_binds
|
45
|
-
bv = Nodes::BindParam.new('?')
|
46
|
-
collector = collect ast_with_binds bv
|
47
|
-
|
48
|
-
values = collector.value
|
49
|
-
|
50
|
-
offsets = values.map.with_index { |v,i|
|
51
|
-
[v,i]
|
52
|
-
}.find_all { |(v,_)| Nodes::BindParam === v }.map(&:last)
|
53
|
-
|
54
|
-
list = collector.substitute_binds ["hello", "world"]
|
55
|
-
assert_equal "hello", list[offsets[0]]
|
56
|
-
assert_equal "world", list[offsets[1]]
|
57
|
-
|
58
|
-
assert_equal 'SELECT FROM "users" WHERE "users"."age" = hello AND "users"."name" = world', list.join
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_compile
|
62
|
-
bv = Nodes::BindParam.new('?')
|
63
|
-
collector = collect ast_with_binds bv
|
64
|
-
|
65
|
-
sql = collector.compile ["hello", "world"]
|
66
|
-
assert_equal 'SELECT FROM "users" WHERE "users"."age" = hello AND "users"."name" = world', sql
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'arel/collectors/bind'
|
3
|
-
|
4
|
-
module Arel
|
5
|
-
module Collectors
|
6
|
-
class TestSqlString < Arel::Test
|
7
|
-
def setup
|
8
|
-
@conn = FakeRecord::Base.new
|
9
|
-
@visitor = Visitors::ToSql.new @conn.connection
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
def collect node
|
14
|
-
@visitor.accept(node, Collectors::SQLString.new)
|
15
|
-
end
|
16
|
-
|
17
|
-
def compile node
|
18
|
-
collect(node).value
|
19
|
-
end
|
20
|
-
|
21
|
-
def ast_with_binds bv
|
22
|
-
table = Table.new(:users)
|
23
|
-
manager = Arel::SelectManager.new Table.engine, table
|
24
|
-
manager.where(table[:age].eq(bv))
|
25
|
-
manager.where(table[:name].eq(bv))
|
26
|
-
manager.ast
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_compile
|
30
|
-
bv = Nodes::BindParam.new('?')
|
31
|
-
collector = collect ast_with_binds bv
|
32
|
-
|
33
|
-
sql = collector.compile ["hello", "world"]
|
34
|
-
assert_equal 'SELECT FROM "users" WHERE "users"."age" = ? AND "users"."name" = ?', sql
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'arel'
|
5
|
-
|
6
|
-
require 'support/fake_record'
|
7
|
-
Arel::Table.engine = FakeRecord::Base.new
|
8
|
-
|
9
|
-
class Object
|
10
|
-
def must_be_like other
|
11
|
-
gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
module Arel
|
16
|
-
class Test < MiniTest::Test
|
17
|
-
def assert_like expected, actual
|
18
|
-
assert_equal expected.gsub(/\s+/, ' ').strip,
|
19
|
-
actual.gsub(/\s+/, ' ').strip
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/test/nodes/test_and.rb
DELETED
@@ -1,20 +0,0 @@
|
|
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
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
describe 'As' do
|
6
|
-
describe '#as' do
|
7
|
-
it 'makes an AS node' do
|
8
|
-
attr = Table.new(:users)[:id]
|
9
|
-
as = attr.as(Arel.sql('foo'))
|
10
|
-
assert_equal attr, as.left
|
11
|
-
assert_equal 'foo', as.right
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'converts right to SqlLiteral if a string' do
|
15
|
-
attr = Table.new(:users)[:id]
|
16
|
-
as = attr.as('foo')
|
17
|
-
assert_kind_of Arel::Nodes::SqlLiteral, as.right
|
18
|
-
end
|
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
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
class TestAscending < Minitest::Test
|
6
|
-
def test_construct
|
7
|
-
ascending = Ascending.new 'zomg'
|
8
|
-
assert_equal 'zomg', ascending.expr
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_reverse
|
12
|
-
ascending = Ascending.new 'zomg'
|
13
|
-
descending = ascending.reverse
|
14
|
-
assert_kind_of Descending, descending
|
15
|
-
assert_equal ascending.expr, descending.expr
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_direction
|
19
|
-
ascending = Ascending.new 'zomg'
|
20
|
-
assert_equal :asc, ascending.direction
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_ascending?
|
24
|
-
ascending = Ascending.new 'zomg'
|
25
|
-
assert ascending.ascending?
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_descending?
|
29
|
-
ascending = Ascending.new 'zomg'
|
30
|
-
assert !ascending.descending?
|
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
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/test/nodes/test_bin.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
class TestBin < Minitest::Test
|
6
|
-
def test_new
|
7
|
-
assert Arel::Nodes::Bin.new('zomg')
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_default_to_sql
|
11
|
-
viz = Arel::Visitors::ToSql.new Table.engine.connection_pool
|
12
|
-
node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
|
13
|
-
assert_equal 'zomg', viz.accept(node, Collectors::SQLString.new).value
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_mysql_to_sql
|
17
|
-
viz = Arel::Visitors::MySQL.new Table.engine.connection_pool
|
18
|
-
node = Arel::Nodes::Bin.new(Arel.sql('zomg'))
|
19
|
-
assert_equal 'BINARY zomg', viz.accept(node, Collectors::SQLString.new).value
|
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
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/test/nodes/test_binary.rb
DELETED
@@ -1,26 +0,0 @@
|
|
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
|
data/test/nodes/test_count.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Arel::Nodes::Count do
|
4
|
-
describe "as" do
|
5
|
-
it 'should alias the count' do
|
6
|
-
table = Arel::Table.new :users
|
7
|
-
table[:id].count.as('foo').to_sql.must_be_like %{
|
8
|
-
COUNT("users"."id") AS foo
|
9
|
-
}
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "eq" do
|
14
|
-
it "should compare the count" do
|
15
|
-
table = Arel::Table.new :users
|
16
|
-
table[:id].count.eq(2).to_sql.must_be_like %{
|
17
|
-
COUNT("users"."id") = 2
|
18
|
-
}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'equality' do
|
23
|
-
it 'is equal with equal ivars' do
|
24
|
-
array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo')]
|
25
|
-
assert_equal 1, array.uniq.size
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'is not equal with different ivars' do
|
29
|
-
array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo!')]
|
30
|
-
assert_equal 2, array.uniq.size
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Arel::Nodes::DeleteStatement do
|
4
|
-
describe "#clone" do
|
5
|
-
it "clones wheres" do
|
6
|
-
statement = Arel::Nodes::DeleteStatement.new
|
7
|
-
statement.wheres = %w[a b c]
|
8
|
-
|
9
|
-
dolly = statement.clone
|
10
|
-
dolly.wheres.must_equal statement.wheres
|
11
|
-
dolly.wheres.wont_be_same_as statement.wheres
|
12
|
-
end
|
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
|
34
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
class TestDescending < Minitest::Test
|
6
|
-
def test_construct
|
7
|
-
descending = Descending.new 'zomg'
|
8
|
-
assert_equal 'zomg', descending.expr
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_reverse
|
12
|
-
descending = Descending.new 'zomg'
|
13
|
-
ascending = descending.reverse
|
14
|
-
assert_kind_of Ascending, ascending
|
15
|
-
assert_equal descending.expr, ascending.expr
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_direction
|
19
|
-
descending = Descending.new 'zomg'
|
20
|
-
assert_equal :desc, descending.direction
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_ascending?
|
24
|
-
descending = Descending.new 'zomg'
|
25
|
-
assert !descending.ascending?
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_descending?
|
29
|
-
descending = Descending.new 'zomg'
|
30
|
-
assert descending.descending?
|
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
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/test/nodes/test_distinct.rb
DELETED
@@ -1,20 +0,0 @@
|
|
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
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Nodes
|
5
|
-
describe 'equality' do
|
6
|
-
# FIXME: backwards compat
|
7
|
-
describe 'backwards compat' do
|
8
|
-
describe 'operator' do
|
9
|
-
it 'returns :==' do
|
10
|
-
attr = Table.new(:users)[:id]
|
11
|
-
left = attr.eq(10)
|
12
|
-
left.operator.must_equal :==
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'operand1' do
|
17
|
-
it "should equal left" do
|
18
|
-
attr = Table.new(:users)[:id]
|
19
|
-
left = attr.eq(10)
|
20
|
-
left.left.must_equal left.operand1
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'operand2' do
|
25
|
-
it "should equal right" do
|
26
|
-
attr = Table.new(:users)[:id]
|
27
|
-
left = attr.eq(10)
|
28
|
-
left.right.must_equal left.operand2
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'to_sql' do
|
33
|
-
it 'takes an engine' do
|
34
|
-
engine = FakeRecord::Base.new
|
35
|
-
engine.connection.extend Module.new {
|
36
|
-
attr_accessor :quote_count
|
37
|
-
def quote(*args) @quote_count += 1; super; end
|
38
|
-
def quote_column_name(*args) @quote_count += 1; super; end
|
39
|
-
def quote_table_name(*args) @quote_count += 1; super; end
|
40
|
-
}
|
41
|
-
engine.connection.quote_count = 0
|
42
|
-
|
43
|
-
attr = Table.new(:users)[:id]
|
44
|
-
test = attr.eq(10)
|
45
|
-
test.to_sql engine
|
46
|
-
engine.connection.quote_count.must_equal 3
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe 'or' do
|
52
|
-
it 'makes an OR node' do
|
53
|
-
attr = Table.new(:users)[:id]
|
54
|
-
left = attr.eq(10)
|
55
|
-
right = attr.eq(11)
|
56
|
-
node = left.or right
|
57
|
-
node.expr.left.must_equal left
|
58
|
-
node.expr.right.must_equal right
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe 'and' do
|
63
|
-
it 'makes and AND node' do
|
64
|
-
attr = Table.new(:users)[:id]
|
65
|
-
left = attr.eq(10)
|
66
|
-
right = attr.eq(11)
|
67
|
-
node = left.and right
|
68
|
-
node.left.must_equal left
|
69
|
-
node.right.must_equal right
|
70
|
-
end
|
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
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|