sequel 4.48.0 → 4.49.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +56 -0
  3. data/doc/advanced_associations.rdoc +1 -1
  4. data/doc/opening_databases.rdoc +3 -2
  5. data/doc/release_notes/4.49.0.txt +222 -0
  6. data/lib/sequel/adapters/ibmdb.rb +6 -1
  7. data/lib/sequel/adapters/jdbc.rb +3 -1
  8. data/lib/sequel/adapters/jdbc/h2.rb +10 -1
  9. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -2
  10. data/lib/sequel/adapters/jdbc/sqlserver.rb +9 -2
  11. data/lib/sequel/adapters/mock.rb +3 -0
  12. data/lib/sequel/adapters/mysql2.rb +1 -1
  13. data/lib/sequel/adapters/postgres.rb +2 -1
  14. data/lib/sequel/adapters/shared/mysql.rb +4 -1
  15. data/lib/sequel/adapters/shared/oracle.rb +26 -3
  16. data/lib/sequel/connection_pool.rb +9 -2
  17. data/lib/sequel/connection_pool/sharded_single.rb +1 -1
  18. data/lib/sequel/connection_pool/sharded_threaded.rb +1 -1
  19. data/lib/sequel/connection_pool/single.rb +2 -2
  20. data/lib/sequel/connection_pool/threaded.rb +2 -2
  21. data/lib/sequel/database/connecting.rb +3 -3
  22. data/lib/sequel/database/dataset_defaults.rb +14 -1
  23. data/lib/sequel/dataset.rb +1 -1
  24. data/lib/sequel/dataset/actions.rb +54 -0
  25. data/lib/sequel/dataset/dataset_module.rb +58 -0
  26. data/lib/sequel/dataset/query.rb +3 -3
  27. data/lib/sequel/exceptions.rb +8 -0
  28. data/lib/sequel/extensions/_model_pg_row.rb +5 -2
  29. data/lib/sequel/extensions/current_datetime_timestamp.rb +2 -1
  30. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  31. data/lib/sequel/extensions/duplicate_columns_handler.rb +2 -2
  32. data/lib/sequel/extensions/migration.rb +5 -2
  33. data/lib/sequel/extensions/null_dataset.rb +1 -0
  34. data/lib/sequel/model/associations.rb +3 -0
  35. data/lib/sequel/model/base.rb +10 -55
  36. data/lib/sequel/model/dataset_module.rb +5 -43
  37. data/lib/sequel/model/errors.rb +2 -1
  38. data/lib/sequel/model/inflections.rb +17 -5
  39. data/lib/sequel/plugins/active_model.rb +2 -2
  40. data/lib/sequel/plugins/class_table_inheritance.rb +1 -0
  41. data/lib/sequel/plugins/composition.rb +2 -2
  42. data/lib/sequel/plugins/dataset_associations.rb +25 -13
  43. data/lib/sequel/plugins/json_serializer.rb +2 -2
  44. data/lib/sequel/plugins/pg_row.rb +4 -2
  45. data/lib/sequel/plugins/serialization.rb +1 -0
  46. data/lib/sequel/plugins/single_table_inheritance.rb +6 -1
  47. data/lib/sequel/plugins/touch.rb +2 -1
  48. data/lib/sequel/plugins/validation_helpers.rb +10 -2
  49. data/lib/sequel/sql.rb +16 -7
  50. data/lib/sequel/version.rb +1 -1
  51. data/spec/adapters/mssql_spec.rb +4 -4
  52. data/spec/adapters/mysql_spec.rb +5 -1
  53. data/spec/adapters/oracle_spec.rb +4 -0
  54. data/spec/bin_spec.rb +7 -1
  55. data/spec/core/connection_pool_spec.rb +28 -14
  56. data/spec/core/database_spec.rb +149 -0
  57. data/spec/core/dataset_spec.rb +173 -0
  58. data/spec/extensions/class_table_inheritance_spec.rb +58 -17
  59. data/spec/extensions/composition_spec.rb +13 -0
  60. data/spec/extensions/dataset_associations_spec.rb +12 -0
  61. data/spec/extensions/many_through_many_spec.rb +4 -4
  62. data/spec/extensions/null_dataset_spec.rb +1 -1
  63. data/spec/extensions/serialization_spec.rb +1 -1
  64. data/spec/extensions/single_table_inheritance_spec.rb +16 -0
  65. data/spec/extensions/validation_helpers_spec.rb +1 -2
  66. data/spec/integration/associations_test.rb +8 -0
  67. data/spec/integration/plugin_test.rb +8 -3
  68. data/spec/model/association_reflection_spec.rb +1 -1
  69. data/spec/model/associations_spec.rb +29 -9
  70. data/spec/model/class_dataset_methods_spec.rb +6 -0
  71. data/spec/model/eager_loading_spec.rb +8 -8
  72. data/spec/model/plugins_spec.rb +34 -0
  73. data/spec/model/record_spec.rb +1 -1
  74. data/spec/spec_config.rb +2 -0
  75. metadata +5 -2
