sequel 4.44.0 → 4.45.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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +110 -0
  3. data/README.rdoc +8 -9
  4. data/doc/active_record.rdoc +2 -3
  5. data/doc/model_plugins.rdoc +1 -1
  6. data/doc/opening_databases.rdoc +0 -46
  7. data/doc/release_notes/4.45.0.txt +370 -0
  8. data/lib/sequel/adapters/cubrid.rb +2 -0
  9. data/lib/sequel/adapters/do.rb +2 -0
  10. data/lib/sequel/adapters/jdbc/as400.rb +2 -0
  11. data/lib/sequel/adapters/jdbc/cubrid.rb +2 -0
  12. data/lib/sequel/adapters/jdbc/firebirdsql.rb +2 -0
  13. data/lib/sequel/adapters/jdbc/informix-sqli.rb +2 -0
  14. data/lib/sequel/adapters/jdbc/jdbcprogress.rb +2 -0
  15. data/lib/sequel/adapters/jdbc/mysql.rb +1 -0
  16. data/lib/sequel/adapters/jdbc/postgresql.rb +5 -0
  17. data/lib/sequel/adapters/mysql.rb +1 -0
  18. data/lib/sequel/adapters/mysql2.rb +1 -0
  19. data/lib/sequel/adapters/odbc/oracle.rb +11 -0
  20. data/lib/sequel/adapters/odbc/progress.rb +2 -0
  21. data/lib/sequel/adapters/postgres.rb +0 -2
  22. data/lib/sequel/adapters/shared/cubrid.rb +2 -0
  23. data/lib/sequel/adapters/shared/firebird.rb +2 -0
  24. data/lib/sequel/adapters/shared/informix.rb +2 -0
  25. data/lib/sequel/adapters/shared/mssql.rb +47 -7
  26. data/lib/sequel/adapters/shared/mysql.rb +16 -1
  27. data/lib/sequel/adapters/shared/postgres.rb +9 -1
  28. data/lib/sequel/adapters/shared/progress.rb +2 -0
  29. data/lib/sequel/adapters/shared/sqlanywhere.rb +1 -1
  30. data/lib/sequel/adapters/swift.rb +2 -0
  31. data/lib/sequel/ast_transformer.rb +13 -6
  32. data/lib/sequel/core.rb +13 -16
  33. data/lib/sequel/database/connecting.rb +25 -10
  34. data/lib/sequel/database/dataset.rb +6 -1
  35. data/lib/sequel/database/dataset_defaults.rb +9 -2
  36. data/lib/sequel/database/misc.rb +10 -3
  37. data/lib/sequel/database/schema_methods.rb +4 -0
  38. data/lib/sequel/dataset/mutation.rb +8 -20
  39. data/lib/sequel/dataset/prepared_statements.rb +2 -0
  40. data/lib/sequel/dataset/query.rb +32 -7
  41. data/lib/sequel/dataset/sql.rb +13 -3
  42. data/lib/sequel/deprecated.rb +9 -1
  43. data/lib/sequel/exceptions.rb +37 -8
  44. data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +117 -0
  45. data/lib/sequel/extensions/date_arithmetic.rb +1 -0
  46. data/lib/sequel/extensions/identifier_mangling.rb +3 -2
  47. data/lib/sequel/extensions/pg_hstore.rb +1 -5
  48. data/lib/sequel/extensions/schema_dumper.rb +3 -1
  49. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +2 -2
  50. data/lib/sequel/extensions/string_agg.rb +1 -0
  51. data/lib/sequel/model.rb +23 -10
  52. data/lib/sequel/model/associations.rb +17 -5
  53. data/lib/sequel/model/base.rb +115 -62
  54. data/lib/sequel/model/dataset_module.rb +10 -3
  55. data/lib/sequel/model/exceptions.rb +7 -5
  56. data/lib/sequel/plugins/association_pks.rb +13 -1
  57. data/lib/sequel/plugins/association_proxies.rb +8 -1
  58. data/lib/sequel/plugins/before_after_save.rb +1 -0
  59. data/lib/sequel/plugins/class_table_inheritance.rb +7 -3
  60. data/lib/sequel/plugins/columns_updated.rb +42 -0
  61. data/lib/sequel/plugins/composition.rb +10 -5
  62. data/lib/sequel/plugins/error_splitter.rb +1 -1
  63. data/lib/sequel/plugins/hook_class_methods.rb +39 -5
  64. data/lib/sequel/plugins/instance_hooks.rb +58 -5
  65. data/lib/sequel/plugins/lazy_attributes.rb +10 -5
  66. data/lib/sequel/plugins/nested_attributes.rb +10 -5
  67. data/lib/sequel/plugins/prepared_statements.rb +7 -0
  68. data/lib/sequel/plugins/prepared_statements_associations.rb +2 -0
  69. data/lib/sequel/plugins/prepared_statements_with_pk.rb +2 -0
  70. data/lib/sequel/plugins/schema.rb +2 -0
  71. data/lib/sequel/plugins/scissors.rb +2 -0
  72. data/lib/sequel/plugins/serialization.rb +10 -5
  73. data/lib/sequel/plugins/split_values.rb +5 -1
  74. data/lib/sequel/plugins/static_cache.rb +2 -2
  75. data/lib/sequel/plugins/tactical_eager_loading.rb +1 -1
  76. data/lib/sequel/plugins/validation_contexts.rb +49 -0
  77. data/lib/sequel/plugins/validation_helpers.rb +1 -0
  78. data/lib/sequel/sql.rb +1 -1
  79. data/lib/sequel/version.rb +1 -1
  80. data/spec/adapters/mssql_spec.rb +31 -0
  81. data/spec/adapters/mysql_spec.rb +20 -2
  82. data/spec/adapters/postgres_spec.rb +43 -12
  83. data/spec/adapters/spec_helper.rb +5 -8
  84. data/spec/core/database_spec.rb +47 -12
  85. data/spec/core/dataset_mutation_spec.rb +22 -22
  86. data/spec/core/dataset_spec.rb +88 -20
  87. data/spec/core/deprecated_spec.rb +1 -1
  88. data/spec/core/expression_filters_spec.rb +1 -1
  89. data/spec/core/mock_adapter_spec.rb +0 -3
  90. data/spec/core/placeholder_literalizer_spec.rb +1 -1
  91. data/spec/core/schema_spec.rb +8 -1
  92. data/spec/core/spec_helper.rb +6 -1
  93. data/spec/core_extensions_spec.rb +4 -0
  94. data/spec/deprecation_helper.rb +17 -0
  95. data/spec/extensions/_deprecated_identifier_mangling_spec.rb +314 -0
  96. data/spec/extensions/association_pks_spec.rb +61 -13
  97. data/spec/extensions/association_proxies_spec.rb +3 -3
  98. data/spec/extensions/class_table_inheritance_spec.rb +39 -0
  99. data/spec/extensions/columns_updated_spec.rb +35 -0
  100. data/spec/extensions/composition_spec.rb +6 -1
  101. data/spec/extensions/hook_class_methods_spec.rb +114 -26
  102. data/spec/extensions/identifier_mangling_spec.rb +107 -73
  103. data/spec/extensions/instance_hooks_spec.rb +78 -14
  104. data/spec/extensions/lazy_attributes_spec.rb +8 -2
  105. data/spec/extensions/many_through_many_spec.rb +2 -2
  106. data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
  107. data/spec/extensions/nested_attributes_spec.rb +8 -2
  108. data/spec/extensions/pg_array_spec.rb +18 -4
  109. data/spec/extensions/prepared_statements_associations_spec.rb +48 -39
  110. data/spec/extensions/prepared_statements_with_pk_spec.rb +13 -11
  111. data/spec/extensions/query_spec.rb +1 -1
  112. data/spec/extensions/schema_dumper_spec.rb +34 -6
  113. data/spec/extensions/schema_spec.rb +13 -7
  114. data/spec/extensions/scissors_spec.rb +3 -1
  115. data/spec/extensions/sequel_3_dataset_methods_spec.rb +4 -4
  116. data/spec/extensions/serialization_spec.rb +7 -1
  117. data/spec/extensions/set_overrides_spec.rb +2 -2
  118. data/spec/extensions/shared_caching_spec.rb +19 -15
  119. data/spec/extensions/spec_helper.rb +7 -3
  120. data/spec/extensions/split_values_spec.rb +45 -10
  121. data/spec/extensions/string_agg_spec.rb +2 -2
  122. data/spec/extensions/subset_conditions_spec.rb +3 -3
  123. data/spec/extensions/tactical_eager_loading_spec.rb +1 -1
  124. data/spec/extensions/validation_contexts_spec.rb +31 -0
  125. data/spec/guards_helper.rb +2 -0
  126. data/spec/integration/associations_test.rb +22 -20
  127. data/spec/integration/dataset_test.rb +25 -2
  128. data/spec/integration/model_test.rb +1 -1
  129. data/spec/integration/plugin_test.rb +11 -16
  130. data/spec/integration/prepared_statement_test.rb +40 -32
  131. data/spec/integration/spec_helper.rb +5 -8
  132. data/spec/model/association_reflection_spec.rb +4 -0
  133. data/spec/model/associations_spec.rb +37 -10
  134. data/spec/model/base_spec.rb +6 -0
  135. data/spec/model/hooks_spec.rb +56 -35
  136. data/spec/model/model_spec.rb +21 -5
  137. data/spec/model/record_spec.rb +14 -11
  138. data/spec/model/spec_helper.rb +7 -1
  139. data/spec/sequel_warning.rb +11 -0
  140. metadata +13 -3
