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
@@ -77,7 +77,7 @@ describe "Sequel::Plugins::TacticalEagerLoading" do
|
|
77
77
|
sql_match('SELECT * FROM t WHERE (t.id = 101) LIMIT 1', 'SELECT * FROM t WHERE (t.id = 102) LIMIT 1')
|
78
78
|
end
|
79
79
|
|
80
|
-
|
80
|
+
deprecated "association getter methods should not eagerly load the association if true is passed" do
|
81
81
|
ts.map{|x| x.parent(true)}.must_equal [ts[2], ts[3], nil, nil]
|
82
82
|
sql_match('SELECT * FROM t WHERE id = 101', 'SELECT * FROM t WHERE id = 102')
|
83
83
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
2
|
+
|
3
|
+
describe "Sequel::Plugins::ValidationHelpers" do
|
4
|
+
before do
|
5
|
+
@c = Class.new(Sequel::Model(:foo))
|
6
|
+
@c.class_eval do
|
7
|
+
columns :a, :b, :c
|
8
|
+
plugin :validation_contexts
|
9
|
+
def validate
|
10
|
+
errors.add(:a, 'bad') if a == 1 && validation_context == :create
|
11
|
+
errors.add(:b, 'bad') if b == 2 && validation_context == :update
|
12
|
+
errors.add(:c, 'bad') if c == 3 && validation_context == :foo
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should support :validation_context option to valid?" do
|
18
|
+
@c.new(:c=>3).valid?.must_equal true
|
19
|
+
@c.new(:c=>3).valid?(:validation_context=>:foo).must_equal false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should support :validation_context option to save?" do
|
23
|
+
@c.new(:c=>3).save
|
24
|
+
proc{@c.new(:c=>3).save(:validation_context=>:foo)}.must_raise Sequel::ValidationFailed
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise error if using a validation context on a frozen model instance" do
|
28
|
+
@c.new(:c=>3).freeze.valid?.must_equal true
|
29
|
+
proc{@c.new(:c=>3).freeze.valid?(:validation_context=>:foo)}.must_raise RuntimeError, TypeError
|
30
|
+
end
|
31
|
+
end
|
data/spec/guards_helper.rb
CHANGED
@@ -1588,22 +1588,24 @@ BasicRegularAndCompositeKeyAssociations = shared_description do
|
|
1588
1588
|
end
|
1589
1589
|
|
1590
1590
|
it "should work correctly with prepared_statements_association plugin" do
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1591
|
+
deprecated do
|
1592
|
+
@album.update(:artist => @artist)
|
1593
|
+
@album.add_tag(@tag)
|
1594
|
+
|
1595
|
+
@album.reload
|
1596
|
+
@artist.reload
|
1597
|
+
@tag.reload
|
1598
|
+
|
1599
|
+
[Tag, Album, Artist].each{|x| x.plugin :prepared_statements_associations}
|
1600
|
+
@album.artist.must_equal @artist
|
1601
|
+
@artist.first_album.must_equal @album
|
1602
|
+
@artist.albums.must_equal [@album]
|
1603
|
+
@album.tags.must_equal [@tag]
|
1604
|
+
@album.alias_tags.must_equal [@tag]
|
1605
|
+
@tag.albums.must_equal [@album]
|
1606
|
+
unless @no_many_through_many
|
1607
|
+
@album.first_tag.must_equal @tag
|
1608
|
+
end
|
1607
1609
|
end
|
1608
1610
|
end
|
1609
1611
|
|
@@ -2037,12 +2039,12 @@ describe "Sequel::Model Simple Associations" do
|
|
2037
2039
|
@artist.add_album(@album)
|
2038
2040
|
|
2039
2041
|
@artist.albums.must_equal [@album]
|
2040
|
-
@artist.albums
|
2041
|
-
@artist.albums
|
2042
|
+
@artist.albums{|ds| ds.exclude(:id=>@album.id)}.must_equal []
|
2043
|
+
@artist.albums{|ds| ds.filter(:id=>@album.id)}.must_equal [@album]
|
2042
2044
|
|
2043
2045
|
@album.artist.must_equal @artist
|
2044
|
-
@album.artist
|
2045
|
-
@album.artist
|
2046
|
+
@album.artist{|ds| ds.exclude(:id=>@artist.id)}.must_be_nil
|
2047
|
+
@album.artist{|ds| ds.filter(:id=>@artist.id)}.must_equal @artist
|
2046
2048
|
|
2047
2049
|
@artist.albums{|ds| ds.exclude(:id=>@album.id)}.must_equal []
|
2048
2050
|
@artist.albums{|ds| ds.filter(:id=>@album.id)}.must_equal [@album]
|
@@ -616,6 +616,10 @@ describe "Dataset UNION, EXCEPT, and INTERSECT" do
|
|
616
616
|
DB.drop_table?(:i1, :i2, :i3)
|
617
617
|
end
|
618
618
|
|
619
|
+
it "should give the correct results for UNION with an existing order" do
|
620
|
+
@ds1.order(:number).union(@ds2).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 20 30'
|
621
|
+
end
|
622
|
+
|
619
623
|
it "should give the correct results for simple UNION, EXCEPT, and INTERSECT" do
|
620
624
|
@ds1.union(@ds2).order(:number).map{|x| x[:number].to_s}.must_equal %w'10 20 30'
|
621
625
|
if @ds1.supports_intersect_except?
|
@@ -624,7 +628,10 @@ describe "Dataset UNION, EXCEPT, and INTERSECT" do
|
|
624
628
|
end
|
625
629
|
end
|
626
630
|
|
627
|
-
|
631
|
+
it "should give the correct results for UNION, EXCEPT, and INTERSECT when used with ordering and limits and offsets" do
|
632
|
+
[%w'10 30', %w'10 20 30'].must_include @ds1.limit(1).union(@ds2).order(:number).map{|x| x[:number].to_s}
|
633
|
+
[%w'10 30', %w'10 20 30'].must_include @ds1.offset(1).union(@ds2).order(:number).map{|x| x[:number].to_s}
|
634
|
+
|
628
635
|
@ds1.insert(:number=>8)
|
629
636
|
@ds2.insert(:number=>9)
|
630
637
|
@ds1.insert(:number=>38)
|
@@ -635,15 +642,31 @@ describe "Dataset UNION, EXCEPT, and INTERSECT" do
|
|
635
642
|
|
636
643
|
@ds1.reverse_order(:number).limit(1).union(@ds2).order(:number).map{|x| x[:number].to_s}.must_equal %w'9 10 30 38 39'
|
637
644
|
@ds2.reverse_order(:number).limit(1).union(@ds1).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 10 20 38 39'
|
645
|
+
@ds1.reverse_order(:number).limit(1, 1).union(@ds2).order(:number).map{|x| x[:number].to_s}.must_equal %w'9 10 20 30 39'
|
646
|
+
@ds2.reverse_order(:number).limit(1, 1).union(@ds1).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 10 20 30 38'
|
647
|
+
@ds1.reverse_order(:number).offset(1).union(@ds2).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 9 10 20 30 39'
|
648
|
+
@ds2.reverse_order(:number).offset(1).union(@ds1).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 9 10 20 30 38'
|
638
649
|
|
639
650
|
@ds1.union(@ds2.order(:number).limit(1)).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 9 10 20 38'
|
640
651
|
@ds2.union(@ds1.order(:number).limit(1)).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 9 10 30 39'
|
652
|
+
@ds1.union(@ds2.order(:number).limit(1, 1)).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 10 20 38'
|
653
|
+
@ds2.union(@ds1.order(:number).limit(1, 1)).order(:number).map{|x| x[:number].to_s}.must_equal %w'9 10 30 39'
|
654
|
+
@ds1.union(@ds2.order(:number).offset(1)).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 10 20 30 38 39'
|
655
|
+
@ds2.union(@ds1.order(:number).offset(1)).order(:number).map{|x| x[:number].to_s}.must_equal %w'9 10 20 30 38 39'
|
641
656
|
|
642
657
|
@ds1.union(@ds2).limit(2).order(:number).map{|x| x[:number].to_s}.must_equal %w'8 9'
|
643
658
|
@ds2.union(@ds1).reverse_order(:number).limit(2).map{|x| x[:number].to_s}.must_equal %w'39 38'
|
659
|
+
@ds1.union(@ds2).limit(2, 1).order(:number).map{|x| x[:number].to_s}.must_equal %w'9 10'
|
660
|
+
@ds2.union(@ds1).reverse_order(:number).limit(2, 1).map{|x| x[:number].to_s}.must_equal %w'38 30'
|
661
|
+
@ds1.union(@ds2).offset(1).order(:number).map{|x| x[:number].to_s}.must_equal %w'9 10 20 30 38 39'
|
662
|
+
@ds2.union(@ds1).reverse_order(:number).offset(1).map{|x| x[:number].to_s}.must_equal %w'38 30 20 10 9 8'
|
644
663
|
|
645
664
|
@ds1.reverse_order(:number).limit(2).union(@ds2.reverse_order(:number).limit(2)).order(:number).limit(3).map{|x| x[:number].to_s}.must_equal %w'20 30 38'
|
646
665
|
@ds2.order(:number).limit(2).union(@ds1.order(:number).limit(2)).reverse_order(:number).limit(3).map{|x| x[:number].to_s}.must_equal %w'10 9 8'
|
666
|
+
@ds1.reverse_order(:number).limit(2, 1).union(@ds2.reverse_order(:number).limit(2, 1)).order(:number).limit(3, 1).map{|x| x[:number].to_s}.must_equal %w'20 30'
|
667
|
+
@ds2.order(:number).limit(2, 1).union(@ds1.order(:number).limit(2, 1)).reverse_order(:number).limit(3, 1).map{|x| x[:number].to_s}.must_equal %w'20 10'
|
668
|
+
@ds1.reverse_order(:number).offset(1).union(@ds2.reverse_order(:number).offset(1)).order(:number).offset(1).map{|x| x[:number].to_s}.must_equal %w'9 10 20 30'
|
669
|
+
@ds2.order(:number).offset(1).union(@ds1.order(:number).offset(1)).reverse_order(:number).offset(1).map{|x| x[:number].to_s}.must_equal %w'38 30 20 10'
|
647
670
|
end
|
648
671
|
|
649
672
|
it "should give the correct results for compound UNION, EXCEPT, and INTERSECT" do
|
@@ -1511,7 +1534,7 @@ describe "Sequel::Dataset DSL support" do
|
|
1511
1534
|
@ds.insert(20, 10)
|
1512
1535
|
@ds.filter(:a=>20, :b=>10).all.must_equal [{:a=>20, :b=>10}]
|
1513
1536
|
@ds.filter([[:a, 20], [:b, 10]]).all.must_equal [{:a=>20, :b=>10}]
|
1514
|
-
@ds.filter({:a=>20}, {:b=>10}).all.must_equal [{:a=>20, :b=>10}]
|
1537
|
+
@ds.filter(Sequel.&({:a=>20}, {:b=>10})).all.must_equal [{:a=>20, :b=>10}]
|
1515
1538
|
@ds.filter(Sequel.|({:a=>20}, {:b=>5})).all.must_equal [{:a=>20, :b=>10}]
|
1516
1539
|
@ds.filter(Sequel.~(:a=>10)).all.must_equal [{:a=>20, :b=>10}]
|
1517
1540
|
end
|
@@ -86,7 +86,7 @@ describe "Sequel::Model basic support" do
|
|
86
86
|
i.save.must_be_nil
|
87
87
|
end
|
88
88
|
|
89
|
-
|
89
|
+
deprecated "#should respect after_commit, after_rollback, after_destroy_commit, and after_destroy_rollback hooks" do
|
90
90
|
i = Item.create(:name=>'J')
|
91
91
|
i.use_transactions = true
|
92
92
|
def i.hooks
|
@@ -237,7 +237,6 @@ describe "Many Through Many Plugin" do
|
|
237
237
|
Artist[@artist3.id].albums.map{|x| x.name}.sort.must_equal %w'B C'
|
238
238
|
Artist[@artist4.id].albums.map{|x| x.name}.sort.must_equal %w'B D'
|
239
239
|
|
240
|
-
Artist.plugin :prepared_statements_associations
|
241
240
|
Artist[@artist1.id].albums.map{|x| x.name}.sort.must_equal %w'A D'
|
242
241
|
Artist[@artist2.id].albums.map{|x| x.name}.sort.must_equal %w'A C'
|
243
242
|
Artist[@artist3.id].albums.map{|x| x.name}.sort.must_equal %w'B C'
|
@@ -294,13 +293,12 @@ describe "Many Through Many Plugin" do
|
|
294
293
|
end
|
295
294
|
|
296
295
|
it "should handle typical case with 3 join tables" do
|
297
|
-
Artist.many_through_many :related_artists, [[:albums_artists, :artist_id, :album_id], [:albums, :id, :id], [:albums_artists, :album_id, :artist_id]], :class=>Artist, :distinct=>true
|
296
|
+
Artist.many_through_many :related_artists, [[:albums_artists, :artist_id, :album_id], [:albums, :id, :id], [:albums_artists, :album_id, :artist_id]], :class=>Artist, :distinct=>true, :delay_pks=>false
|
298
297
|
Artist[@artist1.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 2 4'
|
299
298
|
Artist[@artist2.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 2 3'
|
300
299
|
Artist[@artist3.id].related_artists.map{|x| x.name}.sort.must_equal %w'2 3 4'
|
301
300
|
Artist[@artist4.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 3 4'
|
302
301
|
|
303
|
-
Artist.plugin :prepared_statements_associations
|
304
302
|
Artist[@artist1.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 2 4'
|
305
303
|
Artist[@artist2.id].related_artists.map{|x| x.name}.sort.must_equal %w'1 2 3'
|
306
304
|
Artist[@artist3.id].related_artists.map{|x| x.name}.sort.must_equal %w'2 3 4'
|
@@ -366,7 +364,6 @@ describe "Many Through Many Plugin" do
|
|
366
364
|
Artist[@artist3.id].related_albums.map{|x| x.name}.sort.must_equal %w'A B D'
|
367
365
|
Artist[@artist4.id].related_albums.map{|x| x.name}.sort.must_equal %w'B D'
|
368
366
|
|
369
|
-
Artist.plugin :prepared_statements_associations
|
370
367
|
Artist[@artist1.id].related_albums.map{|x| x.name}.sort.must_equal %w'A B C'
|
371
368
|
Artist[@artist2.id].related_albums.map{|x| x.name}.sort.must_equal %w'A B C D'
|
372
369
|
Artist[@artist3.id].related_albums.map{|x| x.name}.sort.must_equal %w'A B D'
|
@@ -1193,11 +1190,11 @@ describe "AssociationPks plugin" do
|
|
1193
1190
|
end
|
1194
1191
|
class ::Artist < Sequel::Model
|
1195
1192
|
plugin :association_pks
|
1196
|
-
one_to_many :albums, :order=>:id
|
1193
|
+
one_to_many :albums, :order=>:id, :delay_pks=>false
|
1197
1194
|
end
|
1198
1195
|
class ::Album < Sequel::Model
|
1199
1196
|
plugin :association_pks
|
1200
|
-
many_to_many :tags, :order=>:id
|
1197
|
+
many_to_many :tags, :order=>:id, :delay_pks=>false
|
1201
1198
|
end
|
1202
1199
|
class ::Tag < Sequel::Model
|
1203
1200
|
end
|
@@ -1293,7 +1290,7 @@ describe "AssociationPks plugin" do
|
|
1293
1290
|
Vocalist.order(:first, :last).all.map{|a| a.hit_pks.sort}.must_equal [[@h1, @h2, @h3], [@h2], []]
|
1294
1291
|
end
|
1295
1292
|
|
1296
|
-
|
1293
|
+
deprecated "should handle :delay_pks=>true association option for new instances" do
|
1297
1294
|
album_class = Class.new(Album)
|
1298
1295
|
album_class.many_to_many :tags, :clone=>:tags, :delay_pks=>true, :join_table=>:albums_tags, :left_key=>:album_id
|
1299
1296
|
album = album_class.new(:name=>'test album')
|
@@ -1309,7 +1306,7 @@ describe "AssociationPks plugin" do
|
|
1309
1306
|
album_class.with_pk!(album.pk).tag_pks.sort.must_equal []
|
1310
1307
|
end
|
1311
1308
|
|
1312
|
-
it "should handle :
|
1309
|
+
it "should handle :delay_pks=>:always association option for existing instances" do
|
1313
1310
|
album_class = Class.new(Album)
|
1314
1311
|
album_class.many_to_many :tags, :clone=>:tags, :delay_pks=>:always, :join_table=>:albums_tags, :left_key=>:album_id
|
1315
1312
|
album = album_class.with_pk!(@al1)
|
@@ -1368,7 +1365,7 @@ describe "AssociationPks plugin" do
|
|
1368
1365
|
|
1369
1366
|
it "should set associated right-side cpks correctly for a one_to_many association" do
|
1370
1367
|
Album.use_transactions = true
|
1371
|
-
Album.one_to_many :vocalists, :order=>:first
|
1368
|
+
Album.one_to_many :vocalists, :order=>:first, :delay_pks=>false
|
1372
1369
|
Album.order(:id).all.map{|a| a.vocalist_pks.sort}.must_equal [[@v1, @v2, @v3], [], []]
|
1373
1370
|
|
1374
1371
|
Album[@al2].vocalist_pks = [@v1, @v3]
|
@@ -1389,7 +1386,7 @@ describe "AssociationPks plugin" do
|
|
1389
1386
|
|
1390
1387
|
it "should set associated right-side cpks correctly for a many_to_many association" do
|
1391
1388
|
Album.use_transactions = true
|
1392
|
-
Album.many_to_many :vocalists, :join_table=>:albums_vocalists, :right_key=>[:first, :last], :order=>:first
|
1389
|
+
Album.many_to_many :vocalists, :join_table=>:albums_vocalists, :right_key=>[:first, :last], :order=>:first, :delay_pks=>false
|
1393
1390
|
|
1394
1391
|
@db[:albums_vocalists].filter(:album_id=>@al1).select_order_map([:first, :last]).must_equal [@v1, @v2, @v3]
|
1395
1392
|
Album[@al1].vocalist_pks = [@v1, @v3]
|
@@ -1412,7 +1409,7 @@ describe "AssociationPks plugin" do
|
|
1412
1409
|
|
1413
1410
|
it "should set associated pks correctly with left-side cpks for a one_to_many association" do
|
1414
1411
|
Vocalist.use_transactions = true
|
1415
|
-
Vocalist.one_to_many :instruments, :key=>[:first, :last], :order=>:id
|
1412
|
+
Vocalist.one_to_many :instruments, :key=>[:first, :last], :order=>:id, :delay_pks=>false
|
1416
1413
|
Vocalist.order(:first, :last).all.map{|a| a.instrument_pks.sort}.must_equal [[@i1, @i2, @i3], [], []]
|
1417
1414
|
|
1418
1415
|
Vocalist[@v2].instrument_pks = [@i1, @i3]
|
@@ -1433,7 +1430,7 @@ describe "AssociationPks plugin" do
|
|
1433
1430
|
|
1434
1431
|
it "should set associated pks correctly with left-side cpks for a many_to_many association" do
|
1435
1432
|
Vocalist.use_transactions = true
|
1436
|
-
Vocalist.many_to_many :instruments, :join_table=>:vocalists_instruments, :left_key=>[:first, :last], :order=>:id
|
1433
|
+
Vocalist.many_to_many :instruments, :join_table=>:vocalists_instruments, :left_key=>[:first, :last], :order=>:id, :delay_pks=>false
|
1437
1434
|
|
1438
1435
|
@db[:vocalists_instruments].filter([:first, :last]=>[@v1]).select_order_map(:instrument_id).must_equal [@i1, @i2, @i3]
|
1439
1436
|
Vocalist[@v1].instrument_pks = [@i1, @i3]
|
@@ -1456,7 +1453,7 @@ describe "AssociationPks plugin" do
|
|
1456
1453
|
|
1457
1454
|
it "should set associated right-side cpks correctly with left-side cpks for a one_to_many association" do
|
1458
1455
|
Vocalist.use_transactions = true
|
1459
|
-
Vocalist.one_to_many :hits, :key=>[:first, :last], :order=>:week
|
1456
|
+
Vocalist.one_to_many :hits, :key=>[:first, :last], :order=>:week, :delay_pks=>false
|
1460
1457
|
Vocalist.order(:first, :last).all.map{|a| a.hit_pks.sort}.must_equal [[@h1, @h2, @h3], [], []]
|
1461
1458
|
|
1462
1459
|
Vocalist[@v2].hit_pks = [@h1, @h3]
|
@@ -1477,7 +1474,7 @@ describe "AssociationPks plugin" do
|
|
1477
1474
|
|
1478
1475
|
it "should set associated right-side cpks correctly with left-side cpks for a many_to_many association" do
|
1479
1476
|
Vocalist.use_transactions = true
|
1480
|
-
Vocalist.many_to_many :hits, :join_table=>:vocalists_hits, :left_key=>[:first, :last], :right_key=>[:year, :week], :order=>:week
|
1477
|
+
Vocalist.many_to_many :hits, :join_table=>:vocalists_hits, :left_key=>[:first, :last], :right_key=>[:year, :week], :order=>:week, :delay_pks=>false
|
1481
1478
|
|
1482
1479
|
@db[:vocalists_hits].filter([:first, :last]=>[@v1]).select_order_map([:year, :week]).must_equal [@h1, @h2, @h3]
|
1483
1480
|
Vocalist[@v1].hit_pks = [@h1, @h3]
|
@@ -1819,7 +1816,6 @@ describe "Sequel::Plugins::PreparedStatements" do
|
|
1819
1816
|
Integer :i
|
1820
1817
|
end
|
1821
1818
|
@c = Class.new(Sequel::Model(@db[:ps_test]))
|
1822
|
-
@c.plugin :prepared_statements_with_pk
|
1823
1819
|
end
|
1824
1820
|
before do
|
1825
1821
|
@c.dataset.delete
|
@@ -1895,7 +1891,6 @@ describe "Sequel::Plugins::PreparedStatements with schema changes" do
|
|
1895
1891
|
@c.one_to_many :ps_tests, :key=>:id, :class=>@c
|
1896
1892
|
@c.many_to_many :mps_tests, :left_key=>:id, :right_key=>:id, :class=>@c, :join_table=>Sequel[:ps_test].as(:x)
|
1897
1893
|
@c.plugin :prepared_statements
|
1898
|
-
@c.plugin :prepared_statements_associations
|
1899
1894
|
end
|
1900
1895
|
after do
|
1901
1896
|
@db.drop_table?(:ps_test)
|
@@ -396,20 +396,22 @@ end
|
|
396
396
|
|
397
397
|
describe "Dataset#unbind" do
|
398
398
|
before do
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
399
|
+
deprecated do
|
400
|
+
@ds = ds = DB[:items]
|
401
|
+
@ct = proc do |t, v|
|
402
|
+
DB.create_table!(:items) do
|
403
|
+
column :c, t
|
404
|
+
end
|
405
|
+
ds.insert(:c=>v)
|
403
406
|
end
|
404
|
-
|
407
|
+
@u = proc{|ds1| ds2, bv = ds1.unbind; ds2.call(:first, bv)}
|
405
408
|
end
|
406
|
-
@u = proc{|ds1| ds2, bv = ds1.unbind; ds2.call(:first, bv)}
|
407
409
|
end
|
408
410
|
after do
|
409
411
|
DB.drop_table?(:items)
|
410
412
|
end
|
411
413
|
|
412
|
-
|
414
|
+
deprecated "should unbind values assigned to equality and inequality statements" do
|
413
415
|
@ct[Integer, 10]
|
414
416
|
@u[@ds.filter(:c=>10)].must_equal(:c=>10)
|
415
417
|
@u[@ds.exclude(:c=>10)].must_be_nil
|
@@ -420,46 +422,52 @@ describe "Dataset#unbind" do
|
|
420
422
|
end
|
421
423
|
|
422
424
|
cspecify "should handle numerics and strings", [:odbc], [:swift, :sqlite] do
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
425
|
+
deprecated do
|
426
|
+
@ct[Integer, 10]
|
427
|
+
@u[@ds.filter(:c=>10)].must_equal(:c=>10)
|
428
|
+
@ct[Float, 0.0]
|
429
|
+
@u[@ds.filter{c < 1}].must_equal(:c=>0.0)
|
430
|
+
@ct[String, 'foo']
|
431
|
+
@u[@ds.filter(:c=>'foo')].must_equal(:c=>'foo')
|
429
432
|
|
430
|
-
|
431
|
-
|
433
|
+
DB.create_table!(:items) do
|
434
|
+
BigDecimal :c, :size=>[15,2]
|
435
|
+
end
|
436
|
+
@ds.insert(:c=>BigDecimal.new('1.1'))
|
437
|
+
@u[@ds.filter{c > 0}].must_equal(:c=>BigDecimal.new('1.1'))
|
432
438
|
end
|
433
|
-
@ds.insert(:c=>BigDecimal.new('1.1'))
|
434
|
-
@u[@ds.filter{c > 0}].must_equal(:c=>BigDecimal.new('1.1'))
|
435
439
|
end
|
436
440
|
|
437
441
|
cspecify "should handle dates and times", [:do], [:jdbc, :mssql], [:jdbc, :sqlite], [:swift], [:tinytds], :oracle do
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
442
|
+
deprecated do
|
443
|
+
@ct[Date, Date.today]
|
444
|
+
@u[@ds.filter(:c=>Date.today)].must_equal(:c=>Date.today)
|
445
|
+
t = Time.now
|
446
|
+
@ct[Time, t]
|
447
|
+
@u[@ds.filter{c < t + 1}][:c].to_i.must_equal t.to_i
|
448
|
+
end
|
443
449
|
end
|
444
450
|
|
445
|
-
|
451
|
+
deprecated "should handle QualifiedIdentifiers" do
|
446
452
|
@ct[Integer, 10]
|
447
453
|
@u[@ds.filter{items[:c] > 1}].must_equal(:c=>10)
|
448
454
|
end
|
449
455
|
|
450
456
|
cspecify "should handle deep nesting", :h2 do
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
457
|
+
deprecated do
|
458
|
+
DB.create_table!(:items) do
|
459
|
+
Integer :a
|
460
|
+
Integer :b
|
461
|
+
Integer :c
|
462
|
+
Integer :d
|
463
|
+
end
|
464
|
+
@ds.insert(:a=>2, :b=>0, :c=>3, :d=>5)
|
465
|
+
@u[@ds.filter{a > 1}.and{b < 2}.or(:c=>3).and(Sequel.case({~Sequel.expr(:d=>4)=>1}, 0) => 1)].must_equal(:a=>2, :b=>0, :c=>3, :d=>5)
|
466
|
+
@u[@ds.filter{a > 1}.and{b < 2}.or(:c=>3).and(Sequel.case({~Sequel.expr(:d=>5)=>1}, 0) => 1)].must_be_nil
|
456
467
|
end
|
457
|
-
@ds.insert(:a=>2, :b=>0, :c=>3, :d=>5)
|
458
|
-
@u[@ds.filter{a > 1}.and{b < 2}.or(:c=>3).and(Sequel.case({~Sequel.expr(:d=>4)=>1}, 0) => 1)].must_equal(:a=>2, :b=>0, :c=>3, :d=>5)
|
459
|
-
@u[@ds.filter{a > 1}.and{b < 2}.or(:c=>3).and(Sequel.case({~Sequel.expr(:d=>5)=>1}, 0) => 1)].must_be_nil
|
460
468
|
end
|
461
469
|
|
462
|
-
|
470
|
+
deprecated "should handle case where the same variable has the same value in multiple places " do
|
463
471
|
@ct[Integer, 1]
|
464
472
|
@u[@ds.filter{c > 1}.or{c < 1}.invert].must_equal(:c=>1)
|
465
473
|
@u[@ds.filter{c > 1}.or{c < 1}].must_be_nil
|
@@ -20,22 +20,19 @@ Sequel::Deprecation.backtrace_filter = lambda{|line, lineno| lineno < 4 || line
|
|
20
20
|
Sequel.split_symbols = false if ENV['SEQUEL_NO_SPLIT_SYMBOLS']
|
21
21
|
Sequel::Database.extension :columns_introspection if ENV['SEQUEL_COLUMNS_INTROSPECTION']
|
22
22
|
Sequel::Model.cache_associations = false if ENV['SEQUEL_NO_CACHE_ASSOCIATIONS']
|
23
|
-
if ENV['SEQUEL_MODEL_PREPARED_STATEMENTS']
|
24
|
-
Sequel::Model.plugin :prepared_statements
|
25
|
-
Sequel::Model.plugin :prepared_statements_associations
|
26
|
-
end
|
23
|
+
Sequel::Model.plugin :prepared_statements if ENV['SEQUEL_MODEL_PREPARED_STATEMENTS']
|
27
24
|
Sequel::Model.use_transactions = false
|
28
|
-
Sequel.cache_anonymous_models = false
|
25
|
+
Sequel::Model.cache_anonymous_models = false
|
29
26
|
|
30
27
|
require './spec/guards_helper'
|
31
28
|
|
32
29
|
IDENTIFIER_MANGLING = !ENV['SEQUEL_NO_MANGLE'] unless defined?(IDENTIFIER_MANGLING)
|
33
30
|
|
34
31
|
unless defined?(DB)
|
35
|
-
|
36
|
-
|
37
|
-
DB = Sequel.connect(ENV['SEQUEL_INTEGRATION_URL'], opts)
|
32
|
+
# SEQUEL5: Remove :identifier_mangling=>false
|
33
|
+
DB = Sequel.connect(ENV['SEQUEL_INTEGRATION_URL'], :identifier_mangling=>false)
|
38
34
|
DB.extension(:freeze_datasets) if ENV['SEQUEL_FREEZE_DATASETS']
|
35
|
+
DB.extension(:identifier_mangling) if IDENTIFIER_MANGLING
|
39
36
|
end
|
40
37
|
|
41
38
|
if DB.adapter_scheme == :ibmdb || (DB.adapter_scheme == :ado && DB.database_type == :access)
|