sequel 2.11.0 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/CHANGELOG +168 -0
  2. data/README.rdoc +77 -95
  3. data/Rakefile +100 -80
  4. data/bin/sequel +2 -1
  5. data/doc/advanced_associations.rdoc +23 -32
  6. data/doc/cheat_sheet.rdoc +23 -40
  7. data/doc/dataset_filtering.rdoc +6 -6
  8. data/doc/prepared_statements.rdoc +22 -22
  9. data/doc/release_notes/2.12.0.txt +534 -0
  10. data/doc/schema.rdoc +3 -1
  11. data/doc/sharding.rdoc +8 -8
  12. data/doc/virtual_rows.rdoc +65 -0
  13. data/lib/sequel.rb +1 -1
  14. data/lib/{sequel_core → sequel}/adapters/ado.rb +3 -3
  15. data/lib/{sequel_core → sequel}/adapters/db2.rb +0 -0
  16. data/lib/{sequel_core → sequel}/adapters/dbi.rb +1 -1
  17. data/lib/{sequel_core → sequel}/adapters/do.rb +9 -5
  18. data/lib/{sequel_core → sequel}/adapters/do/mysql.rb +1 -1
  19. data/lib/{sequel_core → sequel}/adapters/do/postgres.rb +1 -1
  20. data/lib/{sequel_core → sequel}/adapters/do/sqlite.rb +1 -1
  21. data/lib/{sequel_core → sequel}/adapters/firebird.rb +84 -80
  22. data/lib/{sequel_core → sequel}/adapters/informix.rb +1 -1
  23. data/lib/{sequel_core → sequel}/adapters/jdbc.rb +21 -14
  24. data/lib/{sequel_core → sequel}/adapters/jdbc/h2.rb +14 -13
  25. data/lib/{sequel_core → sequel}/adapters/jdbc/mysql.rb +1 -1
  26. data/lib/{sequel_core → sequel}/adapters/jdbc/oracle.rb +1 -1
  27. data/lib/{sequel_core → sequel}/adapters/jdbc/postgresql.rb +1 -1
  28. data/lib/{sequel_core → sequel}/adapters/jdbc/sqlite.rb +1 -1
  29. data/lib/{sequel_core → sequel}/adapters/mysql.rb +60 -39
  30. data/lib/{sequel_core → sequel}/adapters/odbc.rb +8 -4
  31. data/lib/{sequel_core → sequel}/adapters/openbase.rb +0 -0
  32. data/lib/{sequel_core → sequel}/adapters/oracle.rb +38 -7
  33. data/lib/{sequel_core → sequel}/adapters/postgres.rb +24 -24
  34. data/lib/{sequel_core → sequel}/adapters/shared/mssql.rb +5 -5
  35. data/lib/{sequel_core → sequel}/adapters/shared/mysql.rb +126 -71
  36. data/lib/{sequel_core → sequel}/adapters/shared/oracle.rb +7 -10
  37. data/lib/{sequel_core → sequel}/adapters/shared/postgres.rb +159 -125
  38. data/lib/{sequel_core → sequel}/adapters/shared/progress.rb +1 -2
  39. data/lib/{sequel_core → sequel}/adapters/shared/sqlite.rb +72 -67
  40. data/lib/{sequel_core → sequel}/adapters/sqlite.rb +11 -7
  41. data/lib/{sequel_core → sequel}/adapters/utils/date_format.rb +0 -0
  42. data/lib/{sequel_core → sequel}/adapters/utils/stored_procedures.rb +0 -0
  43. data/lib/{sequel_core → sequel}/adapters/utils/unsupported.rb +19 -0
  44. data/lib/{sequel_core → sequel}/connection_pool.rb +7 -5
  45. data/lib/sequel/core.rb +221 -0
  46. data/lib/{sequel_core → sequel}/core_sql.rb +91 -49
  47. data/lib/{sequel_core → sequel}/database.rb +264 -149
  48. data/lib/{sequel_core/schema/generator.rb → sequel/database/schema_generator.rb} +6 -2
  49. data/lib/{sequel_core/database/schema.rb → sequel/database/schema_methods.rb} +12 -12
  50. data/lib/sequel/database/schema_sql.rb +224 -0
  51. data/lib/{sequel_core → sequel}/dataset.rb +78 -236
  52. data/lib/{sequel_core → sequel}/dataset/convenience.rb +99 -61
  53. data/lib/{sequel_core/object_graph.rb → sequel/dataset/graph.rb} +16 -14
  54. data/lib/{sequel_core → sequel}/dataset/prepared_statements.rb +1 -1
  55. data/lib/{sequel_core → sequel}/dataset/sql.rb +150 -99
  56. data/lib/sequel/deprecated.rb +593 -0
  57. data/lib/sequel/deprecated_migration.rb +91 -0
  58. data/lib/sequel/exceptions.rb +48 -0
  59. data/lib/sequel/extensions/blank.rb +42 -0
  60. data/lib/{sequel_model → sequel/extensions}/inflector.rb +8 -1
  61. data/lib/{sequel_core → sequel/extensions}/migration.rb +1 -1
  62. data/lib/{sequel_core/dataset → sequel/extensions}/pagination.rb +0 -0
  63. data/lib/{sequel_core → sequel/extensions}/pretty_table.rb +7 -0
  64. data/lib/{sequel_core/dataset → sequel/extensions}/query.rb +7 -0
  65. data/lib/sequel/extensions/string_date_time.rb +47 -0
  66. data/lib/sequel/metaprogramming.rb +43 -0
  67. data/lib/sequel/model.rb +110 -0
  68. data/lib/sequel/model/associations.rb +1300 -0
  69. data/lib/sequel/model/base.rb +937 -0
  70. data/lib/sequel/model/deprecated.rb +204 -0
  71. data/lib/sequel/model/deprecated_hooks.rb +103 -0
  72. data/lib/sequel/model/deprecated_inflector.rb +335 -0
  73. data/lib/sequel/model/deprecated_validations.rb +388 -0
  74. data/lib/sequel/model/errors.rb +39 -0
  75. data/lib/{sequel_model → sequel/model}/exceptions.rb +4 -4
  76. data/lib/sequel/model/inflections.rb +208 -0
  77. data/lib/sequel/model/plugins.rb +76 -0
  78. data/lib/sequel/plugins/caching.rb +122 -0
  79. data/lib/sequel/plugins/hook_class_methods.rb +122 -0
  80. data/lib/sequel/plugins/schema.rb +53 -0
  81. data/lib/sequel/plugins/serialization.rb +117 -0
  82. data/lib/sequel/plugins/single_table_inheritance.rb +63 -0
  83. data/lib/sequel/plugins/validation_class_methods.rb +384 -0
  84. data/lib/sequel/plugins/validation_helpers.rb +150 -0
  85. data/lib/{sequel_core → sequel}/sql.rb +125 -190
  86. data/lib/{sequel_core → sequel}/version.rb +2 -1
  87. data/lib/sequel_core.rb +1 -172
  88. data/lib/sequel_model.rb +1 -91
  89. data/spec/adapters/firebird_spec.rb +5 -5
  90. data/spec/adapters/informix_spec.rb +1 -1
  91. data/spec/adapters/mysql_spec.rb +128 -42
  92. data/spec/adapters/oracle_spec.rb +47 -19
  93. data/spec/adapters/postgres_spec.rb +64 -52
  94. data/spec/adapters/spec_helper.rb +1 -1
  95. data/spec/adapters/sqlite_spec.rb +12 -17
  96. data/spec/{sequel_core → core}/connection_pool_spec.rb +10 -10
  97. data/spec/{sequel_core → core}/core_ext_spec.rb +19 -19
  98. data/spec/{sequel_core → core}/core_sql_spec.rb +68 -71
  99. data/spec/{sequel_core → core}/database_spec.rb +135 -99
  100. data/spec/{sequel_core → core}/dataset_spec.rb +398 -242
  101. data/spec/{sequel_core → core}/expression_filters_spec.rb +13 -13
  102. data/spec/core/migration_spec.rb +263 -0
  103. data/spec/{sequel_core → core}/object_graph_spec.rb +10 -10
  104. data/spec/{sequel_core → core}/pretty_table_spec.rb +2 -2
  105. data/spec/{sequel_core → core}/schema_generator_spec.rb +0 -0
  106. data/spec/{sequel_core → core}/schema_spec.rb +8 -10
  107. data/spec/{sequel_core → core}/spec_helper.rb +29 -2
  108. data/spec/{sequel_core → core}/version_spec.rb +0 -0
  109. data/spec/extensions/blank_spec.rb +67 -0
  110. data/spec/extensions/caching_spec.rb +201 -0
  111. data/spec/{sequel_model/hooks_spec.rb → extensions/hook_class_methods_spec.rb} +8 -23
  112. data/spec/{sequel_model → extensions}/inflector_spec.rb +3 -0
  113. data/spec/{sequel_core → extensions}/migration_spec.rb +4 -4
  114. data/spec/extensions/pagination_spec.rb +99 -0
  115. data/spec/extensions/pretty_table_spec.rb +91 -0
  116. data/spec/extensions/query_spec.rb +85 -0
  117. data/spec/{sequel_model → extensions}/schema_spec.rb +22 -1
  118. data/spec/extensions/serialization_spec.rb +109 -0
  119. data/spec/extensions/single_table_inheritance_spec.rb +53 -0
  120. data/spec/{sequel_model → extensions}/spec_helper.rb +13 -4
  121. data/spec/extensions/string_date_time_spec.rb +93 -0
  122. data/spec/{sequel_model/validations_spec.rb → extensions/validation_class_methods_spec.rb} +15 -103
  123. data/spec/extensions/validation_helpers_spec.rb +291 -0
  124. data/spec/integration/dataset_test.rb +31 -0
  125. data/spec/integration/eager_loader_test.rb +17 -30
  126. data/spec/integration/schema_test.rb +8 -5
  127. data/spec/integration/spec_helper.rb +17 -0
  128. data/spec/integration/transaction_test.rb +68 -0
  129. data/spec/{sequel_model → model}/association_reflection_spec.rb +0 -0
  130. data/spec/{sequel_model → model}/associations_spec.rb +23 -10
  131. data/spec/{sequel_model → model}/base_spec.rb +29 -20
  132. data/spec/{sequel_model → model}/caching_spec.rb +16 -14
  133. data/spec/{sequel_model → model}/dataset_methods_spec.rb +0 -0
  134. data/spec/{sequel_model → model}/eager_loading_spec.rb +8 -8
  135. data/spec/model/hooks_spec.rb +472 -0
  136. data/spec/model/inflector_spec.rb +126 -0
  137. data/spec/{sequel_model → model}/model_spec.rb +25 -20
  138. data/spec/model/plugins_spec.rb +142 -0
  139. data/spec/{sequel_model → model}/record_spec.rb +121 -62
  140. data/spec/model/schema_spec.rb +92 -0
  141. data/spec/model/spec_helper.rb +124 -0
  142. data/spec/model/validations_spec.rb +1080 -0
  143. metadata +136 -107
  144. data/lib/sequel_core/core_ext.rb +0 -217
  145. data/lib/sequel_core/dataset/callback.rb +0 -13
  146. data/lib/sequel_core/dataset/schema.rb +0 -15
  147. data/lib/sequel_core/deprecated.rb +0 -26
  148. data/lib/sequel_core/exceptions.rb +0 -44
  149. data/lib/sequel_core/schema.rb +0 -2
  150. data/lib/sequel_core/schema/sql.rb +0 -325
  151. data/lib/sequel_model/association_reflection.rb +0 -267
  152. data/lib/sequel_model/associations.rb +0 -499
  153. data/lib/sequel_model/base.rb +0 -539
  154. data/lib/sequel_model/caching.rb +0 -82
  155. data/lib/sequel_model/dataset_methods.rb +0 -26
  156. data/lib/sequel_model/eager_loading.rb +0 -370
  157. data/lib/sequel_model/hooks.rb +0 -101
  158. data/lib/sequel_model/plugins.rb +0 -62
  159. data/lib/sequel_model/record.rb +0 -568
  160. data/lib/sequel_model/schema.rb +0 -49
  161. data/lib/sequel_model/validations.rb +0 -429
  162. data/spec/sequel_model/plugins_spec.rb +0 -80