@@ -650,6 +650,10 @@ describe "Sequel::Model.finalize_associations" do
650
650
  Object.send(:remove_const, :OtoItem)
651
651
  end
652
652
 
653
+ it "AssociationReflection should have default finalize_settings method" do
654
+ Sequel::Model::Associations::AssociationReflection.new.finalize_settings[:associated_class].must_equal :class
655
+ end
656
+
653
657
  it "should finalize many_to_one associations" do
654
658
  r = Item.association_reflection(:item)
655
659
  r[:class].must_equal Item
@@ -447,12 +447,14 @@ describe Sequel::Model, "many_to_one" do
447
447
  DB.reset
448
448
  d.parent_id = 234
449
449
  d.associations[:parent] = 42
450
- d.parent(true).wont_equal 42
451
- DB.sqls.must_equal ["SELECT * FROM nodes WHERE id = 234"]
452
450
  d.parent(:reload=>true).wont_equal 42
453
451
  DB.sqls.must_equal ["SELECT * FROM nodes WHERE id = 234"]
454
- d.parent(Object.new).wont_equal 42
455
- DB.sqls.must_equal ["SELECT * FROM nodes WHERE id = 234"]
452
+ deprecated do
453
+ d.parent(true).wont_equal 42
454
+ DB.sqls.must_equal ["SELECT * FROM nodes WHERE id = 234"]
455
+ d.parent(Object.new).wont_equal 42
456
+ DB.sqls.must_equal ["SELECT * FROM nodes WHERE id = 234"]
457
+ end
456
458
  end