@@ -73,7 +73,7 @@ describe "null_dataset extension" do
73
73
  @i.must_equal 1
74
74
  end
75
75
 
76
- it "should have nullify! method modify receiver" do
76
+ deprecated "should have nullify! method modify receiver" do
77
77
  ds = @db[:table]
78
78
  # SEQUEL5: Remove
79
79
  unless ds.frozen?
@@ -59,7 +59,7 @@ describe "Serialization plugin" do
59
59
  DB.sqls.map{|s| s.sub("...\n", '')}.must_equal ["INSERT INTO items (abc) VALUES ('--- 1\n')", "INSERT INTO items (abc) VALUES ('--- hello\n')"]
60
60
  end
61
61
 
62
- it "serialized_columns should be the columns serialized" do
62
+ deprecated "serialized_columns should be the columns serialized" do
63
63
  @c.plugin :serialization, :yaml, :abc
64
64
  @c.serialized_columns.must_equal [:abc]
65
65
  end
@@ -19,6 +19,22 @@ describe Sequel::Model, "single table inheritance plugin" do
19
19
  Object.send(:remove_const, :StiTest)
20
20
  end
21
21
 
22
+ describe ".sti_load" do
23
+ it "should load instances of the correct type" do
24
+ StiTest.sti_load(:id => 3).must_be_instance_of StiTest
25
+ StiTest.sti_load(:id => 3, :kind => 'StiTestSub1').must_be_instance_of StiTestSub1
26
+ StiTest.sti_load(:id => 3, :kind => 'StiTestSub2').must_be_instance_of StiTestSub2
27
+ end
28
+ end
29
+
30
+ describe ".sti_class_from_sti_key" do
31
+ it "should load the correct subclass based on the key" do
32
+ StiTest.sti_class_from_sti_key('StiTest').must_equal StiTest
33
+ StiTest.sti_class_from_sti_key('StiTestSub1').must_equal StiTestSub1
34
+ StiTest.sti_class_from_sti_key('StiTestSub2').must_equal StiTestSub2
35
+ end
36
+ end
37
+
22
38
  it "should freeze sti metadata when freezing model class" do
23
39
  StiTest.freeze
24
40
  StiTest.sti_dataset.frozen?.must_equal true
@@ -86,7 +86,7 @@ describe "Sequel::Plugins::ValidationHelpers" do
86
86
  @m.must_be :valid?
87
87
  end
88
88
 
89
- it "should support modifying default options for all models" do
89
+ deprecated "should support modifying default options for all models" do
90
90
  @c.set_validations{validates_presence(:value)}
91
91
  @m.wont_be :valid?
92
92
  @m.errors.must_equal(:value=>['is not present'])
@@ -104,7 +104,6 @@ describe "Sequel::Plugins::ValidationHelpers" do
104
104
  @m.wont_be :valid?
105
105
  @m.errors.must_equal(:value=>["was not entered"])
106
106
 
107
-
108
107
  c = Class.new(Sequel::Model)
109
108
  c.class_eval do
110
109
  plugin :validation_helpers