@@ -0,0 +1,126 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe String do
4
+ deprec_specify "#camelize and #camelcase should transform the word to CamelCase" do
5
+ "egg_and_hams".camelize.should == "EggAndHams"
6
+ "egg_and_hams".camelize(false).should == "eggAndHams"
7
+ "post".camelize.should == "Post"
8
+ "post".camelcase.should == "Post"
9
+ end
10
+
11
+ deprec_specify "#constantize should eval the string to get a constant" do
12
+ "String".constantize.should == String
13
+ "String::Inflections".constantize.should == String::Inflections
14
+ proc{"BKSDDF".constantize}.should raise_error
15
+ proc{"++A++".constantize}.should raise_error
16
+ end
17
+
18
+ deprec_specify "#dasherize should transform underscores to dashes" do
19
+ "egg_and_hams".dasherize.should == "egg-and-hams"
20
+ "post".dasherize.should == "post"
21
+ end
22
+
23
+ deprec_specify "#demodulize should remove any preceding modules" do
24
+ "String::Inflections::Blah".demodulize.should == "Blah"
25
+ "String::Inflections".demodulize.should == "Inflections"
26
+ "String".demodulize.should == "String"
27
+ end
28
+
29
+ deprec_specify "#humanize should remove _i, transform underscore to spaces, and capitalize" do
30
+ "egg_and_hams".humanize.should == "Egg and hams"
31
+ "post".humanize.should == "Post"
32
+ "post_id".humanize.should == "Post"
33
+ end
34
+
35
+ deprec_specify "#titleize and #titlecase should underscore, humanize, and capitalize all words" do
36
+ "egg-and: hams".titleize.should == "Egg And: Hams"
37
+ "post".titleize.should == "Post"
38
+ "post".titlecase.should == "Post"
39
+ end
40
+
41
+ deprec_specify "#underscore should add underscores between CamelCased words, change :: to / and - to _, and downcase" do
42
+ "EggAndHams".underscore.should == "egg_and_hams"
43
+ "EGGAndHams".underscore.should == "egg_and_hams"
44
+ "Egg::And::Hams".underscore.should == "egg/and/hams"
45
+ "post".underscore.should == "post"
46
+ "post-id".underscore.should == "post_id"
47
+ end
48
+
49
+ deprec_specify "#pluralize should transform words from singular to plural" do
50
+ "post".pluralize.should == "posts"
51
+ "octopus".pluralize.should =="octopi"
52
+ "the blue mailman".pluralize.should == "the blue mailmen"
53
+ "CamelOctopus".pluralize.should == "CamelOctopi"
54
+ end
55
+
56
+ deprec_specify "#singularize should transform words from plural to singular" do
57
+ "posts".singularize.should == "post"
58
+ "octopi".singularize.should == "octopus"
59
+ "the blue mailmen".singularize.should == "the blue mailman"
60
+ "CamelOctopi".singularize.should == "CamelOctopus"
61
+ end
62
+
63
+ deprec_specify "#tableize should transform class names to table names" do
64
+ "RawScaledScorer".tableize.should == "raw_scaled_scorers"
65
+ "egg_and_ham".tableize.should == "egg_and_hams"
66
+ "fancyCategory".tableize.should == "fancy_categories"
67
+ end
68
+
69
+ deprec_specify "#classify should tranform table names to class names" do
70
+ "egg_and_hams".classify.should == "EggAndHam"
71
+ "post".classify.should == "Post"
72
+ end
73
+
74
+ deprec_specify "#foreign_key should create a foreign key name from a class name" do
75
+ "Message".foreign_key.should == "message_id"
76
+ "Message".foreign_key(false).should == "messageid"
77
+ "Admin::Post".foreign_key.should == "post_id"
78
+ end
79
+ end
80
+
81
+ describe String::Inflections do
82
+ before do
83
+ deprec do
84
+ @plurals, @singulars, @uncountables = String.inflections.plurals.dup, String.inflections.singulars.dup, String.inflections.uncountables.dup
85
+ end
86
+ end
87
+ after do
88
+ deprec do
89
+ String.inflections.plurals.replace(@plurals)
90
+ String.inflections.singulars.replace(@singulars)
91
+ String.inflections.uncountables.replace(@uncountables)
92
+ Sequel.inflections.plurals.replace(@plurals)
93
+ Sequel.inflections.singulars.replace(@singulars)
94
+ Sequel.inflections.uncountables.replace(@uncountables)
95
+ end
96
+ end
97
+
98
+ deprec_specify "should be possible to clear the list of singulars, plurals, and uncountables" do
99
+ String.inflections.clear(:plurals)
100
+ String.inflections.plurals.should == []
101
+ String.inflections.plural('blah', 'blahs')
102
+ String.inflections.clear
103
+ String.inflections.plurals.should == []
104
+ String.inflections.singulars.should == []
105
+ String.inflections.uncountables.should == []
106
+ end
107
+
108
+ deprec_specify "should be able to specify new inflection rules" do
109
+ String.inflections do |i|
110
+ i.plural(/xx$/i, 'xxx')
111
+ i.singular(/ttt$/i, 'tt')
112
+ i.irregular('yy', 'yyy')
113
+ i.uncountable(%w'zz')
114
+ end
115
+ 'roxx'.pluralize.should == 'roxxx'
116
+ 'rottt'.singularize.should == 'rott'
117
+ 'yy'.pluralize.should == 'yyy'
118
+ 'yyy'.singularize.should == 'yy'
119
+ 'zz'.pluralize.should == 'zz'
120
+ 'zz'.singularize.should == 'zz'
121
+ end
122
+
123
+ deprec_specify "should be yielded and returned by String.inflections" do
124
+ String.inflections{|i| i.should == String::Inflections}.should == String::Inflections
125
+ end
126
+ end
@@ -64,7 +64,7 @@ describe Sequel::Model, "dataset & schema" do
64
64
  ds.should respond_to(:destroy)