457
459
 
458
460
  it "should use a callback if given one as the argument" do
@@ -462,7 +464,7 @@ describe Sequel::Model, "many_to_one" do
462
464
  DB.reset
463
465
  d.parent_id = 234
464
466
  d.associations[:parent] = 42
465
- d.parent(proc{|ds| ds.filter{name > 'M'}}).wont_equal 42
467
+ d.parent{|ds| ds.where{name > 'M'}}.wont_equal 42
466
468
  DB.sqls.must_equal ["SELECT * FROM nodes WHERE ((nodes.id = 234) AND (name > 'M')) LIMIT 1"]
467
469
  end
468
470
 
@@ -995,8 +997,12 @@ describe Sequel::Model, "one_to_one" do
995
997
  @c2.one_to_one :parent, :class => @c2
996
998
  d = @c2.load(:id => 1)
997
999
  d.associations[:parent] = [42]
998
- d.parent(true).wont_equal 42
1000
+ d.parent(:reload=>true).wont_equal 42
999
1001
  DB.sqls.must_equal ["SELECT * FROM nodes WHERE (nodes.node_id = 1) LIMIT 1"]
1002
+ deprecated do
1003
+ d.parent(true).wont_equal 42
1004
+ DB.sqls.must_equal ["SELECT * FROM nodes WHERE (nodes.node_id = 1) LIMIT 1"]
1005
+ end
1000
1006
  end
1001
1007
 
1002
1008
  it "should have the setter set the reciprocal many_to_one cached association" do
@@ -1223,7 +1229,16 @@ describe Sequel::Model, "one_to_many" do
1223
1229
  end
1224
1230
  end
1225
1231
 
1226
- it "should use a callback if given one as the argument" do
1232
+ it "should use a callback if given one as a block" do
1233
+ @c2.one_to_many :attributes, :class => @c1, :key => :nodeid
1234
+
1235
+ d = @c2.load(:id => 1234)
1236
+ d.associations[:attributes] = []
1237
+ d.attributes{|ds| ds.where{name > 'M'}}.wont_equal []
1238
+ DB.sqls.must_equal ["SELECT * FROM attributes WHERE ((attributes.nodeid = 1234) AND (name > 'M'))"]
1239
+ end
1240
+
1241
+ deprecated "should use a callback if given one as the argument" do
1227
1242
  @c2.one_to_many :attributes, :class => @c1, :key => :nodeid
1228
1243
 
1229
1244
  d = @c2.load(:id => 1234)
@@ -1552,8 +1567,12 @@ describe Sequel::Model, "one_to_many" do
1552
1567
  @c2.one_to_many :attributes, :class => @c1
1553
1568
  n = @c2.new(:id => 1234)
1554
1569
  n.associations[:attributes] = 42
