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
@@ -1,7 +1,34 @@
1
1
  require 'rubygems'
2
2
  unless Object.const_defined?('Sequel')
3
3
  $:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
4
- require 'sequel_core'
4
+ require 'sequel/core'
5
+ end
6
+
7
+ Sequel.virtual_row_instance_eval = true
8
+
9
+ module Spec::Example::ExampleMethods
10
+ def deprec
11
+ output = Sequel::Deprecation.output = nil
12
+ begin
13
+ yield
14
+ ensure
15
+ Sequel::Deprecation.output = output
16
+ end
17
+ end
18
+ end
19
+
20
+ module Spec::Example::ExampleGroupMethods
21
+ def deprec_specify(*args, &block)
22
+ specify(*args) do
23
+ output = Sequel::Deprecation.output
24
+ Sequel::Deprecation.output = nil
25
+ begin
26
+ instance_eval(&block)
27
+ ensure
28
+ Sequel::Deprecation.output = output
29
+ end
30
+ end
31
+ end
5
32
  end
6
33
 
7
34
  class MockDataset < Sequel::Dataset
@@ -38,7 +65,7 @@ class MockDatabase < Sequel::Database
38
65
  @sqls = []
39
66
  end
40
67
 
41
- def transaction; yield; end
68
+ def transaction(opts={}); yield; end
42
69
 
43
70
  def dataset; MockDataset.new(self); end
44
71
  end