@@ -1621,6 +1621,7 @@ BasicRegularAndCompositeKeyAssociations = shared_description do
1621
1621
  Album.first_tags.all.must_equal []
1622
1622
  Artist.tags.all.must_equal []
1623
1623
  Artist.first_tags.all.must_equal []
1624
+ Tag.tags.all.must_equal []
1624
1625
  end
1625
1626
  Artist.albums.tags.all.must_equal []
1626
1627
 
@@ -1637,6 +1638,7 @@ BasicRegularAndCompositeKeyAssociations = shared_description do
1637
1638
  Album.first_tags.all.must_equal [@tag]
1638
1639
  Artist.tags.all.must_equal [@tag]
1639
1640
  Artist.first_tags.all.must_equal [@tag]
1641
+ Tag.tags.all.must_equal [@tag]
1640
1642
  end
1641
1643
  Artist.albums.tags.all.must_equal [@tag]
1642
1644
 
@@ -1652,6 +1654,7 @@ BasicRegularAndCompositeKeyAssociations = shared_description do
1652
1654
  Album.first_tags.order(:name).all.must_equal [@tag, tag]
1653
1655
  Artist.tags.order(:name).all.must_equal [@tag, tag]
1654
1656
  Artist.first_tags.order(:name).all.must_equal [@tag, tag]
1657
+ Tag.tags.order(:name).all.must_equal [@tag, tag]
1655
1658
  end
1656
1659
  Artist.albums.tags.order(:name).all.must_equal [@tag, tag]
1657
1660
 
@@ -1664,6 +1667,7 @@ BasicRegularAndCompositeKeyAssociations = shared_description do
1664
1667
  Album.filter(Album.qualified_primary_key_hash(album.pk)).first_tags.all.must_equal [tag]
1665
1668
  Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).tags.all.must_equal [tag]
1666
1669
  Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).first_tags.all.must_equal [tag]
1670
+ Tag.filter(Tag.qualified_primary_key_hash(tag.pk)).tags.all.must_equal [tag]
1667
1671
  end
1668
1672
  Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.tags.all.must_equal [tag]
1669
1673
 
@@ -1891,6 +1895,8 @@ describe "Sequel::Model Simple Associations" do
1891
1895
  class ::Tag < Sequel::Model(@db)
1892
1896
  plugin :dataset_associations
1893
1897
  many_to_many :albums