1555
- n.attributes(true).wont_equal 42
1570
+ n.attributes(:reload=>true).wont_equal 42
1556
1571
  DB.sqls.must_equal ['SELECT * FROM attributes WHERE (attributes.node_id = 1234)']
1572
+ deprecated do
1573
+ n.attributes(true).wont_equal 42
1574
+ DB.sqls.must_equal ['SELECT * FROM attributes WHERE (attributes.node_id = 1234)']
1575
+ end
1557
1576
  end
1558
1577
 
1559
1578
  it "should add item to cache if it exists when calling add_" do
@@ -2416,8 +2435,12 @@ describe Sequel::Model, "many_to_many" do
2416
2435
 
2417
2436
  n = @c2.new(:id => 1234)
2418
2437
  n.associations[:attributes] = 42
2419
- n.attributes(true).wont_equal 42
2438
+ n.attributes(:reload=>true).wont_equal 42
2420
2439
  DB.sqls.must_equal ["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id = 1234)"]
2440
+ deprecated do
2441
+ n.attributes(true).wont_equal 42
2442
+ DB.sqls.must_equal ["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id = 1234)"]
2443
+ end
2421
2444
  end
2422
2445
 
2423
2446
  it "should add item to cache if it exists when calling add_" do
@@ -3004,8 +3027,12 @@ describe Sequel::Model, "one_through_one" do
3004
3027
 
3005
3028
  n = @c2.new(:id => 1234)
3006
3029
  n.associations[:attribute] = 42
3007
- n.attribute(true).wont_equal 42
3030
+ n.attribute(:reload=>true).wont_equal 42
3008
3031
  DB.sqls.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"]
3032
+ deprecated do
3033
+ n.attribute(true).wont_equal 42
3034
+ DB.sqls.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"]
3035
+ end
3009
3036
  end
3010
3037
 
3011
3038
  it "should not add associations methods directly to class" do
@@ -285,6 +285,12 @@ describe Sequel::Model, ".dataset_module" do
285
285
  @c.where(:foo).released.sql.must_equal 'SELECT * FROM items WHERE (foo AND released)'
286
286
  end
287
287
 
288
+ if Sequel::Model.dataset_module_class == Sequel::Model::DatasetModule
289
+ it "should have dataset_module not support an eager method" do
290
+ proc{@c.dataset_module{eager :foo}}.must_raise NoMethodError
291
+ end
292
+ end
293
+
288
294
  it "should have dataset_module support a having method" do
289
295
  @c.dataset_module{having(:released){released}}
290
296
  @c.released.sql.must_equal 'SELECT * FROM items HAVING released'
@@ -20,7 +20,7 @@ describe "Model#before_create && Model#after_create" do
20
20
  DB.sqls.must_equal ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after', 'SELECT * FROM items WHERE x = 2']
21
21
  end
22
22
 
23
- it ".create should cancel the save and raise an error if before_create returns false and raise_on_save_failure is true" do
23
+ deprecated ".create should cancel the save and raise an error if before_create returns false and raise_on_save_failure is true" do
24
24
  @c.send(:define_method, :before_create){false}
25
25
  proc{@c.create(:x => 2)}.must_raise(Sequel::HookFailed)
26
26
  DB.sqls.must_equal []
@@ -34,7 +34,7 @@ describe "Model#before_create && Model#after_create" do
34
34
  @c.load(:id => 2233).save
35
35
  end
36
36
 
37
- it ".create should cancel the save and return nil if before_create returns false and raise_on_save_failure is false" do
37
+ deprecated ".create should cancel the save and return nil if before_create returns false and raise_on_save_failure is false" do
38
38
  @c.send(:define_method, :before_create){false}
39
39
  @c.raise_on_save_failure = false
40
40
  @c.create(:x => 2).must_be_nil
@@ -67,7 +67,7 @@ describe "Model#before_update && Model#after_update" do
67
67
  DB.sqls.must_equal ['BLAH before', 'UPDATE items SET x = 123 WHERE (id = 2233)', 'BLAH after']
68
68
  end
69
69
 
70
- it "#save should cancel the save and raise an error if before_update returns false and raise_on_save_failure is true" do
70
+ deprecated "#save should cancel the save and raise an error if before_update returns false and raise_on_save_failure is true" do
71
71
  @c.send(:define_method, :before_update){false}
72
72
  proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
73
73
  DB.sqls.must_equal []
@@ -79,14 +79,14 @@ describe "Model#before_update && Model#after_update" do
79
79
  DB.sqls.must_equal []
80
80
  end
81
81
 
