arel 1.0.1 → 2.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/MIT-LICENSE.txt +20 -0
- data/Manifest.txt +105 -0
- data/README.markdown +12 -32
- data/Rakefile +17 -0
- data/arel.gemspec +39 -0
- data/lib/arel.rb +30 -9
- data/lib/arel/attributes.rb +20 -0
- data/lib/arel/attributes/attribute.rb +190 -0
- data/lib/arel/compatibility/wheres.rb +33 -0
- data/lib/arel/crud.rb +37 -0
- data/lib/arel/delete_manager.rb +22 -0
- data/lib/arel/deprecated.rb +4 -0
- data/lib/arel/expression.rb +4 -0
- data/lib/arel/expressions.rb +23 -0
- data/lib/arel/insert_manager.rb +34 -0
- data/lib/arel/nodes.rb +44 -0
- data/lib/arel/nodes/and.rb +6 -0
- data/lib/arel/nodes/assignment.rb +6 -0
- data/lib/arel/nodes/avg.rb +6 -0
- data/lib/arel/nodes/between.rb +6 -0
- data/lib/arel/nodes/binary.rb +12 -0
- data/lib/arel/nodes/count.rb +13 -0
- data/lib/arel/nodes/delete_statement.rb +17 -0
- data/lib/arel/nodes/does_not_match.rb +6 -0
- data/lib/arel/nodes/equality.rb +9 -0
- data/lib/arel/nodes/exists.rb +11 -0
- data/lib/arel/nodes/function.rb +18 -0
- data/lib/arel/nodes/greater_than.rb +6 -0
- data/lib/arel/nodes/greater_than_or_equal.rb +6 -0
- data/lib/arel/nodes/group.rb +11 -0
- data/lib/arel/nodes/grouping.rb +11 -0
- data/lib/arel/nodes/having.rb +11 -0
- data/lib/arel/nodes/in.rb +6 -0
- data/lib/arel/nodes/inner_join.rb +6 -0
- data/lib/arel/nodes/insert_statement.rb +19 -0
- data/lib/arel/nodes/join.rb +13 -0
- data/lib/arel/nodes/less_than.rb +6 -0
- data/lib/arel/nodes/less_than_or_equal.rb +6 -0
- data/lib/arel/nodes/lock.rb +6 -0
- data/lib/arel/nodes/matches.rb +6 -0
- data/lib/arel/nodes/max.rb +6 -0
- data/lib/arel/nodes/min.rb +6 -0
- data/lib/arel/nodes/node.rb +30 -0
- data/lib/arel/nodes/not_equal.rb +6 -0
- data/lib/arel/nodes/not_in.rb +6 -0
- data/lib/arel/nodes/offset.rb +11 -0
- data/lib/arel/nodes/on.rb +11 -0
- data/lib/arel/nodes/or.rb +6 -0
- data/lib/arel/nodes/ordering.rb +19 -0
- data/lib/arel/nodes/outer_join.rb +6 -0
- data/lib/arel/nodes/select_core.rb +25 -0
- data/lib/arel/nodes/select_statement.rb +22 -0
- data/lib/arel/nodes/sql_literal.rb +7 -0
- data/lib/arel/nodes/string_join.rb +11 -0
- data/lib/arel/nodes/sum.rb +6 -0
- data/lib/arel/nodes/table_alias.rb +21 -0
- data/lib/arel/nodes/unqualified_column.rb +19 -0
- data/lib/arel/nodes/update_statement.rb +21 -0
- data/lib/arel/nodes/values.rb +12 -0
- data/lib/arel/relation.rb +6 -0
- data/lib/arel/select_manager.rb +203 -0
- data/lib/arel/sql/engine.rb +10 -0
- data/lib/arel/sql_literal.rb +1 -10
- data/lib/arel/table.rb +126 -0
- data/lib/arel/tree_manager.rb +26 -0
- data/lib/arel/update_manager.rb +48 -0
- data/lib/arel/visitors.rb +30 -0
- data/lib/arel/visitors/dot.rb +233 -0
- data/lib/arel/visitors/join_sql.rb +38 -0
- data/lib/arel/visitors/mysql.rb +16 -0
- data/lib/arel/visitors/oracle.rb +69 -0
- data/lib/arel/visitors/order_clauses.rb +9 -0
- data/lib/arel/visitors/postgresql.rb +54 -0
- data/lib/arel/visitors/to_sql.rb +301 -0
- data/lib/arel/visitors/where_sql.rb +9 -0
- data/spec/activerecord_compat_spec.rb +18 -0
- data/spec/attributes/attribute_spec.rb +648 -0
- data/spec/attributes_spec.rb +33 -6
- data/spec/crud_spec.rb +69 -0
- data/spec/delete_manager_spec.rb +53 -0
- data/spec/insert_manager_spec.rb +141 -0
- data/spec/nodes/count_spec.rb +18 -0
- data/spec/nodes/delete_statement_spec.rb +15 -0
- data/spec/nodes/equality_spec.rb +72 -0
- data/spec/nodes/insert_statement_spec.rb +18 -0
- data/spec/nodes/or_spec.rb +20 -0
- data/spec/nodes/select_core_spec.rb +21 -0
- data/spec/nodes/select_statement_spec.rb +14 -0
- data/spec/nodes/sql_literal_spec.rb +26 -0
- data/spec/nodes/sum_spec.rb +12 -0
- data/spec/nodes/update_statement_spec.rb +18 -0
- data/spec/select_manager_spec.rb +581 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +6 -21
- data/spec/support/fake_record.rb +89 -0
- data/spec/support/shared/tree_manager_shared.rb +9 -0
- data/spec/table_spec.rb +176 -0
- data/spec/update_manager_spec.rb +89 -0
- data/spec/visitors/join_sql_spec.rb +35 -0
- data/spec/visitors/oracle_spec.rb +111 -0
- data/spec/visitors/to_sql_spec.rb +134 -0
- metadata +160 -260
- data/lib/arel/algebra.rb +0 -10
- data/lib/arel/algebra/attributes.rb +0 -7
- data/lib/arel/algebra/attributes/attribute.rb +0 -304
- data/lib/arel/algebra/attributes/boolean.rb +0 -21
- data/lib/arel/algebra/attributes/decimal.rb +0 -9
- data/lib/arel/algebra/attributes/float.rb +0 -9
- data/lib/arel/algebra/attributes/integer.rb +0 -10
- data/lib/arel/algebra/attributes/string.rb +0 -10
- data/lib/arel/algebra/attributes/time.rb +0 -6
- data/lib/arel/algebra/core_extensions.rb +0 -3
- data/lib/arel/algebra/core_extensions/hash.rb +0 -7
- data/lib/arel/algebra/core_extensions/object.rb +0 -13
- data/lib/arel/algebra/core_extensions/symbol.rb +0 -9
- data/lib/arel/algebra/expression.rb +0 -56
- data/lib/arel/algebra/header.rb +0 -66
- data/lib/arel/algebra/ordering.rb +0 -31
- data/lib/arel/algebra/predicates.rb +0 -306
- data/lib/arel/algebra/relations.rb +0 -16
- data/lib/arel/algebra/relations/operations/from.rb +0 -14
- data/lib/arel/algebra/relations/operations/group.rb +0 -14
- data/lib/arel/algebra/relations/operations/having.rb +0 -14
- data/lib/arel/algebra/relations/operations/join.rb +0 -103
- data/lib/arel/algebra/relations/operations/lock.rb +0 -10
- data/lib/arel/algebra/relations/operations/order.rb +0 -23
- data/lib/arel/algebra/relations/operations/project.rb +0 -20
- data/lib/arel/algebra/relations/operations/skip.rb +0 -14
- data/lib/arel/algebra/relations/operations/take.rb +0 -18
- data/lib/arel/algebra/relations/operations/where.rb +0 -24
- data/lib/arel/algebra/relations/relation.rb +0 -205
- data/lib/arel/algebra/relations/row.rb +0 -29
- data/lib/arel/algebra/relations/utilities/compound.rb +0 -55
- data/lib/arel/algebra/relations/utilities/externalization.rb +0 -26
- data/lib/arel/algebra/relations/utilities/nil.rb +0 -7
- data/lib/arel/algebra/relations/writes.rb +0 -47
- data/lib/arel/algebra/value.rb +0 -53
- data/lib/arel/engines.rb +0 -2
- data/lib/arel/engines/memory.rb +0 -2
- data/lib/arel/engines/memory/engine.rb +0 -10
- data/lib/arel/engines/memory/relations.rb +0 -2
- data/lib/arel/engines/memory/relations/array.rb +0 -37
- data/lib/arel/engines/memory/relations/operations.rb +0 -9
- data/lib/arel/engines/sql.rb +0 -6
- data/lib/arel/engines/sql/attributes.rb +0 -45
- data/lib/arel/engines/sql/christener.rb +0 -20
- data/lib/arel/engines/sql/compilers/ibm_db_compiler.rb +0 -48
- data/lib/arel/engines/sql/compilers/mysql_compiler.rb +0 -11
- data/lib/arel/engines/sql/compilers/oracle_compiler.rb +0 -106
- data/lib/arel/engines/sql/compilers/postgresql_compiler.rb +0 -50
- data/lib/arel/engines/sql/compilers/sqlite_compiler.rb +0 -9
- data/lib/arel/engines/sql/core_extensions.rb +0 -4
- data/lib/arel/engines/sql/core_extensions/array.rb +0 -24
- data/lib/arel/engines/sql/core_extensions/nil_class.rb +0 -15
- data/lib/arel/engines/sql/core_extensions/object.rb +0 -19
- data/lib/arel/engines/sql/core_extensions/range.rb +0 -19
- data/lib/arel/engines/sql/engine.rb +0 -47
- data/lib/arel/engines/sql/formatters.rb +0 -138
- data/lib/arel/engines/sql/relations.rb +0 -3
- data/lib/arel/engines/sql/relations/compiler.rb +0 -153
- data/lib/arel/engines/sql/relations/table.rb +0 -100
- data/lib/arel/engines/sql/relations/utilities/nil.rb +0 -6
- data/lib/arel/recursion/base_case.rb +0 -13
- data/lib/arel/session.rb +0 -35
- data/lib/arel/version.rb +0 -3
- data/spec/algebra/unit/predicates/binary_spec.rb +0 -35
- data/spec/algebra/unit/predicates/equality_spec.rb +0 -29
- data/spec/algebra/unit/predicates/in_spec.rb +0 -12
- data/spec/algebra/unit/predicates/inequality_spec.rb +0 -32
- data/spec/algebra/unit/predicates/predicate_spec.rb +0 -22
- data/spec/algebra/unit/primitives/attribute_spec.rb +0 -175
- data/spec/algebra/unit/primitives/expression_spec.rb +0 -39
- data/spec/algebra/unit/primitives/value_spec.rb +0 -15
- data/spec/algebra/unit/relations/alias_spec.rb +0 -16
- data/spec/algebra/unit/relations/delete_spec.rb +0 -9
- data/spec/algebra/unit/relations/group_spec.rb +0 -10
- data/spec/algebra/unit/relations/insert_spec.rb +0 -9
- data/spec/algebra/unit/relations/join_spec.rb +0 -18
- data/spec/algebra/unit/relations/order_spec.rb +0 -21
- data/spec/algebra/unit/relations/project_spec.rb +0 -34
- data/spec/algebra/unit/relations/relation_spec.rb +0 -241
- data/spec/algebra/unit/relations/skip_spec.rb +0 -10
- data/spec/algebra/unit/relations/table_spec.rb +0 -38
- data/spec/algebra/unit/relations/take_spec.rb +0 -10
- data/spec/algebra/unit/relations/update_spec.rb +0 -9
- data/spec/algebra/unit/relations/where_spec.rb +0 -19
- data/spec/algebra/unit/session/session_spec.rb +0 -84
- data/spec/attributes/boolean_spec.rb +0 -57
- data/spec/attributes/float_spec.rb +0 -119
- data/spec/attributes/header_spec.rb +0 -42
- data/spec/attributes/integer_spec.rb +0 -119
- data/spec/attributes/string_spec.rb +0 -43
- data/spec/attributes/time_spec.rb +0 -24
- data/spec/engines/memory/integration/joins/cross_engine_spec.rb +0 -61
- data/spec/engines/memory/unit/relations/array_spec.rb +0 -33
- data/spec/engines/memory/unit/relations/insert_spec.rb +0 -28
- data/spec/engines/memory/unit/relations/join_spec.rb +0 -32
- data/spec/engines/memory/unit/relations/order_spec.rb +0 -28
- data/spec/engines/memory/unit/relations/project_spec.rb +0 -27
- data/spec/engines/memory/unit/relations/skip_spec.rb +0 -31
- data/spec/engines/memory/unit/relations/take_spec.rb +0 -28
- data/spec/engines/memory/unit/relations/where_spec.rb +0 -43
- data/spec/engines/sql/integration/joins/with_adjacency_spec.rb +0 -258
- data/spec/engines/sql/integration/joins/with_aggregations_spec.rb +0 -221
- data/spec/engines/sql/integration/joins/with_compounds_spec.rb +0 -137
- data/spec/engines/sql/unit/engine_spec.rb +0 -65
- data/spec/engines/sql/unit/predicates/binary_spec.rb +0 -140
- data/spec/engines/sql/unit/predicates/equality_spec.rb +0 -75
- data/spec/engines/sql/unit/predicates/in_spec.rb +0 -179
- data/spec/engines/sql/unit/predicates/noteq_spec.rb +0 -75
- data/spec/engines/sql/unit/predicates/predicates_spec.rb +0 -79
- data/spec/engines/sql/unit/primitives/attribute_spec.rb +0 -36
- data/spec/engines/sql/unit/primitives/expression_spec.rb +0 -28
- data/spec/engines/sql/unit/primitives/literal_spec.rb +0 -43
- data/spec/engines/sql/unit/primitives/value_spec.rb +0 -29
- data/spec/engines/sql/unit/relations/alias_spec.rb +0 -53
- data/spec/engines/sql/unit/relations/delete_spec.rb +0 -83
- data/spec/engines/sql/unit/relations/from_spec.rb +0 -64
- data/spec/engines/sql/unit/relations/group_spec.rb +0 -72
- data/spec/engines/sql/unit/relations/having_spec.rb +0 -78
- data/spec/engines/sql/unit/relations/insert_spec.rb +0 -143
- data/spec/engines/sql/unit/relations/join_spec.rb +0 -180
- data/spec/engines/sql/unit/relations/lock_spec.rb +0 -86
- data/spec/engines/sql/unit/relations/order_spec.rb +0 -161
- data/spec/engines/sql/unit/relations/project_spec.rb +0 -143
- data/spec/engines/sql/unit/relations/skip_spec.rb +0 -41
- data/spec/engines/sql/unit/relations/table_spec.rb +0 -122
- data/spec/engines/sql/unit/relations/take_spec.rb +0 -75
- data/spec/engines/sql/unit/relations/update_spec.rb +0 -203
- data/spec/engines/sql/unit/relations/where_spec.rb +0 -72
- data/spec/relations/join_spec.rb +0 -42
- data/spec/relations/relation_spec.rb +0 -31
- data/spec/shared/relation_spec.rb +0 -255
- data/spec/sql/christener_spec.rb +0 -70
- data/spec/support/connections/mysql_connection.rb +0 -14
- data/spec/support/connections/oracle_connection.rb +0 -17
- data/spec/support/connections/postgresql_connection.rb +0 -13
- data/spec/support/connections/sqlite3_connection.rb +0 -24
- data/spec/support/guards.rb +0 -28
- data/spec/support/matchers/disambiguate_attributes.rb +0 -28
- data/spec/support/matchers/hash_the_same_as.rb +0 -26
- data/spec/support/matchers/have_rows.rb +0 -18
- data/spec/support/model.rb +0 -67
- data/spec/support/schemas/mysql_schema.rb +0 -26
- data/spec/support/schemas/oracle_schema.rb +0 -20
- data/spec/support/schemas/postgresql_schema.rb +0 -26
- data/spec/support/schemas/sqlite3_schema.rb +0 -26
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Predicates
|
5
|
-
describe Equality do
|
6
|
-
before do
|
7
|
-
@relation1 = Arel::Table.new(:users)
|
8
|
-
@relation2 = Arel::Table.new(:photos)
|
9
|
-
@attribute1 = @relation1[:id]
|
10
|
-
@attribute2 = @relation2[:user_id]
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#to_sql' do
|
14
|
-
describe 'when relating to a non-nil value' do
|
15
|
-
it "manufactures an equality predicate" do
|
16
|
-
sql = Equality.new(@attribute1, @attribute2).to_sql
|
17
|
-
|
18
|
-
adapter_is :mysql do
|
19
|
-
sql.should be_like(%Q{`users`.`id` = `photos`.`user_id`})
|
20
|
-
end
|
21
|
-
|
22
|
-
adapter_is :oracle do
|
23
|
-
sql.should be_like(%Q{"USERS"."ID" = "PHOTOS"."USER_ID"})
|
24
|
-
end
|
25
|
-
|
26
|
-
adapter_is_not :mysql, :oracle do
|
27
|
-
sql.should be_like(%Q{"users"."id" = "photos"."user_id"})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'when relation to a nil value' do
|
33
|
-
before do
|
34
|
-
@nil = nil
|
35
|
-
end
|
36
|
-
|
37
|
-
it "manufactures an is null predicate" do
|
38
|
-
sql = Equality.new(@attribute1, @nil).to_sql
|
39
|
-
|
40
|
-
adapter_is :mysql do
|
41
|
-
sql.should be_like(%Q{`users`.`id` IS NULL})
|
42
|
-
end
|
43
|
-
|
44
|
-
adapter_is :oracle do
|
45
|
-
sql.should be_like(%Q{"USERS"."ID" IS NULL})
|
46
|
-
end
|
47
|
-
|
48
|
-
adapter_is_not :mysql, :oracle do
|
49
|
-
sql.should be_like(%Q{"users"."id" IS NULL})
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "when relating to a nil Value" do
|
55
|
-
it "manufactures an IS NULL predicate" do
|
56
|
-
value = nil.bind(@relation1)
|
57
|
-
sql = Equality.new(@attribute1, value).to_sql
|
58
|
-
|
59
|
-
adapter_is :mysql do
|
60
|
-
sql.should be_like(%Q{`users`.`id` IS NULL})
|
61
|
-
end
|
62
|
-
|
63
|
-
adapter_is :oracle do
|
64
|
-
sql.should be_like(%Q{"USERS"."ID" IS NULL})
|
65
|
-
end
|
66
|
-
|
67
|
-
adapter_is_not :mysql, :oracle do
|
68
|
-
sql.should be_like(%Q{"users"."id" IS NULL})
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,179 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Predicates
|
5
|
-
describe In do
|
6
|
-
before do
|
7
|
-
@relation = Arel::Table.new(:users)
|
8
|
-
@attribute = @relation[:id]
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#to_sql' do
|
12
|
-
describe 'when relating to an array' do
|
13
|
-
describe 'when the array\'s elements are the same type as the attribute' do
|
14
|
-
before do
|
15
|
-
@array = [1, 2, 3]
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'manufactures sql with a comma separated list' do
|
19
|
-
sql = In.new(@attribute, @array).to_sql
|
20
|
-
|
21
|
-
adapter_is :mysql do
|
22
|
-
sql.should be_like(%Q{`users`.`id` IN (1, 2, 3)})
|
23
|
-
end
|
24
|
-
|
25
|
-
adapter_is :oracle do
|
26
|
-
sql.should be_like(%Q{"USERS"."ID" IN (1, 2, 3)})
|
27
|
-
end
|
28
|
-
|
29
|
-
adapter_is_not :mysql, :oracle do
|
30
|
-
sql.should be_like(%Q{"users"."id" IN (1, 2, 3)})
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'when the array\'s elements are not same type as the attribute' do
|
36
|
-
before do
|
37
|
-
@array = ['1-asdf', 2, 3]
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'formats values in the array as the type of the attribute' do
|
41
|
-
sql = In.new(@attribute, @array).to_sql
|
42
|
-
|
43
|
-
adapter_is :mysql do
|
44
|
-
sql.should be_like(%Q{`users`.`id` IN (1, 2, 3)})
|
45
|
-
end
|
46
|
-
|
47
|
-
adapter_is :oracle do
|
48
|
-
sql.should be_like(%Q{"USERS"."ID" IN (1, 2, 3)})
|
49
|
-
end
|
50
|
-
|
51
|
-
adapter_is_not :mysql, :oracle do
|
52
|
-
sql.should be_like(%Q{"users"."id" IN (1, 2, 3)})
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe 'when the array is empty' do
|
58
|
-
before do
|
59
|
-
@array = []
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'manufactures sql with a comma separated list' do
|
63
|
-
sql = In.new(@attribute, @array).to_sql
|
64
|
-
|
65
|
-
adapter_is :mysql do
|
66
|
-
sql.should be_like(%Q{`users`.`id` IN (NULL)})
|
67
|
-
end
|
68
|
-
|
69
|
-
adapter_is :oracle do
|
70
|
-
sql.should be_like(%Q{"USERS"."ID" IN (NULL)})
|
71
|
-
end
|
72
|
-
|
73
|
-
adapter_is_not :mysql, :oracle do
|
74
|
-
sql.should be_like(%Q{"users"."id" IN (NULL)})
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
describe 'when relating to a range' do
|
82
|
-
before do
|
83
|
-
@range = 1..2
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'manufactures sql with a between' do
|
87
|
-
sql = In.new(@attribute, @range).to_sql
|
88
|
-
|
89
|
-
adapter_is :mysql do
|
90
|
-
sql.should be_like(%Q{`users`.`id` BETWEEN 1 AND 2})
|
91
|
-
end
|
92
|
-
|
93
|
-
adapter_is :oracle do
|
94
|
-
sql.should be_like(%Q{"USERS"."ID" BETWEEN 1 AND 2})
|
95
|
-
end
|
96
|
-
|
97
|
-
adapter_is_not :mysql, :oracle do
|
98
|
-
sql.should be_like(%Q{"users"."id" BETWEEN 1 AND 2})
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe 'when relating to a range with an excluded end' do
|
104
|
-
before do
|
105
|
-
@range = 1...3
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'manufactures sql with a >= and <' do
|
109
|
-
sql = In.new(@attribute, @range).to_sql
|
110
|
-
|
111
|
-
adapter_is :mysql do
|
112
|
-
sql.should be_like(%Q{(`users`.`id` >= 1 AND `users`.`id` < 3)})
|
113
|
-
end
|
114
|
-
|
115
|
-
adapter_is :oracle do
|
116
|
-
sql.should be_like(%Q{("USERS"."ID" >= 1 AND "USERS"."ID" < 3)})
|
117
|
-
end
|
118
|
-
|
119
|
-
adapter_is_not :mysql, :oracle do
|
120
|
-
sql.should be_like(%Q{("users"."id" >= 1 AND "users"."id" < 3)})
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe 'when relating to a time range' do
|
126
|
-
before do
|
127
|
-
@relation = Arel::Table.new(:developers)
|
128
|
-
@attribute = @relation[:created_at]
|
129
|
-
@range = Time.mktime(2010, 01, 01)..Time.mktime(2010, 02, 01)
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'manufactures sql with a between' do
|
133
|
-
sql = In.new(@attribute, @range).to_sql
|
134
|
-
|
135
|
-
adapter_is :mysql do
|
136
|
-
sql.should be_like(%Q{`developers`.`created_at` BETWEEN '2010-01-01 00:00:00' AND '2010-02-01 00:00:00'})
|
137
|
-
end
|
138
|
-
|
139
|
-
adapter_is :sqlite3 do
|
140
|
-
sql.should match(/"developers"."created_at" BETWEEN '2010-01-01 00:00:00(?:\.\d+)' AND '2010-02-01 00:00:00(?:\.\d+)'/)
|
141
|
-
end
|
142
|
-
|
143
|
-
adapter_is :postgresql do
|
144
|
-
sql.should be_like(%Q{"developers"."created_at" BETWEEN '2010-01-01 00:00:00.000000' AND '2010-02-01 00:00:00.000000'})
|
145
|
-
end
|
146
|
-
|
147
|
-
adapter_is :oracle do
|
148
|
-
sql.should be_like(%Q{"DEVELOPERS"."CREATED_AT" BETWEEN TO_TIMESTAMP('2010-01-01 00:00:00:000000','YYYY-MM-DD HH24:MI:SS:FF6') AND TO_TIMESTAMP('2010-02-01 00:00:00:000000','YYYY-MM-DD HH24:MI:SS:FF6')})
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe 'when relating to a relation' do
|
154
|
-
it 'manufactures sql with a subselect' do
|
155
|
-
sql = In.new(@attribute, @relation).to_sql
|
156
|
-
|
157
|
-
adapter_is :mysql do
|
158
|
-
sql.should be_like(%Q{
|
159
|
-
`users`.`id` IN (SELECT `users`.`id`, `users`.`name` FROM `users`)
|
160
|
-
})
|
161
|
-
end
|
162
|
-
|
163
|
-
adapter_is :oracle do
|
164
|
-
sql.should be_like(%Q{
|
165
|
-
"USERS"."ID" IN (SELECT "USERS"."ID", "USERS"."NAME" FROM "USERS")
|
166
|
-
})
|
167
|
-
end
|
168
|
-
|
169
|
-
adapter_is_not :mysql, :oracle do
|
170
|
-
sql.should be_like(%Q{
|
171
|
-
"users"."id" IN (SELECT "users"."id", "users"."name" FROM "users")
|
172
|
-
})
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Predicates
|
5
|
-
describe Equality do
|
6
|
-
before do
|
7
|
-
@relation1 = Arel::Table.new(:users)
|
8
|
-
@relation2 = Arel::Table.new(:photos)
|
9
|
-
@attribute1 = @relation1[:id]
|
10
|
-
@attribute2 = @relation2[:user_id]
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#to_sql' do
|
14
|
-
describe 'when relating to a non-nil value' do
|
15
|
-
it "manufactures a not predicate" do
|
16
|
-
sql = Inequality.new(@attribute1, @attribute2).to_sql
|
17
|
-
|
18
|
-
adapter_is :mysql do
|
19
|
-
sql.should be_like(%Q{`users`.`id` != `photos`.`user_id`})
|
20
|
-
end
|
21
|
-
|
22
|
-
adapter_is :oracle do
|
23
|
-
sql.should be_like(%Q{"USERS"."ID" != "PHOTOS"."USER_ID"})
|
24
|
-
end
|
25
|
-
|
26
|
-
adapter_is_not :mysql, :oracle do
|
27
|
-
sql.should be_like(%Q{"users"."id" != "photos"."user_id"})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'when relation to a nil value' do
|
33
|
-
before do
|
34
|
-
@nil = nil
|
35
|
-
end
|
36
|
-
|
37
|
-
it "manufactures an is null predicate" do
|
38
|
-
sql = Inequality.new(@attribute1, @nil).to_sql
|
39
|
-
|
40
|
-
adapter_is :mysql do
|
41
|
-
sql.should be_like(%Q{`users`.`id` IS NOT NULL})
|
42
|
-
end
|
43
|
-
|
44
|
-
adapter_is :oracle do
|
45
|
-
sql.should be_like(%Q{"USERS"."ID" IS NOT NULL})
|
46
|
-
end
|
47
|
-
|
48
|
-
adapter_is_not :mysql, :oracle do
|
49
|
-
sql.should be_like(%Q{"users"."id" IS NOT NULL})
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "when relating to a nil Value" do
|
55
|
-
it "manufactures an IS NULL predicate" do
|
56
|
-
value = nil.bind(@relation1)
|
57
|
-
sql = Inequality.new(@attribute1, value).to_sql
|
58
|
-
|
59
|
-
adapter_is :mysql do
|
60
|
-
sql.should be_like(%Q{`users`.`id` IS NOT NULL})
|
61
|
-
end
|
62
|
-
|
63
|
-
adapter_is :oracle do
|
64
|
-
sql.should be_like(%Q{"USERS"."ID" IS NOT NULL})
|
65
|
-
end
|
66
|
-
|
67
|
-
adapter_is_not :mysql, :oracle do
|
68
|
-
sql.should be_like(%Q{"users"."id" IS NOT NULL})
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
module Predicates
|
5
|
-
describe Predicate do
|
6
|
-
before do
|
7
|
-
@relation = Arel::Table.new(:users)
|
8
|
-
@attribute1 = @relation[:id]
|
9
|
-
@attribute2 = @relation[:name]
|
10
|
-
@operand1 = Arel::Predicates::Equality.new(@attribute1, 1)
|
11
|
-
@operand2 = Arel::Predicates::Equality.new(@attribute2, "name")
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "when being combined with another predicate with AND logic" do
|
15
|
-
describe "#to_sql" do
|
16
|
-
it "manufactures sql with an AND operation" do
|
17
|
-
sql = @operand1.and(@operand2).to_sql
|
18
|
-
|
19
|
-
adapter_is :mysql do
|
20
|
-
sql.should be_like(%Q{
|
21
|
-
(`users`.`id` = 1 AND `users`.`name` = 'name')
|
22
|
-
})
|
23
|
-
end
|
24
|
-
|
25
|
-
adapter_is :sqlite3 do
|
26
|
-
sql.should be_like(%Q{
|
27
|
-
("users"."id" = 1 AND "users"."name" = 'name')
|
28
|
-
})
|
29
|
-
end
|
30
|
-
|
31
|
-
adapter_is :postgresql do
|
32
|
-
sql.should be_like(%Q{
|
33
|
-
("users"."id" = 1 AND "users"."name" = E'name')
|
34
|
-
})
|
35
|
-
end
|
36
|
-
|
37
|
-
adapter_is :oracle do
|
38
|
-
sql.should be_like(%Q{
|
39
|
-
("USERS"."ID" = 1 AND "USERS"."NAME" = 'name')
|
40
|
-
})
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "when being combined with another predicate with OR logic" do
|
47
|
-
describe "#to_sql" do
|
48
|
-
it "manufactures sql with an OR operation" do
|
49
|
-
sql = @operand1.or(@operand2).to_sql
|
50
|
-
|
51
|
-
adapter_is :mysql do
|
52
|
-
sql.should be_like(%Q{
|
53
|
-
(`users`.`id` = 1 OR `users`.`name` = 'name')
|
54
|
-
})
|
55
|
-
end
|
56
|
-
|
57
|
-
adapter_is :sqlite3 do
|
58
|
-
sql.should be_like(%Q{
|
59
|
-
("users"."id" = 1 OR "users"."name" = 'name')
|
60
|
-
})
|
61
|
-
end
|
62
|
-
|
63
|
-
adapter_is :postgresql do
|
64
|
-
sql.should be_like(%Q{
|
65
|
-
("users"."id" = 1 OR "users"."name" = E'name')
|
66
|
-
})
|
67
|
-
end
|
68
|
-
|
69
|
-
adapter_is :oracle do
|
70
|
-
sql.should be_like(%Q{
|
71
|
-
("USERS"."ID" = 1 OR "USERS"."NAME" = 'name')
|
72
|
-
})
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
describe Attribute do
|
5
|
-
before do
|
6
|
-
@relation = Table.new(:users)
|
7
|
-
@attribute = @relation[:id]
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#column' do
|
11
|
-
it "returns the corresponding column in the relation" do
|
12
|
-
@attribute.column.should == @relation.column_for(@attribute)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#to_sql' do
|
17
|
-
describe 'for a simple attribute' do
|
18
|
-
it "manufactures sql with an alias" do
|
19
|
-
sql = @attribute.to_sql
|
20
|
-
|
21
|
-
adapter_is :mysql do
|
22
|
-
sql.should be_like(%Q{`users`.`id`})
|
23
|
-
end
|
24
|
-
|
25
|
-
adapter_is :oracle do
|
26
|
-
sql.should be_like(%Q{"USERS"."ID"})
|
27
|
-
end
|
28
|
-
|
29
|
-
adapter_is_not :mysql, :oracle do
|
30
|
-
sql.should be_like(%Q{"users"."id"})
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Arel
|
4
|
-
describe Expression do
|
5
|
-
before do
|
6
|
-
@relation = Table.new(:users)
|
7
|
-
@attribute = @relation[:id]
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#to_sql' do
|
11
|
-
it "manufactures sql with the expression and alias" do
|
12
|
-
sql = Count.new(@attribute, :alias).to_sql
|
13
|
-
|
14
|
-
adapter_is :mysql do
|
15
|
-
sql.should be_like(%Q{COUNT(`users`.`id`) AS `alias`})
|
16
|
-
end
|
17
|
-
|
18
|
-
adapter_is :oracle do
|
19
|
-
sql.should be_like(%Q{COUNT("USERS"."ID") AS "ALIAS"})
|
20
|
-
end
|
21
|
-
|
22
|
-
adapter_is_not :mysql, :oracle do
|
23
|
-
sql.should be_like(%Q{COUNT("users"."id") AS "alias"})
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|