1898
+ plugin :many_through_many
1899
+ many_through_many :tags, [[:albums_tags, :tag_id, :album_id], [:albums, :id, :artist_id], [:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :class=>:Tag
1894
1900
  end
1895
1901
  @album = Album.create(:name=>'Al')
1896
1902
  @artist = Artist.create(:name=>'Ar')
@@ -2184,6 +2190,8 @@ describe "Sequel::Model Composite Key Associations" do
2184
2190
  set_primary_key [:id1, :id2]
2185
2191
  unrestrict_primary_key
2186
2192
  many_to_many :albums, :right_key=>[:album_id1, :album_id2], :left_key=>[:tag_id1, :tag_id2]
2193
+ plugin :many_through_many
2194
+ many_through_many :tags, [[:albums_tags, [:tag_id1, :tag_id2], [:album_id1, :album_id2]], [:albums, [:id1, :id2], [:artist_id1, :artist_id2]], [:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :class=>:Tag
2187
2195
  end
2188
2196
  @album = Album.create(:name=>'Al', :id1=>1, :id2=>2)
2189
2197
  @artist = Artist.create(:name=>'Ar', :id1=>3, :id2=>4)
@@ -38,7 +38,8 @@ describe "Class Table Inheritance Plugin" do
38
38
  class ::Staff < Employee
39
39
  many_to_one :manager
40
40
  end
41
-
41
+ class ::Intern < Employee
42
+ end
42
43
 
43
44
  @i1 = @db[:employees].insert(:name=>'E', :kind=>'Employee')
44
45
  @i2 = @db[:employees].insert(:name=>'S', :kind=>'Staff')
@@ -51,9 +52,10 @@ describe "Class Table Inheritance Plugin" do
51
52
  @db[:managers].insert(:id=>@i5, :num_staff=>2)
52
53
  @db[:executives].insert(:id=>@i5, :num_managers=>1)
53
54
  @db[:staff].insert(:id=>@i2, :manager_id=>@i4)
55
+ @i6 = @db[:employees].insert(:name=>'I', :kind=>'Intern')
54
56
  end
55
57
  after do
56
- [:Ceo, :Executive, :Manager, :Staff, :Employee].each{|s| Object.send(:remove_const, s)}
58
+ [:Intern, :Ceo, :Executive, :Manager, :Staff, :Employee].each{|s| Object.send(:remove_const, s)}
57
59
  end
58
60
  after(:all) do
59
61
  @db.drop_table? :staff, :executives, :managers, :employees
@@ -65,7 +67,8 @@ describe "Class Table Inheritance Plugin" do
65
67
  Staff.load(:id=>@i2, :name=>'S', :kind=>'Staff'),
66
68
  Manager.load(:id=>@i3, :name=>'M', :kind=>'Manager'),
67
69
  Executive.load(:id=>@i4, :name=>'Ex', :kind=>'Executive'),
68
- Ceo.load(:id=>@i5, :name=>'C', :kind=>'Ceo')
70
+ Ceo.load(:id=>@i5, :name=>'C', :kind=>'Ceo'),
71
+ Intern.load(:id=>@i6, :name=>'I', :kind=>'Intern'),
69
72
  ]
70
73
  end
71
74
 
@@ -102,6 +105,7 @@ describe "Class Table Inheritance Plugin" do
102
105
  Manager.db_schema.keys.sort_by{|x| x.to_s}.must_equal [:id, :kind, :name, :num_staff]
103
106
  Executive.db_schema.keys.sort_by{|x| x.to_s}.must_equal [:id, :kind, :name, :num_managers, :num_staff]
104
107
  Ceo.db_schema.keys.sort_by{|x| x.to_s}.must_equal [:id, :kind, :name, :num_managers, :num_staff]
108
+ Intern.db_schema.keys.sort_by{|x| x.to_s}.must_equal [:id, :kind, :name]
105
109
  end
106
110
 
107
111
  it "should include columns for tables for ancestor classes" do
@@ -110,6 +114,7 @@ describe "Class Table Inheritance Plugin" do
110
114
  Manager.columns.must_equal [:id, :name, :kind, :num_staff]
111
115
  Executive.columns.must_equal [:id, :name, :kind, :num_staff, :num_managers]
112
116
  Ceo.columns.must_equal [:id, :name, :kind, :num_staff, :num_managers]
117
+ Intern.columns.must_equal [:id, :name, :kind]
113
118
  end
114
119
 
115
120
  it "should delete rows from all tables" do
@@ -286,7 +286,7 @@ describe Sequel::Model::Associations::AssociationReflection do
286
286
  def @c.name() "C" end
287
287
  end
288
288
 
289
- it "#eager_loading_predicate_key should be an alias of predicate_key for backwards compatibility" do
289
+ deprecated "#eager_loading_predicate_key should be an alias of predicate_key for backwards compatibility" do
290
290
  @c.one_to_many :cs, :class=>@c
291
291
  @c.dataset.literal(@c.association_reflection(:cs).eager_loading_predicate_key).must_equal 'foo.c_id'
292
292
  end
@@ -679,7 +679,7 @@ describe Sequel::Model, "many_to_one" do
679
679
  p.associations[:parent].must_equal :foo
680
680
  end
681
681
 
682
- it "should raise error and not call internal add or remove method if before callback returns false, even if raise_on_save_failure is false" do
682
+ deprecated "should raise error and not call internal add or remove method if before callback returns false, even if raise_on_save_failure is false" do
683
683
  p = @c2.new
684
684
  c = @c2.load(:id=>123)
685
685
  p.raise_on_save_failure = false
@@ -1126,7 +1126,7 @@ describe Sequel::Model, "one_to_one" do
1126
1126
  parent.pk.must_equal 20
1127
1127
  end
1128
1128
 
1129
- it "should raise error and not call internal add or remove method if before callback returns false, even if raise_on_save_failure is false" do
1129
+ deprecated "should raise error and not call internal add or remove method if before callback returns false, even if raise_on_save_failure is false" do
1130
1130
  p = @c2.load(:id=>321)
1131
1131
  c = @c2.load(:id=>123)
1132
1132
  p.raise_on_save_failure = false
@@ -1141,6 +1141,21 @@ describe Sequel::Model, "one_to_one" do
1141
1141
  proc{p.parent = nil}.must_raise(Sequel::HookFailed)
1142
1142
  end
1143
1143
 
1144
+ it "should raise error and not call internal add or remove method if before callback calls cancel_action, even if raise_on_save_failure is false" do
1145
+ p = @c2.load(:id=>321)
1146
+ c = @c2.load(:id=>123)
1147
+ p.raise_on_save_failure = false
1148
+ @c2.one_to_one :parent, :class => @c2, :before_set=>:bs
1149
+ def p.bs(x) cancel_action end
1150
+ def p._parent=; raise; end
1151
+ proc{p.parent = c}.must_raise(Sequel::HookFailed)
1152
+
1153
+ p.associations[:parent].must_be_nil
1154
+ p.associations[:parent] = c
1155
+ p.parent.must_equal c
1156
+ proc{p.parent = nil}.must_raise(Sequel::HookFailed)
1157
+ end
1158
+
1144
1159
  it "should not validate the associated object in setter if the :validate=>false option is used" do
1145
1160
  @c2.one_to_one :parent, :class => @c2, :validate=>false
1146
1161
  n = @c2.new(:id => 1234)
@@ -1878,7 +1893,7 @@ describe Sequel::Model, "one_to_many" do
1878
1893
  attributes.collect{|a| a.pk}.must_equal [20, 30]
1879
1894
  end
1880
1895
 
1881
- it "should raise error and not call internal add or remove method if before callback returns false if raise_on_save_failure is true" do
1896
+ deprecated "should raise error and not call internal add or remove method if before callback returns false if raise_on_save_failure is true" do
1882
1897
  p = @c2.load(:id=>10)
1883
1898
  c = @c1.load(:id=>123)
1884
1899
  @c2.one_to_many :attributes, :class => @c1, :before_add=>:ba, :before_remove=>:br
@@ -1894,7 +1909,7 @@ describe Sequel::Model, "one_to_many" do
1894
1909
  p.attributes.must_equal [c]
1895
1910
  end
1896
1911
 
1897
- it "should return nil and not call internal add or remove method if before callback returns false if raise_on_save_failure is false" do
1912
+ deprecated "should return nil and not call internal add or remove method if before callback returns false if raise_on_save_failure is false" do
1898
1913
  p = @c2.load(:id=>10)
1899
1914
  c = @c1.load(:id=>123)
1900
1915
  p.raise_on_save_failure = false
@@ -2051,11 +2066,16 @@ describe Sequel::Model, "many_to_many" do
2051
2066
  @c2.new(:id => 1234).attributes_dataset.sql.must_equal 'SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id = 1234)'
2052
2067
  end
2053
2068
 
2054
- it "should respect :eager_loader_predicate_key when lazily loading" do
2069
+ deprecated "should respect :eager_loading_predicate_key when lazily loading" do
2055
2070
  @c2.many_to_many :attributes, :class => @c1, :eager_loading_predicate_key=>Sequel.subscript(Sequel[:attributes_nodes][:node_id], 0)
2056
2071
  @c2.new(:id => 1234).attributes_dataset.sql.must_equal 'SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id[0] = 1234)'
2057
2072
  end
2058
2073
 
2074
+ it "should respect :predicate_key when lazily loading" do
2075
+ @c2.many_to_many :attributes, :class => @c1, :predicate_key=>Sequel.subscript(Sequel[:attributes_nodes][:node_id], 0)
2076
+ @c2.new(:id => 1234).attributes_dataset.sql.must_equal 'SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id[0] = 1234)'
2077
+ end
2078
+
2059
2079
  it "should use explicit key values and join table if given" do
2060
2080
  @c2.many_to_many :attributes, :class => @c1, :left_key => :nodeid, :right_key => :attributeid, :join_table => :attribute2node
2061
2081
  @c2.new(:id => 1234).attributes_dataset.sql.must_equal 'SELECT attributes.* FROM attributes INNER JOIN attribute2node ON (attribute2node.attributeid = attributes.id) WHERE (attribute2node.nodeid = 1234)'
@@ -2746,7 +2766,7 @@ describe Sequel::Model, "many_to_many" do
2746
2766
  attributes.collect{|a| a.pk}.must_equal [20, 30]
2747
2767
  end
2748
2768
 
2749
- it "should raise error and not call internal add or remove method if before callback returns false if raise_on_save_failure is true" do
2769
+ deprecated "should raise error and not call internal add or remove method if before callback returns false if raise_on_save_failure is true" do
2750
2770
  p = @c2.load(:id=>10)
2751
2771
  c = @c1.load(:id=>123)
2752
2772
  @c2.many_to_many :attributes, :class => @c1, :before_add=>:ba, :before_remove=>:br
@@ -2763,7 +2783,7 @@ describe Sequel::Model, "many_to_many" do
2763
2783
  p.attributes.must_equal [c]
2764
2784
  end
2765
2785
 
2766
- it "should return nil and not call internal add or remove method if before callback returns false if raise_on_save_failure is false" do
2786
+ deprecated "should return nil and not call internal add or remove method if before callback returns false if raise_on_save_failure is false" do
2767
2787
  p = @c2.load(:id=>10)
2768
2788
  c = @c1.load(:id=>123)
2769
2789
  p.raise_on_save_failure = false
@@ -2882,8 +2902,8 @@ describe Sequel::Model, "one_through_one" do
2882
2902
  @c2.new(:id => 1234).attribute_dataset.sql.must_equal 'SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id = 1234) LIMIT 1'
2883
2903
  end
2884
2904
 
2885
- it "should respect :eager_loader_predicate_key when lazily loading" do
2886
- @c2.one_through_one :attribute, :class => @c1, :eager_loading_predicate_key=>Sequel.subscript(Sequel[:attributes_nodes][:node_id], 0)
2905
+ it "should respect :predicate_key when lazily loading" do
2906
+ @c2.one_through_one :attribute, :class => @c1, :predicate_key=>Sequel.subscript(Sequel[:attributes_nodes][:node_id], 0)
2887
2907
  @c2.new(:id => 1234).attribute_dataset.sql.must_equal 'SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id[0] = 1234) LIMIT 1'
2888
2908
  end
2889
2909
 
@@ -135,6 +135,12 @@ describe Sequel::Model, "class dataset methods" do
135
135
  @c.with(:a, @d).sql.must_equal "WITH a AS (SELECT * FROM items) SELECT * FROM items"
136
136
  @c.with_recursive(:a, @d, @d).sql.must_equal "WITH a AS (SELECT * FROM items UNION ALL SELECT * FROM items) SELECT * FROM items"
137
137
  @c.with_sql('S').sql.must_equal "S"
138
+ @c.where_all(:id=>1){|r|}.must_equal [@c.load(:id=>1)]
139
+ @db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1)"]
140
+ @c.where_each(:id=>1){|r|}
141
+ @db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1)"]
142
+ @c.where_single_value(:id=>1).must_equal 1
143
+ @db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1) LIMIT 1"]
138
144
 
