arel 0.1.0 → 0.2.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/.gitmodules +3 -0
- data/History.txt +11 -0
- data/README.markdown +26 -26
- data/Rakefile +34 -46
- data/Thorfile +124 -0
- data/arel.gemspec +216 -201
- data/lib/arel/algebra/{primitives/attribute.rb → attribute.rb} +7 -7
- data/lib/arel/algebra/{extensions → core_extensions}/class.rb +2 -2
- data/lib/arel/algebra/{extensions → core_extensions}/hash.rb +1 -1
- data/lib/arel/algebra/{extensions → core_extensions}/object.rb +1 -1
- data/lib/arel/algebra/{extensions → core_extensions}/symbol.rb +1 -1
- data/lib/arel/algebra/core_extensions.rb +4 -0
- data/lib/arel/algebra/{primitives/ordering.rb → ordering.rb} +1 -1
- data/lib/arel/algebra/predicates.rb +32 -30
- data/lib/arel/algebra/relations/operations/from.rb +6 -0
- data/lib/arel/algebra/relations/operations/having.rb +13 -0
- data/lib/arel/algebra/relations/operations/join.rb +4 -0
- data/lib/arel/algebra/relations/operations/lock.rb +12 -0
- data/lib/arel/algebra/relations/operations/project.rb +1 -1
- data/lib/arel/algebra/relations/relation.rb +9 -2
- data/lib/arel/algebra/relations/utilities/compound.rb +2 -2
- data/lib/arel/algebra/relations.rb +3 -0
- data/lib/arel/algebra.rb +7 -2
- data/lib/arel/engines/memory/predicates.rb +26 -24
- data/lib/arel/engines/memory/relations/operations.rb +6 -0
- data/lib/arel/engines/sql/christener.rb +2 -1
- data/lib/arel/engines/sql/{extensions → core_extensions}/array.rb +6 -2
- data/lib/arel/engines/sql/{extensions → core_extensions}/nil_class.rb +1 -1
- data/lib/arel/engines/sql/{extensions → core_extensions}/object.rb +1 -1
- data/lib/arel/engines/sql/{extensions → core_extensions}/range.rb +1 -1
- data/lib/arel/engines/sql/core_extensions.rb +4 -0
- data/lib/arel/engines/sql/engine.rb +4 -0
- data/lib/arel/engines/sql/formatters.rb +12 -3
- data/lib/arel/engines/sql/predicates.rb +37 -35
- data/lib/arel/engines/sql/primitives.rb +10 -2
- data/lib/arel/engines/sql/relations/operations/join.rb +2 -2
- data/lib/arel/engines/sql/relations/relation.rb +46 -10
- data/lib/arel/engines/sql/relations/table.rb +18 -5
- data/lib/arel/engines/sql/relations/utilities/compound.rb +1 -1
- data/lib/arel/engines/sql/relations/writes.rb +58 -11
- data/lib/arel/engines/sql.rb +1 -1
- data/lib/arel/session.rb +9 -6
- data/lib/arel.rb +9 -8
- data/spec/arel/algebra/unit/predicates/binary_spec.rb +23 -21
- data/spec/arel/algebra/unit/predicates/equality_spec.rb +20 -18
- data/spec/arel/algebra/unit/predicates/in_spec.rb +7 -5
- data/spec/arel/algebra/unit/primitives/attribute_spec.rb +10 -12
- data/spec/arel/algebra/unit/primitives/expression_spec.rb +1 -1
- data/spec/arel/algebra/unit/primitives/value_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/alias_spec.rb +2 -2
- data/spec/arel/algebra/unit/relations/delete_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/group_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/insert_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/join_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/order_spec.rb +2 -2
- data/spec/arel/algebra/unit/relations/project_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/relation_spec.rb +9 -9
- data/spec/arel/algebra/unit/relations/skip_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/table_spec.rb +2 -2
- data/spec/arel/algebra/unit/relations/take_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/update_spec.rb +1 -1
- data/spec/arel/algebra/unit/relations/where_spec.rb +1 -1
- data/spec/arel/algebra/unit/session/session_spec.rb +6 -6
- data/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb +3 -4
- data/spec/arel/engines/memory/unit/relations/array_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/insert_spec.rb +8 -8
- data/spec/arel/engines/memory/unit/relations/join_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/order_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/project_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/skip_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/take_spec.rb +1 -1
- data/spec/arel/engines/memory/unit/relations/where_spec.rb +1 -1
- data/spec/arel/engines/sql/integration/joins/with_adjacency_spec.rb +1 -1
- data/spec/arel/engines/sql/integration/joins/with_aggregations_spec.rb +1 -1
- data/spec/arel/engines/sql/integration/joins/with_compounds_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/engine_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/predicates/binary_spec.rb +73 -70
- data/spec/arel/engines/sql/unit/predicates/equality_spec.rb +45 -28
- data/spec/arel/engines/sql/unit/predicates/in_spec.rb +75 -54
- data/spec/arel/engines/sql/unit/predicates/predicates_spec.rb +48 -46
- data/spec/arel/engines/sql/unit/primitives/attribute_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/primitives/expression_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/primitives/literal_spec.rb +13 -1
- data/spec/arel/engines/sql/unit/primitives/value_spec.rb +3 -3
- data/spec/arel/engines/sql/unit/relations/alias_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/delete_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/from_spec.rb +50 -0
- data/spec/arel/engines/sql/unit/relations/group_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/having_spec.rb +36 -0
- data/spec/arel/engines/sql/unit/relations/insert_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/join_spec.rb +85 -4
- data/spec/arel/engines/sql/unit/relations/lock_spec.rb +61 -0
- data/spec/arel/engines/sql/unit/relations/order_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/project_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/skip_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/table_spec.rb +42 -3
- data/spec/arel/engines/sql/unit/relations/take_spec.rb +1 -1
- data/spec/arel/engines/sql/unit/relations/update_spec.rb +13 -7
- data/spec/arel/engines/sql/unit/relations/where_spec.rb +1 -1
- data/spec/connections/mysql_connection.rb +3 -3
- data/spec/connections/postgresql_connection.rb +2 -2
- data/spec/connections/sqlite3_connection.rb +3 -2
- data/spec/doubles/hash.rb +4 -0
- data/spec/schemas/mysql_schema.rb +7 -0
- data/spec/schemas/postgresql_schema.rb +7 -0
- data/spec/schemas/sqlite3_schema.rb +7 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +9 -1
- metadata +50 -25
- data/VERSION +0 -1
- data/lib/arel/.DS_Store +0 -0
- data/lib/arel/algebra/extensions.rb +0 -4
- data/lib/arel/algebra/primitives.rb +0 -5
- data/lib/arel/engines/sql/extensions.rb +0 -4
- /data/lib/arel/algebra/{primitives/expression.rb → expression.rb} +0 -0
- /data/lib/arel/algebra/{primitives/value.rb → value.rb} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
4
|
describe Insert do
|
|
@@ -14,13 +14,13 @@ module Arel
|
|
|
14
14
|
it "manufactures an array of hashes of attributes to values" do
|
|
15
15
|
@relation \
|
|
16
16
|
.insert(@relation[:id] => 4, @relation[:name] => 'guinea fowl') \
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
do |relation|
|
|
18
|
+
relation.should == [
|
|
19
|
+
Row.new(relation, [1, 'duck']),
|
|
20
|
+
Row.new(relation, [2, 'duck']),
|
|
21
|
+
Row.new(relation, [3, 'goose']),
|
|
22
|
+
Row.new(relation, [4, 'guinea fowl'])
|
|
23
|
+
]
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -1,113 +1,116 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@relation = Table.new(:users)
|
|
7
|
-
@attribute1 = @relation[:id]
|
|
8
|
-
@attribute2 = @relation[:name]
|
|
4
|
+
module Predicates
|
|
5
|
+
describe Binary do
|
|
9
6
|
class ConcreteBinary < Binary
|
|
10
7
|
def predicate_sql
|
|
11
8
|
"<=>"
|
|
12
9
|
end
|
|
13
10
|
end
|
|
14
|
-
end
|
|
15
11
|
|
|
16
|
-
describe "with compound predicates" do
|
|
17
12
|
before do
|
|
18
|
-
@
|
|
19
|
-
@
|
|
13
|
+
@relation = Arel::Table.new(:users)
|
|
14
|
+
@attribute1 = @relation[:id]
|
|
15
|
+
@attribute2 = @relation[:name]
|
|
20
16
|
end
|
|
21
17
|
|
|
22
|
-
describe
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
describe "with compound predicates" do
|
|
19
|
+
before do
|
|
20
|
+
@operand1 = ConcreteBinary.new(@attribute1, 1)
|
|
21
|
+
@operand2 = ConcreteBinary.new(@attribute2, "name")
|
|
22
|
+
end
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
describe Or do
|
|
25
|
+
describe "#to_sql" do
|
|
26
|
+
it "manufactures sql with an OR operation" do
|
|
27
|
+
sql = Or.new(@operand1, @operand2).to_sql
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
adapter_is :mysql do
|
|
30
|
+
sql.should be_like(%Q{(`users`.`id` <=> 1 OR `users`.`name` <=> 'name')})
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
adapter_is :postgresql do
|
|
34
|
+
sql.should be_like(%Q{("users"."id" <=> 1 OR "users"."name" <=> E'name')})
|
|
35
|
+
end
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
adapter_is :sqlite3 do
|
|
38
|
+
sql.should be_like(%Q{("users"."id" <=> 1 OR "users"."name" <=> 'name')})
|
|
39
|
+
end
|
|
37
40
|
end
|
|
38
41
|
end
|
|
39
42
|
end
|
|
40
|
-
end
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
describe And do
|
|
45
|
+
describe "#to_sql" do
|
|
46
|
+
it "manufactures sql with an AND operation" do
|
|
47
|
+
sql = And.new(@operand1, @operand2).to_sql
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
adapter_is :mysql do
|
|
50
|
+
sql.should be_like(%Q{(`users`.`id` <=> 1 AND `users`.`name` <=> 'name')})
|
|
51
|
+
end
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
adapter_is :sqlite3 do
|
|
54
|
+
sql.should be_like(%Q{("users"."id" <=> 1 AND "users"."name" <=> 'name')})
|
|
55
|
+
end
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
adapter_is :postgresql do
|
|
58
|
+
sql.should be_like(%Q{("users"."id" <=> 1 AND "users"."name" <=> E'name')})
|
|
59
|
+
end
|
|
57
60
|
end
|
|
58
61
|
end
|
|
59
62
|
end
|
|
60
63
|
end
|
|
61
|
-
end
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
describe '#to_sql' do
|
|
66
|
+
describe 'when relating two attributes' do
|
|
67
|
+
it 'manufactures sql with a binary operation' do
|
|
68
|
+
sql = ConcreteBinary.new(@attribute1, @attribute2).to_sql
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
adapter_is :mysql do
|
|
71
|
+
sql.should be_like(%Q{`users`.`id` <=> `users`.`name`})
|
|
72
|
+
end
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
adapter_is_not :mysql do
|
|
75
|
+
sql.should be_like(%Q{"users"."id" <=> "users"."name"})
|
|
76
|
+
end
|
|
74
77
|
end
|
|
75
78
|
end
|
|
76
|
-
end
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
describe 'when relating an attribute and a value' do
|
|
81
|
+
before do
|
|
82
|
+
@value = "1-asdf"
|
|
83
|
+
end
|
|
82
84
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
describe 'when relating to an integer attribute' do
|
|
86
|
+
it 'formats values as integers' do
|
|
87
|
+
sql = ConcreteBinary.new(@attribute1, @value).to_sql
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
adapter_is :mysql do
|
|
90
|
+
sql.should be_like(%Q{`users`.`id` <=> 1})
|
|
91
|
+
end
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
adapter_is_not :mysql do
|
|
94
|
+
sql.should be_like(%Q{"users"."id" <=> 1})
|
|
95
|
+
end
|
|
93
96
|
end
|
|
94
97
|
end
|
|
95
|
-
end
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
describe 'when relating to a string attribute' do
|
|
100
|
+
it 'formats values as strings' do
|
|
101
|
+
sql = ConcreteBinary.new(@attribute2, @value).to_sql
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
adapter_is :mysql do
|
|
104
|
+
sql.should be_like(%Q{`users`.`name` <=> '1-asdf'})
|
|
105
|
+
end
|
|
104
106
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
adapter_is :sqlite3 do
|
|
108
|
+
sql.should be_like(%Q{"users"."name" <=> '1-asdf'})
|
|
109
|
+
end
|
|
108
110
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
adapter_is :postgresql do
|
|
112
|
+
sql.should be_like(%Q{"users"."name" <=> E'1-asdf'})
|
|
113
|
+
end
|
|
111
114
|
end
|
|
112
115
|
end
|
|
113
116
|
end
|
|
@@ -1,43 +1,60 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
adapter_is :mysql do
|
|
19
|
+
sql.should be_like(%Q{`users`.`id` = `photos`.`user_id`})
|
|
20
|
+
end
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
adapter_is_not :mysql do
|
|
23
|
+
sql.should be_like(%Q{"users"."id" = "photos"."user_id"})
|
|
24
|
+
end
|
|
23
25
|
end
|
|
24
26
|
end
|
|
25
|
-
end
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
describe 'when relation to a nil value' do
|
|
29
|
+
before do
|
|
30
|
+
@nil = nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "manufactures an is null predicate" do
|
|
34
|
+
sql = Equality.new(@attribute1, @nil).to_sql
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
adapter_is :mysql do
|
|
37
|
+
sql.should be_like(%Q{`users`.`id` IS NULL})
|
|
38
|
+
end
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
adapter_is_not :mysql do
|
|
41
|
+
sql.should be_like(%Q{"users"."id" IS NULL})
|
|
42
|
+
end
|
|
37
43
|
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "when relating to a nil Value" do
|
|
47
|
+
it "manufactures an IS NULL predicate" do
|
|
48
|
+
value = nil.bind(@relation1)
|
|
49
|
+
sql = Equality.new(@attribute1, value).to_sql
|
|
50
|
+
|
|
51
|
+
adapter_is :mysql do
|
|
52
|
+
sql.should be_like(%Q{`users`.`id` IS NULL})
|
|
53
|
+
end
|
|
38
54
|
|
|
39
|
-
|
|
40
|
-
|
|
55
|
+
adapter_is_not :mysql do
|
|
56
|
+
sql.should be_like(%Q{"users"."id" IS NULL})
|
|
57
|
+
end
|
|
41
58
|
end
|
|
42
59
|
end
|
|
43
60
|
end
|
|
@@ -1,83 +1,104 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
module Predicates
|
|
5
|
+
describe In do
|
|
6
|
+
before do
|
|
7
|
+
@relation = Arel::Table.new(:users)
|
|
8
|
+
@attribute = @relation[:id]
|
|
9
|
+
end
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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_not :mysql do
|
|
26
|
+
sql.should be_like(%Q{"users"."id" IN (1, 2, 3)})
|
|
27
|
+
end
|
|
28
|
+
end
|
|
15
29
|
end
|
|
16
30
|
|
|
17
|
-
|
|
18
|
-
|
|
31
|
+
describe 'when the array\'s elements are not same type as the attribute' do
|
|
32
|
+
before do
|
|
33
|
+
@array = ['1-asdf', 2, 3]
|
|
34
|
+
end
|
|
19
35
|
|
|
20
|
-
|
|
21
|
-
sql
|
|
36
|
+
it 'formats values in the array as the type of the attribute' do
|
|
37
|
+
sql = In.new(@attribute, @array).to_sql
|
|
38
|
+
|
|
39
|
+
adapter_is :mysql do
|
|
40
|
+
sql.should be_like(%Q{`users`.`id` IN (1, 2, 3)})
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
adapter_is_not :mysql do
|
|
44
|
+
sql.should be_like(%Q{"users"."id" IN (1, 2, 3)})
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe 'when the array is empty' do
|
|
50
|
+
before do
|
|
51
|
+
@array = []
|
|
22
52
|
end
|
|
23
53
|
|
|
24
|
-
|
|
25
|
-
sql
|
|
54
|
+
it 'manufactures sql with a comma separated list' do
|
|
55
|
+
sql = In.new(@attribute, @array).to_sql
|
|
56
|
+
|
|
57
|
+
adapter_is :mysql do
|
|
58
|
+
sql.should be_like(%Q{`users`.`id` IN (NULL)})
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
adapter_is_not :mysql do
|
|
62
|
+
sql.should be_like(%Q{"users"."id" IN (NULL)})
|
|
63
|
+
end
|
|
26
64
|
end
|
|
27
65
|
end
|
|
66
|
+
|
|
28
67
|
end
|
|
29
68
|
|
|
30
|
-
describe 'when
|
|
69
|
+
describe 'when relating to a range' do
|
|
31
70
|
before do
|
|
32
|
-
@
|
|
71
|
+
@range = 1..2
|
|
33
72
|
end
|
|
34
73
|
|
|
35
|
-
it '
|
|
36
|
-
sql = In.new(@attribute, @
|
|
74
|
+
it 'manufactures sql with a between' do
|
|
75
|
+
sql = In.new(@attribute, @range).to_sql
|
|
37
76
|
|
|
38
77
|
adapter_is :mysql do
|
|
39
|
-
sql.should be_like(%Q{`users`.`id`
|
|
78
|
+
sql.should be_like(%Q{`users`.`id` BETWEEN 1 AND 2})
|
|
40
79
|
end
|
|
41
80
|
|
|
42
81
|
adapter_is_not :mysql do
|
|
43
|
-
sql.should be_like(%Q{"users"."id"
|
|
82
|
+
sql.should be_like(%Q{"users"."id" BETWEEN 1 AND 2})
|
|
44
83
|
end
|
|
45
84
|
end
|
|
46
85
|
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe 'when relating to a range' do
|
|
50
|
-
before do
|
|
51
|
-
@range = 1..2
|
|
52
|
-
end
|
|
53
86
|
|
|
54
|
-
|
|
55
|
-
sql
|
|
87
|
+
describe 'when relating to a relation' do
|
|
88
|
+
it 'manufactures sql with a subselect' do
|
|
89
|
+
sql = In.new(@attribute, @relation).to_sql
|
|
56
90
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
sql.should be_like(%Q{"users"."id" BETWEEN 1 AND 2})
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
describe 'when relating to a relation' do
|
|
68
|
-
it 'manufactures sql with a subselect' do
|
|
69
|
-
sql = In.new(@attribute, @relation).to_sql
|
|
70
|
-
|
|
71
|
-
adapter_is :mysql do
|
|
72
|
-
sql.should be_like(%Q{
|
|
73
|
-
`users`.`id` IN (SELECT `users`.`id`, `users`.`name` FROM `users`)
|
|
74
|
-
})
|
|
75
|
-
end
|
|
91
|
+
adapter_is :mysql do
|
|
92
|
+
sql.should be_like(%Q{
|
|
93
|
+
`users`.`id` IN (SELECT `users`.`id`, `users`.`name` FROM `users`)
|
|
94
|
+
})
|
|
95
|
+
end
|
|
76
96
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
97
|
+
adapter_is_not :mysql do
|
|
98
|
+
sql.should be_like(%Q{
|
|
99
|
+
"users"."id" IN (SELECT "users"."id", "users"."name" FROM "users")
|
|
100
|
+
})
|
|
101
|
+
end
|
|
81
102
|
end
|
|
82
103
|
end
|
|
83
104
|
end
|
|
@@ -1,62 +1,64 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Arel
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
adapter_is :mysql do
|
|
20
|
+
sql.should be_like(%Q{
|
|
21
|
+
(`users`.`id` = 1 AND `users`.`name` = 'name')
|
|
22
|
+
})
|
|
23
|
+
end
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
adapter_is :sqlite3 do
|
|
26
|
+
sql.should be_like(%Q{
|
|
27
|
+
("users"."id" = 1 AND "users"."name" = 'name')
|
|
28
|
+
})
|
|
29
|
+
end
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
adapter_is :postgresql do
|
|
32
|
+
sql.should be_like(%Q{
|
|
33
|
+
("users"."id" = 1 AND "users"."name" = E'name')
|
|
34
|
+
})
|
|
35
|
+
end
|
|
34
36
|
end
|
|
35
37
|
end
|
|
36
38
|
end
|
|
37
|
-
end
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
describe "when being combined with another predicate with OR logic" do
|
|
41
|
+
describe "#to_sql" do
|
|
42
|
+
it "manufactures sql with an OR operation" do
|
|
43
|
+
sql = @operand1.or(@operand2).to_sql
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
adapter_is :mysql do
|
|
46
|
+
sql.should be_like(%Q{
|
|
47
|
+
(`users`.`id` = 1 OR `users`.`name` = 'name')
|
|
48
|
+
})
|
|
49
|
+
end
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
adapter_is :sqlite3 do
|
|
52
|
+
sql.should be_like(%Q{
|
|
53
|
+
("users"."id" = 1 OR "users"."name" = 'name')
|
|
54
|
+
})
|
|
55
|
+
end
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
adapter_is :postgresql do
|
|
58
|
+
sql.should be_like(%Q{
|
|
59
|
+
("users"."id" = 1 OR "users"."name" = E'name')
|
|
60
|
+
})
|
|
61
|
+
end
|
|
60
62
|
end
|
|
61
63
|
end
|
|
62
64
|
end
|