65
65
  end
66
66
 
67
- it "sets schema with implicit table name" do
67
+ deprec_specify "sets schema with implicit table name" do
68
68
  @model.set_schema do
69
69
  primary_key :ssn, :string
70
70
  end
@@ -72,7 +72,7 @@ describe Sequel::Model, "dataset & schema" do
72
72
  @model.table_name.should == :items
73
73
  end
74
74
 
75
- it "sets schema with explicit table name" do
75
+ deprec_specify "sets schema with explicit table name" do
76
76
  @model.set_schema :foo do
77
77
  primary_key :id
78
78
  end
@@ -93,10 +93,12 @@ end
93
93
 
94
94
  describe Sequel::Model, "#sti_key" do
95
95
  before do
96
- class ::StiTest < Sequel::Model
97
- def kind=(x); self[:kind] = x; end
98
- def refresh; end
99
- set_sti_key :kind
96
+ deprec do
97
+ class ::StiTest < Sequel::Model
98
+ def kind=(x); self[:kind] = x; end
99
+ def refresh; end
100
+ set_sti_key :kind
101
+ end
100
102
  end
101
103
  class ::StiTestSub1 < StiTest
102
104
  end
@@ -106,7 +108,7 @@ describe Sequel::Model, "#sti_key" do
106
108
  MODEL_DB.reset
107
109
  end
108
110
 
