sequel 2.11.0 → 2.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +168 -0
- data/README.rdoc +77 -95
- data/Rakefile +100 -80
- data/bin/sequel +2 -1
- data/doc/advanced_associations.rdoc +23 -32
- data/doc/cheat_sheet.rdoc +23 -40
- data/doc/dataset_filtering.rdoc +6 -6
- data/doc/prepared_statements.rdoc +22 -22
- data/doc/release_notes/2.12.0.txt +534 -0
- data/doc/schema.rdoc +3 -1
- data/doc/sharding.rdoc +8 -8
- data/doc/virtual_rows.rdoc +65 -0
- data/lib/sequel.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/ado.rb +3 -3
- data/lib/{sequel_core → sequel}/adapters/db2.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/dbi.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/do.rb +9 -5
- data/lib/{sequel_core → sequel}/adapters/do/mysql.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/do/postgres.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/do/sqlite.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/firebird.rb +84 -80
- data/lib/{sequel_core → sequel}/adapters/informix.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc.rb +21 -14
- data/lib/{sequel_core → sequel}/adapters/jdbc/h2.rb +14 -13
- data/lib/{sequel_core → sequel}/adapters/jdbc/mysql.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc/oracle.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc/postgresql.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/jdbc/sqlite.rb +1 -1
- data/lib/{sequel_core → sequel}/adapters/mysql.rb +60 -39
- data/lib/{sequel_core → sequel}/adapters/odbc.rb +8 -4
- data/lib/{sequel_core → sequel}/adapters/openbase.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/oracle.rb +38 -7
- data/lib/{sequel_core → sequel}/adapters/postgres.rb +24 -24
- data/lib/{sequel_core → sequel}/adapters/shared/mssql.rb +5 -5
- data/lib/{sequel_core → sequel}/adapters/shared/mysql.rb +126 -71
- data/lib/{sequel_core → sequel}/adapters/shared/oracle.rb +7 -10
- data/lib/{sequel_core → sequel}/adapters/shared/postgres.rb +159 -125
- data/lib/{sequel_core → sequel}/adapters/shared/progress.rb +1 -2
- data/lib/{sequel_core → sequel}/adapters/shared/sqlite.rb +72 -67
- data/lib/{sequel_core → sequel}/adapters/sqlite.rb +11 -7
- data/lib/{sequel_core → sequel}/adapters/utils/date_format.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/utils/stored_procedures.rb +0 -0
- data/lib/{sequel_core → sequel}/adapters/utils/unsupported.rb +19 -0
- data/lib/{sequel_core → sequel}/connection_pool.rb +7 -5
- data/lib/sequel/core.rb +221 -0
- data/lib/{sequel_core → sequel}/core_sql.rb +91 -49
- data/lib/{sequel_core → sequel}/database.rb +264 -149
- data/lib/{sequel_core/schema/generator.rb → sequel/database/schema_generator.rb} +6 -2
- data/lib/{sequel_core/database/schema.rb → sequel/database/schema_methods.rb} +12 -12
- data/lib/sequel/database/schema_sql.rb +224 -0
- data/lib/{sequel_core → sequel}/dataset.rb +78 -236
- data/lib/{sequel_core → sequel}/dataset/convenience.rb +99 -61
- data/lib/{sequel_core/object_graph.rb → sequel/dataset/graph.rb} +16 -14
- data/lib/{sequel_core → sequel}/dataset/prepared_statements.rb +1 -1
- data/lib/{sequel_core → sequel}/dataset/sql.rb +150 -99
- data/lib/sequel/deprecated.rb +593 -0
- data/lib/sequel/deprecated_migration.rb +91 -0
- data/lib/sequel/exceptions.rb +48 -0
- data/lib/sequel/extensions/blank.rb +42 -0
- data/lib/{sequel_model → sequel/extensions}/inflector.rb +8 -1
- data/lib/{sequel_core → sequel/extensions}/migration.rb +1 -1
- data/lib/{sequel_core/dataset → sequel/extensions}/pagination.rb +0 -0
- data/lib/{sequel_core → sequel/extensions}/pretty_table.rb +7 -0
- data/lib/{sequel_core/dataset → sequel/extensions}/query.rb +7 -0
- data/lib/sequel/extensions/string_date_time.rb +47 -0
- data/lib/sequel/metaprogramming.rb +43 -0
- data/lib/sequel/model.rb +110 -0
- data/lib/sequel/model/associations.rb +1300 -0
- data/lib/sequel/model/base.rb +937 -0
- data/lib/sequel/model/deprecated.rb +204 -0
- data/lib/sequel/model/deprecated_hooks.rb +103 -0
- data/lib/sequel/model/deprecated_inflector.rb +335 -0
- data/lib/sequel/model/deprecated_validations.rb +388 -0
- data/lib/sequel/model/errors.rb +39 -0
- data/lib/{sequel_model → sequel/model}/exceptions.rb +4 -4
- data/lib/sequel/model/inflections.rb +208 -0
- data/lib/sequel/model/plugins.rb +76 -0
- data/lib/sequel/plugins/caching.rb +122 -0
- data/lib/sequel/plugins/hook_class_methods.rb +122 -0
- data/lib/sequel/plugins/schema.rb +53 -0
- data/lib/sequel/plugins/serialization.rb +117 -0
- data/lib/sequel/plugins/single_table_inheritance.rb +63 -0
- data/lib/sequel/plugins/validation_class_methods.rb +384 -0
- data/lib/sequel/plugins/validation_helpers.rb +150 -0
- data/lib/{sequel_core → sequel}/sql.rb +125 -190
- data/lib/{sequel_core → sequel}/version.rb +2 -1
- data/lib/sequel_core.rb +1 -172
- data/lib/sequel_model.rb +1 -91
- data/spec/adapters/firebird_spec.rb +5 -5
- data/spec/adapters/informix_spec.rb +1 -1
- data/spec/adapters/mysql_spec.rb +128 -42
- data/spec/adapters/oracle_spec.rb +47 -19
- data/spec/adapters/postgres_spec.rb +64 -52
- data/spec/adapters/spec_helper.rb +1 -1
- data/spec/adapters/sqlite_spec.rb +12 -17
- data/spec/{sequel_core → core}/connection_pool_spec.rb +10 -10
- data/spec/{sequel_core → core}/core_ext_spec.rb +19 -19
- data/spec/{sequel_core → core}/core_sql_spec.rb +68 -71
- data/spec/{sequel_core → core}/database_spec.rb +135 -99
- data/spec/{sequel_core → core}/dataset_spec.rb +398 -242
- data/spec/{sequel_core → core}/expression_filters_spec.rb +13 -13
- data/spec/core/migration_spec.rb +263 -0
- data/spec/{sequel_core → core}/object_graph_spec.rb +10 -10
- data/spec/{sequel_core → core}/pretty_table_spec.rb +2 -2
- data/spec/{sequel_core → core}/schema_generator_spec.rb +0 -0
- data/spec/{sequel_core → core}/schema_spec.rb +8 -10
- data/spec/{sequel_core → core}/spec_helper.rb +29 -2
- data/spec/{sequel_core → core}/version_spec.rb +0 -0
- data/spec/extensions/blank_spec.rb +67 -0
- data/spec/extensions/caching_spec.rb +201 -0
- data/spec/{sequel_model/hooks_spec.rb → extensions/hook_class_methods_spec.rb} +8 -23
- data/spec/{sequel_model → extensions}/inflector_spec.rb +3 -0
- data/spec/{sequel_core → extensions}/migration_spec.rb +4 -4
- data/spec/extensions/pagination_spec.rb +99 -0
- data/spec/extensions/pretty_table_spec.rb +91 -0
- data/spec/extensions/query_spec.rb +85 -0
- data/spec/{sequel_model → extensions}/schema_spec.rb +22 -1
- data/spec/extensions/serialization_spec.rb +109 -0
- data/spec/extensions/single_table_inheritance_spec.rb +53 -0
- data/spec/{sequel_model → extensions}/spec_helper.rb +13 -4
- data/spec/extensions/string_date_time_spec.rb +93 -0
- data/spec/{sequel_model/validations_spec.rb → extensions/validation_class_methods_spec.rb} +15 -103
- data/spec/extensions/validation_helpers_spec.rb +291 -0
- data/spec/integration/dataset_test.rb +31 -0
- data/spec/integration/eager_loader_test.rb +17 -30
- data/spec/integration/schema_test.rb +8 -5
- data/spec/integration/spec_helper.rb +17 -0
- data/spec/integration/transaction_test.rb +68 -0
- data/spec/{sequel_model → model}/association_reflection_spec.rb +0 -0
- data/spec/{sequel_model → model}/associations_spec.rb +23 -10
- data/spec/{sequel_model → model}/base_spec.rb +29 -20
- data/spec/{sequel_model → model}/caching_spec.rb +16 -14
- data/spec/{sequel_model → model}/dataset_methods_spec.rb +0 -0
- data/spec/{sequel_model → model}/eager_loading_spec.rb +8 -8
- data/spec/model/hooks_spec.rb +472 -0
- data/spec/model/inflector_spec.rb +126 -0
- data/spec/{sequel_model → model}/model_spec.rb +25 -20
- data/spec/model/plugins_spec.rb +142 -0
- data/spec/{sequel_model → model}/record_spec.rb +121 -62
- data/spec/model/schema_spec.rb +92 -0
- data/spec/model/spec_helper.rb +124 -0
- data/spec/model/validations_spec.rb +1080 -0
- metadata +136 -107
- data/lib/sequel_core/core_ext.rb +0 -217
- data/lib/sequel_core/dataset/callback.rb +0 -13
- data/lib/sequel_core/dataset/schema.rb +0 -15
- data/lib/sequel_core/deprecated.rb +0 -26
- data/lib/sequel_core/exceptions.rb +0 -44
- data/lib/sequel_core/schema.rb +0 -2
- data/lib/sequel_core/schema/sql.rb +0 -325
- data/lib/sequel_model/association_reflection.rb +0 -267
- data/lib/sequel_model/associations.rb +0 -499
- data/lib/sequel_model/base.rb +0 -539
- data/lib/sequel_model/caching.rb +0 -82
- data/lib/sequel_model/dataset_methods.rb +0 -26
- data/lib/sequel_model/eager_loading.rb +0 -370
- data/lib/sequel_model/hooks.rb +0 -101
- data/lib/sequel_model/plugins.rb +0 -62
- data/lib/sequel_model/record.rb +0 -568
- data/lib/sequel_model/schema.rb +0 -49
- data/lib/sequel_model/validations.rb +0 -429
- data/spec/sequel_model/plugins_spec.rb +0 -80
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
3
|
context "A new Database" do
|
4
|
-
|
4
|
+
before do
|
5
5
|
@db = Sequel::Database.new(1 => 2, :logger => 3)
|
6
6
|
end
|
7
|
-
|
7
|
+
after do
|
8
8
|
Sequel.quote_identifiers = false
|
9
9
|
Sequel.identifier_input_method = nil
|
10
10
|
Sequel.identifier_output_method = nil
|
@@ -15,15 +15,10 @@ context "A new Database" do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
specify "should set the logger from opts[:logger] and opts[:loggers]" do
|
18
|
-
@db.logger.should == 3
|
19
18
|
@db.loggers.should == [3]
|
20
|
-
Sequel::Database.new(1 => 2, :loggers => 3).logger.should == 3
|
21
19
|
Sequel::Database.new(1 => 2, :loggers => 3).loggers.should == [3]
|
22
|
-
Sequel::Database.new(1 => 2, :loggers => [3]).logger.should == 3
|
23
20
|
Sequel::Database.new(1 => 2, :loggers => [3]).loggers.should == [3]
|
24
|
-
Sequel::Database.new(1 => 2, :logger => 4, :loggers => 3).logger.should == 4
|
25
21
|
Sequel::Database.new(1 => 2, :logger => 4, :loggers => 3).loggers.should == [4,3]
|
26
|
-
Sequel::Database.new(1 => 2, :logger => [4], :loggers => [3]).logger.should == 4
|
27
22
|
Sequel::Database.new(1 => 2, :logger => [4], :loggers => [3]).loggers.should == [4,3]
|
28
23
|
end
|
29
24
|
|
@@ -61,7 +56,7 @@ context "A new Database" do
|
|
61
56
|
db.send(:identifier_output_method_default).should == :downcase
|
62
57
|
end
|
63
58
|
|
64
|
-
|
59
|
+
deprec_specify "should respect the :upcase_identifiers option" do
|
65
60
|
Sequel.upcase_identifiers = false
|
66
61
|
db = Sequel::Database.new(:upcase_identifiers=>false)
|
67
62
|
db.upcase_identifiers?.should == false
|
@@ -139,7 +134,7 @@ context "A new Database" do
|
|
139
134
|
Sequel::Database.new({}).quote_identifiers?.should == false
|
140
135
|
end
|
141
136
|
|
142
|
-
|
137
|
+
deprec_specify "should use the default Sequel.upcase_identifiers value" do
|
143
138
|
Sequel.upcase_identifiers = true
|
144
139
|
Sequel::Database.new({}).upcase_identifiers?.should == true
|
145
140
|
Sequel.upcase_identifiers = false
|
@@ -191,7 +186,7 @@ context "A new Database" do
|
|
191
186
|
y.new({}).identifier_input_method.should == :camelize
|
192
187
|
end
|
193
188
|
|
194
|
-
specify "should respect the identifier_output_method_default method if Sequel.
|
189
|
+
specify "should respect the identifier_output_method_default method if Sequel.identifier_output_method is not called" do
|
195
190
|
class Sequel::Database
|
196
191
|
@@identifier_output_method = nil
|
197
192
|
end
|
@@ -220,21 +215,19 @@ context "Database#disconnect" do
|
|
220
215
|
specify "should call pool.disconnect" do
|
221
216
|
d = Sequel::Database.new
|
222
217
|
p = d.pool
|
223
|
-
|
224
|
-
p.meta_def(:disconnect){a += 1}
|
218
|
+
p.should_receive(:disconnect).once.and_return(2)
|
225
219
|
d.disconnect.should == 2
|
226
|
-
a.should == 2
|
227
220
|
end
|
228
221
|
end
|
229
222
|
|
230
223
|
context "Database#connect" do
|
231
|
-
specify "should raise
|
224
|
+
specify "should raise NotImplementedError" do
|
232
225
|
proc {Sequel::Database.new.connect}.should raise_error(NotImplementedError)
|
233
226
|
end
|
234
227
|
end
|
235
228
|
|
236
229
|
context "Database#uri" do
|
237
|
-
|
230
|
+
before do
|
238
231
|
@c = Class.new(Sequel::Database) do
|
239
232
|
set_adapter_scheme :mau
|
240
233
|
end
|
@@ -264,7 +257,7 @@ context "Database.adapter_scheme" do
|
|
264
257
|
end
|
265
258
|
|
266
259
|
context "Database#dataset" do
|
267
|
-
|
260
|
+
before do
|
268
261
|
@db = Sequel::Database.new
|
269
262
|
@ds = @db.dataset
|
270
263
|
end
|
@@ -296,17 +289,23 @@ context "Database#dataset" do
|
|
296
289
|
d.should be_a_kind_of(Sequel::Dataset)
|
297
290
|
d.sql.should == 'SELECT a, b, c FROM mau'
|
298
291
|
end
|
292
|
+
|
293
|
+
specify "should allow #select to take a block" do
|
294
|
+
d = @db.select(:a, :b){c}.from(:mau)
|
295
|
+
d.should be_a_kind_of(Sequel::Dataset)
|
296
|
+
d.sql.should == 'SELECT a, b, c FROM mau'
|
297
|
+
end
|
299
298
|
end
|
300
299
|
|
301
300
|
context "Database#execute" do
|
302
|
-
specify "should raise
|
301
|
+
specify "should raise NotImplementedError" do
|
303
302
|
proc {Sequel::Database.new.execute('blah blah')}.should raise_error(NotImplementedError)
|
304
303
|
proc {Sequel::Database.new << 'blah blah'}.should raise_error(NotImplementedError)
|
305
304
|
end
|
306
305
|
end
|
307
306
|
|
308
307
|
context "Database#<<" do
|
309
|
-
|
308
|
+
before do
|
310
309
|
@c = Class.new(Sequel::Database) do
|
311
310
|
define_method(:execute) {|sql, opts| sql}
|
312
311
|
end
|
@@ -317,7 +316,7 @@ context "Database#<<" do
|
|
317
316
|
(@db << "DELETE FROM items").should == "DELETE FROM items"
|
318
317
|
end
|
319
318
|
|
320
|
-
|
319
|
+
deprec_specify "should accept an array and convert it to SQL" do
|
321
320
|
a = %[
|
322
321
|
--
|
323
322
|
CREATE TABLE items (a integer, /*b integer*/
|
@@ -328,7 +327,7 @@ context "Database#<<" do
|
|
328
327
|
"CREATE TABLE items (a integer, b text, c integer); DROP TABLE old_items;"
|
329
328
|
end
|
330
329
|
|
331
|
-
|
330
|
+
deprec_specify "should remove comments and whitespace from arrays" do
|
332
331
|
s = %[
|
333
332
|
--
|
334
333
|
CREATE TABLE items (a integer, /*b integer*/
|
@@ -346,7 +345,7 @@ context "Database#<<" do
|
|
346
345
|
end
|
347
346
|
|
348
347
|
context "Database#synchronize" do
|
349
|
-
|
348
|
+
before do
|
350
349
|
@db = Sequel::Database.new(:max_connections => 1)
|
351
350
|
@db.pool.connection_proc = proc {12345}
|
352
351
|
end
|
@@ -370,7 +369,7 @@ context "Database#synchronize" do
|
|
370
369
|
end
|
371
370
|
|
372
371
|
context "Database#test_connection" do
|
373
|
-
|
372
|
+
before do
|
374
373
|
@db = Sequel::Database.new
|
375
374
|
@test = nil
|
376
375
|
@db.pool.connection_proc = proc {@test = rand(100)}
|
@@ -409,7 +408,7 @@ class DummyDatabase < Sequel::Database
|
|
409
408
|
end
|
410
409
|
|
411
410
|
context "Database#create_table" do
|
412
|
-
|
411
|
+
before do
|
413
412
|
@db = DummyDatabase.new
|
414
413
|
end
|
415
414
|
|
@@ -427,7 +426,7 @@ context "Database#create_table" do
|
|
427
426
|
end
|
428
427
|
|
429
428
|
context "Database#alter_table" do
|
430
|
-
|
429
|
+
before do
|
431
430
|
@db = DummyDatabase.new
|
432
431
|
end
|
433
432
|
|
@@ -457,7 +456,7 @@ context "Database#alter_table" do
|
|
457
456
|
end
|
458
457
|
|
459
458
|
context "Database#add_column" do
|
460
|
-
|
459
|
+
before do
|
461
460
|
@db = DummyDatabase.new
|
462
461
|
end
|
463
462
|
|
@@ -470,7 +469,7 @@ context "Database#add_column" do
|
|
470
469
|
end
|
471
470
|
|
472
471
|
context "Database#drop_column" do
|
473
|
-
|
472
|
+
before do
|
474
473
|
@db = DummyDatabase.new
|
475
474
|
end
|
476
475
|
|
@@ -483,7 +482,7 @@ context "Database#drop_column" do
|
|
483
482
|
end
|
484
483
|
|
485
484
|
context "Database#rename_column" do
|
486
|
-
|
485
|
+
before do
|
487
486
|
@db = DummyDatabase.new
|
488
487
|
end
|
489
488
|
|
@@ -496,7 +495,7 @@ context "Database#rename_column" do
|
|
496
495
|
end
|
497
496
|
|
498
497
|
context "Database#set_column_type" do
|
499
|
-
|
498
|
+
before do
|
500
499
|
@db = DummyDatabase.new
|
501
500
|
end
|
502
501
|
|
@@ -509,7 +508,7 @@ context "Database#set_column_type" do
|
|
509
508
|
end
|
510
509
|
|
511
510
|
context "Database#set_column_default" do
|
512
|
-
|
511
|
+
before do
|
513
512
|
@db = DummyDatabase.new
|
514
513
|
end
|
515
514
|
|
@@ -522,7 +521,7 @@ context "Database#set_column_default" do
|
|
522
521
|
end
|
523
522
|
|
524
523
|
context "Database#add_index" do
|
525
|
-
|
524
|
+
before do
|
526
525
|
@db = DummyDatabase.new
|
527
526
|
end
|
528
527
|
|
@@ -542,7 +541,7 @@ context "Database#add_index" do
|
|
542
541
|
end
|
543
542
|
|
544
543
|
context "Database#drop_index" do
|
545
|
-
|
544
|
+
before do
|
546
545
|
@db = DummyDatabase.new
|
547
546
|
end
|
548
547
|
|
@@ -562,7 +561,7 @@ class Dummy2Database < Sequel::Database
|
|
562
561
|
end
|
563
562
|
|
564
563
|
context "Database#drop_table" do
|
565
|
-
|
564
|
+
before do
|
566
565
|
@db = DummyDatabase.new
|
567
566
|
end
|
568
567
|
|
@@ -582,7 +581,7 @@ context "Database#drop_table" do
|
|
582
581
|
end
|
583
582
|
|
584
583
|
context "Database#rename_table" do
|
585
|
-
|
584
|
+
before do
|
586
585
|
@db = DummyDatabase.new
|
587
586
|
end
|
588
587
|
|
@@ -593,7 +592,7 @@ context "Database#rename_table" do
|
|
593
592
|
end
|
594
593
|
|
595
594
|
context "Database#table_exists?" do
|
596
|
-
|
595
|
+
before do
|
597
596
|
@db = DummyDatabase.new
|
598
597
|
@db.instance_variable_set(:@schemas, {:a=>[]})
|
599
598
|
@db2 = DummyDatabase.new
|
@@ -620,7 +619,7 @@ class Dummy3Database < Sequel::Database
|
|
620
619
|
end
|
621
620
|
|
622
621
|
context "Database#transaction" do
|
623
|
-
|
622
|
+
before do
|
624
623
|
@db = Dummy3Database.new
|
625
624
|
@db.pool.connection_proc = proc {Dummy3Database::DummyConnection.new(@db)}
|
626
625
|
end
|
@@ -649,10 +648,10 @@ context "Database#transaction" do
|
|
649
648
|
proc {@db.transaction {raise RuntimeError}}.should raise_error(RuntimeError)
|
650
649
|
end
|
651
650
|
|
652
|
-
specify "should issue ROLLBACK if Sequel::
|
651
|
+
specify "should issue ROLLBACK if Sequel::Rollback is called in the transaction" do
|
653
652
|
@db.transaction do
|
654
653
|
@db.drop_table(:a)
|
655
|
-
raise Sequel::
|
654
|
+
raise Sequel::Rollback
|
656
655
|
@db.drop_table(:b)
|
657
656
|
end
|
658
657
|
|
@@ -677,12 +676,8 @@ context "Database#transaction" do
|
|
677
676
|
end
|
678
677
|
end
|
679
678
|
|
680
|
-
class Sequel::Database
|
681
|
-
def self.get_adapters; @@adapters; end
|
682
|
-
end
|
683
|
-
|
684
679
|
context "A Database adapter with a scheme" do
|
685
|
-
|
680
|
+
before do
|
686
681
|
class CCC < Sequel::Database
|
687
682
|
if defined?(DISCONNECTS)
|
688
683
|
DISCONNECTS.clear
|
@@ -696,8 +691,8 @@ context "A Database adapter with a scheme" do
|
|
696
691
|
end
|
697
692
|
end
|
698
693
|
|
699
|
-
specify "should be registered in
|
700
|
-
Sequel::
|
694
|
+
specify "should be registered in the ADAPTER_MAP" do
|
695
|
+
Sequel::ADAPTER_MAP[:ccc].should == CCC
|
701
696
|
end
|
702
697
|
|
703
698
|
specify "should be instantiated when its scheme is specified" do
|
@@ -738,7 +733,7 @@ context "A Database adapter with a scheme" do
|
|
738
733
|
CCC::DISCONNECTS.should == [z, y, x]
|
739
734
|
end
|
740
735
|
|
741
|
-
|
736
|
+
deprec_specify "should be accessible through Sequel.open" do
|
742
737
|
c = Sequel.open 'ccc://localhost/db'
|
743
738
|
c.should be_a_kind_of(CCC)
|
744
739
|
c.opts[:host].should == 'localhost'
|
@@ -786,35 +781,31 @@ end
|
|
786
781
|
|
787
782
|
context "An unknown database scheme" do
|
788
783
|
specify "should raise an error in Sequel::Database.connect" do
|
789
|
-
proc {Sequel::Database.connect('ddd://localhost/db')}.should raise_error(Sequel::
|
784
|
+
proc {Sequel::Database.connect('ddd://localhost/db')}.should raise_error(Sequel::AdapterNotFound)
|
790
785
|
end
|
791
786
|
|
792
787
|
specify "should raise an error in Sequel.connect" do
|
793
|
-
proc {Sequel.connect('ddd://localhost/db')}.should raise_error(Sequel::
|
794
|
-
end
|
795
|
-
|
796
|
-
specify "should raise an error in Sequel.open" do
|
797
|
-
proc {Sequel.open('ddd://localhost/db')}.should raise_error(Sequel::Error::AdapterNotFound)
|
788
|
+
proc {Sequel.connect('ddd://localhost/db')}.should raise_error(Sequel::AdapterNotFound)
|
798
789
|
end
|
799
790
|
end
|
800
791
|
|
801
792
|
context "A broken adapter (lib is there but the class is not)" do
|
802
|
-
|
803
|
-
@fn = File.join(File.dirname(__FILE__), '../../lib/
|
793
|
+
before do
|
794
|
+
@fn = File.join(File.dirname(__FILE__), '../../lib/sequel/adapters/blah.rb')
|
804
795
|
File.open(@fn,'a'){}
|
805
796
|
end
|
806
797
|
|
807
|
-
|
798
|
+
after do
|
808
799
|
File.delete(@fn)
|
809
800
|
end
|
810
801
|
|
811
802
|
specify "should raise an error" do
|
812
|
-
proc {Sequel.connect('blah://blow')}.should raise_error(Sequel::
|
803
|
+
proc {Sequel.connect('blah://blow')}.should raise_error(Sequel::AdapterNotFound)
|
813
804
|
end
|
814
805
|
end
|
815
806
|
|
816
807
|
context "A single threaded database" do
|
817
|
-
|
808
|
+
after do
|
818
809
|
Sequel::Database.single_threaded = false
|
819
810
|
end
|
820
811
|
|
@@ -842,7 +833,7 @@ context "A single threaded database" do
|
|
842
833
|
end
|
843
834
|
|
844
835
|
context "A single threaded database" do
|
845
|
-
|
836
|
+
before do
|
846
837
|
conn = 1234567
|
847
838
|
@db = Sequel::Database.new(:single_threaded => true) do
|
848
839
|
conn += 1
|
@@ -864,71 +855,91 @@ context "A single threaded database" do
|
|
864
855
|
end
|
865
856
|
|
866
857
|
context "A database" do
|
867
|
-
|
858
|
+
before do
|
868
859
|
Sequel::Database.single_threaded = false
|
869
860
|
end
|
870
861
|
|
871
|
-
|
862
|
+
after do
|
872
863
|
Sequel::Database.single_threaded = false
|
873
864
|
end
|
874
865
|
|
875
|
-
|
866
|
+
deprec_specify "should have a multi_threaded? method" do
|
876
867
|
db = Sequel::Database.new(:single_threaded => true)
|
877
|
-
db.should be_single_threaded
|
878
868
|
db.should_not be_multi_threaded
|
879
869
|
|
880
870
|
db = Sequel::Database.new(:max_options => 1)
|
881
|
-
db.should_not be_single_threaded
|
882
871
|
db.should be_multi_threaded
|
872
|
+
|
873
|
+
db = Sequel::Database.new
|
874
|
+
db.should be_multi_threaded
|
875
|
+
|
876
|
+
Sequel::Database.single_threaded = true
|
877
|
+
|
878
|
+
db = Sequel::Database.new
|
879
|
+
db.should_not be_multi_threaded
|
880
|
+
|
881
|
+
db = Sequel::Database.new(:max_options => 4)
|
882
|
+
db.should_not be_multi_threaded
|
883
|
+
end
|
884
|
+
|
885
|
+
specify "should have single_threaded? respond to true if in single threaded mode" do
|
886
|
+
db = Sequel::Database.new(:single_threaded => true)
|
887
|
+
db.should be_single_threaded
|
888
|
+
|
889
|
+
db = Sequel::Database.new(:max_options => 1)
|
890
|
+
db.should_not be_single_threaded
|
883
891
|
|
884
892
|
db = Sequel::Database.new
|
885
893
|
db.should_not be_single_threaded
|
886
|
-
db.should be_multi_threaded
|
887
894
|
|
888
895
|
Sequel::Database.single_threaded = true
|
889
896
|
|
890
897
|
db = Sequel::Database.new
|
891
898
|
db.should be_single_threaded
|
892
|
-
db.should_not be_multi_threaded
|
893
899
|
|
894
900
|
db = Sequel::Database.new(:max_options => 4)
|
895
901
|
db.should be_single_threaded
|
896
|
-
db.should_not be_multi_threaded
|
897
902
|
end
|
898
903
|
|
899
|
-
|
904
|
+
deprec_specify "should have a logger method" do
|
900
905
|
db = Sequel::Database.new
|
901
906
|
s = "I'm a logger"
|
902
907
|
db.logger = s
|
903
908
|
db.logger.should == s
|
904
|
-
db.loggers.should == [s]
|
905
909
|
db.logger = nil
|
906
910
|
db.logger.should == nil
|
911
|
+
db.loggers = []
|
912
|
+
db.logger.should == nil
|
913
|
+
t = "I'm also a logger"
|
914
|
+
db.loggers = [s, t]
|
915
|
+
db.logger.should == s
|
916
|
+
end
|
917
|
+
|
918
|
+
specify "should be able to set loggers via the logger= and loggers= methods" do
|
919
|
+
db = Sequel::Database.new
|
920
|
+
s = "I'm a logger"
|
921
|
+
db.logger = s
|
922
|
+
db.loggers.should == [s]
|
923
|
+
db.logger = nil
|
907
924
|
db.loggers.should == []
|
908
925
|
|
909
926
|
db.loggers = [s]
|
910
|
-
db.logger.should == s
|
911
927
|
db.loggers.should == [s]
|
912
928
|
db.loggers = []
|
913
|
-
db.logger.should == nil
|
914
929
|
db.loggers.should == []
|
915
930
|
|
916
931
|
t = "I'm also a logger"
|
917
932
|
db.loggers = [s, t]
|
918
|
-
db.logger.should == s
|
919
933
|
db.loggers.should == [s,t]
|
920
|
-
db.loggers = []
|
921
|
-
db.logger.should == nil
|
922
|
-
db.loggers.should == []
|
923
934
|
end
|
924
935
|
end
|
925
936
|
|
926
937
|
context "Database#dataset" do
|
927
|
-
|
938
|
+
before do
|
928
939
|
@db = Sequel::Database.new
|
929
940
|
end
|
930
941
|
|
931
|
-
|
942
|
+
deprec_specify "should delegate to Dataset#query if block is provided" do
|
932
943
|
@d = @db.query {select :x; from :y}
|
933
944
|
@d.should be_a_kind_of(Sequel::Dataset)
|
934
945
|
@d.sql.should == "SELECT x FROM y"
|
@@ -936,7 +947,7 @@ context "Database#dataset" do
|
|
936
947
|
end
|
937
948
|
|
938
949
|
context "Database#fetch" do
|
939
|
-
|
950
|
+
before do
|
940
951
|
@db = Sequel::Database.new
|
941
952
|
c = Class.new(Sequel::Dataset) do
|
942
953
|
def fetch_rows(sql); yield({:sql => sql}); end
|
@@ -983,7 +994,7 @@ end
|
|
983
994
|
|
984
995
|
|
985
996
|
context "Database#[]" do
|
986
|
-
|
997
|
+
before do
|
987
998
|
@db = Sequel::Database.new
|
988
999
|
end
|
989
1000
|
|
@@ -1006,63 +1017,77 @@ context "Database#[]" do
|
|
1006
1017
|
end
|
1007
1018
|
|
1008
1019
|
context "Database#create_view" do
|
1009
|
-
|
1020
|
+
before do
|
1010
1021
|
@db = DummyDatabase.new
|
1011
1022
|
end
|
1012
1023
|
|
1013
1024
|
specify "should construct proper SQL with raw SQL" do
|
1014
1025
|
@db.create_view :test, "SELECT * FROM xyz"
|
1015
1026
|
@db.sqls.should == ['CREATE VIEW test AS SELECT * FROM xyz']
|
1027
|
+
@db.sqls.clear
|
1028
|
+
@db.create_view :test.identifier, "SELECT * FROM xyz"
|
1029
|
+
@db.sqls.should == ['CREATE VIEW test AS SELECT * FROM xyz']
|
1016
1030
|
end
|
1017
1031
|
|
1018
1032
|
specify "should construct proper SQL with dataset" do
|
1019
1033
|
@db.create_view :test, @db[:items].select(:a, :b).order(:c)
|
1020
1034
|
@db.sqls.should == ['CREATE VIEW test AS SELECT a, b FROM items ORDER BY c']
|
1035
|
+
@db.sqls.clear
|
1036
|
+
@db.create_view :test.qualify(:sch), @db[:items].select(:a, :b).order(:c)
|
1037
|
+
@db.sqls.should == ['CREATE VIEW sch.test AS SELECT a, b FROM items ORDER BY c']
|
1021
1038
|
end
|
1022
1039
|
end
|
1023
1040
|
|
1024
1041
|
context "Database#create_or_replace_view" do
|
1025
|
-
|
1042
|
+
before do
|
1026
1043
|
@db = DummyDatabase.new
|
1027
1044
|
end
|
1028
1045
|
|
1029
1046
|
specify "should construct proper SQL with raw SQL" do
|
1030
1047
|
@db.create_or_replace_view :test, "SELECT * FROM xyz"
|
1031
1048
|
@db.sqls.should == ['CREATE OR REPLACE VIEW test AS SELECT * FROM xyz']
|
1049
|
+
@db.sqls.clear
|
1050
|
+
@db.create_or_replace_view :sch__test, "SELECT * FROM xyz"
|
1051
|
+
@db.sqls.should == ['CREATE OR REPLACE VIEW sch.test AS SELECT * FROM xyz']
|
1032
1052
|
end
|
1033
1053
|
|
1034
1054
|
specify "should construct proper SQL with dataset" do
|
1035
1055
|
@db.create_or_replace_view :test, @db[:items].select(:a, :b).order(:c)
|
1036
1056
|
@db.sqls.should == ['CREATE OR REPLACE VIEW test AS SELECT a, b FROM items ORDER BY c']
|
1057
|
+
@db.sqls.clear
|
1058
|
+
@db.create_or_replace_view :test.identifier, @db[:items].select(:a, :b).order(:c)
|
1059
|
+
@db.sqls.should == ['CREATE OR REPLACE VIEW test AS SELECT a, b FROM items ORDER BY c']
|
1037
1060
|
end
|
1038
1061
|
end
|
1039
1062
|
|
1040
1063
|
context "Database#drop_view" do
|
1041
|
-
|
1064
|
+
before do
|
1042
1065
|
@db = DummyDatabase.new
|
1043
1066
|
end
|
1044
1067
|
|
1045
1068
|
specify "should construct proper SQL" do
|
1046
1069
|
@db.drop_view :test
|
1047
|
-
@db.
|
1070
|
+
@db.drop_view :test.identifier
|
1071
|
+
@db.drop_view :sch__test
|
1072
|
+
@db.drop_view :test.qualify(:sch)
|
1073
|
+
@db.sqls.should == ['DROP VIEW test', 'DROP VIEW test', 'DROP VIEW sch.test', 'DROP VIEW sch.test']
|
1048
1074
|
end
|
1049
1075
|
end
|
1050
1076
|
|
1051
|
-
# TODO: beaf this up with specs for all supported ops
|
1052
1077
|
context "Database#alter_table_sql" do
|
1053
|
-
|
1078
|
+
before do
|
1054
1079
|
@db = DummyDatabase.new
|
1055
1080
|
end
|
1056
1081
|
|
1057
1082
|
specify "should raise error for an invalid op" do
|
1058
|
-
proc {@db.
|
1083
|
+
proc {@db.send(:alter_table_sql, :mau, :op => :blah)}.should raise_error(Sequel::Error)
|
1059
1084
|
end
|
1060
1085
|
end
|
1061
1086
|
|
1062
1087
|
context "Database.connect" do
|
1063
1088
|
EEE_YAML = "development:\r\n adapter: eee\r\n username: mau\r\n password: tau\r\n host: alfonso\r\n database: mydb\r\n"
|
1064
1089
|
|
1065
|
-
|
1090
|
+
before do
|
1066
1091
|
class EEE < Sequel::Database
|
1067
1092
|
set_adapter_scheme :eee
|
1068
1093
|
end
|
@@ -1071,7 +1096,7 @@ context "Database.connect" do
|
|
1071
1096
|
File.open(@fn, 'wb') {|f| f << EEE_YAML}
|
1072
1097
|
end
|
1073
1098
|
|
1074
|
-
|
1099
|
+
after do
|
1075
1100
|
File.delete(@fn)
|
1076
1101
|
end
|
1077
1102
|
|
@@ -1086,7 +1111,7 @@ context "Database.connect" do
|
|
1086
1111
|
end
|
1087
1112
|
|
1088
1113
|
context "Database#inspect" do
|
1089
|
-
|
1114
|
+
before do
|
1090
1115
|
@db = DummyDatabase.new
|
1091
1116
|
|
1092
1117
|
@db.meta_def(:uri) {'blah://blahblah/blah'}
|
@@ -1098,11 +1123,14 @@ context "Database#inspect" do
|
|
1098
1123
|
end
|
1099
1124
|
|
1100
1125
|
context "Database#get" do
|
1101
|
-
|
1126
|
+
before do
|
1102
1127
|
@c = Class.new(DummyDatabase) do
|
1103
1128
|
def dataset
|
1104
1129
|
ds = super
|
1105
|
-
ds.
|
1130
|
+
def ds.get(*args, &block)
|
1131
|
+
@db.execute select(*args, &block).sql
|
1132
|
+
args
|
1133
|
+
end
|
1106
1134
|
ds
|
1107
1135
|
end
|
1108
1136
|
end
|
@@ -1111,12 +1139,20 @@ context "Database#get" do
|
|
1111
1139
|
end
|
1112
1140
|
|
1113
1141
|
specify "should use Dataset#get to get a single value" do
|
1114
|
-
@db.get(1).should == 1
|
1142
|
+
@db.get(1).should == [1]
|
1115
1143
|
@db.sqls.last.should == 'SELECT 1'
|
1116
1144
|
|
1117
1145
|
@db.get(:version.sql_function)
|
1118
1146
|
@db.sqls.last.should == 'SELECT version()'
|
1119
1147
|
end
|
1148
|
+
|
1149
|
+
specify "should accept a block" do
|
1150
|
+
@db.get{1}
|
1151
|
+
@db.sqls.last.should == 'SELECT 1'
|
1152
|
+
|
1153
|
+
@db.get{version(1)}
|
1154
|
+
@db.sqls.last.should == 'SELECT version(1)'
|
1155
|
+
end
|
1120
1156
|
end
|
1121
1157
|
|
1122
1158
|
context "Database#call" do
|
@@ -1173,16 +1209,16 @@ context "Database#raise_error" do
|
|
1173
1209
|
end
|
1174
1210
|
|
1175
1211
|
context "Database#typecast_value" do
|
1176
|
-
|
1212
|
+
before do
|
1177
1213
|
@db = Sequel::Database.new
|
1178
1214
|
end
|
1179
|
-
specify "should raise an
|
1180
|
-
proc{@db.typecast_value(:integer, "13a")}.should raise_error(Sequel::
|
1181
|
-
proc{@db.typecast_value(:float, "4.e2")}.should raise_error(Sequel::
|
1182
|
-
proc{@db.typecast_value(:decimal, :invalid_value)}.should raise_error(Sequel::
|
1183
|
-
proc{@db.typecast_value(:date, Object.new)}.should raise_error(Sequel::
|
1184
|
-
proc{@db.typecast_value(:date, 'a')}.should raise_error(Sequel::
|
1185
|
-
proc{@db.typecast_value(:time, Date.new)}.should raise_error(Sequel::
|
1186
|
-
proc{@db.typecast_value(:datetime, 4)}.should raise_error(Sequel::
|
1215
|
+
specify "should raise an InvalidValue when given an invalid value" do
|
1216
|
+
proc{@db.typecast_value(:integer, "13a")}.should raise_error(Sequel::InvalidValue)
|
1217
|
+
proc{@db.typecast_value(:float, "4.e2")}.should raise_error(Sequel::InvalidValue)
|
1218
|
+
proc{@db.typecast_value(:decimal, :invalid_value)}.should raise_error(Sequel::InvalidValue)
|
1219
|
+
proc{@db.typecast_value(:date, Object.new)}.should raise_error(Sequel::InvalidValue)
|
1220
|
+
proc{@db.typecast_value(:date, 'a')}.should raise_error(Sequel::InvalidValue)
|
1221
|
+
proc{@db.typecast_value(:time, Date.new)}.should raise_error(Sequel::InvalidValue)
|
1222
|
+
proc{@db.typecast_value(:datetime, 4)}.should raise_error(Sequel::InvalidValue)
|
1187
1223
|
end
|
1188
1224
|
end
|