139
145
  sc = Class.new(@c)
140
146
  sc.set_dataset(@d.where(:a).order(:a).select(:a).group(:a).limit(2))
@@ -380,8 +380,8 @@ describe Sequel::Model, "#eager" do
380
380
  DB.sqls.must_equal []
381
381
  end
382
382
 
383
- it "should handle a :eager_loading_predicate_key option to change the SQL used in the lookup, for many_to_one associations" do
384
- EagerAlbum.many_to_one :sband, :clone=>:band, :eager_loading_predicate_key=>(Sequel[:bands][:id] / 3), :primary_key_method=>:id3
383
+ it "should handle a :predicate_key option to change the SQL used in the lookup, for many_to_one associations" do
384
+ EagerAlbum.many_to_one :sband, :clone=>:band, :predicate_key=>(Sequel[:bands][:id] / 3), :primary_key_method=>:id3
385
385
  EagerBand.dataset = EagerBand.dataset.with_fetch(:id=>6)
386
386
  a = EagerAlbum.eager(:sband).all
387
387
  DB.sqls.must_equal ['SELECT * FROM albums', 'SELECT * FROM bands WHERE ((bands.id / 3) IN (2))']
@@ -390,8 +390,8 @@ describe Sequel::Model, "#eager" do
390
390
  DB.sqls.must_equal []