109
- it "should return rows with the correct class based on the polymorphic_key value" do
111
+ deprec_specify "should return rows with the correct class based on the polymorphic_key value" do
110
112
  def @ds.fetch_rows(sql)
111
113
  yield({:kind=>'StiTest'})
112
114
  yield({:kind=>'StiTestSub1'})
@@ -115,28 +117,28 @@ describe Sequel::Model, "#sti_key" do
115
117
  StiTest.all.collect{|x| x.class}.should == [StiTest, StiTestSub1, StiTestSub2]
116
118
  end
117
119
 
118
- it "should fallback to the main class if polymophic_key value is NULL" do
120
+ deprec_specify "should fallback to the main class if polymophic_key value is NULL" do
119
121
  def @ds.fetch_rows(sql)
120
122
  yield({:kind=>nil})
121
123
  end
122
124
  StiTest.all.collect{|x| x.class}.should == [StiTest]
123
125
  end
124
126
 
125
- it "should fallback to the main class if the given class does not exist" do
127
+ deprec_specify "should fallback to the main class if the given class does not exist" do
126
128
  def @ds.fetch_rows(sql)
127
129
  yield({:kind=>'StiTestSub3'})
128
130
  end
129
131
  StiTest.all.collect{|x| x.class}.should == [StiTest]
130
132
  end
131
133
 
132
- it "should add a before_create hook that sets the model class name for the key" do
134
+ deprec_specify "should add a before_create hook that sets the model class name for the key" do
133
135
  StiTest.new.save
134
136
  StiTestSub1.new.save
135
137
  StiTestSub2.new.save
