sequel 4.44.0 → 4.45.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +110 -0
- data/README.rdoc +8 -9
- data/doc/active_record.rdoc +2 -3
- data/doc/model_plugins.rdoc +1 -1
- data/doc/opening_databases.rdoc +0 -46
- data/doc/release_notes/4.45.0.txt +370 -0
- data/lib/sequel/adapters/cubrid.rb +2 -0
- data/lib/sequel/adapters/do.rb +2 -0
- data/lib/sequel/adapters/jdbc/as400.rb +2 -0
- data/lib/sequel/adapters/jdbc/cubrid.rb +2 -0
- data/lib/sequel/adapters/jdbc/firebirdsql.rb +2 -0
- data/lib/sequel/adapters/jdbc/informix-sqli.rb +2 -0
- data/lib/sequel/adapters/jdbc/jdbcprogress.rb +2 -0
- data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
- data/lib/sequel/adapters/jdbc/postgresql.rb +5 -0
- data/lib/sequel/adapters/mysql.rb +1 -0
- data/lib/sequel/adapters/mysql2.rb +1 -0
- data/lib/sequel/adapters/odbc/oracle.rb +11 -0
- data/lib/sequel/adapters/odbc/progress.rb +2 -0
- data/lib/sequel/adapters/postgres.rb +0 -2
- data/lib/sequel/adapters/shared/cubrid.rb +2 -0
- data/lib/sequel/adapters/shared/firebird.rb +2 -0
- data/lib/sequel/adapters/shared/informix.rb +2 -0
- data/lib/sequel/adapters/shared/mssql.rb +47 -7
- data/lib/sequel/adapters/shared/mysql.rb +16 -1
- data/lib/sequel/adapters/shared/postgres.rb +9 -1
- data/lib/sequel/adapters/shared/progress.rb +2 -0
- data/lib/sequel/adapters/shared/sqlanywhere.rb +1 -1
- data/lib/sequel/adapters/swift.rb +2 -0
- data/lib/sequel/ast_transformer.rb +13 -6
- data/lib/sequel/core.rb +13 -16
- data/lib/sequel/database/connecting.rb +25 -10
- data/lib/sequel/database/dataset.rb +6 -1
- data/lib/sequel/database/dataset_defaults.rb +9 -2
- data/lib/sequel/database/misc.rb +10 -3
- data/lib/sequel/database/schema_methods.rb +4 -0
- data/lib/sequel/dataset/mutation.rb +8 -20
- data/lib/sequel/dataset/prepared_statements.rb +2 -0
- data/lib/sequel/dataset/query.rb +32 -7
- data/lib/sequel/dataset/sql.rb +13 -3
- data/lib/sequel/deprecated.rb +9 -1
- data/lib/sequel/exceptions.rb +37 -8
- data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +117 -0
- data/lib/sequel/extensions/date_arithmetic.rb +1 -0
- data/lib/sequel/extensions/identifier_mangling.rb +3 -2
- data/lib/sequel/extensions/pg_hstore.rb +1 -5
- data/lib/sequel/extensions/schema_dumper.rb +3 -1
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +1 -0
- data/lib/sequel/model.rb +23 -10
- data/lib/sequel/model/associations.rb +17 -5
- data/lib/sequel/model/base.rb +115 -62
- data/lib/sequel/model/dataset_module.rb +10 -3
- data/lib/sequel/model/exceptions.rb +7 -5
- data/lib/sequel/plugins/association_pks.rb +13 -1
- data/lib/sequel/plugins/association_proxies.rb +8 -1
- data/lib/sequel/plugins/before_after_save.rb +1 -0
- data/lib/sequel/plugins/class_table_inheritance.rb +7 -3
- data/lib/sequel/plugins/columns_updated.rb +42 -0
- data/lib/sequel/plugins/composition.rb +10 -5
- data/lib/sequel/plugins/error_splitter.rb +1 -1
- data/lib/sequel/plugins/hook_class_methods.rb +39 -5
- data/lib/sequel/plugins/instance_hooks.rb +58 -5
- data/lib/sequel/plugins/lazy_attributes.rb +10 -5
- data/lib/sequel/plugins/nested_attributes.rb +10 -5
- data/lib/sequel/plugins/prepared_statements.rb +7 -0
- data/lib/sequel/plugins/prepared_statements_associations.rb +2 -0
- data/lib/sequel/plugins/prepared_statements_with_pk.rb +2 -0
- data/lib/sequel/plugins/schema.rb +2 -0
- data/lib/sequel/plugins/scissors.rb +2 -0
- data/lib/sequel/plugins/serialization.rb +10 -5
- data/lib/sequel/plugins/split_values.rb +5 -1
- data/lib/sequel/plugins/static_cache.rb +2 -2
- data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
- data/lib/sequel/plugins/validation_contexts.rb +49 -0
- data/lib/sequel/plugins/validation_helpers.rb +1 -0
- data/lib/sequel/sql.rb +1 -1
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/mssql_spec.rb +31 -0
- data/spec/adapters/mysql_spec.rb +20 -2
- data/spec/adapters/postgres_spec.rb +43 -12
- data/spec/adapters/spec_helper.rb +5 -8
- data/spec/core/database_spec.rb +47 -12
- data/spec/core/dataset_mutation_spec.rb +22 -22
- data/spec/core/dataset_spec.rb +88 -20
- data/spec/core/deprecated_spec.rb +1 -1
- data/spec/core/expression_filters_spec.rb +1 -1
- data/spec/core/mock_adapter_spec.rb +0 -3
- data/spec/core/placeholder_literalizer_spec.rb +1 -1
- data/spec/core/schema_spec.rb +8 -1
- data/spec/core/spec_helper.rb +6 -1
- data/spec/core_extensions_spec.rb +4 -0
- data/spec/deprecation_helper.rb +17 -0
- data/spec/extensions/_deprecated_identifier_mangling_spec.rb +314 -0
- data/spec/extensions/association_pks_spec.rb +61 -13
- data/spec/extensions/association_proxies_spec.rb +3 -3
- data/spec/extensions/class_table_inheritance_spec.rb +39 -0
- data/spec/extensions/columns_updated_spec.rb +35 -0
- data/spec/extensions/composition_spec.rb +6 -1
- data/spec/extensions/hook_class_methods_spec.rb +114 -26
- data/spec/extensions/identifier_mangling_spec.rb +107 -73
- data/spec/extensions/instance_hooks_spec.rb +78 -14
- data/spec/extensions/lazy_attributes_spec.rb +8 -2
- data/spec/extensions/many_through_many_spec.rb +2 -2
- data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
- data/spec/extensions/nested_attributes_spec.rb +8 -2
- data/spec/extensions/pg_array_spec.rb +18 -4
- data/spec/extensions/prepared_statements_associations_spec.rb +48 -39
- data/spec/extensions/prepared_statements_with_pk_spec.rb +13 -11
- data/spec/extensions/query_spec.rb +1 -1
- data/spec/extensions/schema_dumper_spec.rb +34 -6
- data/spec/extensions/schema_spec.rb +13 -7
- data/spec/extensions/scissors_spec.rb +3 -1
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +4 -4
- data/spec/extensions/serialization_spec.rb +7 -1
- data/spec/extensions/set_overrides_spec.rb +2 -2
- data/spec/extensions/shared_caching_spec.rb +19 -15
- data/spec/extensions/spec_helper.rb +7 -3
- data/spec/extensions/split_values_spec.rb +45 -10
- data/spec/extensions/string_agg_spec.rb +2 -2
- data/spec/extensions/subset_conditions_spec.rb +3 -3
- data/spec/extensions/tactical_eager_loading_spec.rb +1 -1
- data/spec/extensions/validation_contexts_spec.rb +31 -0
- data/spec/guards_helper.rb +2 -0
- data/spec/integration/associations_test.rb +22 -20
- data/spec/integration/dataset_test.rb +25 -2
- data/spec/integration/model_test.rb +1 -1
- data/spec/integration/plugin_test.rb +11 -16
- data/spec/integration/prepared_statement_test.rb +40 -32
- data/spec/integration/spec_helper.rb +5 -8
- data/spec/model/association_reflection_spec.rb +4 -0
- data/spec/model/associations_spec.rb +37 -10
- data/spec/model/base_spec.rb +6 -0
- data/spec/model/hooks_spec.rb +56 -35
- data/spec/model/model_spec.rb +21 -5
- data/spec/model/record_spec.rb +14 -11
- data/spec/model/spec_helper.rb +7 -1
- data/spec/sequel_warning.rb +11 -0
- metadata +13 -3
@@ -44,13 +44,13 @@ describe "Sequel::Plugins::AssociationProxies" do
|
|
44
44
|
proxy_block = opts[:proxy_block]
|
45
45
|
cached = opts[:instance].associations[opts[:reflection][:name]]
|
46
46
|
is_size = opts[:method] == :size
|
47
|
-
is_size && !cached && !proxy_arg && !proxy_block
|
47
|
+
is_size && !cached && !proxy_arg[:reload] && !proxy_block
|
48
48
|
end
|
49
49
|
@t.size.must_equal 1
|
50
50
|
Item.db.sqls.must_equal ["SELECT count(*) AS count FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1) LIMIT 1"]
|
51
51
|
@i.tags{|ds| ds}.size.must_equal 1
|
52
52
|
Item.db.sqls.must_equal ["SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1)"]
|
53
|
-
@i.tags(true).size.must_equal 1
|
53
|
+
@i.tags(:reload=>true).size.must_equal 1
|
54
54
|
Item.db.sqls.must_equal ["SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE (items_tags.item_id = 1)"]
|
55
55
|
@t.size.must_equal 1
|
56
56
|
Item.db.sqls.must_equal []
|
@@ -61,7 +61,7 @@ describe "Sequel::Plugins::AssociationProxies" do
|
|
61
61
|
Item.db.sqls.length.must_equal 1
|
62
62
|
@t.select{|x| false}.must_equal []
|
63
63
|
Item.db.sqls.length.must_equal 0
|
64
|
-
@i.tags(true).select{|x| false}.must_equal []
|
64
|
+
@i.tags(:reload=>true).select{|x| false}.must_equal []
|
65
65
|
Item.db.sqls.length.must_equal 1
|
66
66
|
@t.filter(:a=>1).sql.must_equal "SELECT tags.* FROM tags INNER JOIN items_tags ON (items_tags.tag_id = tags.id) WHERE ((items_tags.item_id = 1) AND (a = 1))"
|
67
67
|
Item.db.sqls.length.must_equal 0
|
@@ -457,3 +457,42 @@ describe "class_table_inheritance plugin without sti_key" do
|
|
457
457
|
@db.sqls.must_equal ['SELECT employees.id, employees.name, staff.manager_id FROM employees INNER JOIN staff ON (staff.id = employees.id) WHERE (staff.manager_id = 3)']
|
458
458
|
end
|
459
459
|
end
|
460
|
+
|
461
|
+
describe "class_table_inheritance plugin with duplicate columns" do
|
462
|
+
before do
|
463
|
+
@db = Sequel.mock(:autoid=>proc{|sql| 1})
|
464
|
+
def @db.supports_schema_parsing?() true end
|
465
|
+
def @db.schema(table, opts={})
|
466
|
+
{:employees=>[[:id, {:primary_key=>true, :type=>:integer}], [:name, {:type=>:string}], [:kind, {:type=>:string}]],
|
467
|
+
:managers=>[[:id, {:type=>:integer}], [:name, {:type=>:string}]],
|
468
|
+
}[table.is_a?(Sequel::Dataset) ? table.first_source_table : table]
|
469
|
+
end
|
470
|
+
@db.extend_datasets do
|
471
|
+
def columns
|
472
|
+
{[:employees]=>[:id, :name, :kind],
|
473
|
+
[:managers]=>[:id, :name],
|
474
|
+
}[opts[:from] + (opts[:join] || []).map{|x| x.table}]
|
475
|
+
end
|
476
|
+
end
|
477
|
+
class ::Employee < Sequel::Model(@db)
|
478
|
+
def _save_refresh; @values[:id] = 1 end
|
479
|
+
def self.columns
|
480
|
+
dataset.columns
|
481
|
+
end
|
482
|
+
plugin :class_table_inheritance, :key=>:kind, :table_map=>{:Staff=>:staff}
|
483
|
+
end
|
484
|
+
deprecated do
|
485
|
+
class ::Manager < Employee; end
|
486
|
+
end
|
487
|
+
@ds = Employee.dataset
|
488
|
+
@db.sqls
|
489
|
+
end
|
490
|
+
after do
|
491
|
+
Object.send(:remove_const, :Manager)
|
492
|
+
Object.send(:remove_const, :Employee)
|
493
|
+
end
|
494
|
+
|
495
|
+
it "should select names from both tables" do
|
496
|
+
Manager.dataset.sql.must_equal 'SELECT employees.id, employees.name, employees.kind, managers.name FROM employees INNER JOIN managers ON (managers.id = employees.id)'
|
497
|
+
end
|
498
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
2
|
+
|
3
|
+
describe "Sequel::Plugins::ColumnsUpdated" do
|
4
|
+
before do
|
5
|
+
@c = Class.new(Sequel::Model(DB[:items].with_autoid(13)))
|
6
|
+
@c.columns :id, :x, :y
|
7
|
+
@c.plugin :columns_updated
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should make hash used for updating available in columns_updated until after hooks finish running" do
|
11
|
+
res = nil
|
12
|
+
@c.send(:define_method, :after_save){res = columns_updated}
|
13
|
+
o = @c.new(:x => 1, :y => nil)
|
14
|
+
o[:x] = 2
|
15
|
+
o.save
|
16
|
+
res.must_be_nil
|
17
|
+
o.after_save
|
18
|
+
res.must_be_nil
|
19
|
+
|
20
|
+
o = @c.load(:id => 23,:x => 1, :y => nil)
|
21
|
+
o[:x] = 2
|
22
|
+
o.save
|
23
|
+
res.must_equal(:x=>2, :y=>nil)
|
24
|
+
o.after_save
|
25
|
+
res.must_be_nil
|
26
|
+
|
27
|
+
o = @c.load(:id => 23,:x => 2, :y => nil)
|
28
|
+
o[:x] = 2
|
29
|
+
o[:y] = 22
|
30
|
+
o.save(:columns=>:x)
|
31
|
+
res.must_equal(:x=>2)
|
32
|
+
o.after_save
|
33
|
+
res.must_be_nil
|
34
|
+
end
|
35
|
+
end
|
@@ -9,6 +9,12 @@ describe "Composition plugin" do
|
|
9
9
|
DB.reset
|
10
10
|
end
|
11
11
|
|
12
|
+
deprecated "should allow access to composition_module" do
|
13
|
+
@c.composition_module.must_be_kind_of Module
|
14
|
+
@c.composition_module = v = Module.new
|
15
|
+
@c.composition_module.must_equal v
|
16
|
+
end
|
17
|
+
|
12
18
|
it ".composition should add compositions" do
|
13
19
|
@o.wont_respond_to(:date)
|
14
20
|
@c.composition :date, :mapping=>[:year, :month, :day]
|
@@ -247,6 +253,5 @@ describe "Composition plugin" do
|
|
247
253
|
@c.freeze
|
248
254
|
@c.compositions.frozen?.must_equal true
|
249
255
|
@c.compositions[:date].frozen?.must_equal true
|
250
|
-
@c.composition_module.frozen?.must_equal true
|
251
256
|
end
|
252
257
|
end
|
@@ -140,7 +140,7 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
140
140
|
adds.must_equal ['456']
|
141
141
|
end
|
142
142
|
|
143
|
-
|
143
|
+
deprecated "should stop processing if a before hook returns false" do
|
144
144
|
flag = true
|
145
145
|
adds = []
|
146
146
|
|
@@ -172,6 +172,40 @@ describe Sequel::Model, "hook_class_methods plugin" do
|
|
172
172
|
b.new.before_save
|
173
173
|
adds.must_equal ['mau', 'blah']
|
174
174
|
end
|
175
|
+
|
176
|
+
it "should stop processing if a before hook calls cancel_action" do
|
177
|
+
flag = true
|
178
|
+
adds = []
|
179
|
+
|
180
|
+
a = model_class.call Sequel::Model(:items) do
|
181
|
+
before_save{adds << 'cruel'; cancel_action if flag == false}
|
182
|
+
before_save{adds << 'blah'; cancel_action if flag == false}
|
183
|
+
end
|
184
|
+
|
185
|
+
a.raise_on_save_failure = false
|
186
|
+
a.new.save
|
187
|
+
adds.must_equal ['blah', 'cruel']
|
188
|
+
|
189
|
+
# chain should not break on nil
|
190
|
+
adds = []
|
191
|
+
flag = nil
|
192
|
+
a.new.save
|
193
|
+
adds.must_equal ['blah', 'cruel']
|
194
|
+
|
195
|
+
adds = []
|
196
|
+
flag = false
|
197
|
+
a.new.save
|
198
|
+
adds.must_equal ['blah']
|
199
|
+
|
200
|
+
b = Class.new(a)
|
201
|
+
b.class_eval do
|
202
|
+
before_save{adds << 'mau'}
|
203
|
+
end
|
204
|
+
|
205
|
+
adds = []
|
206
|
+
b.new.save
|
207
|
+
adds.must_equal ['mau', 'blah']
|
208
|
+
end
|
175
209
|
end
|
176
210
|
|
177
211
|
describe "Model#before_create && Model#after_create" do
|
@@ -192,7 +226,7 @@ describe "Model#before_create && Model#after_create" do
|
|
192
226
|
DB.sqls.must_equal ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after']
|
193
227
|
end
|
194
228
|
|
195
|
-
|
229
|
+
deprecated ".create should cancel the save and raise an error if before_create returns false and raise_on_save_failure is true" do
|
196
230
|
@c.before_create{false}
|
197
231
|
proc{@c.create(:x => 2)}.must_raise(Sequel::HookFailed)
|
198
232
|
DB.sqls.must_equal []
|
@@ -204,7 +238,7 @@ describe "Model#before_create && Model#after_create" do
|
|
204
238
|
DB.sqls.must_equal []
|
205
239
|
end
|
206
240
|
|
207
|
-
|
241
|
+
deprecated ".create should cancel the save and return nil if before_create returns false and raise_on_save_failure is false" do
|
208
242
|
@c.before_create{false}
|
209
243
|
@c.raise_on_save_failure = false
|
210
244
|
@c.create(:x => 2).must_be_nil
|
@@ -235,18 +269,31 @@ describe "Model#before_update && Model#after_update" do
|
|
235
269
|
DB.sqls.must_equal ['BLAH before', 'UPDATE items SET x = 123 WHERE (id = 2233)', 'BLAH after']
|
236
270
|
end
|
237
271
|
|
238
|
-
|
272
|
+
deprecated "#save should cancel the save and raise an error if before_update returns false and raise_on_save_failure is true" do
|
239
273
|
@c.before_update{false}
|
240
274
|
proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
|
241
275
|
DB.sqls.must_equal []
|
242
276
|
end
|
243
277
|
|
244
|
-
it "#save should cancel the save and
|
278
|
+
it "#save should cancel the save and raise an error if before_update calls cancel_action and raise_on_save_failure is true" do
|
279
|
+
@c.before_update{cancel_action}
|
280
|
+
proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
|
281
|
+
DB.sqls.must_equal []
|
282
|
+
end
|
283
|
+
|
284
|
+
deprecated "#save should cancel the save and return nil if before_update returns false and raise_on_save_failure is false" do
|
245
285
|
@c.before_update{false}
|
246
286
|
@c.raise_on_save_failure = false
|
247
287
|
@c.load(:id => 2233).save.must_be_nil
|
248
288
|
DB.sqls.must_equal []
|
249
289
|
end
|
290
|
+
|
291
|
+
it "#save should cancel the save and return nil if before_update calls cancel_action and raise_on_save_failure is false" do
|
292
|
+
@c.before_update{cancel_action}
|
293
|
+
@c.raise_on_save_failure = false
|
294
|
+
@c.load(:id => 2233).save.must_be_nil
|
295
|
+
DB.sqls.must_equal []
|
296
|
+
end
|
250
297
|
end
|
251
298
|
|
252
299
|
describe "Model#before_save && Model#after_save" do
|
@@ -273,18 +320,31 @@ describe "Model#before_save && Model#after_save" do
|
|
273
320
|
DB.sqls.must_equal ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after']
|
274
321
|
end
|
275
322
|
|
276
|
-
|
323
|
+
deprecated "#save should cancel the save and raise an error if before_save returns false and raise_on_save_failure is true" do
|
277
324
|
@c.before_save{false}
|
278
325
|
proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
|
279
326
|
DB.sqls.must_equal []
|
280
327
|
end
|
281
328
|
|
282
|
-
it "#save should cancel the save and
|
329
|
+
it "#save should cancel the save and raise an error if before_save calls cancel_action and raise_on_save_failure is true" do
|
330
|
+
@c.before_save{cancel_action}
|
331
|
+
proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
|
332
|
+
DB.sqls.must_equal []
|
333
|
+
end
|
334
|
+
|
335
|
+
deprecated "#save should cancel the save and return nil if before_save returns false and raise_on_save_failure is false" do
|
283
336
|
@c.before_save{false}
|
284
337
|
@c.raise_on_save_failure = false
|
285
338
|
@c.load(:id => 2233).save.must_be_nil
|
286
339
|
DB.sqls.must_equal []
|
287
340
|
end
|
341
|
+
|
342
|
+
it "#save should cancel the save and return nil if before_save calls cancel_action and raise_on_save_failure is false" do
|
343
|
+
@c.before_save{cancel_action}
|
344
|
+
@c.raise_on_save_failure = false
|
345
|
+
@c.load(:id => 2233).save.must_be_nil
|
346
|
+
DB.sqls.must_equal []
|
347
|
+
end
|
288
348
|
end
|
289
349
|
|
290
350
|
describe "Model#before_destroy && Model#after_destroy" do
|
@@ -303,18 +363,31 @@ describe "Model#before_destroy && Model#after_destroy" do
|
|
303
363
|
DB.sqls.must_equal ['BLAH before', "DELETE FROM items WHERE id = 2233", 'BLAH after']
|
304
364
|
end
|
305
365
|
|
306
|
-
|
366
|
+
deprecated "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_save_failure is true" do
|
307
367
|
@c.before_destroy{false}
|
308
368
|
proc{@c.load(:id => 2233).destroy}.must_raise(Sequel::HookFailed)
|
309
369
|
DB.sqls.must_equal []
|
310
370
|
end
|
311
371
|
|
312
|
-
it "#destroy should cancel the destroy and
|
372
|
+
it "#destroy should cancel the destroy and raise an error if before_destroy calls cancel_action and raise_on_save_failure is true" do
|
373
|
+
@c.before_destroy{cancel_action}
|
374
|
+
proc{@c.load(:id => 2233).destroy}.must_raise(Sequel::HookFailed)
|
375
|
+
DB.sqls.must_equal []
|
376
|
+
end
|
377
|
+
|
378
|
+
deprecated "#destroy should cancel the destroy and return nil if before_destroy returns false and raise_on_save_failure is false" do
|
313
379
|
@c.before_destroy{false}
|
314
380
|
@c.raise_on_save_failure = false
|
315
381
|
@c.load(:id => 2233).destroy.must_be_nil
|
316
382
|
DB.sqls.must_equal []
|
317
383
|
end
|
384
|
+
|
385
|
+
it "#destroy should cancel the destroy and return nil if before_destroy calls cancel_action and raise_on_save_failure is false" do
|
386
|
+
@c.before_destroy{cancel_action}
|
387
|
+
@c.raise_on_save_failure = false
|
388
|
+
@c.load(:id => 2233).destroy.must_be_nil
|
389
|
+
DB.sqls.must_equal []
|
390
|
+
end
|
318
391
|
end
|
319
392
|
|
320
393
|
describe "Model#before_validation && Model#after_validation" do
|
@@ -357,18 +430,31 @@ describe "Model#before_validation && Model#after_validation" do
|
|
357
430
|
DB.sqls.must_equal ['BLAH before', 'BLAH after']
|
358
431
|
end
|
359
432
|
|
360
|
-
|
433
|
+
deprecated "#save should cancel the save and raise an error if before_validation returns false and raise_on_save_failure is true" do
|
361
434
|
@c.before_validation{false}
|
362
435
|
proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
|
363
436
|
DB.sqls.must_equal []
|
364
437
|
end
|
365
438
|
|
366
|
-
it "#save should cancel the save and
|
439
|
+
it "#save should cancel the save and raise an error if before_validation calls cancel_action and raise_on_save_failure is true" do
|
440
|
+
@c.before_validation{cancel_action}
|
441
|
+
proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
|
442
|
+
DB.sqls.must_equal []
|
443
|
+
end
|
444
|
+
|
445
|
+
deprecated "#save should cancel the save and return nil if before_validation returns false and raise_on_save_failure is false" do
|
367
446
|
@c.before_validation{false}
|
368
447
|
@c.raise_on_save_failure = false
|
369
448
|
@c.load(:id => 2233).save.must_be_nil
|
370
449
|
DB.sqls.must_equal []
|
371
450
|
end
|
451
|
+
|
452
|
+
it "#save should cancel the save and return nil if before_validation calls cancel_action and raise_on_save_failure is false" do
|
453
|
+
@c.before_validation{cancel_action}
|
454
|
+
@c.raise_on_save_failure = false
|
455
|
+
@c.load(:id => 2233).save.must_be_nil
|
456
|
+
DB.sqls.must_equal []
|
457
|
+
end
|
372
458
|
end
|
373
459
|
|
374
460
|
describe "Model transaction hooks" do
|
@@ -383,7 +469,7 @@ describe "Model transaction hooks" do
|
|
383
469
|
end
|
384
470
|
end
|
385
471
|
|
386
|
-
|
472
|
+
deprecated "should call after_commit or after_rollback depending on whether the transaction commits or rolls back" do
|
387
473
|
@c.after_commit{DB << 'AC'}
|
388
474
|
@c.after_rollback{DB << 'AR'}
|
389
475
|
m = @c.load(:id => 2233, :x=>123)
|
@@ -400,7 +486,7 @@ describe "Model transaction hooks" do
|
|
400
486
|
end
|
401
487
|
end
|
402
488
|
|
403
|
-
|
489
|
+
deprecated "should call after_destroy_commit or after_destroy_rollback depending on whether the transaction commits or rolls back" do
|
404
490
|
@c.after_destroy_commit {DB << 'ADC'}
|
405
491
|
@c.after_destroy_rollback{DB << 'ADR'}
|
406
492
|
|
@@ -439,33 +525,35 @@ end
|
|
439
525
|
|
440
526
|
describe "Model#add_hook_type" do
|
441
527
|
before do
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
528
|
+
deprecated do
|
529
|
+
class ::Foo < Sequel::Model(:items)
|
530
|
+
plugin :hook_class_methods
|
531
|
+
add_hook_type :before_bar, :after_bar
|
532
|
+
|
533
|
+
def bar
|
534
|
+
return :b if before_bar == false
|
535
|
+
return :a if after_bar == false
|
536
|
+
true
|
537
|
+
end
|
450
538
|
end
|
539
|
+
@f = Class.new(Foo)
|
451
540
|
end
|
452
|
-
@f = Class.new(Foo)
|
453
541
|
end
|
454
542
|
after do
|
455
543
|
Object.send(:remove_const, :Foo)
|
456
544
|
end
|
457
545
|
|
458
|
-
|
546
|
+
deprecated "should have before_bar and after_bar class methods" do
|
459
547
|
@f.must_respond_to(:before_bar)
|
460
548
|
@f.must_respond_to(:before_bar)
|
461
549
|
end
|
462
550
|
|
463
|
-
|
551
|
+
deprecated "should have before_bar and after_bar instance methods" do
|
464
552
|
@f.new.must_respond_to(:before_bar)
|
465
553
|
@f.new.must_respond_to(:before_bar)
|
466
554
|
end
|
467
555
|
|
468
|
-
|
556
|
+
deprecated "it should return true for bar when before_bar and after_bar hooks are returing true" do
|
469
557
|
a = 1
|
470
558
|
@f.before_bar { a += 1}
|
471
559
|
@f.new.bar.must_equal true
|
@@ -475,7 +563,7 @@ describe "Model#add_hook_type" do
|
|
475
563
|
a.must_equal 6
|
476
564
|
end
|
477
565
|
|
478
|
-
|
566
|
+
deprecated "it should return nil for bar when before_bar and after_bar hooks are returing false" do
|
479
567
|
@f.new.bar.must_equal true
|
480
568
|
@f.after_bar { false }
|
481
569
|
@f.new.bar.must_equal :a
|
@@ -2,117 +2,149 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
2
2
|
|
3
3
|
describe "identifier_mangling extension" do
|
4
4
|
after do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
deprecated do
|
6
|
+
Sequel.quote_identifiers = false
|
7
|
+
Sequel.identifier_input_method = nil
|
8
|
+
Sequel.identifier_output_method = nil
|
9
|
+
end
|
8
10
|
end
|
9
11
|
|
10
12
|
it "should respect the :quote_identifiers option" do
|
11
|
-
db = Sequel::Database.new(:quote_identifiers=>false
|
13
|
+
db = Sequel::Database.new(:quote_identifiers=>false).extension(:identifier_mangling)
|
12
14
|
db.quote_identifiers?.must_equal false
|
13
|
-
db = Sequel::Database.new(:quote_identifiers=>true
|
15
|
+
db = Sequel::Database.new(:quote_identifiers=>true).extension(:identifier_mangling)
|
14
16
|
db.quote_identifiers?.must_equal true
|
15
17
|
end
|
16
18
|
|
17
19
|
it "should respect the :quote_identifiers setting" do
|
18
|
-
db = Sequel::Database.new(:identifier_mangling
|
20
|
+
db = Sequel::Database.new.extension(:identifier_mangling)
|
19
21
|
db.quote_identifiers?.must_equal false
|
20
22
|
db.quote_identifiers = true
|
21
23
|
db.quote_identifiers?.must_equal true
|
22
24
|
end
|
23
25
|
|
24
26
|
it "should upcase on input and downcase on output by default" do
|
25
|
-
db = Sequel::Database.new(:identifier_mangling
|
27
|
+
db = Sequel::Database.new.extension(:identifier_mangling)
|
26
28
|
db.send(:identifier_input_method_default).must_equal :upcase
|
27
29
|
db.send(:identifier_output_method_default).must_equal :downcase
|
28
30
|
end
|
29
31
|
|
30
32
|
it "should respect the :identifier_input_method option" do
|
31
|
-
|
32
|
-
Sequel::Database.identifier_input_method.must_equal false
|
33
|
-
db = Sequel::Database.new(:identifier_input_method=>nil, :identifier_mangling=>true)
|
33
|
+
db = Sequel::Database.new.extension(:identifier_mangling)
|
34
34
|
db.identifier_input_method.must_be_nil
|
35
35
|
db.identifier_input_method = :downcase
|
36
36
|
db.identifier_input_method.must_equal :downcase
|
37
|
-
db = Sequel::Database.new(:identifier_input_method
|
37
|
+
db = Sequel::Database.new(:identifier_input_method=>nil).extension(:identifier_mangling)
|
38
|
+
db.identifier_input_method.must_be_nil
|
39
|
+
db.identifier_input_method = :downcase
|
40
|
+
db.identifier_input_method.must_equal :downcase
|
41
|
+
db = Sequel::Database.new(:identifier_input_method=>:upcase).extension(:identifier_mangling)
|
38
42
|
db.identifier_input_method.must_equal :upcase
|
39
43
|
db.identifier_input_method = nil
|
40
44
|
db.identifier_input_method.must_be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
deprecated "should default to Sequel.identifier_input_method" do
|
41
48
|
Sequel.identifier_input_method = :downcase
|
42
49
|
Sequel::Database.identifier_input_method.must_equal :downcase
|
43
|
-
db = Sequel::Database.new(:
|
50
|
+
db = Sequel::Database.new.extension(:identifier_mangling)
|
51
|
+
db.identifier_input_method.must_equal :downcase
|
52
|
+
db.identifier_input_method = :upcase
|
53
|
+
db.identifier_input_method.must_equal :upcase
|
54
|
+
db = Sequel::Database.new(:identifier_input_method=>nil).extension(:identifier_mangling)
|
44
55
|
db.identifier_input_method.must_be_nil
|
45
56
|
db.identifier_input_method = :upcase
|
46
57
|
db.identifier_input_method.must_equal :upcase
|
47
|
-
db = Sequel::Database.new(:identifier_input_method=>:upcase
|
58
|
+
db = Sequel::Database.new(:identifier_input_method=>:upcase).extension(:identifier_mangling)
|
48
59
|
db.identifier_input_method.must_equal :upcase
|
49
60
|
db.identifier_input_method = nil
|
50
61
|
db.identifier_input_method.must_be_nil
|
62
|
+
Sequel.identifier_input_method = nil
|
63
|
+
Sequel::Database.identifier_input_method.must_equal false
|
64
|
+
db = Sequel::Database.new.extension(:identifier_mangling)
|
65
|
+
db.identifier_input_method.must_be_nil
|
66
|
+
db.identifier_input_method = :upcase
|
67
|
+
db.identifier_input_method.must_equal :upcase
|
51
68
|
end
|
52
69
|
|
53
70
|
it "should respect the :identifier_output_method option" do
|
54
|
-
|
55
|
-
|
56
|
-
db =
|
71
|
+
db = Sequel::Database.new.extension(:identifier_mangling)
|
72
|
+
db.identifier_output_method.must_be_nil
|
73
|
+
db.identifier_output_method = :upcase
|
74
|
+
db.identifier_output_method.must_equal :upcase
|
75
|
+
db = Sequel::Database.new(:identifier_output_method=>nil).extension(:identifier_mangling)
|
57
76
|
db.identifier_output_method.must_be_nil
|
58
77
|
db.identifier_output_method = :downcase
|
59
78
|
db.identifier_output_method.must_equal :downcase
|
60
|
-
db = Sequel::Database.new(:identifier_output_method=>:upcase
|
79
|
+
db = Sequel::Database.new(:identifier_output_method=>:upcase).extension(:identifier_mangling)
|
61
80
|
db.identifier_output_method.must_equal :upcase
|
62
81
|
db.identifier_output_method = nil
|
63
82
|
db.identifier_output_method.must_be_nil
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
83
|
+
end
|
84
|
+
|
85
|
+
deprecated "should default to Sequel.identifier_output_method" do
|
86
|
+
Sequel.identifier_output_method = :upcase
|
87
|
+
Sequel::Database.identifier_output_method.must_equal :upcase
|
88
|
+
db = Sequel::Database.new.extension(:identifier_mangling)
|
69
89
|
db.identifier_output_method.must_equal :upcase
|
70
|
-
db =
|
90
|
+
db.identifier_output_method = :downcase
|
91
|
+
db.identifier_output_method.must_equal :downcase
|
92
|
+
db = Sequel::Database.new(:identifier_output_method=>nil).extension(:identifier_mangling)
|
93
|
+
db.identifier_output_method.must_be_nil
|
94
|
+
db.identifier_output_method = :downcase
|
95
|
+
db.identifier_output_method.must_equal :downcase
|
96
|
+
db = Sequel::Database.new(:identifier_output_method=>:upcase).extension(:identifier_mangling)
|
71
97
|
db.identifier_output_method.must_equal :upcase
|
72
98
|
db.identifier_output_method = nil
|
73
99
|
db.identifier_output_method.must_be_nil
|
100
|
+
Sequel.identifier_output_method = nil
|
101
|
+
Sequel::Database.identifier_output_method.must_equal false
|
102
|
+
db = Sequel::Database.new.extension(:identifier_mangling)
|
103
|
+
db.identifier_output_method.must_be_nil
|
104
|
+
db.identifier_output_method = :downcase
|
105
|
+
db.identifier_output_method.must_equal :downcase
|
74
106
|
end
|
75
107
|
|
76
|
-
|
108
|
+
deprecated "should use the default Sequel.quote_identifiers value" do
|
77
109
|
Sequel.quote_identifiers = true
|
78
|
-
Sequel::Database.new(:identifier_mangling
|
110
|
+
Sequel::Database.new.extension(:identifier_mangling).quote_identifiers?.must_equal true
|
79
111
|
Sequel.quote_identifiers = false
|
80
|
-
Sequel::Database.new(:identifier_mangling
|
112
|
+
Sequel::Database.new.extension(:identifier_mangling).quote_identifiers?.must_equal false
|
81
113
|
Sequel::Database.quote_identifiers = true
|
82
|
-
Sequel::Database.new(:identifier_mangling
|
114
|
+
Sequel::Database.new.extension(:identifier_mangling).quote_identifiers?.must_equal true
|
83
115
|
Sequel::Database.quote_identifiers = false
|
84
|
-
Sequel::Database.new(:identifier_mangling
|
116
|
+
Sequel::Database.new.extension(:identifier_mangling).quote_identifiers?.must_equal false
|
85
117
|
end
|
86
118
|
|
87
|
-
|
119
|
+
deprecated "should use the default Sequel.identifier_input_method value" do
|
88
120
|
Sequel.identifier_input_method = :downcase
|
89
|
-
Sequel::Database.new(:identifier_mangling
|
121
|
+
Sequel::Database.new.extension(:identifier_mangling).identifier_input_method.must_equal :downcase
|
90
122
|
Sequel.identifier_input_method = :upcase
|
91
|
-
Sequel::Database.new(:identifier_mangling
|
123
|
+
Sequel::Database.new.extension(:identifier_mangling).identifier_input_method.must_equal :upcase
|
92
124
|
Sequel::Database.identifier_input_method = :downcase
|
93
|
-
Sequel::Database.new(:identifier_mangling
|
125
|
+
Sequel::Database.new.extension(:identifier_mangling).identifier_input_method.must_equal :downcase
|
94
126
|
Sequel::Database.identifier_input_method = :upcase
|
95
|
-
Sequel::Database.new(:identifier_mangling
|
127
|
+
Sequel::Database.new.extension(:identifier_mangling).identifier_input_method.must_equal :upcase
|
96
128
|
end
|
97
129
|
|
98
|
-
|
130
|
+
deprecated "should use the default Sequel.identifier_output_method value" do
|
99
131
|
Sequel.identifier_output_method = :downcase
|
100
|
-
Sequel::Database.new(:identifier_mangling
|
132
|
+
Sequel::Database.new.extension(:identifier_mangling).identifier_output_method.must_equal :downcase
|
101
133
|
Sequel.identifier_output_method = :upcase
|
102
|
-
Sequel::Database.new(:identifier_mangling
|
134
|
+
Sequel::Database.new.extension(:identifier_mangling).identifier_output_method.must_equal :upcase
|
103
135
|
Sequel::Database.identifier_output_method = :downcase
|
104
|
-
Sequel::Database.new(:identifier_mangling
|
136
|
+
Sequel::Database.new.extension(:identifier_mangling).identifier_output_method.must_equal :downcase
|
105
137
|
Sequel::Database.identifier_output_method = :upcase
|
106
|
-
Sequel::Database.new(:identifier_mangling
|
138
|
+
Sequel::Database.new.extension(:identifier_mangling).identifier_output_method.must_equal :upcase
|
107
139
|
end
|
108
140
|
|
109
|
-
|
141
|
+
deprecated "should respect the quote_indentifiers_default method if Sequel.quote_identifiers = nil" do
|
110
142
|
Sequel.quote_identifiers = nil
|
111
|
-
Sequel::Database.new(:identifier_mangling
|
143
|
+
Sequel::Database.new.extension(:identifier_mangling).quote_identifiers?.must_equal true
|
112
144
|
x = Class.new(Sequel::Database){def quote_identifiers_default; false end}
|
113
|
-
x.new(:identifier_mangling
|
145
|
+
x.new.extension(:identifier_mangling).quote_identifiers?.must_equal false
|
114
146
|
y = Class.new(Sequel::Database){def quote_identifiers_default; true end}
|
115
|
-
y.new(:identifier_mangling
|
147
|
+
y.new.extension(:identifier_mangling).quote_identifiers?.must_equal true
|
116
148
|
end
|
117
149
|
|
118
150
|
it "should respect the identifier_input_method_default method if Sequel.identifier_input_method is not called" do
|
@@ -120,9 +152,9 @@ describe "identifier_mangling extension" do
|
|
120
152
|
@identifier_input_method = nil
|
121
153
|
end
|
122
154
|
x = Class.new(Sequel::Database){def identifier_input_method_default; :downcase end}
|
123
|
-
x.new(:identifier_mangling
|
155
|
+
x.new.extension(:identifier_mangling).identifier_input_method.must_equal :downcase
|
124
156
|
y = Class.new(Sequel::Database){def identifier_input_method_default; :camelize end}
|
125
|
-
y.new(:identifier_mangling
|
157
|
+
y.new.extension(:identifier_mangling).identifier_input_method.must_equal :camelize
|
126
158
|
end
|
127
159
|
|
128
160
|
it "should respect the identifier_output_method_default method if Sequel.identifier_output_method is not called" do
|
@@ -130,15 +162,15 @@ describe "identifier_mangling extension" do
|
|
130
162
|
@identifier_output_method = nil
|
131
163
|
end
|
132
164
|
x = Class.new(Sequel::Database){def identifier_output_method_default; :upcase end}
|
133
|
-
x.new(:identifier_mangling
|
165
|
+
x.new.extension(:identifier_mangling).identifier_output_method.must_equal :upcase
|
134
166
|
y = Class.new(Sequel::Database){def identifier_output_method_default; :underscore end}
|
135
|
-
y.new(:identifier_mangling
|
167
|
+
y.new.extension(:identifier_mangling).identifier_output_method.must_equal :underscore
|
136
168
|
end
|
137
169
|
end
|
138
170
|
|
139
171
|
describe "Database#input_identifier_meth" do
|
140
172
|
it "should be the input_identifer method of a default dataset for this database" do
|
141
|
-
db = Sequel::Database.new(:identifier_mangling
|
173
|
+
db = Sequel::Database.new.extension(:identifier_mangling)
|
142
174
|
db.send(:input_identifier_meth).call(:a).must_equal 'a'
|
143
175
|
db.identifier_input_method = :upcase
|
144
176
|
db.send(:input_identifier_meth).call(:a).must_equal 'A'
|
@@ -147,7 +179,7 @@ end
|
|
147
179
|
|
148
180
|
describe "Database#output_identifier_meth" do
|
149
181
|
it "should be the output_identifer method of a default dataset for this database" do
|
150
|
-
db = Sequel::Database.new(:identifier_mangling
|
182
|
+
db = Sequel::Database.new.extension(:identifier_mangling)
|
151
183
|
db.send(:output_identifier_meth).call('A').must_equal :A
|
152
184
|
db.identifier_output_method = :downcase
|
153
185
|
db.send(:output_identifier_meth).call('A').must_equal :a
|
@@ -156,7 +188,7 @@ end
|
|
156
188
|
|
157
189
|
describe "Database#metadata_dataset" do
|
158
190
|
it "should be a dataset with the default settings for identifier_mangling" do
|
159
|
-
ds = Sequel::Database.new(:identifier_mangling
|
191
|
+
ds = Sequel::Database.new.extension(:identifier_mangling).send(:metadata_dataset)
|
160
192
|
ds.literal(:a).must_equal 'A'
|
161
193
|
ds.send(:output_identifier, 'A').must_equal :a
|
162
194
|
end
|
@@ -164,40 +196,40 @@ end
|
|
164
196
|
|
165
197
|
describe "Dataset" do
|
166
198
|
before do
|
167
|
-
@dataset = Sequel.mock(:identifier_mangling
|
199
|
+
@dataset = Sequel.mock.extension(:identifier_mangling).dataset
|
168
200
|
end
|
169
201
|
|
170
202
|
it "should get quote_identifiers default from database" do
|
171
|
-
db = Sequel::Database.new(:quote_identifiers=>true
|
203
|
+
db = Sequel::Database.new(:quote_identifiers=>true).extension(:identifier_mangling)
|
172
204
|
db[:a].quote_identifiers?.must_equal true
|
173
|
-
db = Sequel::Database.new(:quote_identifiers=>false
|
205
|
+
db = Sequel::Database.new(:quote_identifiers=>false).extension(:identifier_mangling)
|
174
206
|
db[:a].quote_identifiers?.must_equal false
|
175
207
|
end
|
176
208
|
|
177
209
|
it "should get identifier_input_method default from database" do
|
178
|
-
db = Sequel::Database.new(:identifier_input_method=>:upcase
|
210
|
+
db = Sequel::Database.new(:identifier_input_method=>:upcase).extension(:identifier_mangling)
|
179
211
|
db[:a].identifier_input_method.must_equal :upcase
|
180
|
-
db = Sequel::Database.new(:identifier_input_method=>:downcase
|
212
|
+
db = Sequel::Database.new(:identifier_input_method=>:downcase).extension(:identifier_mangling)
|
181
213
|
db[:a].identifier_input_method.must_equal :downcase
|
182
214
|
end
|
183
215
|
|
184
216
|
it "should get identifier_output_method default from database" do
|
185
|
-
db = Sequel::Database.new(:identifier_output_method=>:upcase
|
217
|
+
db = Sequel::Database.new(:identifier_output_method=>:upcase).extension(:identifier_mangling)
|
186
218
|
db[:a].identifier_output_method.must_equal :upcase
|
187
|
-
db = Sequel::Database.new(:identifier_output_method=>:downcase
|
219
|
+
db = Sequel::Database.new(:identifier_output_method=>:downcase).extension(:identifier_mangling)
|
188
220
|
db[:a].identifier_output_method.must_equal :downcase
|
189
221
|
end
|
190
222
|
|
191
223
|
# SEQUEL5: Remove
|
192
224
|
unless Sequel.mock(:identifier_mangling=>true).dataset.frozen?
|
193
|
-
|
225
|
+
deprecated "should have quote_identifiers= method which changes literalization of identifiers" do
|
194
226
|
@dataset.quote_identifiers = true
|
195
227
|
@dataset.literal(:a).must_equal '"a"'
|
196
228
|
@dataset.quote_identifiers = false
|
197
229
|
@dataset.literal(:a).must_equal 'a'
|
198
230
|
end
|
199
231
|
|
200
|
-
|
232
|
+
deprecated "should have identifier_input_method= method which changes literalization of identifiers" do
|
201
233
|
@dataset.identifier_input_method = :upcase
|
202
234
|
@dataset.literal(:a).must_equal 'A'
|
203
235
|
@dataset.identifier_input_method = :downcase
|
@@ -206,7 +238,7 @@ describe "Dataset" do
|
|
206
238
|
@dataset.literal(:at_b).must_equal 'b_ta'
|
207
239
|
end
|
208
240
|
|
209
|
-
|
241
|
+
deprecated "should have identifier_output_method= method which changes identifiers returned from the database" do
|
210
242
|
@dataset.send(:output_identifier, "at_b_C").must_equal :at_b_C
|
211
243
|
@dataset.identifier_output_method = :upcase
|
212
244
|
@dataset.send(:output_identifier, "at_b_C").must_equal :AT_B_C
|
@@ -257,7 +289,7 @@ describe "Frozen Datasets" do
|
|
257
289
|
@ds = Sequel.mock(:identifier_mangling=>true)[:test].freeze
|
258
290
|
end
|
259
291
|
|
260
|
-
|
292
|
+
deprecated "should raise an error when calling mutation methods" do
|
261
293
|
proc{@ds.identifier_input_method = :a}.must_raise RuntimeError
|
262
294
|
proc{@ds.identifier_output_method = :a}.must_raise RuntimeError
|
263
295
|
proc{@ds.quote_identifiers = false}.must_raise RuntimeError
|
@@ -267,17 +299,17 @@ end
|
|
267
299
|
describe "identifier_mangling extension" do
|
268
300
|
it "should be able to load dialects based on the database name" do
|
269
301
|
begin
|
270
|
-
qi
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
302
|
+
qi, ii, io = nil
|
303
|
+
deprecated do
|
304
|
+
qi = class Sequel::Database; @quote_identifiers; end
|
305
|
+
ii = class Sequel::Database; @identifier_input_method; end
|
306
|
+
io = class Sequel::Database; @identifier_output_method; end
|
307
|
+
Sequel.quote_identifiers = nil
|
308
|
+
class Sequel::Database; @identifier_input_method=nil; end
|
309
|
+
class Sequel::Database; @identifier_output_method=nil; end
|
310
|
+
end
|
276
311
|
Sequel.mock(:host=>'access').select(Date.new(2011, 12, 13)).sql.must_equal 'SELECT #2011-12-13#'
|
277
|
-
Sequel.mock(:host=>'cubrid').from(:a).offset(1).sql.must_equal 'SELECT * FROM "a" LIMIT 1,4294967295'
|
278
312
|
Sequel.mock(:host=>'db2').select(1).sql.must_equal 'SELECT 1 FROM "SYSIBM"."SYSDUMMY1"'
|
279
|
-
Sequel.mock(:host=>'firebird')[:a].distinct.limit(1, 2).sql.must_equal 'SELECT DISTINCT FIRST 1 SKIP 2 * FROM "A"'
|
280
|
-
Sequel.mock(:host=>'informix')[:a].distinct.limit(1, 2).sql.must_equal 'SELECT SKIP 2 FIRST 1 DISTINCT * FROM A'
|
281
313
|
Sequel.mock(:host=>'mssql')[:a].full_text_search(:b, 'c').sql.must_equal "SELECT * FROM [A] WHERE (CONTAINS ([B], 'c'))"
|
282
314
|
Sequel.mock(:host=>'mysql')[:a].full_text_search(:b, 'c').sql.must_equal "SELECT * FROM `a` WHERE (MATCH (`b`) AGAINST ('c'))"
|
283
315
|
Sequel.mock(:host=>'oracle')[:a].limit(1).sql.must_equal 'SELECT * FROM (SELECT * FROM "A") "T1" WHERE (ROWNUM <= 1)'
|
@@ -285,16 +317,18 @@ describe "identifier_mangling extension" do
|
|
285
317
|
Sequel.mock(:host=>'sqlanywhere').from(:a).offset(1).sql.must_equal 'SELECT TOP 2147483647 START AT (1 + 1) * FROM "A"'
|
286
318
|
Sequel.mock(:host=>'sqlite')[:a___b].sql.must_equal "SELECT * FROM `a` AS 'b'"
|
287
319
|
ensure
|
288
|
-
|
289
|
-
|
290
|
-
|
320
|
+
deprecated do
|
321
|
+
Sequel.quote_identifiers = qi
|
322
|
+
Sequel::Database.send(:instance_variable_set, :@identifier_input_method, ii)
|
323
|
+
Sequel::Database.send(:instance_variable_set, :@identifier_output_method, io)
|
324
|
+
end
|
291
325
|
end
|
292
326
|
end
|
293
327
|
end
|
294
328
|
|
295
329
|
describe Sequel::Model, ".[] optimization" do
|
296
330
|
before do
|
297
|
-
@db = Sequel.mock(:
|
331
|
+
@db = Sequel.mock(:quote_identifiers=>true).extension(:identifier_mangling)
|
298
332
|
def @db.schema(*) [[:id, {:primary_key=>true}]] end
|
299
333
|
def @db.supports_schema_parsing?() true end
|
300
334
|
@c = Class.new(Sequel::Model(@db))
|