391
391
  end
392
392
 
393
- it "should handle a :eager_loading_predicate_key option to change the SQL used in the lookup, for one_to_many associations" do
394
- EagerBand.one_to_many :salbums, :clone=>:albums, :eager_loading_predicate_key=>(Sequel[:albums][:band_id] * 3), :key_method=>:band_id3, :eager=>nil, :reciprocal=>nil
393
+ it "should handle a :predicate_key option to change the SQL used in the lookup, for one_to_many associations" do
394
+ EagerBand.one_to_many :salbums, :clone=>:albums, :predicate_key=>(Sequel[:albums][:band_id] * 3), :key_method=>:band_id3, :eager=>nil, :reciprocal=>nil
395
395
  EagerBand.dataset = EagerBand.dataset.with_fetch(:id=>6)
396
396
  a = EagerBand.eager(:salbums).all
397
397
  DB.sqls.must_equal ['SELECT * FROM bands', 'SELECT * FROM albums WHERE ((albums.band_id * 3) IN (6))']
@@ -400,8 +400,8 @@ describe Sequel::Model, "#eager" do
400
400
  DB.sqls.must_equal []
401
401
  end
402
402
 
403
- it "should handle a :eager_loading_predicate_key option to change the SQL used in the lookup, for many_to_many associations" do
404
- EagerAlbum.many_to_many :sgenres, :clone=>:genres, :eager_loading_predicate_key=>(Sequel[:ag][:album_id] * 1)
403
+ it "should handle a :predicate_key option to change the SQL used in the lookup, for many_to_many associations" do
404
+ EagerAlbum.many_to_many :sgenres, :clone=>:genres, :predicate_key=>(Sequel[:ag][:album_id] * 1)
405
405
  a = EagerAlbum.eager(:sgenres).all