136
138
  MODEL_DB.sqls.should == ["INSERT INTO sti_tests (kind) VALUES ('StiTest')", "INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "INSERT INTO sti_tests (kind) VALUES ('StiTestSub2')"]
137
139
  end
138
140
 
139
- it "should add a filter to model datasets inside subclasses hook to only retreive objects with the matching key" do
141
+ deprec_specify "should add a filter to model datasets inside subclasses hook to only retreive objects with the matching key" do
140
142
  StiTest.dataset.sql.should == "SELECT * FROM sti_tests"
141
143
  StiTestSub1.dataset.sql.should == "SELECT * FROM sti_tests WHERE (kind = 'StiTestSub1')"
142
144
  StiTestSub2.dataset.sql.should == "SELECT * FROM sti_tests WHERE (kind = 'StiTestSub2')"
@@ -233,6 +235,11 @@ describe Sequel::Model, ".subset" do
233
235
  @c.new_only.pricey.sql.should == "SELECT * FROM items WHERE ((age < 'new') AND (price > 100))"
234
236
  end
235
237
 
238
+ specify "should not override existing model methods" do
239
+ @c.meta_def(:active){true}
240
+ @c.subset(:active, :active)
241
+ @c.active.should == true
242
+ end
236
243
  end
237
244
 
238
245
  describe Sequel::Model, ".find" do
@@ -284,10 +291,9 @@ describe Sequel::Model, ".fetch" do
284
291
 
285
292
  it "should return true for .empty? and not raise an error on empty selection" do
286
293
  rows = @c.fetch("SELECT * FROM items WHERE FALSE")
287
- @c.class_def(:fetch_rows) {|sql| yield({:count => 0})}
294
+ @c.send(:define_method, :fetch_rows){|sql| yield({:count => 0})}
288
295
  proc {rows.empty?}.should_not raise_error
289
296
  end
290
-
291
297
  end
292
298
 
293
299
  describe Sequel::Model, ".find_or_create" do
@@ -332,7 +338,7 @@ describe Sequel::Model, ".delete_all" do
332
338
  @c.dataset.meta_def(:delete) {MODEL_DB << delete_sql}
333
339
  end
334
340
 
335
- it "should delete all records in the dataset" do
341
+ deprec_specify "should delete all records in the dataset" do
336
342
  @c.delete_all
337
343
  MODEL_DB.sqls.should == ["DELETE FROM items"]
338
344
  end
@@ -350,13 +356,13 @@ describe Sequel::Model, ".destroy_all" do
350
356
  @c.dataset.meta_def(:delete) {MODEL_DB << delete_sql}
351
357
  end
352
358
 
353
- it "should delete all records in the dataset" do
359
+ deprec_specify "should delete all records in the dataset" do
354
360
  @c.dataset.meta_def(:destroy) {MODEL_DB << "DESTROY this stuff"}
355
361
  @c.destroy_all
356
362
  MODEL_DB.sqls.should == ["DESTROY this stuff"]
357
363
  end
358
364
 
359
- it "should call dataset.destroy" do
365
+ deprec_specify "should call dataset.destroy" do
360
366
  @c.dataset.should_receive(:destroy).and_return(true)
361
367
  @c.destroy_all
362
368
  end
@@ -511,7 +517,7 @@ describe Sequel::Model, ".[]" do
511
517
  end
512
518
 
513
519
  context "Model#inspect" do
514
- setup do
520
+ before do
515
521
  @o = Sequel::Model.load(:x => 333)
516
522
  end
517
523
 
@@ -521,13 +527,12 @@ context "Model#inspect" do
521
527
  end
522
528
 
523
529
  context "Model.db_schema" do
524
- setup do
530
+ before do
525
531
  @c = Class.new(Sequel::Model(:items)) do
526
532
  def self.columns; orig_columns; end
527
533
  end
528
534
  @dataset = Sequel::Dataset.new(nil).from(:items)
529
535
  @dataset.meta_def(:db){@db ||= Sequel::Database.new}
530
- def @dataset.set_model(blah); end
531
536
  def @dataset.naked; self; end
532
537
  def @dataset.columns; []; end
533
538
  def @dataset.def_mutation_method(*names); end
@@ -579,7 +584,7 @@ context "Model.db_schema" do
579
584
  end
580
585
 
581
586
  context "Model.str_columns" do
582
- specify "should return the columns as frozen strings" do
587
+ deprec_specify "should return the columns as frozen strings" do
583
588
  c = Class.new(Sequel::Model)
584
589
  c.meta_def(:columns){[:a, :b]}
585
590
  c.orig_str_columns.should == %w'a b'
@@ -0,0 +1,142 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ module Sequel::Plugins
4
+
5
+ module Timestamped
6
+ def self.apply(m, opts)
7
+ m.meta_def(:stamp_opts) {opts}
8
+ m.send(:define_method, :before_save){@values[:stamp] = Time.now}
9
+ end
10
+
11
+ module InstanceMethods
12
+ def get_stamp(*args); @values[:stamp] end
13
+ def abc; timestamped_opts; end
14
+ end
15
+
16
+ module ClassMethods
17
+ def deff; timestamped_opts; end
18
+ end
19
+
20
+ module DatasetMethods
21
+ def ghi; timestamped_opts; end
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ describe Sequel::Model, "using a plugin" do
28
+
29
+ it "should fail if the plugin is not found" do
30
+ proc do
31
+ c = Class.new(Sequel::Model)
32
+ c.class_eval do
33
+ plugin :something_or_other
34
+ end
35
+ end.should raise_error(LoadError)
36
+ end
37
+
38
+ it "should apply the plugin to the class" do
39
+ c = nil
40
+ proc do
41
+ c = Class.new(Sequel::Model)
42
+ c.class_eval do
43
+ set_dataset MODEL_DB[:items]
44
+ plugin :timestamped, :a => 1, :b => 2
45
+ end
46
+ end.should_not raise_error(LoadError)
47
+
48
+ c.should respond_to(:stamp_opts)
49
+ c.stamp_opts.should == {:a => 1, :b => 2}
50
+
51
+ # instance methods
52
+ m = c.new
53
+ m.should respond_to(:get_stamp)
54
+ m.should respond_to(:abc)
55
+ m.abc.should == {:a => 1, :b => 2}
56
+ t = Time.now
57
+ m[:stamp] = t
58
+ m.get_stamp.should == t
59
+
60
+ # class methods
61
+ c.should respond_to(:deff)
62
+ c.deff.should == {:a => 1, :b => 2}
63
+
64
+ # dataset methods
65
+ c.dataset.should respond_to(:ghi)
66
+ c.dataset.ghi.should == {:a => 1, :b => 2}
67
+
68
+ # dataset methods called on the class
69
+ c.should respond_to(:ghi)
70
+ c.ghi.should == {:a => 1, :b => 2}
71
+ end
72
+
73
+ deprec_specify "should have an .is alias" do
74
+ c = nil
75
+ proc do
76
+ c = Class.new(Sequel::Model)
77
+ c.class_eval do
78
+ set_dataset MODEL_DB[:items]
79
+ is :timestamped, :a => 1, :b => 2
80
+ end
81
+ end.should_not raise_error(LoadError)
82
+
83
+ c.should respond_to(:stamp_opts)
84
+ c.stamp_opts.should == {:a => 1, :b => 2}
85
+
86
+ # instance methods
87
+ m = c.new
88
+ m.should respond_to(:get_stamp)
89
+ m.should respond_to(:abc)
90
+ m.abc.should == {:a => 1, :b => 2}
91
+ t = Time.now
92
+ m[:stamp] = t
93
+ m.get_stamp.should == t
94
+
95
+ # class methods
96
+ c.should respond_to(:deff)
97
+ c.deff.should == {:a => 1, :b => 2}
98
+
99
+ # dataset methods
100
+ c.dataset.should respond_to(:ghi)
101
+ c.dataset.ghi.should == {:a => 1, :b => 2}
102
+
103
+ # dataset methods called on the class
104
+ c.should respond_to(:ghi)
105
+ c.ghi.should == {:a => 1, :b => 2}
106
+ end
107
+
108
+ deprec_specify "should have an .is_a alias" do
109
+ c = nil
110
+ proc do
111
+ c = Class.new(Sequel::Model)
112
+ c.class_eval do
113
+ set_dataset MODEL_DB[:items]
114
+ is_a :timestamped, :a => 1, :b => 2
115
+ end
116
+ end.should_not raise_error(LoadError)
117
+
118
+ c.should respond_to(:stamp_opts)
119
+ c.stamp_opts.should == {:a => 1, :b => 2}
120
+
121
+ # instance methods
122
+ m = c.new
123
+ m.should respond_to(:get_stamp)
124
+ m.should respond_to(:abc)
125
+ m.abc.should == {:a => 1, :b => 2}
126
+ t = Time.now
127
+ m[:stamp] = t
128
+ m.get_stamp.should == t
129
+
130
+ # class methods
131
+ c.should respond_to(:deff)
132
+ c.deff.should == {:a => 1, :b => 2}
133
+
134
+ # dataset methods
135
+ c.dataset.should respond_to(:ghi)
136
+ c.dataset.ghi.should == {:a => 1, :b => 2}
137
+
138
+ # dataset methods called on the class
139
+ c.should respond_to(:ghi)
140
+ c.ghi.should == {:a => 1, :b => 2}
141
+ end
142
+ end
@@ -3,11 +3,10 @@ require File.join(File.dirname(__FILE__), "spec_helper")
3
3
  describe "Model#save" do
4
4
 
5
5
  before(:each) do
6
- MODEL_DB.reset
7
-
8
6
  @c = Class.new(Sequel::Model(:items)) do
9
7
  columns :id, :x, :y
10
8
  end
9
+ MODEL_DB.reset
11
10
  end
12
11
 
13
12
  it "should insert a record for a new model instance" do
@@ -41,7 +40,6 @@ describe "Model#save" do
41
40
  it "should update only the given columns if given" do
42
41
  o = @c.load(:id => 3, :x => 1, :y => nil)
43
42
  o.save(:y)
44
-
45
43
  MODEL_DB.sqls.first.should == "UPDATE items SET y = NULL WHERE (id = 3)"
46
44
  end
47
45
 
@@ -55,28 +53,83 @@ describe "Model#save" do
55
53
  o.changed_columns.should == []
56
54
  end
57
55
 
58
- it "should preserve changed_columns' and @new's value until all hook finish running" do
56
+ it "should store previous value of @new in @was_new and as well as the hash used for updating in @columns_updated until after hooks finish running" do
59
57
  res = nil
60
- @c.after_save { res = [changed_columns, @new].flatten}
58
+ @c.send(:define_method, :after_save){ res = [@columns_updated, @was_new]}
61
59
  o = @c.new(:x => 1, :y => nil)
62
60
  o[:x] = 2
63
61
  o.save
64
- res.should == [:x,true]
62
+ res.should == [nil, true]
63
+ o.after_save
64
+ res.should == [nil, nil]
65
65
 
66
66
  res = nil
67
67
  o = @c.load(:id => 23,:x => 1, :y => nil)
68
68
  o[:x] = 2
69
69
  o.save
70
- res.should == [:x,false]
70
+ res.should == [{:id => 23,:x => 2, :y => nil}, nil]
71
+ o.after_save
72
+ res.should == [nil, nil]
71
73
 
72
74
  res = nil
73
- o = @c.load(:id => 23,:x => 1, :y => nil)
75
+ o = @c.load(:id => 23,:x => 2, :y => nil)
74
76
  o[:x] = 2
75
77
  o[:y] = 22
76
78
  o.save(:x)
77
- res.should == [:x,:y,false]
79
+ res.should == [{:x=>2},nil]
80
+ o.after_save
81
+ res.should == [nil, nil]
78
82
  end
79
83
 
84
+ it "should use Model's save_in_transaction setting by default" do
85
+ @c.use_transactions = true
86
+ @c.load(:id => 3, :x => 1, :y => nil).save(:y)
87
+ MODEL_DB.sqls.should == ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
88
+ MODEL_DB.reset
89
+ @c.use_transactions = false
90
+ @c.load(:id => 3, :x => 1, :y => nil).save(:y)
91
+ MODEL_DB.sqls.should == ["UPDATE items SET y = NULL WHERE (id = 3)"]
92
+ MODEL_DB.reset
93
+ end
94
+
95
+ it "should inherit Model's save_in_transaction setting" do
96
+ @c.use_transactions = true
97
+ Class.new(@c).load(:id => 3, :x => 1, :y => nil).save(:y)
98
+ MODEL_DB.sqls.should == ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
99
+ MODEL_DB.reset
100
+ @c.use_transactions = false
101
+ Class.new(@c).load(:id => 3, :x => 1, :y => nil).save(:y)
102
+ MODEL_DB.sqls.should == ["UPDATE items SET y = NULL WHERE (id = 3)"]
103
+ MODEL_DB.reset
104
+ end
105
+
106
+ it "should use object's save_in_transaction setting" do
107
+ o = @c.load(:id => 3, :x => 1, :y => nil)
108
+ o.use_transactions = false
109
+ @c.use_transactions = true
110
+ o.save(:y)
111
+ MODEL_DB.sqls.should == ["UPDATE items SET y = NULL WHERE (id = 3)"]
112
+ MODEL_DB.reset
113
+ o = @c.load(:id => 3, :x => 1, :y => nil)
114
+ o.use_transactions = true
115
+ @c.use_transactions = false
116
+ o.save(:y)
117
+ MODEL_DB.sqls.should == ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
118
+ MODEL_DB.reset
119
+ end
120
+
121
+ it "should use :transaction option if given" do
122
+ o = @c.load(:id => 3, :x => 1, :y => nil)
123
+ o.use_transactions = true
124
+ o.save(:y, :transaction=>false)
125
+ MODEL_DB.sqls.should == ["UPDATE items SET y = NULL WHERE (id = 3)"]
126
+ MODEL_DB.reset
127
+ o = @c.load(:id => 3, :x => 1, :y => nil)
128
+ o.use_transactions = false
129
+ o.save(:y, :transaction=>true)
130
+ MODEL_DB.sqls.should == ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
131
+ MODEL_DB.reset
132
+ end
80
133
  end
81
134
 
82
135
  describe "Model#save_changes" do
@@ -142,7 +195,7 @@ describe "Model#save_changes" do
142
195
 
143
196
  it "should update columns changed in a before_update hook" do
144
197
  o = @c.load(:id => 3, :x => 1, :y => nil)
145
- @c.before_update{self.x += 1}
198
+ @c.send(:define_method, :before_update){self.x += 1}
146
199
  o.save_changes
147
200
  MODEL_DB.sqls.should == []
148
201
  o.x = 2
@@ -159,7 +212,7 @@ describe "Model#save_changes" do
159
212
 
160
213
  it "should update columns changed in a before_save hook" do
161
214
  o = @c.load(:id => 3, :x => 1, :y => nil)
162
- @c.before_save{self.x += 1}
215
+ @c.send(:define_method, :before_update){self.x += 1}
163
216
  o.save_changes
164
217
  MODEL_DB.sqls.should == []
165
218
  o.x = 2
@@ -185,20 +238,20 @@ describe "Model#update_values" do
185
238
  end
186
239
  end
187
240
 
188
- it "should generate an update statement" do
241
+ deprec_specify "should generate an update statement" do
189
242
  o = @c.new(:id => 1)
190
243
  o.update_values(:x => 1)
191
244
  MODEL_DB.sqls.first.should == "UPDATE items SET x = 1 WHERE (id = 1)"
192
245
  end
193
246
 
194
- it "should update attribute values" do
247
+ deprec_specify "should update attribute values" do
195
248
  o = @c.new(:id => 1)
196
249
  o.x.should be_nil
197
250
  o.update_values(:x => 1)
198
251
  o.x.should == 1
199
252
  end
200
253
 
201
- it "should support string keys" do
254
+ deprec_specify "should support string keys" do
202
255
  o = @c.new(:id => 1)
203
256
  o.x.should be_nil
204
257
  o.update_values('x' => 1)
@@ -217,27 +270,27 @@ describe "Model#set_values" do
217
270
  end
218
271
  end
219
272
 
220
- it "should not touch the database" do
273
+ deprec_specify "should not touch the database" do
221
274
  o = @c.new(:id => 1)
222
275
  o.set_values(:x => 1)
223
276
  MODEL_DB.sqls.should == []
224
277
  end
225
278
 
226
- it "should update attribute values" do
279
+ deprec_specify "should update attribute values" do
227
280
  o = @c.new(:id => 1)
228
281
  o.x.should be_nil
229
282
  o.set_values(:x => 1)
230
283
  o.x.should == 1
231
284
  end
232
285
 
233
- it "should support string keys" do
286
+ deprec_specify "should support string keys" do
234
287
  o = @c.new(:id => 1)
235
288
  o.x.should be_nil
236
289
  o.set_values('x' => 1)
237
290
  o.x.should == 1
238
291
  end
239
292
 
240
- it "should raise an error if used with a non-String, non-Symbol key" do
293
+ deprec_specify "should raise an error if used with a non-String, non-Symbol key" do
241
294
  proc{@c.new.set_values(1=>2)}.should raise_error(Sequel::Error)
242
295
  end
243
296
  end
@@ -435,7 +488,7 @@ describe Sequel::Model, "#set" do
435
488
  end
436
489
 
437
490
  it "should support virtual attributes" do
438
- @c.class_def(:blah=) {|v| self.x = v}
491
+ @c.send(:define_method, :blah=){|v| self.x = v}
439
492
  @o1.set(:blah => 333)
440
493
  @o1.values.should == {:x => 333}
441
494
  MODEL_DB.sqls.should == []
@@ -453,19 +506,19 @@ describe Sequel::Model, "#set" do
453
506
  MODEL_DB.sqls.should == []
454
507
  end
455
508
 
456
- it "should be aliased as set_with_params" do
509
+ deprec_specify "should be aliased as set_with_params" do
457
510
  @o1.set_with_params(:x => 1, :z => 2)
458
511
  @o1.values.should == {:x => 1}
459
512
  MODEL_DB.sqls.should == []
460
513
  end
461
514
 
462
515
  it "should return self" do
463
- returned_value = @o1.set_with_params(:x => 1, :z => 2)
516
+ returned_value = @o1.set(:x => 1, :z => 2)
464
517
  returned_value.should == @o1
465
518
  MODEL_DB.sqls.should == []
466
519
  end
467
520
 
468
- it "should assume it is a column if no column information is present and the key is a symbol" do
521
+ deprec_specify "should assume it is a column if no column information is present and the key is a symbol" do
469
522
  @c.instance_variable_set(:@columns, nil)
470
523
  o = @c.new.set(:x123=>1)
471
524
  o[:x123].should == 1
@@ -496,7 +549,7 @@ describe Sequel::Model, "#update" do
496
549
  end
497
550
 
498
551
  it "should support virtual attributes" do
499
- @c.class_def(:blah=) {|v| self.x = v}
552
+ @c.send(:define_method, :blah=){|v| self.x = v}
500
553
  @o1.update(:blah => 333)
501
554
  MODEL_DB.sqls.first.should == "INSERT INTO items (x) VALUES (333)"
502
555
  end
@@ -510,7 +563,7 @@ describe Sequel::Model, "#update" do
510
563
  MODEL_DB.sqls.first.should == "UPDATE items SET y = 1 WHERE (id = 5)"
511
564
  end
512
565
 
513
- it "should be aliased as update_with_params" do
566
+ deprec_specify "should be aliased as update_with_params" do
514
567
  @o1.update_with_params(:x => 1, :z => 2)
515
568
  MODEL_DB.sqls.first.should == "INSERT INTO items (x) VALUES (1)"
516
569
  end
@@ -589,19 +642,25 @@ describe Sequel::Model, "#destroy" do
589
642
  end
590
643
 
591
644
  it "should return self" do
592
- @model.db.should_receive(:transaction)
593
- @model.after_destroy{3}
645
+ @model.send(:define_method, :after_destroy){3}
594
646
  @instance.destroy.should == @instance
595
647
  end
596
648
 
597
- it "should run within a transaction" do
649
+ it "should run within a transaction if use_transactions is true" do
650
+ @instance.use_transactions = true
598
651
  @model.db.should_receive(:transaction)
599
652
  @instance.destroy
600
653
  end
601
654
 
655
+ it "should not run within a transaction if use_transactions is false" do
656
+ @instance.use_transactions = false
657
+ @model.db.should_not_receive(:transaction)
658
+ @instance.destroy
659
+ end
660
+
602
661
  it "should run before_destroy and after_destroy hooks" do
603
- @model.before_destroy {MODEL_DB.execute('before blah')}
604
- @model.after_destroy {MODEL_DB.execute('after blah')}
662
+ @model.send(:define_method, :before_destroy){MODEL_DB.execute('before blah')}
663
+ @model.send(:define_method, :after_destroy){MODEL_DB.execute('after blah')}
605
664
  @instance.destroy
606
665
 
607
666
  MODEL_DB.sqls.should == [
@@ -630,7 +689,7 @@ describe Sequel::Model, "#exists?" do
630
689
  end
631
690
 
632
691
  describe Sequel::Model, "#each" do
633
- setup do
692
+ before do
634
693
  @model = Class.new(Sequel::Model(:items))
635
694
  @model.columns :a, :b, :id
636
695
  @m = @model.load(:a => 1, :b => 2, :id => 4444)
@@ -644,7 +703,7 @@ describe Sequel::Model, "#each" do
644
703
  end
645
704
 
646
705
  describe Sequel::Model, "#keys" do
647
- setup do
706
+ before do
648
707
  @model = Class.new(Sequel::Model(:items))
649
708
  @model.columns :a, :b, :id
650
709
  @m = @model.load(:a => 1, :b => 2, :id => 4444)
@@ -750,7 +809,7 @@ describe Sequel::Model, "#hash" do
750
809
  end
751
810
 
752
811
  describe Sequel::Model, "#initialize" do
753
- setup do
812
+ before do
754
813
  @c = Class.new(Sequel::Model) do
755
814
  columns :id, :x
756
815
  end
@@ -778,8 +837,8 @@ describe Sequel::Model, "#initialize" do
778
837
  end
779
838
 
780
839
  specify "should accept virtual attributes" do
781
- @c.class_def(:blah=) {|x| @blah = x}
782
- @c.class_def(:blah) {@blah}
840
+ @c.send(:define_method, :blah=){|x| @blah = x}
841
+ @c.send(:define_method, :blah){@blah}
783
842
 
784
843
  m = @c.new(:x => 2, :blah => 3)
785
844
  m.values.should == {:x => 2}
@@ -833,7 +892,7 @@ describe Sequel::Model, ".create" do
833
892
  end
834
893
 
835
894
  describe Sequel::Model, "#refresh" do
836
- setup do
895
+ before do
837
896
  MODEL_DB.reset
838
897
  @c = Class.new(Sequel::Model(:items)) do
839
898
  unrestrict_primary_key
@@ -872,14 +931,14 @@ describe Sequel::Model, "#refresh" do
872
931
  end
873
932
 
874
933
  describe Sequel::Model, "typecasting" do
875
- setup do
934
+ before do
876
935
  MODEL_DB.reset
877
936
  @c = Class.new(Sequel::Model(:items)) do
878
937
  columns :x
879
938
  end
880
939
  end
881
940
 
882
- teardown do
941
+ after do
883
942
  Sequel.datetime_class = Time
884
943
  end
885
944
 
@@ -891,7 +950,7 @@ describe Sequel::Model, "typecasting" do
891
950
  m.x.should == '1'
892
951
  end
893
952
 
894
- specify "should not convert if serializing the field" do
953
+ deprec_specify "should not convert if serializing the field" do
895
954
  @c.serialize :x
896
955
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:string}})
897
956
  m = @c.new