File without changes
@@ -0,0 +1,67 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ context "Object#blank?" do
4
+ specify "it should be true if the object responds true to empty?" do
5
+ [].blank?.should == true
6
+ {}.blank?.should == true
7
+ o = Object.new
8
+ def o.empty?; true; end
9
+ o.blank?.should == true
10
+ end
11
+
12
+ specify "it should be false if the object doesn't respond true to empty?" do
13
+ [2].blank?.should == false
14
+ {1=>2}.blank?.should == false
15
+ Object.new.blank?.should == false
16
+ end
17
+ end
18
+
19
+ context "Numeric#blank?" do
20
+ specify "it should always be false" do
21
+ 1.blank?.should == false
22
+ 0.blank?.should == false
23
+ -1.blank?.should == false
24
+ 1.0.blank?.should == false
25
+ 0.0.blank?.should == false
26
+ -1.0.blank?.should == false
27
+ 10000000000000000.blank?.should == false
28
+ -10000000000000000.blank?.should == false
29
+ 10000000000000000.0.blank?.should == false
30
+ -10000000000000000.0.blank?.should == false
31
+ end
32
+ end
33
+
34
+ context "NilClass#blank?" do
35
+ specify "it should always be true" do
36
+ nil.blank?.should == true
37
+ end
38
+ end
39
+
40
+ context "TrueClass#blank?" do
41
+ specify "it should always be false" do
42
+ true.blank?.should == false
43
+ end
44
+ end
45
+
46
+ context "FalseClass#blank?" do
47
+ specify "it should always be true" do
48
+ false.blank?.should == true
49
+ end
50
+ end
51
+
52
+ context "String#blank?" do
53
+ specify "it should be true if the string is empty" do
54
+ ''.blank?.should == true
55
+ end
56
+ specify "it should be true if the string is composed of just whitespace" do
57
+ ' '.blank?.should == true
58
+ "\r\n\t".blank?.should == true
59
+ (' '*4000).blank?.should == true
60
+ ("\r\n\t"*4000).blank?.should == true
61
+ end
62
+ specify "it should be false if the string has any non whitespace characters" do
63
+ '1'.blank?.should == false
64
+ ("\r\n\t"*4000 + 'a').blank?.should == false
65
+ ("\r\na\t"*4000).blank?.should == false
66
+ end
67
+ end
@@ -0,0 +1,201 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe Sequel::Model, "caching" do
4
+ before do
5
+ MODEL_DB.reset
6
+
7
+ @cache_class = Class.new(Hash) do
8
+ attr_accessor :ttl
9
+ def set(k, v, ttl); self[k] = v; @ttl = ttl; end
10
+ def get(k); self[k]; end
11
+ end
12
+ cache = @cache_class.new
13
+ @cache = cache
14
+
15
+ @c = Class.new(Sequel::Model(:items))
16
+ @c.class_eval do
17
+ plugin :caching, cache
18
+ def self.name; 'Item' end
19
+
20
+ columns :name, :id
21
+ end
22
+
23
+ $cache_dataset_row = {:name => 'sharon', :id => 1}
24
+ @dataset = @c.dataset
25
+ $sqls = []
26
+ @dataset.extend(Module.new {
27
+ def fetch_rows(sql)
28
+ $sqls << sql
29
+ yield $cache_dataset_row
30
+ end
31
+
32
+ def update(values)
33
+ $sqls << update_sql(values)
34
+ $cache_dataset_row.merge!(values)
35
+ end
36
+
37
+ def delete
38
+ $sqls << delete_sql
39
+ end
40
+ })
41
+ @c2 = Class.new(@c) do
42
+ def self.name; 'SubItem' end
43
+ end
44
+ end
45
+
46
+ it "should set the model's cache store" do
47
+ @c.cache_store.should be(@cache)
48
+ @c2.cache_store.should be(@cache)
49
+ end
50
+
51
+ it "should have a default ttl of 3600" do
52
+ @c.cache_ttl.should == 3600
53
+ @c2.cache_ttl.should == 3600
54
+ end
55
+
56
+ it "should take a ttl option" do
57
+ @c.plugin :caching, @cache, :ttl => 1234
58
+ @c.cache_ttl.should == 1234
59
+ Class.new(@c).cache_ttl.should == 1234
60
+ end
61
+
62
+ it "should offer a set_cache_ttl method for setting the ttl" do
63
+ @c.cache_ttl.should == 3600
64
+ @c.set_cache_ttl 1234
65
+ @c.cache_ttl.should == 1234
66
+ Class.new(@c).cache_ttl.should == 1234
67
+ end
68
+
69
+ it "should generate a cache key appropriate to the class" do
70
+ m = @c.new
71
+ m.values[:id] = 1
72
+ m.cache_key.should == "#{m.class}:1"
73
+ m = @c2.new
74
+ m.values[:id] = 1
75
+ m.cache_key.should == "#{m.class}:1"
76
+
77
+ # custom primary key
78
+ @c.set_primary_key :ttt
79
+ m = @c.new
80
+ m.values[:ttt] = 333
81
+ m.cache_key.should == "#{m.class}:333"
82
+ c = Class.new(@c)
83
+ m = c.new
84
+ m.values[:ttt] = 333
85
+ m.cache_key.should == "#{m.class}:333"
86
+
87
+ # composite primary key
88
+ @c.set_primary_key [:a, :b, :c]
89
+ m = @c.new
90
+ m.values[:a] = 123
91
+ m.values[:c] = 456
92
+ m.values[:b] = 789
93
+ m.cache_key.should == "#{m.class}:123,789,456"
94
+ c = Class.new(@c)
95
+ m = c.new
96
+ m.values[:a] = 123
97
+ m.values[:c] = 456
98
+ m.values[:b] = 789
99
+ m.cache_key.should == "#{m.class}:123,789,456"
100
+ end
101
+
102
+ it "should raise error if attempting to generate cache_key and primary key value is null" do
103
+ m = @c.new
104
+ proc {m.cache_key}.should raise_error(Sequel::Error)
105
+ m.values[:id] = 1
106
+ proc {m.cache_key}.should_not raise_error(Sequel::Error)
107
+
108
+ m = @c2.new
109
+ proc {m.cache_key}.should raise_error(Sequel::Error)
110
+ m.values[:id] = 1
111
+ proc {m.cache_key}.should_not raise_error(Sequel::Error)
112
+ end
113
+
114
+ it "should not raise error if trying to save a new record" do
115
+ proc {@c.new(:name=>'blah').save}.should_not raise_error
116
+ proc {@c.create(:name=>'blah')}.should_not raise_error
117
+ proc {@c2.new(:name=>'blah').save}.should_not raise_error
118
+ proc {@c2.create(:name=>'blah')}.should_not raise_error
119
+ end
120
+
121
+ it "should set the cache when reading from the database" do
122
+ $sqls.should == []
123
+ @cache.should be_empty
124
+
125
+ m = @c[1]
126
+ $sqls.should == ['SELECT * FROM items WHERE (id = 1) LIMIT 1']
127
+ m.values.should == $cache_dataset_row
128
+ @cache[m.cache_key].should == m
129
+ m2 = @c[1]
130
+ $sqls.should == ['SELECT * FROM items WHERE (id = 1) LIMIT 1']
131
+ m2.should == m
132
+ m2.values.should == $cache_dataset_row
133
+
134
+ $sqls.clear
135
+ m = @c2[1]
136
+ $sqls.should == ['SELECT * FROM items WHERE (id = 1) LIMIT 1']
137
+ m.values.should == $cache_dataset_row
138
+ @cache[m.cache_key].should == m
139
+ m2 = @c2[1]
140
+ $sqls.should == ['SELECT * FROM items WHERE (id = 1) LIMIT 1']
141
+ m2.should == m
142
+ m2.values.should == $cache_dataset_row
143
+ end
144
+
145
+ it "should delete the cache when writing to the database" do
146
+ m = @c[1]
147
+ @cache[m.cache_key].should == m
148
+ m.name = 'hey'
149
+ m.save
150
+ @cache.has_key?(m.cache_key).should be_false
151
+ $sqls.last.should == "UPDATE items SET name = 'hey', id = 1 WHERE (id = 1)"
152
+
153
+ m = @c2[1]
154
+ @cache[m.cache_key].should == m
155
+ m.name = 'hey'
156
+ m.save
157
+ @cache.has_key?(m.cache_key).should be_false
158
+ $sqls.last.should == "UPDATE items SET name = 'hey', id = 1 WHERE (id = 1)"
159
+ end
160
+
161
+ it "should delete the cache when deleting the record" do
162
+ m = @c[1]
163
+ @cache[m.cache_key].should == m
164
+ m.delete
165
+ @cache.has_key?(m.cache_key).should be_false
166
+ $sqls.last.should == "DELETE FROM items WHERE (id = 1)"
167
+
168
+ m = @c2[1]
169
+ @cache[m.cache_key].should == m
170
+ m.delete
171
+ @cache.has_key?(m.cache_key).should be_false
172
+ $sqls.last.should == "DELETE FROM items WHERE (id = 1)"
173
+ end
174
+
175
+ it "should support #[] as a shortcut to #find with hash" do
176
+ m = @c[:id => 3]
177
+ @cache[m.cache_key].should be_nil
178
+ $sqls.last.should == "SELECT * FROM items WHERE (id = 3) LIMIT 1"
179
+ m = @c[1]
180
+ @cache[m.cache_key].should == m
181
+ $sqls.should == ["SELECT * FROM items WHERE (id = 3) LIMIT 1", \
182
+ "SELECT * FROM items WHERE (id = 1) LIMIT 1"]
183
+ @c[:id => 4]
184
+ $sqls.should == ["SELECT * FROM items WHERE (id = 3) LIMIT 1", \
185
+ "SELECT * FROM items WHERE (id = 1) LIMIT 1", \
186
+ "SELECT * FROM items WHERE (id = 4) LIMIT 1"]
187
+
188
+ $sqls.clear
189
+ m = @c2[:id => 3]
190
+ @cache[m.cache_key].should be_nil
191
+ $sqls.last.should == "SELECT * FROM items WHERE (id = 3) LIMIT 1"
192
+ m = @c2[1]
193
+ @cache[m.cache_key].should == m
194
+ $sqls.should == ["SELECT * FROM items WHERE (id = 3) LIMIT 1", \
195
+ "SELECT * FROM items WHERE (id = 1) LIMIT 1"]
196
+ @c2[:id => 4]
197
+ $sqls.should == ["SELECT * FROM items WHERE (id = 3) LIMIT 1", \
198
+ "SELECT * FROM items WHERE (id = 1) LIMIT 1", \
199
+ "SELECT * FROM items WHERE (id = 4) LIMIT 1"]
200
+ end
201
+ end
@@ -5,16 +5,6 @@ describe "Model hooks" do
5
5
  MODEL_DB.reset