406
406
  a.must_equal [EagerAlbum.load(:id => 1, :band_id => 2)]
407
407
  DB.sqls.must_equal ['SELECT * FROM albums', "SELECT genres.*, (ag.album_id * 1) AS x_foreign_key_x FROM genres INNER JOIN ag ON (ag.genre_id = genres.id) WHERE ((ag.album_id * 1) IN (1))"]
@@ -409,8 +409,8 @@ describe Sequel::Model, "#eager" do
409
409
  DB.sqls.must_equal []
410
410
  end
411
411
 
412
- it "should handle a :eager_loading_predicate_key option to change the SQL used in the lookup, for one_through_one associations" do
413
- EagerAlbum.one_through_one :sgenre, :clone=>:genre, :eager_loading_predicate_key=>(Sequel[:ag][:album_id] * 1)
412
+ it "should handle a :predicate_key option to change the SQL used in the lookup, for one_through_one associations" do
413
+ EagerAlbum.one_through_one :sgenre, :clone=>:genre, :predicate_key=>(Sequel[:ag][:album_id] * 1)
414
414
  a = EagerAlbum.eager(:sgenre).all
415
415
  a.must_equal [EagerAlbum.load(:id => 1, :band_id => 2)]
416
416
  DB.sqls.must_equal ['SELECT * FROM albums', "SELECT genres.*, (ag.album_id * 1) AS x_foreign_key_x FROM genres INNER JOIN ag ON (ag.genre_id = genres.id) WHERE ((ag.album_id * 1) IN (1))"]
@@ -295,4 +295,38 @@ describe Sequel::Plugins do
295
295
  @c.foo.must_equal 1