@@ -968,7 +1027,7 @@ describe Sequel::Model, "typecasting" do
968
1027
 
969
1028
  specify "should raise an error if invalid data is used in an integer field" do
970
1029
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:integer}})
971
- proc{@c.new.x = 'a'}.should raise_error(Sequel::Error::InvalidValue)
1030
+ proc{@c.new.x = 'a'}.should raise_error(Sequel::InvalidValue)
972
1031
  end
973
1032
 
974
1033
  specify "should assign value if raise_on_typecast_failure is off and assigning invalid integer" do
@@ -992,7 +1051,7 @@ describe Sequel::Model, "typecasting" do
992
1051
 
993
1052
  specify "should raise an error if invalid data is used in an float field" do
994
1053
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:float}})
995
- proc{@c.new.x = 'a'}.should raise_error(Sequel::Error::InvalidValue)
1054
+ proc{@c.new.x = 'a'}.should raise_error(Sequel::InvalidValue)
996
1055
  end
997
1056
 
998
1057
  specify "should assign value if raise_on_typecast_failure is off and assigning invalid float" do
@@ -1019,7 +1078,7 @@ describe Sequel::Model, "typecasting" do
1019
1078
 
1020
1079
  specify "should raise an error if invalid data is used in an decimal field" do
1021
1080
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:decimal}})
1022
- proc{@c.new.x = Date.today}.should raise_error(Sequel::Error::InvalidValue)
1081
+ proc{@c.new.x = Date.today}.should raise_error(Sequel::InvalidValue)
1023
1082
  end