82
- it "#save should cancel the save and raise an error if before_update returns false and raise_on_failure option is true" do
82
+ deprecated "#save should cancel the save and raise an error if before_update returns false and raise_on_failure option is true" do
83
83
  @c.send(:define_method, :before_update){false}
84
84
  @c.raise_on_save_failure = false
85
85
  proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.must_raise(Sequel::HookFailed)
86
86
  DB.sqls.must_equal []
87
87
  end
88
88
 
89
- it "#save should cancel the save and return nil if before_update returns false and raise_on_save_failure is false" do
89
+ deprecated "#save should cancel the save and return nil if before_update returns false and raise_on_save_failure is false" do
90
90
  @c.send(:define_method, :before_update){false}
91
91
  @c.raise_on_save_failure = false
92
92
  @c.load(:id => 2233).save.must_be_nil
@@ -127,13 +127,13 @@ describe "Model#before_save && Model#after_save" do
127
127
  DB.sqls.must_equal ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after', 'SELECT * FROM items WHERE x = 2']
128
128
  end
129
129
 
130
- it "#save should cancel the save and raise an error if before_save returns false and raise_on_save_failure is true" do
130
+ deprecated "#save should cancel the save and raise an error if before_save returns false and raise_on_save_failure is true" do
131
131
  @c.send(:define_method, :before_save){false}
132
132
  proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
133
133
  DB.sqls.must_equal []
134
134
  end
135
135
 
136
- it "#save should cancel the save and raise an error if before_save returns false and raise_on_failure option is true" do
136
+ deprecated "#save should cancel the save and raise an error if before_save returns false and raise_on_failure option is true" do
137
137
  @c.send(:define_method, :before_save){false}
138
138
  @c.raise_on_save_failure = false
139
139
  proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.must_raise(Sequel::HookFailed)
@@ -147,7 +147,7 @@ describe "Model#before_save && Model#after_save" do
147
147
  DB.sqls.must_equal []
148
148
  end
149
149
 
150
- it "#save should cancel the save and return nil if before_save returns false and raise_on_save_failure is false" do
150
+ deprecated "#save should cancel the save and return nil if before_save returns false and raise_on_save_failure is false" do
151
151
  @c.send(:define_method, :before_save){false}
152
152
  @c.raise_on_save_failure = false
153
153
  @c.load(:id => 2233).save.must_be_nil
@@ -162,7 +162,7 @@ describe "Model#before_save && Model#after_save" do
162
162
  end
163
163
 
164
164
  it "#save should have a raised exception reference the model instance" do
165
- @c.send(:define_method, :before_save){false}
165
+ @c.send(:define_method, :before_save){cancel_action}
166
166
  proc{@c.create(:x => 2233)}.must_raise(Sequel::HookFailed){|e| e.model.must_equal @c.load(:x=>2233)}
167
167
  DB.sqls.must_equal []
168
168
  end
@@ -185,7 +185,7 @@ describe "Model#before_destroy && Model#after_destroy" do
185
185
  DB.sqls.must_equal ['BLAH before', 'DELETE FROM items WHERE id = 2233', 'BLAH after']
186
186
  end
187
187
 
188
- it "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_save_failure is true" do
188
+ deprecated "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_save_failure is true" do
189
189
  @c.send(:define_method, :before_destroy){false}
190
190
  proc{@c.load(:id => 2233).destroy}.must_raise(Sequel::HookFailed)
191
191
  DB.sqls.must_equal []
@@ -197,14 +197,14 @@ describe "Model#before_destroy && Model#after_destroy" do
197
197
  DB.sqls.must_equal []
198
198
  end
199
199
 
200
- it "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_failure option is true" do
200
+ deprecated "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_failure option is true" do
201
201
  @c.send(:define_method, :before_destroy){false}
202
202
  @c.raise_on_save_failure = false
203
203
  proc{@c.load(:id => 2233).destroy(:raise_on_failure => true)}.must_raise(Sequel::HookFailed)
204
204
  DB.sqls.must_equal []
205
205
  end
206
206
 
207
- it "#destroy should cancel the destroy and return nil if before_destroy returns false and raise_on_save_failure is false" do
207
+ deprecated "#destroy should cancel the destroy and return nil if before_destroy returns false and raise_on_save_failure is false" do
208
208
  @c.send(:define_method, :before_destroy){false}
209
209
  @c.raise_on_save_failure = false
210
210
  @c.load(:id => 2233).destroy.must_be_nil
@@ -257,13 +257,13 @@ describe "Model#before_validation && Model#after_validation" do
257
257
  DB.sqls.must_equal ['BLAH before', 'BLAH after']
258
258
  end
259
259
 