6
6
  end
7
7
 
8
- specify "should be definable using def <hook name>" do
9
- c = Class.new(Sequel::Model) do
10
- def before_save
11
- "hi there"
12
- end
13
- end
14
-
15
- c.new.before_save.should == 'hi there'
16
- end
17
-
18
8
  specify "should be definable using a block" do
19
9
  $adds = []
20
10
  c = Class.new(Sequel::Model)
@@ -201,7 +191,7 @@ describe "Model#after_initialize" do
201
191
  end
202
192
 
203
193
  describe "Model#before_create && Model#after_create" do
204
- setup do
194
+ before do
205
195
  MODEL_DB.reset
206
196
 
207
197
  @c = Class.new(Sequel::Model(:items))
@@ -239,7 +229,7 @@ describe "Model#before_create && Model#after_create" do
239
229
  end
240
230
 
241
231
  describe "Model#before_update && Model#after_update" do
242
- setup do
232
+ before do
243
233
  MODEL_DB.reset
244
234
 
245
235
  @c = Class.new(Sequel::Model(:items))
@@ -275,7 +265,7 @@ describe "Model#before_update && Model#after_update" do
275
265
  end
276
266
 
277
267
  describe "Model#before_save && Model#after_save" do
278
- setup do
268
+ before do
279
269
  MODEL_DB.reset