1024
1083
 
1025
1084
  specify "should assign value if raise_on_typecast_failure is off and assigning invalid decimal" do
@@ -1085,18 +1144,18 @@ describe Sequel::Model, "typecasting" do
1085
1144
  y = Date.new(2007,10,21)
1086
1145
  m.x = '2007-10-21'
1087
1146
  m.x.should == y
1088
- m.x = '2007-10-21'.to_date
1147
+ m.x = Date.parse('2007-10-21')
1089
1148
  m.x.should == y
1090
- m.x = '2007-10-21'.to_time
1149
+ m.x = Time.parse('2007-10-21')
1091
1150
  m.x.should == y
1092
- m.x = '2007-10-21'.to_datetime
1151
+ m.x = DateTime.parse('2007-10-21')
1093
1152
  m.x.should == y
1094
1153
  end
1095
1154
 
1096
1155
  specify "should raise an error if invalid data is used in a date field" do
1097
1156
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:date}})
1098
- proc{@c.new.x = 'a'}.should raise_error(Sequel::Error::InvalidValue)
1099
- proc{@c.new.x = 100}.should raise_error(Sequel::Error::InvalidValue)
1157
+ proc{@c.new.x = 'a'}.should raise_error(Sequel::InvalidValue)
1158
+ proc{@c.new.x = 100}.should raise_error(Sequel::InvalidValue)
1100
1159
  end
