sequel 4.45.0 → 4.46.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.
- checksums.yaml +4 -4
- data/CHANGELOG +108 -0
- data/doc/release_notes/4.46.0.txt +404 -0
- data/doc/security.rdoc +9 -0
- data/doc/sql.rdoc +2 -2
- data/doc/testing.rdoc +1 -1
- data/doc/validations.rdoc +1 -2
- data/lib/sequel/adapters/ado.rb +8 -3
- data/lib/sequel/adapters/ado/access.rb +8 -4
- data/lib/sequel/adapters/ado/mssql.rb +3 -1
- data/lib/sequel/adapters/amalgalite.rb +5 -0
- data/lib/sequel/adapters/cubrid.rb +16 -7
- data/lib/sequel/adapters/do.rb +7 -1
- data/lib/sequel/adapters/do/mysql.rb +8 -4
- data/lib/sequel/adapters/ibmdb.rb +10 -5
- data/lib/sequel/adapters/jdbc.rb +8 -2
- data/lib/sequel/adapters/jdbc/as400.rb +10 -3
- data/lib/sequel/adapters/jdbc/db2.rb +27 -16
- data/lib/sequel/adapters/jdbc/derby.rb +47 -20
- data/lib/sequel/adapters/jdbc/h2.rb +13 -7
- data/lib/sequel/adapters/jdbc/hsqldb.rb +18 -9
- data/lib/sequel/adapters/jdbc/mssql.rb +5 -2
- data/lib/sequel/adapters/jdbc/mysql.rb +3 -2
- data/lib/sequel/adapters/jdbc/oracle.rb +3 -2
- data/lib/sequel/adapters/jdbc/postgresql.rb +4 -3
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +2 -1
- data/lib/sequel/adapters/jdbc/sqlite.rb +10 -3
- data/lib/sequel/adapters/jdbc/sqlserver.rb +23 -0
- data/lib/sequel/adapters/jdbc/transactions.rb +16 -10
- data/lib/sequel/adapters/mock.rb +5 -0
- data/lib/sequel/adapters/mysql.rb +8 -1
- data/lib/sequel/adapters/mysql2.rb +6 -1
- data/lib/sequel/adapters/odbc.rb +20 -8
- data/lib/sequel/adapters/odbc/mssql.rb +6 -3
- data/lib/sequel/adapters/oracle.rb +12 -6
- data/lib/sequel/adapters/postgres.rb +20 -8
- data/lib/sequel/adapters/shared/access.rb +76 -47
- data/lib/sequel/adapters/shared/cubrid.rb +16 -11
- data/lib/sequel/adapters/shared/db2.rb +46 -19
- data/lib/sequel/adapters/shared/firebird.rb +20 -8
- data/lib/sequel/adapters/shared/informix.rb +6 -3
- data/lib/sequel/adapters/shared/mssql.rb +132 -72
- data/lib/sequel/adapters/shared/mysql.rb +112 -65
- data/lib/sequel/adapters/shared/oracle.rb +36 -21
- data/lib/sequel/adapters/shared/postgres.rb +91 -56
- data/lib/sequel/adapters/shared/sqlanywhere.rb +65 -37
- data/lib/sequel/adapters/shared/sqlite.rb +67 -32
- data/lib/sequel/adapters/sqlanywhere.rb +9 -1
- data/lib/sequel/adapters/sqlite.rb +8 -1
- data/lib/sequel/adapters/swift.rb +5 -0
- data/lib/sequel/adapters/swift/mysql.rb +4 -2
- data/lib/sequel/adapters/swift/sqlite.rb +1 -1
- data/lib/sequel/adapters/tinytds.rb +10 -3
- data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +1 -1
- data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +1 -1
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -0
- data/lib/sequel/adapters/utils/pg_types.rb +14 -6
- data/lib/sequel/adapters/utils/replace.rb +4 -2
- data/lib/sequel/connection_pool/single.rb +2 -2
- data/lib/sequel/core.rb +24 -11
- data/lib/sequel/database/connecting.rb +9 -3
- data/lib/sequel/database/dataset_defaults.rb +7 -1
- data/lib/sequel/database/logging.rb +1 -0
- data/lib/sequel/database/misc.rb +5 -2
- data/lib/sequel/database/query.rb +7 -5
- data/lib/sequel/database/schema_generator.rb +1 -0
- data/lib/sequel/database/schema_methods.rb +50 -27
- data/lib/sequel/database/transactions.rb +19 -9
- data/lib/sequel/dataset/actions.rb +15 -6
- data/lib/sequel/dataset/graph.rb +15 -5
- data/lib/sequel/dataset/misc.rb +12 -4
- data/lib/sequel/dataset/mutation.rb +17 -8
- data/lib/sequel/dataset/prepared_statements.rb +3 -2
- data/lib/sequel/dataset/query.rb +84 -38
- data/lib/sequel/dataset/sql.rb +302 -191
- data/lib/sequel/deprecated.rb +26 -17
- data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +2 -2
- data/lib/sequel/extensions/auto_literal_strings.rb +74 -0
- data/lib/sequel/extensions/from_block.rb +1 -0
- data/lib/sequel/extensions/graph_each.rb +1 -1
- data/lib/sequel/extensions/identifier_mangling.rb +2 -2
- data/lib/sequel/extensions/migration.rb +28 -4
- data/lib/sequel/extensions/no_auto_literal_strings.rb +2 -0
- data/lib/sequel/extensions/schema_dumper.rb +4 -4
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +5 -3
- data/lib/sequel/extensions/set_overrides.rb +2 -0
- data/lib/sequel/extensions/split_array_nil.rb +2 -2
- data/lib/sequel/extensions/virtual_row_method_block.rb +44 -0
- data/lib/sequel/model.rb +11 -7
- data/lib/sequel/model/associations.rb +5 -7
- data/lib/sequel/model/base.rb +47 -45
- data/lib/sequel/model/dataset_module.rb +9 -14
- data/lib/sequel/model/plugins.rb +3 -0
- data/lib/sequel/no_core_ext.rb +1 -0
- data/lib/sequel/plugins/blacklist_security.rb +1 -1
- data/lib/sequel/plugins/boolean_subsets.rb +7 -5
- data/lib/sequel/plugins/class_table_inheritance.rb +47 -10
- data/lib/sequel/plugins/dataset_associations.rb +1 -1
- data/lib/sequel/plugins/def_dataset_method.rb +90 -0
- data/lib/sequel/plugins/finder.rb +240 -0
- data/lib/sequel/plugins/inverted_subsets.rb +19 -12
- data/lib/sequel/plugins/many_through_many.rb +1 -1
- data/lib/sequel/plugins/nested_attributes.rb +1 -1
- data/lib/sequel/plugins/schema.rb +1 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +7 -1
- data/lib/sequel/plugins/subset_conditions.rb +11 -3
- data/lib/sequel/plugins/whitelist_security.rb +118 -0
- data/lib/sequel/sql.rb +80 -36
- data/lib/sequel/timezones.rb +2 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/mssql_spec.rb +20 -0
- data/spec/adapters/mysql_spec.rb +1 -1
- data/spec/adapters/oracle_spec.rb +12 -8
- data/spec/adapters/postgres_spec.rb +1 -1
- data/spec/adapters/spec_helper.rb +1 -1
- data/spec/adapters/sqlite_spec.rb +36 -34
- data/spec/core/connection_pool_spec.rb +2 -1
- data/spec/core/database_spec.rb +87 -9
- data/spec/core/dataset_spec.rb +501 -129
- data/spec/core/deprecated_spec.rb +1 -1
- data/spec/core/expression_filters_spec.rb +146 -60
- data/spec/core/mock_adapter_spec.rb +1 -1
- data/spec/core/object_graph_spec.rb +61 -9
- data/spec/core/placeholder_literalizer_spec.rb +20 -2
- data/spec/core/schema_generator_spec.rb +6 -6
- data/spec/core/schema_spec.rb +54 -5
- data/spec/core_extensions_spec.rb +122 -18
- data/spec/deprecation_helper.rb +27 -2
- data/spec/extensions/_deprecated_identifier_mangling_spec.rb +6 -6
- data/spec/extensions/association_proxies_spec.rb +2 -2
- data/spec/extensions/auto_literal_strings_spec.rb +212 -0
- data/spec/extensions/blacklist_security_spec.rb +1 -0
- data/spec/extensions/class_table_inheritance_spec.rb +1037 -39
- data/spec/extensions/column_select_spec.rb +20 -8
- data/spec/extensions/columns_introspection_spec.rb +3 -3
- data/spec/extensions/core_refinements_spec.rb +29 -12
- data/spec/extensions/dataset_associations_spec.rb +12 -12
- data/spec/extensions/def_dataset_method_spec.rb +100 -0
- data/spec/extensions/error_sql_spec.rb +1 -1
- data/spec/extensions/finder_spec.rb +260 -0
- data/spec/extensions/graph_each_spec.rb +2 -2
- data/spec/extensions/identifier_mangling_spec.rb +14 -8
- data/spec/extensions/inverted_subsets_spec.rb +4 -4
- data/spec/extensions/lazy_attributes_spec.rb +7 -0
- data/spec/extensions/many_through_many_spec.rb +38 -14
- data/spec/extensions/nested_attributes_spec.rb +18 -6
- data/spec/extensions/no_auto_literal_strings_spec.rb +1 -1
- data/spec/extensions/pg_enum_spec.rb +16 -1
- data/spec/extensions/pg_interval_spec.rb +11 -2
- data/spec/extensions/pg_loose_count_spec.rb +5 -0
- data/spec/extensions/pg_row_spec.rb +25 -0
- data/spec/extensions/prepared_statements_spec.rb +10 -1
- data/spec/extensions/query_spec.rb +2 -2
- data/spec/extensions/schema_dumper_spec.rb +2 -2
- data/spec/extensions/schema_spec.rb +2 -2
- data/spec/extensions/set_overrides_spec.rb +7 -3
- data/spec/extensions/sql_expr_spec.rb +0 -1
- data/spec/extensions/subset_conditions_spec.rb +6 -6
- data/spec/extensions/table_select_spec.rb +24 -12
- data/spec/extensions/to_dot_spec.rb +4 -4
- data/spec/extensions/whitelist_security_spec.rb +131 -0
- data/spec/integration/dataset_test.rb +9 -5
- data/spec/integration/model_test.rb +2 -0
- data/spec/integration/plugin_test.rb +2 -2
- data/spec/integration/spec_helper.rb +1 -1
- data/spec/model/associations_spec.rb +39 -11
- data/spec/model/base_spec.rb +44 -24
- data/spec/model/class_dataset_methods_spec.rb +18 -16
- data/spec/model/dataset_methods_spec.rb +4 -4
- data/spec/model/eager_loading_spec.rb +84 -24
- data/spec/model/model_spec.rb +97 -63
- data/spec/model/record_spec.rb +21 -13
- metadata +13 -2
data/spec/model/model_spec.rb
CHANGED
|
@@ -185,8 +185,10 @@ end
|
|
|
185
185
|
describe "Sequel::Model.freeze" do
|
|
186
186
|
it "should freeze the model class and not allow any changes" do
|
|
187
187
|
model = Class.new(Sequel::Model(:items))
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
deprecated do
|
|
189
|
+
model.set_allowed_columns [:id]
|
|
190
|
+
model.finder(:name=>:f_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}
|
|
191
|
+
end
|
|
190
192
|
model.freeze
|
|
191
193
|
model.f_by_name(1)
|
|
192
194
|
|
|
@@ -200,7 +202,10 @@ describe "Sequel::Model.freeze" do
|
|
|
200
202
|
model.default_set_fields_options.frozen?.must_equal true
|
|
201
203
|
|
|
202
204
|
proc{model.dataset_module{}}.must_raise RuntimeError, TypeError
|
|
203
|
-
|
|
205
|
+
deprecated do
|
|
206
|
+
model.allowed_columns.frozen?.must_equal true
|
|
207
|
+
proc{model.finder(:name=>:first_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}}.must_raise RuntimeError, TypeError
|
|
208
|
+
end
|
|
204
209
|
end
|
|
205
210
|
|
|
206
211
|
it "should freeze a model class without a dataset without breaking" do
|
|
@@ -215,7 +220,9 @@ describe "Sequel::Model.freeze" do
|
|
|
215
220
|
model.default_set_fields_options.frozen?.must_equal true
|
|
216
221
|
|
|
217
222
|
proc{model.dataset_module{}}.must_raise RuntimeError, TypeError
|
|
218
|
-
|
|
223
|
+
deprecated do
|
|
224
|
+
proc{model.finder(:name=>:first_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}}.must_raise RuntimeError, TypeError
|
|
225
|
+
end
|
|
219
226
|
end
|
|
220
227
|
|
|
221
228
|
it "should allow subclasses of frozen model classes to work correctly" do
|
|
@@ -226,7 +233,9 @@ describe "Sequel::Model.freeze" do
|
|
|
226
233
|
|
|
227
234
|
model.dataset_module{}
|
|
228
235
|
model.plugin Module.new
|
|
229
|
-
|
|
236
|
+
deprecated do
|
|
237
|
+
model.finder(:name=>:first_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}
|
|
238
|
+
end
|
|
230
239
|
model.first_by_name('a').values.must_equal(:id=>1, :x=>1)
|
|
231
240
|
model.dataset.frozen?.must_equal false
|
|
232
241
|
|
|
@@ -304,37 +313,13 @@ describe Sequel::Model do
|
|
|
304
313
|
@model.dataset.sql.must_equal 'SELECT * FROM foo'
|
|
305
314
|
end
|
|
306
315
|
|
|
307
|
-
it "allows set_dataset to accept a Symbol" do
|
|
308
|
-
@model.db = DB
|
|
309
|
-
@model.set_dataset(:foo)
|
|
310
|
-
@model.table_name.must_equal :foo
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
it "allows set_dataset to accept a LiteralString" do
|
|
314
|
-
@model.db = DB
|
|
315
|
-
@model.set_dataset(Sequel.lit('foo'))
|
|
316
|
-
@model.table_name.must_equal Sequel.lit('foo')
|
|
317
|
-
end
|
|
318
|
-
|
|
319
|
-
it "allows set_dataset to acceptan SQL::Identifier" do
|
|
320
|
-
@model.db = DB
|
|
321
|
-
@model.set_dataset(Sequel.identifier(:foo))
|
|
322
|
-
@model.table_name.must_equal Sequel.identifier(:foo)
|
|
323
|
-
end
|
|
324
|
-
|
|
325
|
-
it "allows set_dataset to acceptan SQL::QualifiedIdentifier" do
|
|
326
|
-
@model.db = DB
|
|
327
|
-
@model.set_dataset(Sequel.qualify(:bar, :foo))
|
|
328
|
-
@model.table_name.must_equal Sequel.qualify(:bar, :foo)
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
it "allows set_dataset to acceptan SQL::AliasedExpression" do
|
|
332
|
-
@model.db = DB
|
|
333
|
-
@model.set_dataset(Sequel.as(:foo, :bar))
|
|
334
|
-
@model.table_name.must_equal :bar
|
|
335
|
-
end
|
|
336
316
|
|
|
337
317
|
it "table_name should respect table aliases" do
|
|
318
|
+
@model.set_dataset(Sequel[:foo].as(:x))
|
|
319
|
+
@model.table_name.must_equal :x
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
with_symbol_splitting "table_name should respect table alias symbols" do
|
|
338
323
|
@model.set_dataset(:foo___x)
|
|
339
324
|
@model.table_name.must_equal :x
|
|
340
325
|
end
|
|
@@ -365,12 +350,12 @@ describe Sequel::Model do
|
|
|
365
350
|
|
|
366
351
|
it "should raise an error on set_dataset if there is an error connecting to the database" do
|
|
367
352
|
def @model.columns() raise Sequel::DatabaseConnectionError end
|
|
368
|
-
proc{@model.set_dataset(Sequel::Database.new[:foo].join(:blah))}.must_raise Sequel::DatabaseConnectionError
|
|
353
|
+
proc{@model.set_dataset(Sequel::Database.new[:foo].join(:blah).from_self)}.must_raise Sequel::DatabaseConnectionError
|
|
369
354
|
end
|
|
370
355
|
|
|
371
356
|
it "should not raise an error if there is a problem getting the columns for a dataset" do
|
|
372
357
|
def @model.columns() raise Sequel::Error end
|
|
373
|
-
@model.set_dataset(DB[:foo].join(:blah))
|
|
358
|
+
@model.set_dataset(DB[:foo].join(:blah).from_self)
|
|
374
359
|
end
|
|
375
360
|
|
|
376
361
|
it "doesn't raise an error on set_dataset if there is an error raised getting the schema" do
|
|
@@ -388,7 +373,7 @@ describe Sequel::Model do
|
|
|
388
373
|
it "doesn't raise an error on inherited if there is an error setting the dataset" do
|
|
389
374
|
db = Sequel.mock
|
|
390
375
|
def db.schema(*) raise Sequel::Error; end
|
|
391
|
-
@model.
|
|
376
|
+
@model.dataset = db[:foo]
|
|
392
377
|
Class.new(@model)
|
|
393
378
|
end
|
|
394
379
|
|
|
@@ -421,6 +406,38 @@ describe Sequel::Model do
|
|
|
421
406
|
end
|
|
422
407
|
end
|
|
423
408
|
|
|
409
|
+
describe Sequel::Model do
|
|
410
|
+
before do
|
|
411
|
+
@model = Class.new(Sequel::Model)
|
|
412
|
+
DB.reset
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
it "allows set_dataset to accept a Symbol" do
|
|
416
|
+
@model.set_dataset(:foo)
|
|
417
|
+
@model.table_name.must_equal :foo
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
it "allows set_dataset to accept a LiteralString" do
|
|
421
|
+
@model.set_dataset(Sequel.lit('foo'))
|
|
422
|
+
@model.table_name.must_equal Sequel.lit('foo')
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
it "allows set_dataset to acceptan SQL::Identifier" do
|
|
426
|
+
@model.set_dataset(Sequel.identifier(:foo))
|
|
427
|
+
@model.table_name.must_equal Sequel.identifier(:foo)
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
it "allows set_dataset to acceptan SQL::QualifiedIdentifier" do
|
|
431
|
+
@model.set_dataset(Sequel.qualify(:bar, :foo))
|
|
432
|
+
@model.table_name.must_equal Sequel.qualify(:bar, :foo)
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
it "allows set_dataset to acceptan SQL::AliasedExpression" do
|
|
436
|
+
@model.set_dataset(Sequel.as(:foo, :bar))
|
|
437
|
+
@model.table_name.must_equal :bar
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
|
|
424
441
|
describe Sequel::Model, ".require_valid_table = true" do
|
|
425
442
|
before do
|
|
426
443
|
@db = Sequel.mock
|
|
@@ -556,7 +573,7 @@ describe Sequel::Model, ".subset" do
|
|
|
556
573
|
DB.reset
|
|
557
574
|
end
|
|
558
575
|
|
|
559
|
-
|
|
576
|
+
deprecated "should create a filter on the underlying dataset" do
|
|
560
577
|
proc {@c.new_only}.must_raise(NoMethodError)
|
|
561
578
|
|
|
562
579
|
@c.subset(:new_only){age < 'new'}
|
|
@@ -573,7 +590,7 @@ describe Sequel::Model, ".subset" do
|
|
|
573
590
|
@c.new_only.pricey.sql.must_equal "SELECT * FROM items WHERE ((age < 'new') AND (price > 100))"
|
|
574
591
|
end
|
|
575
592
|
|
|
576
|
-
|
|
593
|
+
deprecated "should not override existing model methods" do
|
|
577
594
|
def @c.active() true end
|
|
578
595
|
@c.subset(:active, :active)
|
|
579
596
|
@c.active.must_equal true
|
|
@@ -604,6 +621,17 @@ describe Sequel::Model, ".find" do
|
|
|
604
621
|
end
|
|
605
622
|
end
|
|
606
623
|
|
|
624
|
+
describe Sequel::Model, ".first_where" do
|
|
625
|
+
deprecated "should take a condition and do a lookup" do
|
|
626
|
+
db = Sequel.mock(:fetch=>[])
|
|
627
|
+
c = Class.new(Sequel::Model(db[:items]))
|
|
628
|
+
db.sqls
|
|
629
|
+
c.first_where(:a)
|
|
630
|
+
db.sqls.must_equal ['SELECT * FROM items WHERE a LIMIT 1']
|
|
631
|
+
proc{c.first_where(1)}.must_raise Sequel::Error
|
|
632
|
+
end
|
|
633
|
+
end
|
|
634
|
+
|
|
607
635
|
describe Sequel::Model, ".finder" do
|
|
608
636
|
before do
|
|
609
637
|
@h = {:id=>1}
|
|
@@ -618,14 +646,14 @@ describe Sequel::Model, ".finder" do
|
|
|
618
646
|
@db.sqls
|
|
619
647
|
end
|
|
620
648
|
|
|
621
|
-
|
|
649
|
+
deprecated "should create a method that calls the method given and returns the first instance" do
|
|
622
650
|
@c.finder :foo
|
|
623
651
|
@c.first_foo(1, 2).must_equal @o
|
|
624
652
|
@c.first_foo(3, 4).must_equal @o
|
|
625
653
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
|
|
626
654
|
end
|
|
627
655
|
|
|
628
|
-
|
|
656
|
+
deprecated "should work correctly when subclassing" do
|
|
629
657
|
@c.finder(:foo)
|
|
630
658
|
@sc = Class.new(@c)
|
|
631
659
|
@sc.set_dataset :foos
|
|
@@ -635,7 +663,7 @@ describe Sequel::Model, ".finder" do
|
|
|
635
663
|
@db.sqls.must_equal ["SELECT * FROM foos WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
|
|
636
664
|
end
|
|
637
665
|
|
|
638
|
-
|
|
666
|
+
deprecated "should work correctly when dataset is modified" do
|
|
639
667
|
@c.finder(:foo)
|
|
640
668
|
@c.first_foo(1, 2).must_equal @o
|
|
641
669
|
@c.set_dataset :foos
|
|
@@ -643,21 +671,21 @@ describe Sequel::Model, ".finder" do
|
|
|
643
671
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM foos LIMIT 1", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
|
|
644
672
|
end
|
|
645
673
|
|
|
646
|
-
|
|
674
|
+
deprecated "should create a method based on the given block if no method symbol provided" do
|
|
647
675
|
@c.finder(:name=>:first_foo){|pl, ds| ds.where(pl.arg).limit(1)}
|
|
648
676
|
@c.first_foo(:id=>1).must_equal @o
|
|
649
677
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1) LIMIT 1"]
|
|
650
678
|
end
|
|
651
679
|
|
|
652
|
-
|
|
680
|
+
deprecated "should raise an error if both a block and method symbol given" do
|
|
653
681
|
proc{@c.finder(:foo, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
|
|
654
682
|
end
|
|
655
683
|
|
|
656
|
-
|
|
684
|
+
deprecated "should raise an error if two option hashes are provided" do
|
|
657
685
|
proc{@c.finder({:name2=>:foo}, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
|
|
658
686
|
end
|
|
659
687
|
|
|
660
|
-
|
|
688
|
+
deprecated "should support :type option" do
|
|
661
689
|
@c.finder :foo, :type=>:all
|
|
662
690
|
@c.finder :foo, :type=>:each
|
|
663
691
|
@c.finder :foo, :type=>:get
|
|
@@ -675,14 +703,14 @@ describe Sequel::Model, ".finder" do
|
|
|
675
703
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4", "SELECT * FROM items WHERE (bar = 5) ORDER BY 6 LIMIT 1"]
|
|
676
704
|
end
|
|
677
705
|
|
|
678
|
-
|
|
706
|
+
deprecated "should support :name option" do
|
|
679
707
|
@c.finder :foo, :name=>:find_foo
|
|
680
708
|
@c.find_foo(1, 2).must_equal @o
|
|
681
709
|
@c.find_foo(3, 4).must_equal @o
|
|
682
710
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
|
|
683
711
|
end
|
|
684
712
|
|
|
685
|
-
|
|
713
|
+
deprecated "should support :arity option" do
|
|
686
714
|
def @c.foobar(*b)
|
|
687
715
|
ds = dataset
|
|
688
716
|
b.each_with_index do |a, i|
|
|
@@ -697,7 +725,7 @@ describe Sequel::Model, ".finder" do
|
|
|
697
725
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (0 = a) LIMIT 1", "SELECT * FROM items WHERE ((0 = a) AND (1 = b)) LIMIT 1"]
|
|
698
726
|
end
|
|
699
727
|
|
|
700
|
-
|
|
728
|
+
deprecated "should support :mod option" do
|
|
701
729
|
m = Module.new
|
|
702
730
|
@c.finder :foo, :mod=>m
|
|
703
731
|
proc{@c.first_foo}.must_raise NoMethodError
|
|
@@ -707,7 +735,7 @@ describe Sequel::Model, ".finder" do
|
|
|
707
735
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
|
|
708
736
|
end
|
|
709
737
|
|
|
710
|
-
|
|
738
|
+
deprecated "should raise error when calling with the wrong arity" do
|
|
711
739
|
@c.finder :foo
|
|
712
740
|
proc{@c.first_foo(1)}.must_raise Sequel::Error
|
|
713
741
|
proc{@c.first_foo(1,2,3)}.must_raise Sequel::Error
|
|
@@ -735,14 +763,14 @@ describe Sequel::Model, ".prepared_finder" do
|
|
|
735
763
|
@db.sqls
|
|
736
764
|
end
|
|
737
765
|
|
|
738
|
-
|
|
766
|
+
deprecated "should create a method that calls the method given and returns the first instance" do
|
|
739
767
|
@c.prepared_finder :foo
|
|
740
768
|
@c.first_foo(1, 2).must_equal @o
|
|
741
769
|
@c.first_foo(3, 4).must_equal @o
|
|
742
770
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
|
|
743
771
|
end
|
|
744
772
|
|
|
745
|
-
|
|
773
|
+
deprecated "should work correctly when subclassing" do
|
|
746
774
|
@c.prepared_finder(:foo)
|
|
747
775
|
@sc = Class.new(@c)
|
|
748
776
|
@sc.set_dataset :foos
|
|
@@ -752,7 +780,7 @@ describe Sequel::Model, ".prepared_finder" do
|
|
|
752
780
|
@db.sqls.must_equal ["SELECT * FROM foos WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
|
|
753
781
|
end
|
|
754
782
|
|
|
755
|
-
|
|
783
|
+
deprecated "should work correctly when dataset is modified" do
|
|
756
784
|
@c.prepared_finder(:foo)
|
|
757
785
|
@c.first_foo(1, 2).must_equal @o
|
|
758
786
|
@c.set_dataset :foos
|
|
@@ -760,21 +788,21 @@ describe Sequel::Model, ".prepared_finder" do
|
|
|
760
788
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM foos LIMIT 1", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
|
|
761
789
|
end
|
|
762
790
|
|
|
763
|
-
|
|
791
|
+
deprecated "should create a method based on the given block if no method symbol provided" do
|
|
764
792
|
@c.prepared_finder(:name=>:first_foo){|a1| where(:id=>a1).limit(1)}
|
|
765
793
|
@c.first_foo(1).must_equal @o
|
|
766
794
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1) LIMIT 1 -- prepared"]
|
|
767
795
|
end
|
|
768
796
|
|
|
769
|
-
|
|
797
|
+
deprecated "should raise an error if both a block and method symbol given" do
|
|
770
798
|
proc{@c.prepared_finder(:foo, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
|
|
771
799
|
end
|
|
772
800
|
|
|
773
|
-
|
|
801
|
+
deprecated "should raise an error if two option hashes are provided" do
|
|
774
802
|
proc{@c.prepared_finder({:name2=>:foo}, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
|
|
775
803
|
end
|
|
776
804
|
|
|
777
|
-
|
|
805
|
+
deprecated "should support :type option" do
|
|
778
806
|
@c.prepared_finder :foo, :type=>:all
|
|
779
807
|
@c.prepared_finder :foo, :type=>:each
|
|
780
808
|
|
|
@@ -789,14 +817,14 @@ describe Sequel::Model, ".prepared_finder" do
|
|
|
789
817
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 -- prepared"]
|
|
790
818
|
end
|
|
791
819
|
|
|
792
|
-
|
|
820
|
+
deprecated "should support :name option" do
|
|
793
821
|
@c.prepared_finder :foo, :name=>:find_foo
|
|
794
822
|
@c.find_foo(1, 2).must_equal @o
|
|
795
823
|
@c.find_foo(3, 4).must_equal @o
|
|
796
824
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
|
|
797
825
|
end
|
|
798
826
|
|
|
799
|
-
|
|
827
|
+
deprecated "should support :arity option" do
|
|
800
828
|
def @c.foobar(*b)
|
|
801
829
|
ds = dataset
|
|
802
830
|
b.each_with_index do |a, i|
|
|
@@ -811,7 +839,7 @@ describe Sequel::Model, ".prepared_finder" do
|
|
|
811
839
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (0 = a) LIMIT 1 -- prepared", "SELECT * FROM items WHERE ((0 = a) AND (1 = b)) LIMIT 1 -- prepared"]
|
|
812
840
|
end
|
|
813
841
|
|
|
814
|
-
|
|
842
|
+
deprecated "should support :mod option" do
|
|
815
843
|
m = Module.new
|
|
816
844
|
@c.prepared_finder :foo, :mod=>m
|
|
817
845
|
proc{@c.first_foo}.must_raise NoMethodError
|
|
@@ -821,7 +849,7 @@ describe Sequel::Model, ".prepared_finder" do
|
|
|
821
849
|
@db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
|
|
822
850
|
end
|
|
823
851
|
|
|
824
|
-
|
|
852
|
+
deprecated "should handle models with names" do
|
|
825
853
|
def @c.name; 'foobar' end
|
|
826
854
|
@c.prepared_finder :foo
|
|
827
855
|
@c.first_foo(1, 2).must_equal @o
|
|
@@ -1010,12 +1038,18 @@ describe Sequel::Model, ".[]" do
|
|
|
1010
1038
|
DB.sqls.must_equal ["SELECT * FROM items WHERE name = 'sharon'"]
|
|
1011
1039
|
end
|
|
1012
1040
|
|
|
1013
|
-
|
|
1041
|
+
deprecated "should use a qualified primary key if the dataset is joined" do
|
|
1014
1042
|
@c.dataset = @c.dataset.cross_join(:a)
|
|
1015
1043
|
@c[1].must_equal @c.load(:name => 'sharon', :id => 1)
|
|
1016
1044
|
DB.sqls.must_equal ["SELECT * FROM items CROSS JOIN a WHERE (items.id = 1) LIMIT 1"]
|
|
1017
1045
|
end
|
|
1018
1046
|
|
|
1047
|
+
it "should handle a dataset that uses a subquery" do
|
|
1048
|
+
@c.dataset = @c.dataset.cross_join(:a).from_self(:alias=>:b)
|
|
1049
|
+
@c[1].must_equal @c.load(:name => 'sharon', :id => 1)
|
|
1050
|
+
DB.sqls.must_equal ["SELECT * FROM (SELECT * FROM items CROSS JOIN a) AS b WHERE (id = 1) LIMIT 1"]
|
|
1051
|
+
end
|
|
1052
|
+
|
|
1019
1053
|
it "should work correctly for composite primary key specified as array" do
|
|
1020
1054
|
@c.set_primary_key [:node_id, :kind]
|
|
1021
1055
|
@c[3921, 201].must_be_kind_of(@c)
|
|
@@ -1084,7 +1118,7 @@ describe "Model.db_schema" do
|
|
|
1084
1118
|
def @db.schema(table, opts={})
|
|
1085
1119
|
raise Sequel::Error
|
|
1086
1120
|
end
|
|
1087
|
-
@c.dataset = @dataset.join(:x, :id).columns(:id, :x)
|
|
1121
|
+
@c.dataset = @dataset.join(:x, :id).from_self.columns(:id, :x)
|
|
1088
1122
|
@c.db_schema.must_equal(:x=>{}, :id=>{})
|
|
1089
1123
|
end
|
|
1090
1124
|
|
data/spec/model/record_spec.rb
CHANGED
|
@@ -849,12 +849,18 @@ describe Sequel::Model, "#this" do
|
|
|
849
849
|
instance.this.sql.must_equal "SELECT * FROM examples WHERE (a = 3) LIMIT 1"
|
|
850
850
|
end
|
|
851
851
|
|
|
852
|
-
|
|
852
|
+
deprecated "should use a qualified primary key if the dataset is joined" do
|
|
853
853
|
@example.dataset = @example.dataset.cross_join(:a)
|
|
854
854
|
instance = @example.load(:id => 3)
|
|
855
855
|
instance.this.sql.must_equal "SELECT * FROM examples CROSS JOIN a WHERE (examples.id = 3) LIMIT 1"
|
|
856
856
|
end
|
|
857
857
|
|
|
858
|
+
it "should use a primary key if the dataset uses a subquery" do
|
|
859
|
+
@example.dataset = @example.dataset.cross_join(:a).from_self(:alias=>:b)
|
|
860
|
+
instance = @example.load(:id => 3)
|
|
861
|
+
instance.this.sql.must_equal "SELECT * FROM (SELECT * FROM examples CROSS JOIN a) AS b WHERE (id = 3) LIMIT 1"
|
|
862
|
+
end
|
|
863
|
+
|
|
858
864
|
it "should support composite primary keys" do
|
|
859
865
|
@example.set_primary_key [:x, :y]
|
|
860
866
|
instance = @example.load(:x => 4, :y => 5)
|
|
@@ -1038,7 +1044,7 @@ describe Sequel::Model, "#set" do
|
|
|
1038
1044
|
|
|
1039
1045
|
it "should raise error if strict_param_setting is true and column is restricted" do
|
|
1040
1046
|
@o1.strict_param_setting = true
|
|
1041
|
-
@c.
|
|
1047
|
+
@c.setter_methods.delete("x=")
|
|
1042
1048
|
proc{@o1.set('x' => 1)}.must_raise(Sequel::MassAssignmentRestriction)
|
|
1043
1049
|
end
|
|
1044
1050
|
|
|
@@ -1277,17 +1283,19 @@ end
|
|
|
1277
1283
|
|
|
1278
1284
|
describe Sequel::Model, "#(set|update)_(all|only)" do
|
|
1279
1285
|
before do
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1286
|
+
deprecated do
|
|
1287
|
+
@c = Class.new(Sequel::Model(:items)) do
|
|
1288
|
+
set_primary_key :id
|
|
1289
|
+
columns :x, :y, :z, :id
|
|
1290
|
+
set_allowed_columns :x
|
|
1291
|
+
end
|
|
1284
1292
|
end
|
|
1285
1293
|
@c.strict_param_setting = false
|
|
1286
1294
|
@o1 = @c.new
|
|
1287
1295
|
DB.reset
|
|
1288
1296
|
end
|
|
1289
1297
|
|
|
1290
|
-
|
|
1298
|
+
deprecated "should raise errors if not all hash fields can be set and strict_param_setting is true" do
|
|
1291
1299
|
@c.strict_param_setting = true
|
|
1292
1300
|
|
|
1293
1301
|
proc{@c.new.set_all(:x => 1, :y => 2, :z=>3, :use_after_commit_rollback => false)}.must_raise(Sequel::MassAssignmentRestriction)
|
|
@@ -1300,19 +1308,19 @@ describe Sequel::Model, "#(set|update)_(all|only)" do
|
|
|
1300
1308
|
o.values.must_equal(:x => 1, :y => 2)
|
|
1301
1309
|
end
|
|
1302
1310
|
|
|
1303
|
-
|
|
1311
|
+
deprecated "#set_all should set all attributes including the primary key" do
|
|
1304
1312
|
@o1.set_all(:x => 1, :y => 2, :z=>3, :id=>4)
|
|
1305
1313
|
@o1.values.must_equal(:id =>4, :x => 1, :y => 2, :z=>3)
|
|
1306
1314
|
end
|
|
1307
1315
|
|
|
1308
|
-
|
|
1316
|
+
deprecated "#set_all should set not set restricted fields" do
|
|
1309
1317
|
@o1.use_after_commit_rollback.must_be_nil
|
|
1310
1318
|
@o1.set_all(:x => 1, :use_after_commit_rollback => true)
|
|
1311
1319
|
@o1.use_after_commit_rollback.must_be_nil
|
|
1312
1320
|
@o1.values.must_equal(:x => 1)
|
|
1313
1321
|
end
|
|
1314
1322
|
|
|
1315
|
-
|
|
1323
|
+
deprecated "#set_only should only set given attributes" do
|
|
1316
1324
|
@o1.set_only({:x => 1, :y => 2, :z=>3, :id=>4}, [:x, :y])
|
|
1317
1325
|
@o1.values.must_equal(:x => 1, :y => 2)
|
|
1318
1326
|
@o1.set_only({:x => 4, :y => 5, :z=>6, :id=>7}, :x, :y)
|
|
@@ -1321,7 +1329,7 @@ describe Sequel::Model, "#(set|update)_(all|only)" do
|
|
|
1321
1329
|
@o1.values.must_equal(:x => 9, :y => 8, :id=>7)
|
|
1322
1330
|
end
|
|
1323
1331
|
|
|
1324
|
-
|
|
1332
|
+
deprecated "#update_all should update all attributes" do
|
|
1325
1333
|
@c.new.update_all(:x => 1)
|
|
1326
1334
|
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE id = 10"]
|
|
1327
1335
|
@c.new.update_all(:y => 1)
|
|
@@ -1330,7 +1338,7 @@ describe Sequel::Model, "#(set|update)_(all|only)" do
|
|
|
1330
1338
|
DB.sqls.must_equal ["INSERT INTO items (z) VALUES (1)", "SELECT * FROM items WHERE id = 10"]
|
|
1331
1339
|
end
|
|
1332
1340
|
|
|
1333
|
-
|
|
1341
|
+
deprecated "#update_only should only update given attributes" do
|
|
1334
1342
|
@o1.update_only({:x => 1, :y => 2, :z=>3, :id=>4}, [:x])
|
|
1335
1343
|
DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE id = 10"]
|
|
1336
1344
|
@c.new.update_only({:x => 1, :y => 2, :z=>3, :id=>4}, :x)
|
|
@@ -1459,7 +1467,7 @@ describe Sequel::Model, "#each" do
|
|
|
1459
1467
|
@m = @model.load(:a => 1, :b => 2, :id => 4444)
|
|
1460
1468
|
end
|
|
1461
1469
|
|
|
1462
|
-
|
|
1470
|
+
deprecated "should iterate over the values" do
|
|
1463
1471
|
h = {}
|
|
1464
1472
|
@m.each{|k, v| h[k] = v}
|
|
1465
1473
|
h.must_equal(:a => 1, :b => 2, :id => 4444)
|