296
296
  end
297
297
  end
298
+
299
+ describe "Sequel::Model.plugin" do
300
+ before do
301
+ @c = Class.new(Sequel::Model)
302
+ end
303
+ after do
304
+ Sequel::Plugins.send(:remove_const, :SomethingOrOther)
305
+ end
306
+
307
+ it "should try loading plugins from sequel/plugins/:plugin" do
308
+ a = []
309
+ m = Module.new
310
+ (class << @c; self end).send(:define_method, :require) do |b|
311
+ a << b
312
+ Sequel::Plugins.const_set(:SomethingOrOther, m)
313
+ end
314
+ @c.plugin :something_or_other
315
+ @c.plugins.must_include m
316
+ a.must_equal ['sequel/plugins/something_or_other']
317
+ end
298
318
 
319
+ deprecated "should try loading plugins from sequel_plugin" do
320
+ proc{@c.plugin :something_or_other}.must_raise(LoadError)
321
+ a = []
322
+ m = Module.new
323
+ (class << @c; self end).send(:define_method, :require) do |b|
324
+ a << b
325
+ raise LoadError if b == 'sequel/plugins/something_or_other'
326
+ Sequel::Plugins.const_set(:SomethingOrOther, m)
327
+ end
328
+ @c.plugin :something_or_other
329
+ @c.plugins.must_include m
330
+ a.must_equal ['sequel/plugins/something_or_other', 'sequel_something_or_other']
331
+ end
332
+ end
@@ -436,7 +436,7 @@ describe "Model#freeze" do
436
436
  end
437
437
 
438
438
  it "should still have working class attr overriddable methods" do
439
- Sequel::Model::BOOLEAN_SETTINGS.each{|m| @o.send(m) == Album.send(m)}
439
+ [:typecast_empty_string_to_nil, :typecast_on_assignment, :strict_param_setting, :raise_on_save_failure, :raise_on_typecast_failure, :require_modification, :use_transactions].each{|m| @o.send(m) == Album.send(m)}
440
440
  end
441
441
 
442
442
  it "should have working new? method" do
@@ -2,6 +2,8 @@ ENV['SEQUEL_POSTGRES_URL'] ||= 'postgres:///sequel_test?user=sequel_test&passwor
2
2
  ENV['SEQUEL_SQLITE_URL'] ||= 'sqlite:/'
3
3
  gem 'minitest'
4
4
  require 'minitest'
5
+ require 'minitest/autorun'
6
+ #at_exit{GC.stress = true}
5
7
  if false # Minitest.respond_to?(:before_parallel_fork)
6
8
  if SEQUEL_ADAPTER_TEST.to_s == 'postgres'
7
9
  Minitest.before_parallel_fork{DB.disconnect}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.48.0
4
+ version: 4.49.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-01 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -250,6 +250,7 @@ extra_rdoc_files:
250
250
  - doc/release_notes/4.46.0.txt
251
251
  - doc/release_notes/4.47.0.txt
252
252
  - doc/release_notes/4.48.0.txt
253
+ - doc/release_notes/4.49.0.txt
253
254
  files:
254
255
  - CHANGELOG
255
256
  - MIT-LICENSE
@@ -389,6 +390,7 @@ files:
389
390
  - doc/release_notes/4.46.0.txt
390
391
  - doc/release_notes/4.47.0.txt
391
392
  - doc/release_notes/4.48.0.txt
393
+ - doc/release_notes/4.49.0.txt
392
394
  - doc/release_notes/4.5.0.txt
393
395
  - doc/release_notes/4.6.0.txt
394
396
  - doc/release_notes/4.7.0.txt
@@ -492,6 +494,7 @@ files:
492
494
  - lib/sequel/database/transactions.rb
493
495
  - lib/sequel/dataset.rb
494
496
  - lib/sequel/dataset/actions.rb
497
+ - lib/sequel/dataset/dataset_module.rb
495
498
  - lib/sequel/dataset/features.rb
496
499
  - lib/sequel/dataset/graph.rb
497
500
  - lib/sequel/dataset/misc.rb