sequel_core 2.2.0 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- metadata +30 -101
- data/CHANGELOG +0 -1519
- data/COPYING +0 -19
- data/README +0 -313
- data/Rakefile +0 -158
- data/bin/sequel +0 -117
- data/doc/cheat_sheet.rdoc +0 -225
- data/doc/dataset_filtering.rdoc +0 -182
- data/lib/sequel_core.rb +0 -136
- data/lib/sequel_core/adapters/adapter_skeleton.rb +0 -68
- data/lib/sequel_core/adapters/ado.rb +0 -90
- data/lib/sequel_core/adapters/db2.rb +0 -160
- data/lib/sequel_core/adapters/dbi.rb +0 -127
- data/lib/sequel_core/adapters/informix.rb +0 -89
- data/lib/sequel_core/adapters/jdbc.rb +0 -110
- data/lib/sequel_core/adapters/mysql.rb +0 -486
- data/lib/sequel_core/adapters/odbc.rb +0 -167
- data/lib/sequel_core/adapters/odbc_mssql.rb +0 -106
- data/lib/sequel_core/adapters/openbase.rb +0 -76
- data/lib/sequel_core/adapters/oracle.rb +0 -182
- data/lib/sequel_core/adapters/postgres.rb +0 -560
- data/lib/sequel_core/adapters/sqlite.rb +0 -270
- data/lib/sequel_core/connection_pool.rb +0 -194
- data/lib/sequel_core/core_ext.rb +0 -197
- data/lib/sequel_core/core_sql.rb +0 -184
- data/lib/sequel_core/database.rb +0 -462
- data/lib/sequel_core/database/schema.rb +0 -156
- data/lib/sequel_core/dataset.rb +0 -457
- data/lib/sequel_core/dataset/callback.rb +0 -13
- data/lib/sequel_core/dataset/convenience.rb +0 -245
- data/lib/sequel_core/dataset/pagination.rb +0 -96
- data/lib/sequel_core/dataset/query.rb +0 -41
- data/lib/sequel_core/dataset/schema.rb +0 -15
- data/lib/sequel_core/dataset/sql.rb +0 -889
- data/lib/sequel_core/deprecated.rb +0 -26
- data/lib/sequel_core/exceptions.rb +0 -42
- data/lib/sequel_core/migration.rb +0 -187
- data/lib/sequel_core/object_graph.rb +0 -216
- data/lib/sequel_core/pretty_table.rb +0 -71
- data/lib/sequel_core/schema.rb +0 -2
- data/lib/sequel_core/schema/generator.rb +0 -239
- data/lib/sequel_core/schema/sql.rb +0 -326
- data/lib/sequel_core/sql.rb +0 -812
- data/lib/sequel_core/worker.rb +0 -68
- data/spec/adapters/informix_spec.rb +0 -96
- data/spec/adapters/mysql_spec.rb +0 -765
- data/spec/adapters/oracle_spec.rb +0 -222
- data/spec/adapters/postgres_spec.rb +0 -441
- data/spec/adapters/sqlite_spec.rb +0 -413
- data/spec/connection_pool_spec.rb +0 -363
- data/spec/core_ext_spec.rb +0 -156
- data/spec/core_sql_spec.rb +0 -427
- data/spec/database_spec.rb +0 -963
- data/spec/dataset_spec.rb +0 -2933
- data/spec/expression_filters_spec.rb +0 -316
- data/spec/migration_spec.rb +0 -261
- data/spec/object_graph_spec.rb +0 -230
- data/spec/pretty_table_spec.rb +0 -58
- data/spec/rcov.opts +0 -6
- data/spec/schema_generator_spec.rb +0 -122
- data/spec/schema_spec.rb +0 -422
- data/spec/spec.opts +0 -0
- data/spec/spec_config.rb +0 -7
- data/spec/spec_config.rb.example +0 -8
- data/spec/spec_helper.rb +0 -55
- data/spec/worker_spec.rb +0 -96
@@ -1,316 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
context "Blockless Ruby Filters" do
|
4
|
-
before do
|
5
|
-
db = Sequel::Database.new
|
6
|
-
db.quote_identifiers = false
|
7
|
-
@d = db[:items]
|
8
|
-
def @d.l(*args, &block)
|
9
|
-
literal(filter_expr(*args, &block))
|
10
|
-
end
|
11
|
-
def @d.lit(*args)
|
12
|
-
literal(*args)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should support boolean columns directly" do
|
17
|
-
@d.l(:x).should == 'x'
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should support NOT via Symbol#~" do
|
21
|
-
@d.l(~:x).should == 'NOT x'
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should support qualified columns" do
|
25
|
-
@d.l(:x__y).should == 'x.y'
|
26
|
-
@d.l(~:x__y).should == 'NOT x.y'
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should support NOT with SQL functions" do
|
30
|
-
@d.l(~:is_blah[]).should == 'NOT is_blah()'
|
31
|
-
@d.l(~:is_blah[:x]).should == 'NOT is_blah(x)'
|
32
|
-
@d.l(~:is_blah[:x__y]).should == 'NOT is_blah(x.y)'
|
33
|
-
@d.l(~:is_blah[:x, :x__y]).should == 'NOT is_blah(x, x.y)'
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should handle multiple ~" do
|
37
|
-
@d.l(~~:x).should == 'x'
|
38
|
-
@d.l(~~~:x).should == 'NOT x'
|
39
|
-
@d.l(~~(:x > 100)).should == '(x > 100)'
|
40
|
-
@d.l(~~(:x & :y)).should == '(x AND y)'
|
41
|
-
@d.l(~~(:x | :y)).should == '(x OR y)'
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should support >, <, >=, and <= via Symbol#>,<,>=,<=" do
|
45
|
-
@d.l(:x > 100).should == '(x > 100)'
|
46
|
-
@d.l(:x < 100.01).should == '(x < 100.01)'
|
47
|
-
@d.l(:x >= 100000000000000000000000000000000000).should == '(x >= 100000000000000000000000000000000000)'
|
48
|
-
@d.l(:x <= 100).should == '(x <= 100)'
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should support negation of >, <, >=, and <= via Symbol#~" do
|
52
|
-
@d.l(~(:x > 100)).should == '(x <= 100)'
|
53
|
-
@d.l(~(:x < 100.01)).should == '(x >= 100.01)'
|
54
|
-
@d.l(~(:x >= 100000000000000000000000000000000000)).should == '(x < 100000000000000000000000000000000000)'
|
55
|
-
@d.l(~(:x <= 100)).should == '(x > 100)'
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should support = via Hash" do
|
59
|
-
@d.l(:x => 100).should == '(x = 100)'
|
60
|
-
@d.l(:x => 'a').should == '(x = \'a\')'
|
61
|
-
@d.l(:x => true).should == '(x = \'t\')'
|
62
|
-
@d.l(:x => false).should == '(x = \'f\')'
|
63
|
-
@d.l(:x => nil).should == '(x IS NULL)'
|
64
|
-
@d.l(:x => [1,2,3]).should == '(x IN (1, 2, 3))'
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should support != via Hash#~" do
|
68
|
-
@d.l(~{:x => 100}).should == '(x != 100)'
|
69
|
-
@d.l(~{:x => 'a'}).should == '(x != \'a\')'
|
70
|
-
@d.l(~{:x => true}).should == '(x != \'t\')'
|
71
|
-
@d.l(~{:x => false}).should == '(x != \'f\')'
|
72
|
-
@d.l(~{:x => nil}).should == '(x IS NOT NULL)'
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should support ~ via Hash and Regexp (if supported by database)" do
|
76
|
-
@d.l(:x => /blah/).should == '(x ~ \'blah\')'
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should support !~ via Hash#~ and Regexp" do
|
80
|
-
@d.l(~{:x => /blah/}).should == '(x !~ \'blah\')'
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should support LIKE via Symbol#like" do
|
84
|
-
@d.l(:x.like('a')).should == '(x LIKE \'a\')'
|
85
|
-
@d.l(:x.like(/a/)).should == '(x ~ \'a\')'
|
86
|
-
@d.l(:x.like('a', 'b')).should == '((x LIKE \'a\') OR (x LIKE \'b\'))'
|
87
|
-
@d.l(:x.like(/a/, /b/i)).should == '((x ~ \'a\') OR (x ~* \'b\'))'
|
88
|
-
@d.l(:x.like('a', /b/)).should == '((x LIKE \'a\') OR (x ~ \'b\'))'
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should support NOT LIKE via Symbol#like and Symbol#~" do
|
92
|
-
@d.l(~:x.like('a')).should == '(x NOT LIKE \'a\')'
|
93
|
-
@d.l(~:x.like(/a/)).should == '(x !~ \'a\')'
|
94
|
-
@d.l(~:x.like('a', 'b')).should == '((x NOT LIKE \'a\') AND (x NOT LIKE \'b\'))'
|
95
|
-
@d.l(~:x.like(/a/, /b/i)).should == '((x !~ \'a\') AND (x !~* \'b\'))'
|
96
|
-
@d.l(~:x.like('a', /b/)).should == '((x NOT LIKE \'a\') AND (x !~ \'b\'))'
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should support ILIKE via Symbol#ilike" do
|
100
|
-
@d.l(:x.ilike('a')).should == '(x ILIKE \'a\')'
|
101
|
-
@d.l(:x.ilike(/a/)).should == '(x ~* \'a\')'
|
102
|
-
@d.l(:x.ilike('a', 'b')).should == '((x ILIKE \'a\') OR (x ILIKE \'b\'))'
|
103
|
-
@d.l(:x.ilike(/a/, /b/i)).should == '((x ~* \'a\') OR (x ~* \'b\'))'
|
104
|
-
@d.l(:x.ilike('a', /b/)).should == '((x ILIKE \'a\') OR (x ~* \'b\'))'
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should support NOT ILIKE via Symbol#ilike and Symbol#~" do
|
108
|
-
@d.l(~:x.ilike('a')).should == '(x NOT ILIKE \'a\')'
|
109
|
-
@d.l(~:x.ilike(/a/)).should == '(x !~* \'a\')'
|
110
|
-
@d.l(~:x.ilike('a', 'b')).should == '((x NOT ILIKE \'a\') AND (x NOT ILIKE \'b\'))'
|
111
|
-
@d.l(~:x.ilike(/a/, /b/i)).should == '((x !~* \'a\') AND (x !~* \'b\'))'
|
112
|
-
@d.l(~:x.ilike('a', /b/)).should == '((x NOT ILIKE \'a\') AND (x !~* \'b\'))'
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should support negating ranges via Hash#~ and Range" do
|
116
|
-
@d.l(~{:x => 1..5}).should == '((x < 1) OR (x > 5))'
|
117
|
-
@d.l(~{:x => 1...5}).should == '((x < 1) OR (x >= 5))'
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should support negating NOT IN via Hash#~ and Dataset or Array" do
|
121
|
-
@d.l(~{:x => @d.select(:i)}).should == '(x NOT IN (SELECT i FROM items))'
|
122
|
-
@d.l(~{:x => [1,2,3]}).should == '(x NOT IN (1, 2, 3))'
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should support + - * / via Symbol#+,-,*,/" do
|
126
|
-
@d.l(:x + 1 > 100).should == '((x + 1) > 100)'
|
127
|
-
@d.l((:x * :y) < 100.01).should == '((x * y) < 100.01)'
|
128
|
-
@d.l((:x - :y/2) >= 100000000000000000000000000000000000).should == '((x - (y / 2)) >= 100000000000000000000000000000000000)'
|
129
|
-
@d.l((((:x - :y)/(:x + :y))*:z) <= 100).should == '((((x - y) / (x + y)) * z) <= 100)'
|
130
|
-
@d.l(~((((:x - :y)/(:x + :y))*:z) <= 100)).should == '((((x - y) / (x + y)) * z) > 100)'
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should not allow negation of string expressions" do
|
134
|
-
proc{~:x.sql_string}.should raise_error
|
135
|
-
proc{~([:x, :y].sql_string_join)}.should raise_error
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should not allow mathematical, inequality, or string operations on true, false, or nil" do
|
139
|
-
proc{:x + 1}.should_not raise_error
|
140
|
-
proc{:x - true}.should raise_error(Sequel::Error)
|
141
|
-
proc{:x / false}.should raise_error(Sequel::Error)
|
142
|
-
proc{:x * nil}.should raise_error(Sequel::Error)
|
143
|
-
proc{:x > 1}.should_not raise_error
|
144
|
-
proc{:x < true}.should raise_error(Sequel::Error)
|
145
|
-
proc{:x >= false}.should raise_error(Sequel::Error)
|
146
|
-
proc{:x <= nil}.should raise_error(Sequel::Error)
|
147
|
-
proc{[:x, nil].sql_string_join}.should raise_error(Sequel::Error)
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should not allow mathematical, inequality, or string operations on boolean complex expressions" do
|
151
|
-
proc{:x + (:y + 1)}.should_not raise_error
|
152
|
-
proc{:x - (~:y)}.should raise_error(Sequel::Error)
|
153
|
-
proc{:x / (:y & :z)}.should raise_error(Sequel::Error)
|
154
|
-
proc{:x * (:y | :z)}.should raise_error(Sequel::Error)
|
155
|
-
proc{:x > (:y > 5)}.should raise_error(Sequel::Error)
|
156
|
-
proc{:x < (:y < 5)}.should raise_error(Sequel::Error)
|
157
|
-
proc{:x >= (:y >= 5)}.should raise_error(Sequel::Error)
|
158
|
-
proc{:x <= (:y <= 5)}.should raise_error(Sequel::Error)
|
159
|
-
proc{:x > {:y => nil}}.should raise_error(Sequel::Error)
|
160
|
-
proc{:x < ~{:y => nil}}.should raise_error(Sequel::Error)
|
161
|
-
proc{:x >= {:y => 5}}.should raise_error(Sequel::Error)
|
162
|
-
proc{:x <= ~{:y => 5}}.should raise_error(Sequel::Error)
|
163
|
-
proc{:x >= {:y => [1,2,3]}}.should raise_error(Sequel::Error)
|
164
|
-
proc{:x <= ~{:y => [1,2,3]}}.should raise_error(Sequel::Error)
|
165
|
-
proc{:x + :y.like('a')}.should raise_error(Sequel::Error)
|
166
|
-
proc{:x - :y.like(/a/)}.should raise_error(Sequel::Error)
|
167
|
-
proc{:x * :y.like(/a/i)}.should raise_error(Sequel::Error)
|
168
|
-
proc{:x + ~:y.like('a')}.should raise_error(Sequel::Error)
|
169
|
-
proc{:x - ~:y.like(/a/)}.should raise_error(Sequel::Error)
|
170
|
-
proc{:x * ~:y.like(/a/i)}.should raise_error(Sequel::Error)
|
171
|
-
proc{[:x, ~:y.like(/a/i)].sql_string_join}.should raise_error(Sequel::Error)
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should support AND conditions via &" do
|
175
|
-
@d.l(:x & :y).should == '(x AND y)'
|
176
|
-
@d.l(:x & :y & :z).should == '((x AND y) AND z)'
|
177
|
-
@d.l(:x & {:y => :z}).should == '(x AND (y = z))'
|
178
|
-
@d.l({:y => :z} & :x).should == '((y = z) AND x)'
|
179
|
-
@d.l({:x => :a} & {:y => :z}).should == '((x = a) AND (y = z))'
|
180
|
-
@d.l((:x > 200) & (:y < 200)).should == '((x > 200) AND (y < 200))'
|
181
|
-
@d.l(:x & ~:y).should == '(x AND NOT y)'
|
182
|
-
@d.l(~:x & :y).should == '(NOT x AND y)'
|
183
|
-
@d.l(~:x & ~:y).should == '(NOT x AND NOT y)'
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should support OR conditions via |" do
|
187
|
-
@d.l(:x | :y).should == '(x OR y)'
|
188
|
-
@d.l(:x | :y | :z).should == '((x OR y) OR z)'
|
189
|
-
@d.l(:x | {:y => :z}).should == '(x OR (y = z))'
|
190
|
-
@d.l({:y => :z} | :x).should == '((y = z) OR x)'
|
191
|
-
@d.l({:x => :a} | {:y => :z}).should == '((x = a) OR (y = z))'
|
192
|
-
@d.l((:x > 200) | (:y < 200)).should == '((x > 200) OR (y < 200))'
|
193
|
-
end
|
194
|
-
|
195
|
-
it "should support & | combinations" do
|
196
|
-
@d.l((:x | :y) & :z).should == '((x OR y) AND z)'
|
197
|
-
@d.l(:x | (:y & :z)).should == '(x OR (y AND z))'
|
198
|
-
@d.l((:x & :w) | (:y & :z)).should == '((x AND w) OR (y AND z))'
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should support & | with ~" do
|
202
|
-
@d.l(~((:x | :y) & :z)).should == '((NOT x AND NOT y) OR NOT z)'
|
203
|
-
@d.l(~(:x | (:y & :z))).should == '(NOT x AND (NOT y OR NOT z))'
|
204
|
-
@d.l(~((:x & :w) | (:y & :z))).should == '((NOT x OR NOT w) AND (NOT y OR NOT z))'
|
205
|
-
@d.l(~((:x > 200) | (:y & :z))).should == '((x <= 200) AND (NOT y OR NOT z))'
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should support LiteralString" do
|
209
|
-
@d.l('x'.lit).should == '(x)'
|
210
|
-
@d.l(~'x'.lit).should == 'NOT x'
|
211
|
-
@d.l(~~'x'.lit).should == 'x'
|
212
|
-
@d.l(~(('x'.lit | :y) & :z)).should == '((NOT x AND NOT y) OR NOT z)'
|
213
|
-
@d.l(~(:x | 'y'.lit)).should == '(NOT x AND NOT y)'
|
214
|
-
@d.l(~('x'.lit & 'y'.lit)).should == '(NOT x OR NOT y)'
|
215
|
-
@d.l({'y'.lit => 'z'.lit} & 'x'.lit).should == '((y = z) AND x)'
|
216
|
-
@d.l(('x'.lit > 200) & ('y'.lit < 200)).should == '((x > 200) AND (y < 200))'
|
217
|
-
@d.l(~('x'.lit + 1 > 100)).should == '((x + 1) <= 100)'
|
218
|
-
@d.l('x'.lit.like(/a/)).should == '(x ~ \'a\')'
|
219
|
-
@d.l('x'.lit + 1 > 100).should == '((x + 1) > 100)'
|
220
|
-
@d.l(('x'.lit * :y) < 100.01).should == '((x * y) < 100.01)'
|
221
|
-
@d.l(('x'.lit - :y/2) >= 100000000000000000000000000000000000).should == '((x - (y / 2)) >= 100000000000000000000000000000000000)'
|
222
|
-
@d.l(('z'.lit * (('x'.lit / :y)/(:x + :y))) <= 100).should == '((z * ((x / y) / (x + y))) <= 100)'
|
223
|
-
@d.l(~(((('x'.lit - :y)/(:x + :y))*:z) <= 100)).should == '((((x - y) / (x + y)) * z) > 100)'
|
224
|
-
end
|
225
|
-
|
226
|
-
it "should support hashes by ANDing the conditions" do
|
227
|
-
@d.l(:x => 100, :y => 'a')[1...-1].split(' AND ').sort.should == ['(x = 100)', '(y = \'a\')']
|
228
|
-
@d.l(:x => true, :y => false)[1...-1].split(' AND ').sort.should == ['(x = \'t\')', '(y = \'f\')']
|
229
|
-
@d.l(:x => nil, :y => [1,2,3])[1...-1].split(' AND ').sort.should == ['(x IS NULL)', '(y IN (1, 2, 3))']
|
230
|
-
end
|
231
|
-
|
232
|
-
it "should support sql_negate on hashes" do
|
233
|
-
@d.l({:x => 100, :y => 'a'}.sql_negate)[1...-1].split(' AND ').sort.should == ['(x != 100)', '(y != \'a\')']
|
234
|
-
@d.l({:x => true, :y => false}.sql_negate)[1...-1].split(' AND ').sort.should == ['(x != \'t\')', '(y != \'f\')']
|
235
|
-
@d.l({:x => nil, :y => [1,2,3]}.sql_negate)[1...-1].split(' AND ').sort.should == ['(x IS NOT NULL)', '(y NOT IN (1, 2, 3))']
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should support ~ on hashes" do
|
239
|
-
@d.l(~{:x => 100, :y => 'a'})[1...-1].split(' OR ').sort.should == ['(x != 100)', '(y != \'a\')']
|
240
|
-
@d.l(~{:x => true, :y => false})[1...-1].split(' OR ').sort.should == ['(x != \'t\')', '(y != \'f\')']
|
241
|
-
@d.l(~{:x => nil, :y => [1,2,3]})[1...-1].split(' OR ').sort.should == ['(x IS NOT NULL)', '(y NOT IN (1, 2, 3))']
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should support sql_or on hashes" do
|
245
|
-
@d.l({:x => 100, :y => 'a'}.sql_or)[1...-1].split(' OR ').sort.should == ['(x = 100)', '(y = \'a\')']
|
246
|
-
@d.l({:x => true, :y => false}.sql_or)[1...-1].split(' OR ').sort.should == ['(x = \'t\')', '(y = \'f\')']
|
247
|
-
@d.l({:x => nil, :y => [1,2,3]}.sql_or)[1...-1].split(' OR ').sort.should == ['(x IS NULL)', '(y IN (1, 2, 3))']
|
248
|
-
end
|
249
|
-
|
250
|
-
it "should support arrays with all two pairs the same as hashes" do
|
251
|
-
@d.l([[:x, 100],[:y, 'a']]).should == '((x = 100) AND (y = \'a\'))'
|
252
|
-
@d.l([[:x, true], [:y, false]]).should == '((x = \'t\') AND (y = \'f\'))'
|
253
|
-
@d.l([[:x, nil], [:y, [1,2,3]]]).should == '((x IS NULL) AND (y IN (1, 2, 3)))'
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should support sql_negate on arrays with all two pairs" do
|
257
|
-
@d.l([[:x, 100],[:y, 'a']].sql_negate).should == '((x != 100) AND (y != \'a\'))'
|
258
|
-
@d.l([[:x, true], [:y, false]].sql_negate).should == '((x != \'t\') AND (y != \'f\'))'
|
259
|
-
@d.l([[:x, nil], [:y, [1,2,3]]].sql_negate).should == '((x IS NOT NULL) AND (y NOT IN (1, 2, 3)))'
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should support ~ on arrays with all two pairs" do
|
263
|
-
@d.l(~[[:x, 100],[:y, 'a']]).should == '((x != 100) OR (y != \'a\'))'
|
264
|
-
@d.l(~[[:x, true], [:y, false]]).should == '((x != \'t\') OR (y != \'f\'))'
|
265
|
-
@d.l(~[[:x, nil], [:y, [1,2,3]]]).should == '((x IS NOT NULL) OR (y NOT IN (1, 2, 3)))'
|
266
|
-
end
|
267
|
-
|
268
|
-
it "should support sql_or on arrays with all two pairs" do
|
269
|
-
@d.l([[:x, 100],[:y, 'a']].sql_or).should == '((x = 100) OR (y = \'a\'))'
|
270
|
-
@d.l([[:x, true], [:y, false]].sql_or).should == '((x = \'t\') OR (y = \'f\'))'
|
271
|
-
@d.l([[:x, nil], [:y, [1,2,3]]].sql_or).should == '((x IS NULL) OR (y IN (1, 2, 3)))'
|
272
|
-
end
|
273
|
-
|
274
|
-
it "should support Array#sql_string_join for concatenation of SQL strings" do
|
275
|
-
@d.lit([:x].sql_string_join).should == '(x)'
|
276
|
-
@d.lit([:x].sql_string_join(', ')).should == '(x)'
|
277
|
-
@d.lit([:x, :y].sql_string_join).should == '(x || y)'
|
278
|
-
@d.lit([:x, :y].sql_string_join(', ')).should == "(x || ', ' || y)"
|
279
|
-
@d.lit([:x[1], :y|1].sql_string_join).should == '(x(1) || y[1])'
|
280
|
-
@d.lit([:x[1], 'y.z'.lit].sql_string_join(', ')).should == "(x(1) || ', ' || y.z)"
|
281
|
-
@d.lit([:x, 1, :y].sql_string_join).should == "(x || '1' || y)"
|
282
|
-
@d.lit([:x, 1, :y].sql_string_join(', ')).should == "(x || ', ' || '1' || ', ' || y)"
|
283
|
-
@d.lit([:x, 1, :y].sql_string_join(:y__z)).should == "(x || y.z || '1' || y.z || y)"
|
284
|
-
@d.lit([:x, 1, :y].sql_string_join(1)).should == "(x || '1' || '1' || '1' || y)"
|
285
|
-
@d.lit([:x, :y].sql_string_join('y.x || x.y'.lit)).should == "(x || y.x || x.y || y)"
|
286
|
-
@d.lit([[:x, :y].sql_string_join, [:a, :b].sql_string_join].sql_string_join).should == "((x || y) || (a || b))"
|
287
|
-
end
|
288
|
-
|
289
|
-
it "should support StringExpression#+ for concatenation of SQL strings" do
|
290
|
-
@d.lit(:x.sql_string + :y).should == '(x || y)'
|
291
|
-
@d.lit([:x].sql_string_join + :y).should == '((x) || y)'
|
292
|
-
@d.lit([:x, :z].sql_string_join(' ') + :y).should == "((x || ' ' || z) || y)"
|
293
|
-
end
|
294
|
-
|
295
|
-
it "should be supported inside blocks" do
|
296
|
-
@d.l{[[:x, nil], [:y, [1,2,3]]].sql_or}.should == '((x IS NULL) OR (y IN (1, 2, 3)))'
|
297
|
-
@d.l{~[[:x, nil], [:y, [1,2,3]]]}.should == '((x IS NOT NULL) OR (y NOT IN (1, 2, 3)))'
|
298
|
-
@d.l{~(((('x'.lit - :y)/(:x + :y))*:z) <= 100)}.should == '((((x - y) / (x + y)) * z) > 100)'
|
299
|
-
@d.l{{:x => :a} & {:y => :z}}.should == '((x = a) AND (y = z))'
|
300
|
-
end
|
301
|
-
|
302
|
-
it "should support &, |, ^, ~, <<, and >> for NumericExpressions" do
|
303
|
-
@d.l(:x.sql_number & 1 > 100).should == '((x & 1) > 100)'
|
304
|
-
@d.l(:x.sql_number | 1 > 100).should == '((x | 1) > 100)'
|
305
|
-
@d.l(:x.sql_number ^ 1 > 100).should == '((x ^ 1) > 100)'
|
306
|
-
@d.l(~:x.sql_number > 100).should == '(~x > 100)'
|
307
|
-
@d.l(:x.sql_number << 1 > 100).should == '((x << 1) > 100)'
|
308
|
-
@d.l(:x.sql_number >> 1 > 100).should == '((x >> 1) > 100)'
|
309
|
-
@d.l((:x + 1) & 1 > 100).should == '(((x + 1) & 1) > 100)'
|
310
|
-
@d.l((:x + 1) | 1 > 100).should == '(((x + 1) | 1) > 100)'
|
311
|
-
@d.l((:x + 1) ^ 1 > 100).should == '(((x + 1) ^ 1) > 100)'
|
312
|
-
@d.l(~(:x + 1) > 100).should == '(~(x + 1) > 100)'
|
313
|
-
@d.l((:x + 1) << 1 > 100).should == '(((x + 1) << 1) > 100)'
|
314
|
-
@d.l((:x + 1) >> 1 > 100).should == '(((x + 1) >> 1) > 100)'
|
315
|
-
end
|
316
|
-
end
|
data/spec/migration_spec.rb
DELETED
@@ -1,261 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
context "Migration classes" do
|
4
|
-
setup do
|
5
|
-
Sequel::Migration.descendants.clear
|
6
|
-
end
|
7
|
-
|
8
|
-
specify "should be registred in Migration.descendants" do
|
9
|
-
@class = Class.new(Sequel::Migration)
|
10
|
-
|
11
|
-
Sequel::Migration.descendants.should == [@class]
|
12
|
-
end
|
13
|
-
|
14
|
-
specify "should be registered in the right order" do
|
15
|
-
@c1 = Class.new(Sequel::Migration)
|
16
|
-
@c2 = Class.new(Sequel::Migration)
|
17
|
-
@c3 = Class.new(Sequel::Migration)
|
18
|
-
|
19
|
-
Sequel::Migration.descendants.should == [@c1, @c2, @c3]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "Migration#apply" do
|
24
|
-
setup do
|
25
|
-
@c = Class.new do
|
26
|
-
define_method(:one) {|x| [1111, x]}
|
27
|
-
define_method(:two) {|x| [2222, x]}
|
28
|
-
end
|
29
|
-
@db = @c.new
|
30
|
-
|
31
|
-
@migration = Class.new(Sequel::Migration) do
|
32
|
-
define_method(:up) {one(3333)}
|
33
|
-
define_method(:down) {two(4444)}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
specify "should raise for an invalid direction" do
|
38
|
-
proc {@migration.apply(@db, :hahaha)}.should raise_error(ArgumentError)
|
39
|
-
end
|
40
|
-
|
41
|
-
specify "should apply the up direction correctly" do
|
42
|
-
@migration.apply(@db, :up).should == [1111, 3333]
|
43
|
-
end
|
44
|
-
|
45
|
-
specify "should apply the down direction correctly" do
|
46
|
-
@migration.apply(@db, :down).should == [2222, 4444]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class DummyMigrationDataset
|
51
|
-
attr_reader :from
|
52
|
-
|
53
|
-
def initialize(x); @from = x; end
|
54
|
-
|
55
|
-
@@version = nil
|
56
|
-
|
57
|
-
def version; @@version; end
|
58
|
-
def version=(x); @@version = x; end
|
59
|
-
def first; @@version ? {:version => @@version} : nil; end
|
60
|
-
def update(h); @@version = h[:version]; end
|
61
|
-
def <<(h); @@version = h[:version]; end
|
62
|
-
end
|
63
|
-
|
64
|
-
class DummyMigrationDB
|
65
|
-
attr_reader :creates, :drops, :table_created
|
66
|
-
|
67
|
-
def initialize
|
68
|
-
@creates = []
|
69
|
-
@drops = []
|
70
|
-
end
|
71
|
-
|
72
|
-
def create(x); @creates << x; end
|
73
|
-
def drop(x); @drops << x; end
|
74
|
-
|
75
|
-
def [](x); DummyMigrationDataset.new(x); end
|
76
|
-
|
77
|
-
def create_table(x); raise if @table_created == x; @table_created = x; end
|
78
|
-
def table_exists?(x); @table_created == x; end
|
79
|
-
|
80
|
-
def transaction; yield; end
|
81
|
-
end
|
82
|
-
|
83
|
-
MIGRATION_001 = %[
|
84
|
-
class CreateSessions < Sequel::Migration
|
85
|
-
def up
|
86
|
-
create(1111)
|
87
|
-
end
|
88
|
-
|
89
|
-
def down
|
90
|
-
drop(1111)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
]
|
94
|
-
|
95
|
-
MIGRATION_002 = %[
|
96
|
-
class CreateNodes < Sequel::Migration
|
97
|
-
def up
|
98
|
-
create(2222)
|
99
|
-
end
|
100
|
-
|
101
|
-
def down
|
102
|
-
drop(2222)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
]
|
106
|
-
|
107
|
-
MIGRATION_003 = %[
|
108
|
-
class CreateUsers < Sequel::Migration
|
109
|
-
def up
|
110
|
-
create(3333)
|
111
|
-
end
|
112
|
-
|
113
|
-
def down
|
114
|
-
drop(3333)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
]
|
118
|
-
|
119
|
-
MIGRATION_005 = %[
|
120
|
-
class CreateAttributes < Sequel::Migration
|
121
|
-
def up
|
122
|
-
create(5555)
|
123
|
-
end
|
124
|
-
|
125
|
-
def down
|
126
|
-
drop(5555)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
]
|
130
|
-
|
131
|
-
context "Sequel::Migrator" do
|
132
|
-
setup do
|
133
|
-
@db = DummyMigrationDB.new
|
134
|
-
|
135
|
-
File.open('001_create_sessions.rb', 'w') {|f| f << MIGRATION_001}
|
136
|
-
File.open('002_create_nodes.rb', 'w') {|f| f << MIGRATION_002}
|
137
|
-
File.open('003_create_users.rb', 'w') {|f| f << MIGRATION_003}
|
138
|
-
File.open('005_create_attributes.rb', 'w') {|f| f << MIGRATION_005}
|
139
|
-
|
140
|
-
@db[:schema_info].version = nil
|
141
|
-
end
|
142
|
-
|
143
|
-
teardown do
|
144
|
-
Object.send(:remove_const, "CreateSessions") if Object.const_defined?("CreateSessions")
|
145
|
-
Object.send(:remove_const, "CreateNodes") if Object.const_defined?("CreateNodes")
|
146
|
-
Object.send(:remove_const, "CreateUsers") if Object.const_defined?("CreateUsers")
|
147
|
-
Object.send(:remove_const, "CreateAttributes") if Object.const_defined?("CreateAttributes")
|
148
|
-
|
149
|
-
FileUtils.rm('001_create_sessions.rb')
|
150
|
-
FileUtils.rm('002_create_nodes.rb')
|
151
|
-
FileUtils.rm('003_create_users.rb')
|
152
|
-
FileUtils.rm('005_create_attributes.rb')
|
153
|
-
end
|
154
|
-
|
155
|
-
specify "should return the list of files for a specified version range" do
|
156
|
-
Sequel::Migrator.migration_files('.', 1..1).should == \
|
157
|
-
['./001_create_sessions.rb']
|
158
|
-
|
159
|
-
Sequel::Migrator.migration_files('.', 1..3).should == \
|
160
|
-
['./001_create_sessions.rb', './002_create_nodes.rb', './003_create_users.rb']
|
161
|
-
|
162
|
-
Sequel::Migrator.migration_files('.', 3..5).should == \
|
163
|
-
['./003_create_users.rb', './005_create_attributes.rb']
|
164
|
-
|
165
|
-
Sequel::Migrator.migration_files('.', 7..8).should == []
|
166
|
-
end
|
167
|
-
|
168
|
-
specify "should return the latest version available" do
|
169
|
-
Sequel::Migrator.latest_migration_version('.').should == 5
|
170
|
-
end
|
171
|
-
|
172
|
-
specify "should load the migration classes for the specified range" do
|
173
|
-
Sequel::Migrator.migration_classes('.', 3, 0, :up).should == \
|
174
|
-
[CreateSessions, CreateNodes, CreateUsers]
|
175
|
-
end
|
176
|
-
|
177
|
-
specify "should load the migration classes for the specified range" do
|
178
|
-
Sequel::Migrator.migration_classes('.', 0, 5, :down).should == \
|
179
|
-
[CreateAttributes, CreateUsers, CreateNodes, CreateSessions]
|
180
|
-
end
|
181
|
-
|
182
|
-
specify "should start from current + 1 for the up direction" do
|
183
|
-
Sequel::Migrator.migration_classes('.', 3, 1, :up).should == \
|
184
|
-
[CreateNodes, CreateUsers]
|
185
|
-
end
|
186
|
-
|
187
|
-
specify "should end on current + 1 for the down direction" do
|
188
|
-
Sequel::Migrator.migration_classes('.', 2, 5, :down).should == \
|
189
|
-
[CreateAttributes, CreateUsers]
|
190
|
-
end
|
191
|
-
|
192
|
-
specify "should automatically create the schema_info table" do
|
193
|
-
@db.table_exists?(:schema_info).should be_false
|
194
|
-
Sequel::Migrator.schema_info_dataset(@db)
|
195
|
-
@db.table_exists?(:schema_info).should be_true
|
196
|
-
|
197
|
-
# should not raise if table already exists
|
198
|
-
proc {Sequel::Migrator.schema_info_dataset(@db)}.should_not raise_error
|
199
|
-
end
|
200
|
-
|
201
|
-
specify "should return a dataset for the schema_info table" do
|
202
|
-
d = Sequel::Migrator.schema_info_dataset(@db)
|
203
|
-
d.from.should == :schema_info
|
204
|
-
end
|
205
|
-
|
206
|
-
specify "should get the migration version stored in the database" do
|
207
|
-
# default is 0
|
208
|
-
Sequel::Migrator.get_current_migration_version(@db).should == 0
|
209
|
-
|
210
|
-
Sequel::Migrator.schema_info_dataset(@db) << {:version => 4321}
|
211
|
-
|
212
|
-
Sequel::Migrator.get_current_migration_version(@db).should == 4321
|
213
|
-
end
|
214
|
-
|
215
|
-
specify "should set the migration version stored in the database" do
|
216
|
-
Sequel::Migrator.get_current_migration_version(@db).should == 0
|
217
|
-
Sequel::Migrator.set_current_migration_version(@db, 6666)
|
218
|
-
Sequel::Migrator.get_current_migration_version(@db).should == 6666
|
219
|
-
end
|
220
|
-
|
221
|
-
specify "should apply migrations correctly in the up direction" do
|
222
|
-
Sequel::Migrator.apply(@db, '.', 3, 2)
|
223
|
-
@db.creates.should == [3333]
|
224
|
-
|
225
|
-
Sequel::Migrator.get_current_migration_version(@db).should == 3
|
226
|
-
|
227
|
-
Sequel::Migrator.apply(@db, '.', 5)
|
228
|
-
@db.creates.should == [3333, 5555]
|
229
|
-
|
230
|
-
Sequel::Migrator.get_current_migration_version(@db).should == 5
|
231
|
-
end
|
232
|
-
|
233
|
-
specify "should apply migrations correctly in the down direction" do
|
234
|
-
Sequel::Migrator.apply(@db, '.', 1, 5)
|
235
|
-
@db.drops.should == [5555, 3333, 2222]
|
236
|
-
|
237
|
-
Sequel::Migrator.get_current_migration_version(@db).should == 1
|
238
|
-
end
|
239
|
-
|
240
|
-
specify "should apply migrations up to the latest version if no target is given" do
|
241
|
-
Sequel::Migrator.apply(@db, '.')
|
242
|
-
@db.creates.should == [1111, 2222, 3333, 5555]
|
243
|
-
|
244
|
-
Sequel::Migrator.get_current_migration_version(@db).should == 5
|
245
|
-
end
|
246
|
-
|
247
|
-
specify "should apply migrations down to 0 version correctly" do
|
248
|
-
Sequel::Migrator.apply(@db, '.', 0, 5)
|
249
|
-
@db.drops.should == [5555, 3333, 2222, 1111]
|
250
|
-
|
251
|
-
Sequel::Migrator.get_current_migration_version(@db).should == 0
|
252
|
-
end
|
253
|
-
|
254
|
-
specify "should return the target version" do
|
255
|
-
Sequel::Migrator.apply(@db, '.', 3, 2).should == 3
|
256
|
-
|
257
|
-
Sequel::Migrator.apply(@db, '.', 0).should == 0
|
258
|
-
|
259
|
-
Sequel::Migrator.apply(@db, '.').should == 5
|
260
|
-
end
|
261
|
-
end
|