260
- it "#save should cancel the save and raise an error if before_validation returns false and raise_on_save_failure is true" do
260
+ deprecated "#save should cancel the save and raise an error if before_validation returns false and raise_on_save_failure is true" do
261
261
  @c.send(:define_method, :before_validation){false}
262
262
  proc{@c.load(:id => 2233).save}.must_raise(Sequel::HookFailed)
263
263
  DB.sqls.must_equal []
264
264
  end
265
265
 
266
- it "#save should cancel the save and raise an error if before_validation returns false and raise_on_failure option is true" do
266
+ deprecated "#save should cancel the save and raise an error if before_validation returns false and raise_on_failure option is true" do
267
267
  @c.send(:define_method, :before_validation){false}
268
268
  @c.raise_on_save_failure = false
269
269
  proc{@c.load(:id => 2233).save(:raise_on_failure => true)}.must_raise(Sequel::HookFailed)
@@ -276,7 +276,7 @@ describe "Model#before_validation && Model#after_validation" do
276
276
  DB.sqls.must_equal []
277
277
  end
278
278
 
279
- it "#save should cancel the save and return nil if before_validation returns false and raise_on_save_failure is false" do
279
+ deprecated "#save should cancel the save and return nil if before_validation returns false and raise_on_save_failure is false" do
280
280
  @c.send(:define_method, :before_validation){false}
281
281
  @c.raise_on_save_failure = false
282
282
  @c.load(:id => 2233).save.must_be_nil
@@ -290,7 +290,12 @@ describe "Model#before_validation && Model#after_validation" do
290
290
  DB.sqls.must_equal []
291
291
  end
292
292
 
293
- it "#valid? should return false if before_validation returns false" do
293
+ it "#valid? should return false if before_validation calls cancel_action" do
294
+ @c.send(:define_method, :before_validation){cancel_action}
295
+ @c.load(:id => 2233).valid?.must_equal false
296
+ end
297
+
298
+ deprecated "#valid? should return false if before_validation returns false" do
294
299
  @c.send(:define_method, :before_validation){false}
295
300
  @c.load(:id => 2233).valid?.must_equal false
296
301
  end
@@ -379,6 +384,22 @@ describe "Model around filters" do
379
384
  DB.sqls.must_equal [ 'av_before', 'validate', 'av_after' ]
380
385
  end
381
386
 
387
+ it "around_validation should handle cancel_action" do
388
+ @c.class_eval do
389
+ def around_validation
390
+ DB << 'av_before'
391
+ cancel_action
392
+ super
393
+ DB << 'av_after'
394
+ end
395
+ def validate
396
+ DB << 'validate'
397
+ end
398
+ end
399
+ @c.new(:x => 2).valid?.must_equal false
400
+ DB.sqls.must_equal [ 'av_before' ]
401
+ end
402
+
382
403
  it "around_validation should be able to catch validation errors and modify them" do
383
404
  @c.class_eval do
384
405
  def validate
@@ -480,25 +501,25 @@ describe "Model#after_commit and #after_rollback" do
480
501
  @db.sqls
481
502
  end
482
503
 
483
- it "should call after_commit for save after the transaction commits if it commits" do
504
+ deprecated "should call after_commit for save after the transaction commits if it commits" do
484
505
  @o.save
485
506
  @db.sqls.must_equal ['BEGIN', 'as', 'COMMIT', 'ac']
486
507
  end
487
508
 
488
- it "should call after_rollback for save after the transaction rolls back if it rolls back" do
509
+ deprecated "should call after_rollback for save after the transaction rolls back if it rolls back" do
489
510
  @o.rb = true
490
511
  @o.save
491
512
  @db.sqls.must_equal ['BEGIN', 'as', 'ROLLBACK', 'ar']
492
513
  end
493
514
 
494
- it "should have after_commit respect any surrounding transactions" do
515
+ deprecated "should have after_commit respect any surrounding transactions" do
495
516
  @db.transaction do
496
517
  @o.save
497
518
  end
498
519
  @db.sqls.must_equal ['BEGIN', 'as', 'COMMIT', 'ac']
499
520
  end
500
521
 
501
- it "should have after_rollback respect any surrounding transactions" do
522
+ deprecated "should have after_rollback respect any surrounding transactions" do
502
523
  @db.transaction do
503
524
  @o.rb = true
504
525
  @o.save
@@ -506,14 +527,14 @@ describe "Model#after_commit and #after_rollback" do
506
527
  @db.sqls.must_equal ['BEGIN', 'as', 'ROLLBACK', 'ar']
507
528
  end
508
529
 
509
- it "should have after_commit work with surrounding transactions and sharding" do
530
+ deprecated "should have after_commit work with surrounding transactions and sharding" do
510
531
  @db.transaction(:server=>:test) do