280
270
 
281
271
  @c = Class.new(Sequel::Model(:items))
@@ -323,7 +313,7 @@ describe "Model#before_save && Model#after_save" do
323
313
  end
324
314
 
325
315
  describe "Model#before_destroy && Model#after_destroy" do
326
- setup do
316
+ before do
327
317
  MODEL_DB.reset
328
318
 
329
319
  @c = Class.new(Sequel::Model(:items))
@@ -362,7 +352,7 @@ describe "Model#before_destroy && Model#after_destroy" do
362
352
  end
363
353
 
364
354
  describe "Model#before_validation && Model#after_validation" do
365
- setup do
355
+ before do
366
356
  MODEL_DB.reset
367
357
 
368
358
  @c = Class.new(Sequel::Model(:items))
@@ -372,11 +362,6 @@ describe "Model#before_validation && Model#after_validation" do
372
362
  def self.validate(o)
373
363
  o.errors[:id] << 'not valid' unless o[:id] == 2233
374
364
  end
375
-
376
- def save!(*columns)
377
- MODEL_DB << "CREATE BLAH"
378
- self
379
- end
380
365
  columns :id
381
366
  end
382
367
  end
@@ -397,7 +382,7 @@ describe "Model#before_validation && Model#after_validation" do
397
382
  @c.before_validation{MODEL_DB << "BLAH before"}
398
383
  m = @c.load(:id => 2233)
399
384
  m.save.should == m
400
- MODEL_DB.sqls.should == ['BLAH before', 'BLAH after', 'CREATE BLAH']
385
+ MODEL_DB.sqls.should == ['BLAH before', 'BLAH after', 'UPDATE items SET id = 2233 WHERE (id = 2233)']
401
386
 
402
387
  MODEL_DB.sqls.clear
403
388
  m = @c.load(:id => 22)
@@ -422,7 +407,7 @@ describe "Model#before_validation && Model#after_validation" do
422
407
  end
423
408
 
424
409
  describe "Model.has_hooks?" do
425
- setup do
410
+ before do
426
411
  @c = Class.new(Sequel::Model(:items))
427
412
  end
428
413
 
@@ -442,7 +427,7 @@ describe "Model.has_hooks?" do
442
427
  end
443
428
 
444
429
  describe "Model#add_hook_type" do
445
- setup do
430
+ before do
446
431
  class Foo < Sequel::Model(:items)
447
432
  add_hook_type :before_bar, :after_bar
448
433
 
@@ -86,6 +86,9 @@ describe String::Inflections do
86
86
  String.inflections.plurals.replace(@plurals)
87
87
  String.inflections.singulars.replace(@singulars)
88
88
  String.inflections.uncountables.replace(@uncountables)
89
+ Sequel.inflections.plurals.replace(@plurals)
90
+ Sequel.inflections.singulars.replace(@singulars)
91
+ Sequel.inflections.uncountables.replace(@uncountables)
89
92
  end
90
93
 
91
94
  it "should be possible to clear the list of singulars, plurals, and uncountables" do
@@ -1,7 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  context "Migration classes" do
4
- setup do
4
+ before do
5
5
  Sequel::Migration.descendants.clear
6
6
  end
7
7
 
@@ -21,7 +21,7 @@ context "Migration classes" do
21
21
  end
22
22
 
23
23
  context "Migration#apply" do
24
- setup do
24
+ before do
25
25
  @c = Class.new do
26
26
  define_method(:one) {|x| [1111, x]}
27
27
  define_method(:two) {|x| [2222, x]}
@@ -129,7 +129,7 @@ MIGRATION_005 = %[
129
129
  ]
130
130
 
131
131
  context "Sequel::Migrator" do
132
- setup do
132
+ before do
133
133
  @db = DummyMigrationDB.new
134
134
 
135
135
  File.open('001_create_sessions.rb', 'w') {|f| f << MIGRATION_001}
@@ -140,7 +140,7 @@ context "Sequel::Migrator" do
140
140
  @db[:schema_info].version = nil
141
141
  end
142
142
 
143
- teardown do
143
+ after do
144
144
  Object.send(:remove_const, "CreateSessions") if Object.const_defined?("CreateSessions")
145
145
  Object.send(:remove_const, "CreateNodes") if Object.const_defined?("CreateNodes")
146
146
  Object.send(:remove_const, "CreateUsers") if Object.const_defined?("CreateUsers")