1101
1160
 
1102
1161
  specify "should assign value if raise_on_typecast_failure is off and assigning invalid date" do
@@ -1111,7 +1170,7 @@ describe Sequel::Model, "typecasting" do
1111
1170
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:time}})
1112
1171
  m = @c.new
1113
1172
  x = '10:20:30'
1114
- y = x.to_time
1173
+ y = Time.parse(x)
1115
1174
  m.x = x
1116
1175
  m.x.should == y
1117
1176
  m.x = y
@@ -1122,8 +1181,8 @@ describe Sequel::Model, "typecasting" do
1122
1181
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:time}})
1123
1182
  proc{@c.new.x = '0000'}.should raise_error
1124
1183
  proc{@c.new.x = 'a'}.should_not raise_error # Valid Time
1125
- proc{@c.new.x = '2008-10-21'.to_date}.should raise_error(Sequel::Error::InvalidValue)
1126
- proc{@c.new.x = '2008-10-21'.to_datetime}.should raise_error(Sequel::Error::InvalidValue)
1184
+ proc{@c.new.x = Date.parse('2008-10-21')}.should raise_error(Sequel::InvalidValue)
1185
+ proc{@c.new.x = DateTime.parse('2008-10-21')}.should raise_error(Sequel::InvalidValue)
1127
1186
  end
1128
1187
 
1129
1188
  specify "should assign value if raise_on_typecast_failure is off and assigning invalid time" do
@@ -1138,34 +1197,34 @@ describe Sequel::Model, "typecasting" do
1138
1197
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:datetime}})
1139
1198
  m = @c.new
1140
1199
  x = '2007-10-21T10:20:30-07:00'
1141
- y = x.to_time
1200
+ y = Time.parse(x)
1142
1201
  m.x = x
1143
1202
  m.x.should == y
1144
- m.x = x.to_datetime
1203
+ m.x = DateTime.parse(x)
1145
1204
  m.x.should == y
1146
- m.x = x.to_time
1205
+ m.x = Time.parse(x)
1147
1206
  m.x.should == y
1148
- m.x = '2007-10-21'.to_date
1149
- m.x.should == '2007-10-21'.to_time
1207
+ m.x = Date.parse('2007-10-21')
1208
+ m.x.should == Time.parse('2007-10-21')
1150
1209
  Sequel.datetime_class = DateTime
1151
- y = x.to_datetime
1210
+ y = DateTime.parse(x)
1152
1211
  m.x = x
1153
1212
  m.x.should == y
1154
- m.x = x.to_datetime
1213
+ m.x = DateTime.parse(x)
1155
1214
  m.x.should == y
1156
- m.x = x.to_time
1215
+ m.x = Time.parse(x)
1157
1216
  m.x.should == y
1158
- m.x = '2007-10-21'.to_date
1159
- m.x.should == '2007-10-21'.to_datetime
1217
+ m.x = Date.parse('2007-10-21')
1218
+ m.x.should == DateTime.parse('2007-10-21')
1160
1219
  end
1161
1220
 
1162
1221
  specify "should raise an error if invalid data is used in a datetime field" do
1163
1222
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:datetime}})
1164
- proc{@c.new.x = '0000'}.should raise_error(Sequel::Error::InvalidValue)
1223
+ proc{@c.new.x = '0000'}.should raise_error(Sequel::InvalidValue)
1165
1224
  proc{@c.new.x = 'a'}.should_not raise_error # Valid Time
1166
1225
  Sequel.datetime_class = DateTime
1167
- proc{@c.new.x = '0000'}.should raise_error(Sequel::Error::InvalidValue)
1168
- proc{@c.new.x = 'a'}.should raise_error(Sequel::Error::InvalidValue)
1226
+ proc{@c.new.x = '0000'}.should raise_error(Sequel::InvalidValue)
1227
+ proc{@c.new.x = 'a'}.should raise_error(Sequel::InvalidValue)
1169
1228
  end
1170
1229
 
1171
1230
  specify "should assign value if raise_on_typecast_failure is off and assigning invalid datetime" do