511
532
  @o.save
512
533
  end
513
534
  @db.sqls.must_equal ['BEGIN -- test', 'BEGIN', 'as', 'COMMIT', 'ac', 'COMMIT -- test']
514
535
  end
515
536
 
516
- it "should have after_rollback work with surrounding transactions and sharding" do
537
+ deprecated "should have after_rollback work with surrounding transactions and sharding" do
517
538
  @db.transaction(:server=>:test) do
518
539
  @o.rb = true
519
540
  @o.save
@@ -521,25 +542,25 @@ describe "Model#after_commit and #after_rollback" do
521
542
  @db.sqls.must_equal ['BEGIN -- test', 'BEGIN', 'as', 'ROLLBACK', 'ar', 'COMMIT -- test']
522
543
  end
523
544
 
524
- it "should call after_destroy_commit for destroy after the transaction commits if it commits" do
545
+ deprecated "should call after_destroy_commit for destroy after the transaction commits if it commits" do
525
546
  @o.destroy
526
547
  @db.sqls.must_equal ['BEGIN', 'ad', 'COMMIT', 'adc']
527
548
  end
528
549
 
529
- it "should call after_destroy_rollback for destroy after the transaction rolls back if it rolls back" do
550
+ deprecated "should call after_destroy_rollback for destroy after the transaction rolls back if it rolls back" do
530
551
  @o.rb = true
531
552
  @o.destroy
532
553
  @db.sqls.must_equal ['BEGIN', 'ad', 'ROLLBACK', 'adr']
533
554
  end
534
555
 
535
- it "should have after_destroy_commit respect any surrounding transactions" do
556
+ deprecated "should have after_destroy_commit respect any surrounding transactions" do
536
557
  @db.transaction do
537
558
  @o.destroy
538
559
  end
539
560
  @db.sqls.must_equal ['BEGIN', 'ad', 'COMMIT', 'adc']
540
561
  end
541
562
 
542
- it "should have after_destroy_rollback respect any surrounding transactions" do
563
+ deprecated "should have after_destroy_rollback respect any surrounding transactions" do
543
564
  @db.transaction do
544
565
  @o.rb = true
545
566
  @o.destroy
@@ -547,14 +568,14 @@ describe "Model#after_commit and #after_rollback" do
547
568
  @db.sqls.must_equal ['BEGIN', 'ad', 'ROLLBACK', 'adr']
548
569
  end
549
570
 
550
- it "should have after_destroy commit work with surrounding transactions and sharding" do
571
+ deprecated "should have after_destroy commit work with surrounding transactions and sharding" do
551
572
  @db.transaction(:server=>:test) do
552
573
  @o.destroy
553
574
  end
554
575
  @db.sqls.must_equal ['BEGIN -- test', 'BEGIN', 'ad', 'COMMIT', 'adc', 'COMMIT -- test']
555
576
  end
556
577
 
557
- it "should have after_destroy_rollback work with surrounding transactions and sharding" do
578
+ deprecated "should have after_destroy_rollback work with surrounding transactions and sharding" do
558
579
  @db.transaction(:server=>:test) do
559
580
  @o.rb = true
560
581
  @o.destroy
@@ -562,39 +583,39 @@ describe "Model#after_commit and #after_rollback" do
562
583
  @db.sqls.must_equal ['BEGIN -- test', 'BEGIN', 'ad', 'ROLLBACK', 'adr', 'COMMIT -- test']
563
584
  end
564
585
 
565
- it "should not call after_commit if use_after_commit_rollback is false" do
586
+ deprecated "should not call after_commit if use_after_commit_rollback is false" do
566
587
  @o.use_after_commit_rollback = false
567
588
  @o.save
568
589
  @db.sqls.must_equal ['BEGIN', 'as', 'COMMIT']
569
590
  end
570
591
 
571
- it "should not call after_rollback if use_after_commit_rollback is false" do
592
+ deprecated "should not call after_rollback if use_after_commit_rollback is false" do
572
593
  @o.use_after_commit_rollback = false
573
594
  @o.rb = true
574
595
  @o.save
575
596
  @db.sqls.must_equal ['BEGIN', 'as', 'ROLLBACK']
576
597
  end
577
598
 
578
- it "should not call after_destroy_commit if use_after_commit_rollback is false" do
599
+ deprecated "should not call after_destroy_commit if use_after_commit_rollback is false" do
579
600
  @o.use_after_commit_rollback = false
580
601
  @o.destroy
581
602
  @db.sqls.must_equal ['BEGIN', 'ad', 'COMMIT']
582
603
  end
583
604
 
