arel 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Rakefile +1 -0
- data/lib/arel.rb +1 -1
- data/lib/arel/predications.rb +7 -7
- data/lib/arel/table.rb +2 -2
- data/test/test_table.rb +12 -1
- data/test/visitors/test_to_sql.rb +46 -0
- metadata +9 -33
data/History.txt
CHANGED
data/Rakefile
CHANGED
data/lib/arel.rb
CHANGED
data/lib/arel/predications.rb
CHANGED
@@ -30,11 +30,11 @@ module Arel
|
|
30
30
|
Nodes::In.new self, other.to_a.map { |x| x.id }
|
31
31
|
when Range
|
32
32
|
if other.exclude_end?
|
33
|
-
left = Nodes::GreaterThanOrEqual.new(self, other.
|
34
|
-
right = Nodes::LessThan.new(self, other.
|
33
|
+
left = Nodes::GreaterThanOrEqual.new(self, other.begin)
|
34
|
+
right = Nodes::LessThan.new(self, other.end)
|
35
35
|
Nodes::And.new left, right
|
36
36
|
else
|
37
|
-
Nodes::Between.new(self, Nodes::And.new(other.
|
37
|
+
Nodes::Between.new(self, Nodes::And.new(other.begin, other.end))
|
38
38
|
end
|
39
39
|
else
|
40
40
|
Nodes::In.new self, other
|
@@ -55,12 +55,12 @@ module Arel
|
|
55
55
|
Nodes::NotIn.new self, other.to_a.map { |x| x.id }
|
56
56
|
when Range
|
57
57
|
if other.exclude_end?
|
58
|
-
left = Nodes::LessThan.new(self, other.
|
59
|
-
right = Nodes::GreaterThanOrEqual.new(self, other.
|
58
|
+
left = Nodes::LessThan.new(self, other.begin)
|
59
|
+
right = Nodes::GreaterThanOrEqual.new(self, other.end)
|
60
60
|
Nodes::Or.new left, right
|
61
61
|
else
|
62
|
-
left = Nodes::LessThan.new(self, other.
|
63
|
-
right = Nodes::GreaterThan.new(self, other.
|
62
|
+
left = Nodes::LessThan.new(self, other.begin)
|
63
|
+
right = Nodes::GreaterThan.new(self, other.end)
|
64
64
|
Nodes::Or.new left, right
|
65
65
|
end
|
66
66
|
else
|
data/lib/arel/table.rb
CHANGED
@@ -8,7 +8,7 @@ module Arel
|
|
8
8
|
attr_accessor :name, :engine, :aliases, :table_alias
|
9
9
|
|
10
10
|
def initialize name, engine = Table.engine
|
11
|
-
@name = name
|
11
|
+
@name = name.to_s
|
12
12
|
@engine = engine
|
13
13
|
@columns = nil
|
14
14
|
@aliases = []
|
@@ -22,7 +22,7 @@ module Arel
|
|
22
22
|
# Sometime AR sends an :as parameter to table, to let the table know
|
23
23
|
# that it is an Alias. We may want to override new, and return a
|
24
24
|
# TableAlias node?
|
25
|
-
@table_alias = engine[:as] unless engine[:as].to_s == name
|
25
|
+
@table_alias = engine[:as] unless engine[:as].to_s == @name
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
data/test/test_table.rb
CHANGED
@@ -156,7 +156,7 @@ module Arel
|
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should have a name" do
|
159
|
-
@relation.name.must_equal
|
159
|
+
@relation.name.must_equal 'users'
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should have an engine" do
|
@@ -179,4 +179,15 @@ module Arel
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
end
|
182
|
+
|
183
|
+
describe Table do
|
184
|
+
describe 'when checking the existence of a table' do
|
185
|
+
it 'should be present in the table cache despite the class of its name' do
|
186
|
+
[ 'users', :users ].each do |name|
|
187
|
+
relation = Table.new name
|
188
|
+
Table.table_cache(relation.engine).key?(relation.name).must_equal true
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
182
193
|
end
|
@@ -132,6 +132,52 @@ module Arel
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
describe "Nodes::NotIn" do
|
136
|
+
it "should know how to visit" do
|
137
|
+
node = @attr.not_in [1, 2, 3]
|
138
|
+
@visitor.accept(node).must_be_like %{
|
139
|
+
"users"."id" NOT IN (1, 2, 3)
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should turn empty right to NULL" do
|
144
|
+
node = @attr.not_in []
|
145
|
+
@visitor.accept(node).must_be_like %{
|
146
|
+
"users"."id" NOT IN (NULL)
|
147
|
+
}
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'can handle two dot ranges' do
|
151
|
+
node = @attr.not_in 1..3
|
152
|
+
@visitor.accept(node).must_be_like %{
|
153
|
+
"users"."id" < 1 OR "users"."id" > 3
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'can handle three dot ranges' do
|
158
|
+
node = @attr.not_in 1...3
|
159
|
+
@visitor.accept(node).must_be_like %{
|
160
|
+
"users"."id" < 1 OR "users"."id" >= 3
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'uses the same column for escaping values' do
|
165
|
+
@attr = Table.new(:users)[:name]
|
166
|
+
visitor = Class.new(ToSql) do
|
167
|
+
attr_accessor :expected
|
168
|
+
|
169
|
+
def quote value, column = nil
|
170
|
+
raise unless column == expected
|
171
|
+
super
|
172
|
+
end
|
173
|
+
end
|
174
|
+
in_node = Nodes::NotIn.new @attr, %w{ a b c }
|
175
|
+
visitor = visitor.new(Table.engine)
|
176
|
+
visitor.expected = @attr.column
|
177
|
+
visitor.accept(in_node).must_equal %("users"."name" NOT IN ('a', 'b', 'c'))
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
135
181
|
describe 'Equality' do
|
136
182
|
it "should escape strings" do
|
137
183
|
test = Table.new(:users)[:name].eq 'Aaron Patterson'
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 9
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 2
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
8
|
+
- 4
|
9
|
+
version: 2.0.4
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Aaron Patterson
|
@@ -18,7 +17,7 @@ autorequire:
|
|
18
17
|
bindir: bin
|
19
18
|
cert_chain: []
|
20
19
|
|
21
|
-
date: 2010-11-
|
20
|
+
date: 2010-11-17 00:00:00 -08:00
|
22
21
|
default_executable:
|
23
22
|
dependencies:
|
24
23
|
- !ruby/object:Gem::Dependency
|
@@ -29,7 +28,6 @@ dependencies:
|
|
29
28
|
requirements:
|
30
29
|
- - ">="
|
31
30
|
- !ruby/object:Gem::Version
|
32
|
-
hash: 7
|
33
31
|
segments:
|
34
32
|
- 2
|
35
33
|
- 0
|
@@ -37,71 +35,51 @@ dependencies:
|
|
37
35
|
version: 2.0.4
|
38
36
|
type: :development
|
39
37
|
version_requirements: *id001
|
40
|
-
- !ruby/object:Gem::Dependency
|
41
|
-
name: minitest
|
42
|
-
prerelease: false
|
43
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
hash: 31098209
|
49
|
-
segments:
|
50
|
-
- 2
|
51
|
-
- 0
|
52
|
-
- 0
|
53
|
-
- beta
|
54
|
-
version: 2.0.0.beta
|
55
|
-
type: :development
|
56
|
-
version_requirements: *id002
|
57
38
|
- !ruby/object:Gem::Dependency
|
58
39
|
name: hoe
|
59
40
|
prerelease: false
|
60
|
-
requirement: &
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
61
42
|
none: false
|
62
43
|
requirements:
|
63
44
|
- - ">="
|
64
45
|
- !ruby/object:Gem::Version
|
65
|
-
hash: 11
|
66
46
|
segments:
|
67
47
|
- 2
|
68
48
|
- 1
|
69
49
|
- 0
|
70
50
|
version: 2.1.0
|
71
51
|
type: :development
|
72
|
-
version_requirements: *
|
52
|
+
version_requirements: *id002
|
73
53
|
- !ruby/object:Gem::Dependency
|
74
54
|
name: minitest
|
75
55
|
prerelease: false
|
76
|
-
requirement: &
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
77
57
|
none: false
|
78
58
|
requirements:
|
79
59
|
- - ">="
|
80
60
|
- !ruby/object:Gem::Version
|
81
|
-
hash: 15
|
82
61
|
segments:
|
83
62
|
- 1
|
84
63
|
- 6
|
85
64
|
- 0
|
86
65
|
version: 1.6.0
|
87
66
|
type: :development
|
88
|
-
version_requirements: *
|
67
|
+
version_requirements: *id003
|
89
68
|
- !ruby/object:Gem::Dependency
|
90
69
|
name: hoe
|
91
70
|
prerelease: false
|
92
|
-
requirement: &
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
93
72
|
none: false
|
94
73
|
requirements:
|
95
74
|
- - ">="
|
96
75
|
- !ruby/object:Gem::Version
|
97
|
-
hash: 19
|
98
76
|
segments:
|
99
77
|
- 2
|
100
78
|
- 6
|
101
79
|
- 2
|
102
80
|
version: 2.6.2
|
103
81
|
type: :development
|
104
|
-
version_requirements: *
|
82
|
+
version_requirements: *id004
|
105
83
|
description: Arel is a Relational Algebra for Ruby. It 1) simplifies the generation complex of SQL queries and it 2) adapts to various RDBMS systems. It is intended to be a framework framework; that is, you can build your own ORM with it, focusing on innovative object and collection modeling as opposed to database compatibility and query generation.
|
106
84
|
email:
|
107
85
|
- aaron@tenderlovemaking.com
|
@@ -240,7 +218,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
240
218
|
requirements:
|
241
219
|
- - ">="
|
242
220
|
- !ruby/object:Gem::Version
|
243
|
-
hash: 3
|
244
221
|
segments:
|
245
222
|
- 0
|
246
223
|
version: "0"
|
@@ -249,7 +226,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
249
226
|
requirements:
|
250
227
|
- - ">="
|
251
228
|
- !ruby/object:Gem::Version
|
252
|
-
hash: 3
|
253
229
|
segments:
|
254
230
|
- 0
|
255
231
|
version: "0"
|