sequel 3.36.1 → 3.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +84 -0
- data/Rakefile +13 -0
- data/bin/sequel +12 -16
- data/doc/advanced_associations.rdoc +36 -67
- data/doc/association_basics.rdoc +11 -16
- data/doc/release_notes/3.37.0.txt +338 -0
- data/doc/schema_modification.rdoc +4 -0
- data/lib/sequel/adapters/jdbc/h2.rb +1 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +26 -8
- data/lib/sequel/adapters/mysql2.rb +4 -3
- data/lib/sequel/adapters/odbc/mssql.rb +2 -2
- data/lib/sequel/adapters/postgres.rb +4 -60
- data/lib/sequel/adapters/shared/mssql.rb +2 -1
- data/lib/sequel/adapters/shared/mysql.rb +0 -5
- data/lib/sequel/adapters/shared/postgres.rb +68 -2
- data/lib/sequel/adapters/shared/sqlite.rb +17 -1
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +12 -1
- data/lib/sequel/adapters/utils/pg_types.rb +76 -0
- data/lib/sequel/core.rb +13 -0
- data/lib/sequel/database/misc.rb +41 -1
- data/lib/sequel/database/schema_generator.rb +23 -10
- data/lib/sequel/database/schema_methods.rb +26 -4
- data/lib/sequel/dataset/graph.rb +2 -1
- data/lib/sequel/dataset/query.rb +62 -2
- data/lib/sequel/extensions/_pretty_table.rb +7 -3
- data/lib/sequel/extensions/arbitrary_servers.rb +5 -4
- data/lib/sequel/extensions/blank.rb +4 -0
- data/lib/sequel/extensions/columns_introspection.rb +13 -2
- data/lib/sequel/extensions/core_extensions.rb +6 -0
- data/lib/sequel/extensions/eval_inspect.rb +158 -0
- data/lib/sequel/extensions/inflector.rb +4 -0
- data/lib/sequel/extensions/looser_typecasting.rb +5 -4
- data/lib/sequel/extensions/migration.rb +4 -1
- data/lib/sequel/extensions/named_timezones.rb +4 -0
- data/lib/sequel/extensions/null_dataset.rb +4 -0
- data/lib/sequel/extensions/pagination.rb +4 -0
- data/lib/sequel/extensions/pg_array.rb +219 -168
- data/lib/sequel/extensions/pg_array_ops.rb +7 -2
- data/lib/sequel/extensions/pg_auto_parameterize.rb +10 -4
- data/lib/sequel/extensions/pg_hstore.rb +3 -1
- data/lib/sequel/extensions/pg_hstore_ops.rb +7 -2
- data/lib/sequel/extensions/pg_inet.rb +28 -3
- data/lib/sequel/extensions/pg_interval.rb +192 -0
- data/lib/sequel/extensions/pg_json.rb +21 -9
- data/lib/sequel/extensions/pg_range.rb +487 -0
- data/lib/sequel/extensions/pg_range_ops.rb +122 -0
- data/lib/sequel/extensions/pg_statement_cache.rb +3 -2
- data/lib/sequel/extensions/pretty_table.rb +12 -1
- data/lib/sequel/extensions/query.rb +4 -0
- data/lib/sequel/extensions/query_literals.rb +6 -6
- data/lib/sequel/extensions/schema_dumper.rb +39 -38
- data/lib/sequel/extensions/select_remove.rb +4 -0
- data/lib/sequel/extensions/server_block.rb +3 -2
- data/lib/sequel/extensions/split_array_nil.rb +65 -0
- data/lib/sequel/extensions/sql_expr.rb +4 -0
- data/lib/sequel/extensions/string_date_time.rb +4 -0
- data/lib/sequel/extensions/thread_local_timezones.rb +9 -3
- data/lib/sequel/extensions/to_dot.rb +4 -0
- data/lib/sequel/model/associations.rb +150 -91
- data/lib/sequel/plugins/identity_map.rb +2 -2
- data/lib/sequel/plugins/list.rb +1 -0
- data/lib/sequel/plugins/many_through_many.rb +33 -32
- data/lib/sequel/plugins/nested_attributes.rb +11 -3
- data/lib/sequel/plugins/rcte_tree.rb +2 -2
- data/lib/sequel/plugins/schema.rb +1 -1
- data/lib/sequel/sql.rb +14 -14
- data/lib/sequel/version.rb +2 -2
- data/spec/adapters/mysql_spec.rb +25 -0
- data/spec/adapters/postgres_spec.rb +572 -28
- data/spec/adapters/sqlite_spec.rb +16 -1
- data/spec/core/database_spec.rb +61 -2
- data/spec/core/dataset_spec.rb +92 -0
- data/spec/core/expression_filters_spec.rb +12 -0
- data/spec/extensions/arbitrary_servers_spec.rb +1 -1
- data/spec/extensions/boolean_readers_spec.rb +25 -25
- data/spec/extensions/eval_inspect_spec.rb +58 -0
- data/spec/extensions/json_serializer_spec.rb +0 -6
- data/spec/extensions/list_spec.rb +1 -1
- data/spec/extensions/looser_typecasting_spec.rb +7 -7
- data/spec/extensions/many_through_many_spec.rb +81 -0
- data/spec/extensions/nested_attributes_spec.rb +21 -4
- data/spec/extensions/pg_array_ops_spec.rb +1 -11
- data/spec/extensions/pg_array_spec.rb +181 -90
- data/spec/extensions/pg_auto_parameterize_spec.rb +3 -3
- data/spec/extensions/pg_hstore_spec.rb +1 -3
- data/spec/extensions/pg_inet_spec.rb +6 -1
- data/spec/extensions/pg_interval_spec.rb +73 -0
- data/spec/extensions/pg_json_spec.rb +5 -9
- data/spec/extensions/pg_range_ops_spec.rb +49 -0
- data/spec/extensions/pg_range_spec.rb +372 -0
- data/spec/extensions/pg_statement_cache_spec.rb +1 -2
- data/spec/extensions/query_literals_spec.rb +1 -2
- data/spec/extensions/schema_dumper_spec.rb +48 -89
- data/spec/extensions/serialization_spec.rb +1 -5
- data/spec/extensions/server_block_spec.rb +2 -2
- data/spec/extensions/spec_helper.rb +12 -2
- data/spec/extensions/split_array_nil_spec.rb +24 -0
- data/spec/integration/associations_test.rb +4 -4
- data/spec/integration/database_test.rb +2 -2
- data/spec/integration/dataset_test.rb +4 -4
- data/spec/integration/eager_loader_test.rb +6 -6
- data/spec/integration/plugin_test.rb +2 -2
- data/spec/integration/spec_helper.rb +2 -2
- data/spec/model/association_reflection_spec.rb +5 -0
- data/spec/model/associations_spec.rb +156 -49
- data/spec/model/eager_loading_spec.rb +137 -2
- data/spec/model/model_spec.rb +10 -10
- metadata +15 -2
|
@@ -23,8 +23,7 @@ describe "pg_statement_cache and pg_auto_parameterize extensions" do
|
|
|
23
23
|
end
|
|
24
24
|
end)
|
|
25
25
|
end)
|
|
26
|
-
@db.
|
|
27
|
-
@db.extend Sequel::Postgres::StatementCache::DatabaseMethods
|
|
26
|
+
@db.extension :pg_auto_parameterize, :pg_statement_cache
|
|
28
27
|
@db.extend(Module.new do
|
|
29
28
|
attr_accessor :exec_raise
|
|
30
29
|
def _execute(c, sql, opts={})
|
|
@@ -2,8 +2,7 @@ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
|
2
2
|
|
|
3
3
|
describe "query_literals extension" do
|
|
4
4
|
before do
|
|
5
|
-
@ds = Sequel::Dataset.new(nil).from(:t)
|
|
6
|
-
@ds.extend(Sequel::QueryLiterals)
|
|
5
|
+
@ds = Sequel::Dataset.new(nil).from(:t).extension(:query_literals)
|
|
7
6
|
end
|
|
8
7
|
|
|
9
8
|
it "should not use special support if given a block" do
|
|
@@ -157,9 +157,9 @@ describe "Sequel::Database dump methods" do
|
|
|
157
157
|
s.should_not =~ /:deferrable/
|
|
158
158
|
end
|
|
159
159
|
|
|
160
|
-
it "should dump primary key columns with explicit
|
|
160
|
+
it "should dump primary key columns with explicit type equal to the database type when :same_db option is passed" do
|
|
161
161
|
@d.meta_def(:schema){|*s| [[:c1, {:db_type=>'somedbspecifictype', :primary_key=>true, :allow_null=>false}]]}
|
|
162
|
-
@d.dump_table_schema(:t7, :same_db => true).should == "create_table(:t7) do\n
|
|
162
|
+
@d.dump_table_schema(:t7, :same_db => true).should == "create_table(:t7) do\n column :c1, \"somedbspecifictype\", :null=>false\n \n primary_key [:c1]\nend"
|
|
163
163
|
end
|
|
164
164
|
|
|
165
165
|
it "should use a composite primary_key calls if there is a composite primary key" do
|
|
@@ -183,7 +183,7 @@ describe "Sequel::Database dump methods" do
|
|
|
183
183
|
it "should support dumping the whole database as a migration" do
|
|
184
184
|
@d.dump_schema_migration.should == <<-END_MIG
|
|
185
185
|
Sequel.migration do
|
|
186
|
-
|
|
186
|
+
change do
|
|
187
187
|
create_table(:t1) do
|
|
188
188
|
primary_key :c1
|
|
189
189
|
String :c2, :size=>20
|
|
@@ -196,10 +196,6 @@ Sequel.migration do
|
|
|
196
196
|
primary_key [:c1, :c2]
|
|
197
197
|
end
|
|
198
198
|
end
|
|
199
|
-
|
|
200
|
-
down do
|
|
201
|
-
drop_table(:t2, :t1)
|
|
202
|
-
end
|
|
203
199
|
end
|
|
204
200
|
END_MIG
|
|
205
201
|
end
|
|
@@ -208,7 +204,7 @@ END_MIG
|
|
|
208
204
|
@d.meta_def(:tables){|o| [:t2, :t1]}
|
|
209
205
|
@d.dump_schema_migration.should == <<-END_MIG
|
|
210
206
|
Sequel.migration do
|
|
211
|
-
|
|
207
|
+
change do
|
|
212
208
|
create_table(:t1) do
|
|
213
209
|
primary_key :c1
|
|
214
210
|
String :c2, :size=>20
|
|
@@ -221,10 +217,6 @@ Sequel.migration do
|
|
|
221
217
|
primary_key [:c1, :c2]
|
|
222
218
|
end
|
|
223
219
|
end
|
|
224
|
-
|
|
225
|
-
down do
|
|
226
|
-
drop_table(:t2, :t1)
|
|
227
|
-
end
|
|
228
220
|
end
|
|
229
221
|
END_MIG
|
|
230
222
|
end
|
|
@@ -239,7 +231,7 @@ END_MIG
|
|
|
239
231
|
end
|
|
240
232
|
@d.dump_schema_migration.should == <<-END_MIG
|
|
241
233
|
Sequel.migration do
|
|
242
|
-
|
|
234
|
+
change do
|
|
243
235
|
create_table(:t2) do
|
|
244
236
|
primary_key :c1
|
|
245
237
|
end
|
|
@@ -248,10 +240,6 @@ Sequel.migration do
|
|
|
248
240
|
foreign_key :c2, :t2, :key=>[:c1]
|
|
249
241
|
end
|
|
250
242
|
end
|
|
251
|
-
|
|
252
|
-
down do
|
|
253
|
-
drop_table(:t1, :t2)
|
|
254
|
-
end
|
|
255
243
|
end
|
|
256
244
|
END_MIG
|
|
257
245
|
end
|
|
@@ -266,7 +254,7 @@ END_MIG
|
|
|
266
254
|
end
|
|
267
255
|
@d.dump_schema_migration.should == <<-END_MIG
|
|
268
256
|
Sequel.migration do
|
|
269
|
-
|
|
257
|
+
change do
|
|
270
258
|
create_table(:t1) do
|
|
271
259
|
Integer :c2
|
|
272
260
|
end
|
|
@@ -279,10 +267,6 @@ Sequel.migration do
|
|
|
279
267
|
add_foreign_key [:c2], :t2, :key=>[:c1]
|
|
280
268
|
end
|
|
281
269
|
end
|
|
282
|
-
|
|
283
|
-
down do
|
|
284
|
-
drop_table(:t2, :t1)
|
|
285
|
-
end
|
|
286
270
|
end
|
|
287
271
|
END_MIG
|
|
288
272
|
end
|
|
@@ -298,7 +282,7 @@ END_MIG
|
|
|
298
282
|
end
|
|
299
283
|
@d.dump_schema_migration.should == <<-END_MIG
|
|
300
284
|
Sequel.migration do
|
|
301
|
-
|
|
285
|
+
change do
|
|
302
286
|
create_table(:t2) do
|
|
303
287
|
primary_key :c1
|
|
304
288
|
end
|
|
@@ -307,10 +291,6 @@ Sequel.migration do
|
|
|
307
291
|
foreign_key :c2, :t2, :key=>[:c1]
|
|
308
292
|
end
|
|
309
293
|
end
|
|
310
|
-
|
|
311
|
-
down do
|
|
312
|
-
drop_table(:t1, :t2)
|
|
313
|
-
end
|
|
314
294
|
end
|
|
315
295
|
END_MIG
|
|
316
296
|
end
|
|
@@ -319,7 +299,7 @@ END_MIG
|
|
|
319
299
|
@d.dump_table_schema(:t1, :same_db=>true).should == "create_table(:t1) do\n primary_key :c1\n column :c2, \"varchar(20)\"\nend"
|
|
320
300
|
@d.dump_schema_migration(:same_db=>true).should == <<-END_MIG
|
|
321
301
|
Sequel.migration do
|
|
322
|
-
|
|
302
|
+
change do
|
|
323
303
|
create_table(:t1) do
|
|
324
304
|
primary_key :c1
|
|
325
305
|
column :c2, "varchar(20)"
|
|
@@ -332,10 +312,6 @@ Sequel.migration do
|
|
|
332
312
|
primary_key [:c1, :c2]
|
|
333
313
|
end
|
|
334
314
|
end
|
|
335
|
-
|
|
336
|
-
down do
|
|
337
|
-
drop_table(:t2, :t1)
|
|
338
|
-
end
|
|
339
315
|
end
|
|
340
316
|
END_MIG
|
|
341
317
|
end
|
|
@@ -348,7 +324,7 @@ END_MIG
|
|
|
348
324
|
@d.dump_table_schema(:t1, :index_names=>false).should == "create_table(:t1, :ignore_index_errors=>true) do\n primary_key :c1\n String :c2, :size=>20\n \n index [:c1]\n index [:c2, :c1], :unique=>true\nend"
|
|
349
325
|
@d.dump_schema_migration(:index_names=>false).should == <<-END_MIG
|
|
350
326
|
Sequel.migration do
|
|
351
|
-
|
|
327
|
+
change do
|
|
352
328
|
create_table(:t1, :ignore_index_errors=>true) do
|
|
353
329
|
primary_key :c1
|
|
354
330
|
String :c2, :size=>20
|
|
@@ -367,10 +343,6 @@ Sequel.migration do
|
|
|
367
343
|
index [:c2, :c1], :unique=>true
|
|
368
344
|
end
|
|
369
345
|
end
|
|
370
|
-
|
|
371
|
-
down do
|
|
372
|
-
drop_table(:t2, :t1)
|
|
373
|
-
end
|
|
374
346
|
end
|
|
375
347
|
END_MIG
|
|
376
348
|
end
|
|
@@ -383,7 +355,7 @@ END_MIG
|
|
|
383
355
|
@d.dump_table_schema(:t1, :index_names=>:namespace).should == "create_table(:t1, :ignore_index_errors=>true) do\n primary_key :c1\n String :c2, :size=>20\n \n index [:c1], :name=>:i1\n index [:c2, :c1]\nend"
|
|
384
356
|
@d.dump_schema_migration(:index_names=>:namespace).should == <<-END_MIG
|
|
385
357
|
Sequel.migration do
|
|
386
|
-
|
|
358
|
+
change do
|
|
387
359
|
create_table(:t1, :ignore_index_errors=>true) do
|
|
388
360
|
primary_key :c1
|
|
389
361
|
String :c2, :size=>20
|
|
@@ -402,10 +374,6 @@ Sequel.migration do
|
|
|
402
374
|
index [:c2, :c1], :name=>:t1_c2_c1_index
|
|
403
375
|
end
|
|
404
376
|
end
|
|
405
|
-
|
|
406
|
-
down do
|
|
407
|
-
drop_table(:t2, :t1)
|
|
408
|
-
end
|
|
409
377
|
end
|
|
410
378
|
END_MIG
|
|
411
379
|
end
|
|
@@ -419,7 +387,7 @@ END_MIG
|
|
|
419
387
|
@d.dump_table_schema(:t1, :index_names=>:namespace).should == "create_table(:t1, :ignore_index_errors=>true) do\n primary_key :c1\n String :c2, :size=>20\n \n index [:c1], :name=>:t1_i1\n index [:c2, :c1]\nend"
|
|
420
388
|
@d.dump_schema_migration(:index_names=>:namespace).should == <<-END_MIG
|
|
421
389
|
Sequel.migration do
|
|
422
|
-
|
|
390
|
+
change do
|
|
423
391
|
create_table(:t1, :ignore_index_errors=>true) do
|
|
424
392
|
primary_key :c1
|
|
425
393
|
String :c2, :size=>20
|
|
@@ -438,10 +406,6 @@ Sequel.migration do
|
|
|
438
406
|
index [:c2, :c1], :name=>:t2_t1_c2_c1_index
|
|
439
407
|
end
|
|
440
408
|
end
|
|
441
|
-
|
|
442
|
-
down do
|
|
443
|
-
drop_table(:t2, :t1)
|
|
444
|
-
end
|
|
445
409
|
end
|
|
446
410
|
END_MIG
|
|
447
411
|
end
|
|
@@ -454,7 +418,7 @@ END_MIG
|
|
|
454
418
|
@d.dump_table_schema(:t1, :indexes=>false).should == "create_table(:t1) do\n primary_key :c1\n String :c2, :size=>20\nend"
|
|
455
419
|
@d.dump_schema_migration(:indexes=>false).should == <<-END_MIG
|
|
456
420
|
Sequel.migration do
|
|
457
|
-
|
|
421
|
+
change do
|
|
458
422
|
create_table(:t1) do
|
|
459
423
|
primary_key :c1
|
|
460
424
|
String :c2, :size=>20
|
|
@@ -467,10 +431,6 @@ Sequel.migration do
|
|
|
467
431
|
primary_key [:c1, :c2]
|
|
468
432
|
end
|
|
469
433
|
end
|
|
470
|
-
|
|
471
|
-
down do
|
|
472
|
-
drop_table(:t2, :t1)
|
|
473
|
-
end
|
|
474
434
|
end
|
|
475
435
|
END_MIG
|
|
476
436
|
end
|
|
@@ -497,15 +457,10 @@ END_MIG
|
|
|
497
457
|
end
|
|
498
458
|
@d.dump_indexes_migration.should == <<-END_MIG
|
|
499
459
|
Sequel.migration do
|
|
500
|
-
|
|
460
|
+
change do
|
|
501
461
|
add_index :t1, [:c1], :ignore_errors=>true, :name=>:i1
|
|
502
462
|
add_index :t1, [:c2, :c1], :ignore_errors=>true, :unique=>true
|
|
503
463
|
end
|
|
504
|
-
|
|
505
|
-
down do
|
|
506
|
-
drop_index :t1, [:c2, :c1], :ignore_errors=>true, :unique=>true
|
|
507
|
-
drop_index :t1, [:c1], :ignore_errors=>true, :name=>:i1
|
|
508
|
-
end
|
|
509
464
|
end
|
|
510
465
|
END_MIG
|
|
511
466
|
end
|
|
@@ -518,15 +473,10 @@ END_MIG
|
|
|
518
473
|
end
|
|
519
474
|
@d.dump_indexes_migration(:index_names=>false).should == <<-END_MIG
|
|
520
475
|
Sequel.migration do
|
|
521
|
-
|
|
476
|
+
change do
|
|
522
477
|
add_index :t1, [:c1], :ignore_errors=>true
|
|
523
478
|
add_index :t1, [:c2, :c1], :ignore_errors=>true, :unique=>true
|
|
524
479
|
end
|
|
525
|
-
|
|
526
|
-
down do
|
|
527
|
-
drop_index :t1, [:c2, :c1], :ignore_errors=>true, :unique=>true
|
|
528
|
-
drop_index :t1, [:c1], :ignore_errors=>true
|
|
529
|
-
end
|
|
530
480
|
end
|
|
531
481
|
END_MIG
|
|
532
482
|
end
|
|
@@ -539,21 +489,13 @@ END_MIG
|
|
|
539
489
|
end
|
|
540
490
|
@d.dump_indexes_migration(:index_names=>:namespace).should == <<-END_MIG
|
|
541
491
|
Sequel.migration do
|
|
542
|
-
|
|
492
|
+
change do
|
|
543
493
|
add_index :t1, [:c1], :ignore_errors=>true, :name=>:i1
|
|
544
494
|
add_index :t1, [:c2, :c1], :ignore_errors=>true
|
|
545
495
|
|
|
546
496
|
add_index :t2, [:c1], :ignore_errors=>true, :name=>:i1
|
|
547
497
|
add_index :t2, [:c2, :c1], :ignore_errors=>true, :name=>:t1_c2_c1_index
|
|
548
498
|
end
|
|
549
|
-
|
|
550
|
-
down do
|
|
551
|
-
drop_index :t2, [:c2, :c1], :ignore_errors=>true, :name=>:t1_c2_c1_index
|
|
552
|
-
drop_index :t2, [:c1], :ignore_errors=>true, :name=>:i1
|
|
553
|
-
|
|
554
|
-
drop_index :t1, [:c2, :c1], :ignore_errors=>true
|
|
555
|
-
drop_index :t1, [:c1], :ignore_errors=>true, :name=>:i1
|
|
556
|
-
end
|
|
557
499
|
end
|
|
558
500
|
END_MIG
|
|
559
501
|
end
|
|
@@ -567,21 +509,13 @@ END_MIG
|
|
|
567
509
|
end
|
|
568
510
|
@d.dump_indexes_migration(:index_names=>:namespace).should == <<-END_MIG
|
|
569
511
|
Sequel.migration do
|
|
570
|
-
|
|
512
|
+
change do
|
|
571
513
|
add_index :t1, [:c1], :ignore_errors=>true, :name=>:t1_i1
|
|
572
514
|
add_index :t1, [:c2, :c1], :ignore_errors=>true
|
|
573
515
|
|
|
574
516
|
add_index :t2, [:c1], :ignore_errors=>true, :name=>:t2_i1
|
|
575
517
|
add_index :t2, [:c2, :c1], :ignore_errors=>true, :name=>:t2_t1_c2_c1_index
|
|
576
518
|
end
|
|
577
|
-
|
|
578
|
-
down do
|
|
579
|
-
drop_index :t2, [:c2, :c1], :ignore_errors=>true, :name=>:t2_t1_c2_c1_index
|
|
580
|
-
drop_index :t2, [:c1], :ignore_errors=>true, :name=>:t2_i1
|
|
581
|
-
|
|
582
|
-
drop_index :t1, [:c2, :c1], :ignore_errors=>true
|
|
583
|
-
drop_index :t1, [:c1], :ignore_errors=>true, :name=>:t1_i1
|
|
584
|
-
end
|
|
585
519
|
end
|
|
586
520
|
END_MIG
|
|
587
521
|
end
|
|
@@ -590,11 +524,7 @@ END_MIG
|
|
|
590
524
|
@d.meta_def(:tables){|o| [:t1]}
|
|
591
525
|
@d.dump_indexes_migration.should == <<-END_MIG
|
|
592
526
|
Sequel.migration do
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
end
|
|
596
|
-
|
|
597
|
-
down do
|
|
527
|
+
change do
|
|
598
528
|
|
|
599
529
|
end
|
|
600
530
|
end
|
|
@@ -605,7 +535,7 @@ END_MIG
|
|
|
605
535
|
@d.meta_def(:tables){|o| [:t1]}
|
|
606
536
|
@d.dump_foreign_key_migration.should == <<-END_MIG
|
|
607
537
|
Sequel.migration do
|
|
608
|
-
|
|
538
|
+
change do
|
|
609
539
|
|
|
610
540
|
end
|
|
611
541
|
end
|
|
@@ -629,7 +559,7 @@ END_MIG
|
|
|
629
559
|
end
|
|
630
560
|
@d.dump_foreign_key_migration.should == <<-END_MIG
|
|
631
561
|
Sequel.migration do
|
|
632
|
-
|
|
562
|
+
change do
|
|
633
563
|
alter_table(:t1) do
|
|
634
564
|
add_foreign_key [:c2], :t2, :key=>[:c1]
|
|
635
565
|
end
|
|
@@ -771,7 +701,36 @@ create_table(:x) do
|
|
|
771
701
|
Integer :c70
|
|
772
702
|
Integer :c71
|
|
773
703
|
Integer :c72
|
|
704
|
+
|
|
705
|
+
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c64), 0)
|
|
706
|
+
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c65), 0)
|
|
707
|
+
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c66), 0)
|
|
708
|
+
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c67), 0)
|
|
709
|
+
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c68), 0)
|
|
710
|
+
check Sequel::SQL::BooleanExpression.new(:>=, Sequel::SQL::Identifier.new(:c69), 0)
|
|
774
711
|
end
|
|
775
712
|
END_MIG
|
|
776
713
|
end
|
|
714
|
+
|
|
715
|
+
it "should use separate primary_key call with non autoincrementable types" do
|
|
716
|
+
@d.meta_def(:schema){|*s| [[:c1, {:db_type=>'varchar(8)', :primary_key=>true}]]}
|
|
717
|
+
@d.dump_table_schema(:t3).should == "create_table(:t3) do\n String :c1, :size=>8\n \n primary_key [:c1]\nend"
|
|
718
|
+
@d.dump_table_schema(:t3, :same_db=>true).should == "create_table(:t3) do\n column :c1, \"varchar(8)\"\n \n primary_key [:c1]\nend"
|
|
719
|
+
end
|
|
720
|
+
|
|
721
|
+
it "should use explicit type for non integer foreign_key types" do
|
|
722
|
+
@d.meta_def(:schema){|*s| [[:c1, {:db_type=>'date', :primary_key=>true}]]}
|
|
723
|
+
@d.meta_def(:foreign_key_list){|t, *a| [{:columns=>[:c1], :table=>:t3, :key=>[:c1]}] if t == :t4}
|
|
724
|
+
["create_table(:t4) do\n foreign_key :c1, :t3, :type=>Date, :key=>[:c1]\n \n primary_key [:c1]\nend",
|
|
725
|
+
"create_table(:t4) do\n foreign_key :c1, :t3, :key=>[:c1], :type=>Date\n \n primary_key [:c1]\nend"].should include(@d.dump_table_schema(:t4))
|
|
726
|
+
["create_table(:t4) do\n foreign_key :c1, :t3, :type=>\"date\", :key=>[:c1]\n \n primary_key [:c1]\nend",
|
|
727
|
+
"create_table(:t4) do\n foreign_key :c1, :t3, :key=>[:c1], :type=>\"date\"\n \n primary_key [:c1]\nend"].should include(@d.dump_table_schema(:t4, :same_db=>true))
|
|
728
|
+
end
|
|
729
|
+
|
|
730
|
+
it "should correctly handing autoincrementing primary keys that are also foreign keys" do
|
|
731
|
+
@d.meta_def(:schema){|*s| [[:c1, {:db_type=>'integer', :primary_key=>true}]]}
|
|
732
|
+
@d.meta_def(:foreign_key_list){|t, *a| [{:columns=>[:c1], :table=>:t3, :key=>[:c1]}] if t == :t4}
|
|
733
|
+
["create_table(:t4) do\n primary_key :c1, :table=>:t3, :key=>[:c1]\nend",
|
|
734
|
+
"create_table(:t4) do\n primary_key :c1, :key=>[:c1], :table=>:t3\nend"].should include(@d.dump_table_schema(:t4))
|
|
735
|
+
end
|
|
777
736
|
end
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
|
2
2
|
|
|
3
|
-
begin
|
|
4
3
|
require 'yaml'
|
|
5
4
|
require 'json'
|
|
6
|
-
|
|
7
|
-
skip_warn "serialization plugin: can't load json (#{e.class}: #{e})"
|
|
8
|
-
else
|
|
5
|
+
|
|
9
6
|
describe "Serialization plugin" do
|
|
10
7
|
before do
|
|
11
8
|
@c = Class.new(Sequel::Model(:items)) do
|
|
@@ -252,4 +249,3 @@ describe "Serialization plugin" do
|
|
|
252
249
|
o.abc.should == 9
|
|
253
250
|
end
|
|
254
251
|
end
|
|
255
|
-
end
|
|
@@ -44,7 +44,7 @@ end
|
|
|
44
44
|
describe "Database#with_server single threaded" do
|
|
45
45
|
before do
|
|
46
46
|
@db = Sequel.mock(:single_threaded=>true, :servers=>{:a=>{}, :b=>{}})
|
|
47
|
-
@db.
|
|
47
|
+
@db.extension :server_block
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it_should_behave_like "Database#with_server"
|
|
@@ -53,7 +53,7 @@ end
|
|
|
53
53
|
describe "Database#with_server multi threaded" do
|
|
54
54
|
before do
|
|
55
55
|
@db = Sequel.mock(:servers=>{:a=>{}, :b=>{}, :c=>{}, :d=>{}})
|
|
56
|
-
@db.
|
|
56
|
+
@db.extension :server_block
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
it_should_behave_like "Database#with_server"
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
if defined?(RSpec)
|
|
4
|
+
begin
|
|
5
|
+
require 'rspec/expectations'
|
|
6
|
+
rescue LoadError
|
|
7
|
+
nil
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
2
11
|
unless Object.const_defined?('Sequel')
|
|
3
12
|
$:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
|
|
4
13
|
require 'sequel/core'
|
|
@@ -12,11 +21,12 @@ begin
|
|
|
12
21
|
# Attempt to load ActiveSupport inflector first, so Sequel inflector
|
|
13
22
|
# can override it.
|
|
14
23
|
require 'active_support/inflector'
|
|
15
|
-
require 'active_support/string/inflections'
|
|
24
|
+
require 'active_support/core_ext/string/inflections'
|
|
16
25
|
rescue LoadError
|
|
26
|
+
nil
|
|
17
27
|
end
|
|
18
28
|
|
|
19
|
-
Sequel.extension(*%w'string_date_time inflector pagination query pretty_table blank migration schema_dumper looser_typecasting sql_expr thread_local_timezones to_dot columns_introspection server_block arbitrary_servers pg_auto_parameterize pg_statement_cache pg_hstore pg_hstore_ops pg_inet schema_caching null_dataset select_remove query_literals')
|
|
29
|
+
Sequel.extension(*%w'string_date_time inflector pagination query pretty_table blank migration schema_dumper looser_typecasting sql_expr thread_local_timezones to_dot columns_introspection server_block arbitrary_servers pg_auto_parameterize pg_statement_cache pg_array pg_array_ops pg_hstore pg_hstore_ops pg_range pg_range_ops pg_json pg_inet schema_caching null_dataset select_remove query_literals eval_inspect')
|
|
20
30
|
{:hook_class_methods=>[], :schema=>[], :validation_class_methods=>[]}.each{|p, opts| Sequel::Model.plugin(p, *opts)}
|
|
21
31
|
|
|
22
32
|
Sequel::Dataset.introspect_all_columns if ENV['SEQUEL_COLUMNS_INTROSPECTION']
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
|
|
2
|
+
|
|
3
|
+
describe "split_array_nil extension" do
|
|
4
|
+
before do
|
|
5
|
+
@ds = Sequel.mock[:table].extension(:split_array_nil)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
specify "should split IN with nil in array into separate OR IS NULL clause" do
|
|
9
|
+
@ds.filter(:a=>[1, nil]).sql.should == "SELECT * FROM table WHERE ((a IN (1)) OR (a IS NULL))"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
specify "should split NOT IN with nil in array into separate AND IS NOT NULL clause" do
|
|
13
|
+
@ds.exclude(:a=>[1, nil]).sql.should == "SELECT * FROM table WHERE ((a NOT IN (1)) AND (a IS NOT NULL))"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
specify "should not affect other IN/NOT in clauses" do
|
|
17
|
+
@ds.filter(:a=>[1, 2]).sql.should == "SELECT * FROM table WHERE (a IN (1, 2))"
|
|
18
|
+
@ds.exclude(:a=>[1, 2]).sql.should == "SELECT * FROM table WHERE (a NOT IN (1, 2))"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
specify "should not affect other types of filters clauses" do
|
|
22
|
+
@ds.filter(:a=>1).sql.should == "SELECT * FROM table WHERE (a = 1)"
|
|
23
|
+
end
|
|
24
|
+
end
|