584
- it "should not call after_destroy_rollback for save if use_after_commit_rollback is false" do
605
+ deprecated "should not call after_destroy_rollback for save if use_after_commit_rollback is false" do
585
606
  @o.use_after_commit_rollback = false
586
607
  @o.rb = true
587
608
  @o.destroy
588
609
  @db.sqls.must_equal ['BEGIN', 'ad', 'ROLLBACK']
589
610
  end
590
611
 
591
- it "should handle use_after_commit_rollback at the class level" do
612
+ deprecated "should handle use_after_commit_rollback at the class level" do
592
613
  @m.use_after_commit_rollback = false
593
614
  @o.save
594
615
  @db.sqls.must_equal ['BEGIN', 'as', 'COMMIT']
595
616
  end
596
617
 
597
- it "should handle use_after_commit_rollback when subclassing" do
618
+ deprecated "should handle use_after_commit_rollback when subclassing" do
598
619
  @m.use_after_commit_rollback = false
599
620
  o = Class.new(@m).load({})
600
621
  @db.sqls
@@ -602,7 +623,7 @@ describe "Model#after_commit and #after_rollback" do
602
623
  @db.sqls.must_equal ['BEGIN', 'as', 'COMMIT']
603
624
  end
604
625
 
605
- it "should handle use_after_commit_rollback when subclassing after loading" do
626
+ deprecated "should handle use_after_commit_rollback when subclassing after loading" do
606
627
  @m = Class.new(Sequel::Model(@db[:items]))
607
628
  @m.use_transactions = true
608
629
  o = @m.load({})
@@ -102,17 +102,19 @@ describe "Sequel::Model()" do
102
102
 
103
103
  describe "reloading" do
104
104
  before do
105
- Sequel.cache_anonymous_models = true
105
+ Sequel::Model.cache_anonymous_models = true
106
106
  end
107
107
  after do
108
- Sequel.cache_anonymous_models = false
108
+ Sequel::Model.cache_anonymous_models = false
109
109
  Object.send(:remove_const, :Album) if defined?(::Album)
110
110
  end
111
111
 
112
- it "Sequel.cache_anonymous_models should return value for Sequel::Model" do
112
+ deprecated "Sequel.cache_anonymous_models should return value for Sequel::Model" do
113
113
  Sequel.cache_anonymous_models.must_equal true
114
114
  Sequel::Model.cache_anonymous_models = false
115
115
  Sequel.cache_anonymous_models.must_equal false
116
+ Sequel.cache_anonymous_models = true
117
+ Sequel.cache_anonymous_models.must_equal true
116
118
  end
117
119
 
118
120
  it "should work without raising an exception with a symbol" do
@@ -156,14 +158,14 @@ describe "Sequel::Model()" do
156
158
  end
157
159
 
158
160
  it "should raise an exception if anonymous model caching is disabled" do
159
- Sequel.cache_anonymous_models = false
161
+ Sequel::Model.cache_anonymous_models = false
160
162
  proc do
161
163
  class ::Album < Sequel::Model(@db[Sequel.identifier(:table)]); end
162
164
  class ::Album < Sequel::Model(@db[Sequel.identifier(:table)]); end
163
165
  end.must_raise TypeError
164
166
  end
165
167
 
166
- it "should use separate cache and cache settings for subclasses" do
168
+ it "should use separate anonymous cache for subclasses" do
167
169
  c = Class.new(Sequel::Model)
168
170
  c.cache_anonymous_models.must_equal true
169
171
  class ::Album < c::Model(:table); end
@@ -268,6 +270,16 @@ describe Sequel::Model do
268
270
  DB.reset
269
271
  end
270
272
 
273
+ deprecated "should allow dup/clone" do
274
+ @model.dup.must_be :<, @model.superclass
275
+ @model.clone.must_be :<, @model.superclass
276
+ end
277
+
278
+ it "should not allow dup/clone" do
279
+ proc{@model.dup}.must_raise Sequel::Error
280
+ proc{@model.clone}.must_raise Sequel::Error
281
+ end if false # SEQUEL5
282
+
271
283
  it "has table_name return name of table" do
272
284
  @model.table_name.must_equal :items
273
285
  end
@@ -1043,6 +1055,10 @@ describe "Model.db_schema" do
1043
1055
  @c.dataset = @dataset
1044
1056
  @c.db_schema.must_equal(:x=>{}, :y=>{})
1045
1057
  @c.columns.must_equal [:x, :y]
1058
+
1059
+ @c.instance_eval{@db_schema = nil}
1060
+ @c.db_schema.must_equal(:x=>{}, :y=>{})
1061
+ @c.columns.must_equal [:x, :y]
1046
1062
  end
1047
1063
 
1048
1064
  it "should use the database's schema and set the columns and dataset columns" do