sequel 3.48.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +114 -0
  3. data/Rakefile +10 -7
  4. data/doc/association_basics.rdoc +25 -23
  5. data/doc/code_order.rdoc +7 -0
  6. data/doc/core_extensions.rdoc +0 -10
  7. data/doc/object_model.rdoc +4 -1
  8. data/doc/querying.rdoc +3 -3
  9. data/doc/release_notes/4.0.0.txt +262 -0
  10. data/doc/security.rdoc +0 -28
  11. data/doc/testing.rdoc +8 -14
  12. data/lib/sequel/adapters/ado.rb +7 -11
  13. data/lib/sequel/adapters/ado/access.rb +8 -8
  14. data/lib/sequel/adapters/ado/mssql.rb +4 -4
  15. data/lib/sequel/adapters/amalgalite.rb +6 -6
  16. data/lib/sequel/adapters/cubrid.rb +7 -7
  17. data/lib/sequel/adapters/db2.rb +5 -9
  18. data/lib/sequel/adapters/dbi.rb +2 -6
  19. data/lib/sequel/adapters/do.rb +4 -4
  20. data/lib/sequel/adapters/firebird.rb +4 -4
  21. data/lib/sequel/adapters/ibmdb.rb +8 -8
  22. data/lib/sequel/adapters/informix.rb +2 -10
  23. data/lib/sequel/adapters/jdbc.rb +17 -17
  24. data/lib/sequel/adapters/jdbc/as400.rb +2 -2
  25. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
  26. data/lib/sequel/adapters/jdbc/db2.rb +1 -1
  27. data/lib/sequel/adapters/jdbc/derby.rb +1 -1
  28. data/lib/sequel/adapters/jdbc/h2.rb +2 -2
  29. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
  30. data/lib/sequel/adapters/jdbc/informix.rb +1 -1
  31. data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
  32. data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
  33. data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
  34. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
  35. data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
  36. data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
  37. data/lib/sequel/adapters/mock.rb +7 -7
  38. data/lib/sequel/adapters/mysql.rb +3 -3
  39. data/lib/sequel/adapters/mysql2.rb +4 -4
  40. data/lib/sequel/adapters/odbc.rb +2 -6
  41. data/lib/sequel/adapters/odbc/mssql.rb +1 -1
  42. data/lib/sequel/adapters/openbase.rb +1 -5
  43. data/lib/sequel/adapters/oracle.rb +13 -17
  44. data/lib/sequel/adapters/postgres.rb +20 -25
  45. data/lib/sequel/adapters/shared/cubrid.rb +3 -3
  46. data/lib/sequel/adapters/shared/db2.rb +2 -2
  47. data/lib/sequel/adapters/shared/firebird.rb +7 -7
  48. data/lib/sequel/adapters/shared/mssql.rb +9 -9
  49. data/lib/sequel/adapters/shared/mysql.rb +29 -13
  50. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
  51. data/lib/sequel/adapters/shared/oracle.rb +22 -13
  52. data/lib/sequel/adapters/shared/postgres.rb +61 -46
  53. data/lib/sequel/adapters/shared/sqlite.rb +9 -9
  54. data/lib/sequel/adapters/sqlite.rb +17 -11
  55. data/lib/sequel/adapters/swift.rb +3 -3
  56. data/lib/sequel/adapters/swift/mysql.rb +1 -1
  57. data/lib/sequel/adapters/swift/sqlite.rb +1 -1
  58. data/lib/sequel/adapters/tinytds.rb +8 -8
  59. data/lib/sequel/ast_transformer.rb +3 -1
  60. data/lib/sequel/connection_pool.rb +4 -2
  61. data/lib/sequel/connection_pool/sharded_single.rb +2 -2
  62. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
  63. data/lib/sequel/connection_pool/threaded.rb +7 -7
  64. data/lib/sequel/core.rb +4 -67
  65. data/lib/sequel/database.rb +1 -0
  66. data/lib/sequel/database/connecting.rb +2 -8
  67. data/lib/sequel/database/dataset.rb +2 -7
  68. data/lib/sequel/database/dataset_defaults.rb +0 -18
  69. data/lib/sequel/database/features.rb +4 -4
  70. data/lib/sequel/database/misc.rb +6 -8
  71. data/lib/sequel/database/query.rb +5 -61
  72. data/lib/sequel/database/schema_generator.rb +22 -20
  73. data/lib/sequel/database/schema_methods.rb +48 -20
  74. data/lib/sequel/database/transactions.rb +7 -17
  75. data/lib/sequel/dataset.rb +2 -0
  76. data/lib/sequel/dataset/actions.rb +23 -91
  77. data/lib/sequel/dataset/features.rb +1 -4
  78. data/lib/sequel/dataset/graph.rb +3 -47
  79. data/lib/sequel/dataset/misc.rb +4 -33
  80. data/lib/sequel/dataset/prepared_statements.rb +3 -1
  81. data/lib/sequel/dataset/query.rb +116 -240
  82. data/lib/sequel/dataset/sql.rb +19 -97
  83. data/lib/sequel/deprecated.rb +0 -16
  84. data/lib/sequel/exceptions.rb +0 -3
  85. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  86. data/lib/sequel/extensions/columns_introspection.rb +1 -12
  87. data/lib/sequel/extensions/constraint_validations.rb +3 -3
  88. data/lib/sequel/extensions/core_extensions.rb +0 -9
  89. data/lib/sequel/extensions/date_arithmetic.rb +1 -2
  90. data/lib/sequel/extensions/graph_each.rb +11 -0
  91. data/lib/sequel/extensions/migration.rb +5 -5
  92. data/lib/sequel/extensions/null_dataset.rb +11 -13
  93. data/lib/sequel/extensions/pagination.rb +3 -6
  94. data/lib/sequel/extensions/pg_array.rb +6 -4
  95. data/lib/sequel/extensions/pg_array_ops.rb +35 -1
  96. data/lib/sequel/extensions/pg_json.rb +12 -2
  97. data/lib/sequel/extensions/pg_json_ops.rb +266 -0
  98. data/lib/sequel/extensions/pg_range.rb +2 -2
  99. data/lib/sequel/extensions/pg_range_ops.rb +0 -8
  100. data/lib/sequel/extensions/pg_row.rb +2 -2
  101. data/lib/sequel/extensions/pretty_table.rb +0 -4
  102. data/lib/sequel/extensions/query.rb +3 -8
  103. data/lib/sequel/extensions/schema_caching.rb +0 -7
  104. data/lib/sequel/extensions/schema_dumper.rb +10 -17
  105. data/lib/sequel/extensions/select_remove.rb +0 -4
  106. data/lib/sequel/extensions/set_overrides.rb +28 -0
  107. data/lib/sequel/extensions/to_dot.rb +6 -10
  108. data/lib/sequel/model.rb +6 -7
  109. data/lib/sequel/model/associations.rb +127 -182
  110. data/lib/sequel/model/base.rb +88 -211
  111. data/lib/sequel/model/errors.rb +0 -13
  112. data/lib/sequel/model/plugins.rb +2 -2
  113. data/lib/sequel/no_core_ext.rb +0 -1
  114. data/lib/sequel/plugins/after_initialize.rb +11 -17
  115. data/lib/sequel/plugins/association_autoreloading.rb +1 -47
  116. data/lib/sequel/plugins/association_dependencies.rb +2 -2
  117. data/lib/sequel/plugins/auto_validations.rb +2 -8
  118. data/lib/sequel/plugins/blacklist_security.rb +32 -2
  119. data/lib/sequel/plugins/caching.rb +1 -1
  120. data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
  121. data/lib/sequel/plugins/composition.rb +10 -8
  122. data/lib/sequel/plugins/constraint_validations.rb +2 -2
  123. data/lib/sequel/plugins/dataset_associations.rb +4 -0
  124. data/lib/sequel/plugins/defaults_setter.rb +8 -6
  125. data/lib/sequel/plugins/dirty.rb +6 -6
  126. data/lib/sequel/plugins/force_encoding.rb +13 -8
  127. data/lib/sequel/plugins/hook_class_methods.rb +1 -7
  128. data/lib/sequel/plugins/json_serializer.rb +13 -74
  129. data/lib/sequel/plugins/lazy_attributes.rb +2 -4
  130. data/lib/sequel/plugins/list.rb +1 -1
  131. data/lib/sequel/plugins/many_through_many.rb +4 -11
  132. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
  133. data/lib/sequel/plugins/nested_attributes.rb +1 -1
  134. data/lib/sequel/plugins/optimistic_locking.rb +3 -5
  135. data/lib/sequel/plugins/pg_array_associations.rb +453 -0
  136. data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
  137. data/lib/sequel/plugins/prepared_statements.rb +1 -1
  138. data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
  139. data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
  140. data/lib/sequel/plugins/rcte_tree.rb +1 -1
  141. data/lib/sequel/plugins/serialization.rb +5 -4
  142. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  143. data/lib/sequel/plugins/sharding.rb +7 -1
  144. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  145. data/lib/sequel/plugins/timestamps.rb +1 -1
  146. data/lib/sequel/plugins/touch.rb +2 -2
  147. data/lib/sequel/plugins/tree.rb +1 -1
  148. data/lib/sequel/plugins/typecast_on_load.rb +19 -4
  149. data/lib/sequel/plugins/validation_class_methods.rb +0 -30
  150. data/lib/sequel/plugins/validation_helpers.rb +13 -31
  151. data/lib/sequel/plugins/xml_serializer.rb +18 -57
  152. data/lib/sequel/sql.rb +20 -22
  153. data/lib/sequel/version.rb +2 -2
  154. data/spec/adapters/db2_spec.rb +14 -23
  155. data/spec/adapters/firebird_spec.rb +25 -29
  156. data/spec/adapters/informix_spec.rb +11 -14
  157. data/spec/adapters/mssql_spec.rb +71 -77
  158. data/spec/adapters/mysql_spec.rb +165 -172
  159. data/spec/adapters/oracle_spec.rb +36 -39
  160. data/spec/adapters/postgres_spec.rb +175 -100
  161. data/spec/adapters/spec_helper.rb +13 -11
  162. data/spec/adapters/sqlite_spec.rb +36 -44
  163. data/spec/core/connection_pool_spec.rb +2 -1
  164. data/spec/core/database_spec.rb +55 -55
  165. data/spec/core/dataset_spec.rb +45 -249
  166. data/spec/core/deprecated_spec.rb +0 -8
  167. data/spec/core/expression_filters_spec.rb +23 -5
  168. data/spec/core/object_graph_spec.rb +4 -66
  169. data/spec/core/schema_spec.rb +35 -12
  170. data/spec/core/spec_helper.rb +3 -2
  171. data/spec/core_extensions_spec.rb +17 -19
  172. data/spec/extensions/arbitrary_servers_spec.rb +2 -3
  173. data/spec/extensions/association_dependencies_spec.rb +14 -14
  174. data/spec/extensions/auto_validations_spec.rb +7 -0
  175. data/spec/extensions/blacklist_security_spec.rb +5 -5
  176. data/spec/extensions/blank_spec.rb +2 -0
  177. data/spec/extensions/class_table_inheritance_spec.rb +2 -2
  178. data/spec/extensions/columns_introspection_spec.rb +2 -29
  179. data/spec/extensions/composition_spec.rb +10 -17
  180. data/spec/extensions/core_refinements_spec.rb +5 -1
  181. data/spec/extensions/dataset_associations_spec.rb +18 -0
  182. data/spec/extensions/date_arithmetic_spec.rb +2 -2
  183. data/spec/extensions/defaults_setter_spec.rb +9 -9
  184. data/spec/extensions/dirty_spec.rb +0 -5
  185. data/spec/extensions/eval_inspect_spec.rb +2 -0
  186. data/spec/extensions/force_encoding_spec.rb +2 -18
  187. data/spec/extensions/hash_aliases_spec.rb +8 -0
  188. data/spec/extensions/hook_class_methods_spec.rb +39 -58
  189. data/spec/extensions/inflector_spec.rb +2 -0
  190. data/spec/extensions/instance_filters_spec.rb +8 -8
  191. data/spec/extensions/json_serializer_spec.rb +1 -41
  192. data/spec/extensions/list_spec.rb +1 -1
  193. data/spec/extensions/many_through_many_spec.rb +106 -109
  194. data/spec/extensions/migration_spec.rb +2 -0
  195. data/spec/extensions/named_timezones_spec.rb +1 -0
  196. data/spec/extensions/pg_array_associations_spec.rb +603 -0
  197. data/spec/extensions/pg_array_ops_spec.rb +25 -0
  198. data/spec/extensions/pg_array_spec.rb +9 -1
  199. data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
  200. data/spec/extensions/pg_hstore_spec.rb +1 -0
  201. data/spec/extensions/pg_json_ops_spec.rb +131 -0
  202. data/spec/extensions/pg_json_spec.rb +10 -4
  203. data/spec/extensions/pg_range_ops_spec.rb +2 -5
  204. data/spec/extensions/pg_range_spec.rb +6 -2
  205. data/spec/extensions/pg_row_ops_spec.rb +2 -0
  206. data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
  207. data/spec/extensions/rcte_tree_spec.rb +15 -15
  208. data/spec/extensions/schema_dumper_spec.rb +0 -1
  209. data/spec/extensions/schema_spec.rb +9 -9
  210. data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
  211. data/spec/extensions/serialization_spec.rb +18 -29
  212. data/spec/extensions/set_overrides_spec.rb +4 -0
  213. data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
  214. data/spec/extensions/single_table_inheritance_spec.rb +4 -4
  215. data/spec/extensions/spec_helper.rb +8 -9
  216. data/spec/extensions/sql_expr_spec.rb +2 -0
  217. data/spec/extensions/string_date_time_spec.rb +2 -0
  218. data/spec/extensions/string_stripper_spec.rb +2 -0
  219. data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
  220. data/spec/extensions/thread_local_timezones_spec.rb +2 -0
  221. data/spec/extensions/timestamps_spec.rb +1 -1
  222. data/spec/extensions/to_dot_spec.rb +1 -1
  223. data/spec/extensions/touch_spec.rb +24 -24
  224. data/spec/extensions/tree_spec.rb +7 -7
  225. data/spec/extensions/typecast_on_load_spec.rb +8 -1
  226. data/spec/extensions/update_primary_key_spec.rb +10 -10
  227. data/spec/extensions/validation_class_methods_spec.rb +10 -39
  228. data/spec/extensions/validation_helpers_spec.rb +29 -47
  229. data/spec/extensions/xml_serializer_spec.rb +1 -23
  230. data/spec/integration/associations_test.rb +231 -40
  231. data/spec/integration/database_test.rb +1 -1
  232. data/spec/integration/dataset_test.rb +64 -64
  233. data/spec/integration/eager_loader_test.rb +28 -28
  234. data/spec/integration/migrator_test.rb +1 -1
  235. data/spec/integration/model_test.rb +2 -2
  236. data/spec/integration/plugin_test.rb +21 -21
  237. data/spec/integration/prepared_statement_test.rb +7 -7
  238. data/spec/integration/schema_test.rb +115 -110
  239. data/spec/integration/spec_helper.rb +17 -27
  240. data/spec/integration/timezone_test.rb +1 -1
  241. data/spec/integration/transaction_test.rb +10 -10
  242. data/spec/integration/type_test.rb +2 -2
  243. data/spec/model/association_reflection_spec.rb +2 -28
  244. data/spec/model/associations_spec.rb +239 -188
  245. data/spec/model/base_spec.rb +27 -68
  246. data/spec/model/dataset_methods_spec.rb +4 -4
  247. data/spec/model/eager_loading_spec.rb +160 -172
  248. data/spec/model/hooks_spec.rb +62 -79
  249. data/spec/model/model_spec.rb +36 -51
  250. data/spec/model/plugins_spec.rb +5 -19
  251. data/spec/model/record_spec.rb +125 -151
  252. data/spec/model/spec_helper.rb +8 -6
  253. data/spec/model/validations_spec.rb +4 -17
  254. data/spec/spec_config.rb +2 -10
  255. metadata +50 -56
  256. data/lib/sequel/deprecated_core_extensions.rb +0 -135
  257. data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
  258. data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
  259. data/lib/sequel/plugins/identity_map.rb +0 -260
  260. data/lib/sequel_core.rb +0 -2
  261. data/lib/sequel_model.rb +0 -2
  262. data/spec/extensions/association_autoreloading_spec.rb +0 -102
  263. data/spec/extensions/identity_map_spec.rb +0 -337
  264. data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
  265. data/spec/extensions/pg_statement_cache_spec.rb +0 -208
  266. data/spec/rcov.opts +0 -8
  267. data/spec/spec_config.rb.example +0 -10
@@ -43,6 +43,13 @@ describe "Sequel::Plugins::AutoValidations" do
43
43
  @m.errors.should == {[:name, :num]=>["is already taken"]}
44
44
  end
45
45
 
46
+ it "should handle databases that don't support index parsing" do
47
+ def (@m.db).supports_index_parsing?() false end
48
+ @m.model.send(:setup_auto_validations)
49
+ @m.set(:d=>Date.today, :num=>1, :name=>'1')
50
+ @m.valid?.should be_true
51
+ end
52
+
46
53
  it "should support :not_null=>:presence option" do
47
54
  @c.plugin :auto_validations, :not_null=>:presence
48
55
  @m.set(:d=>Date.today, :num=>'')
@@ -11,7 +11,7 @@ describe Sequel::Model, "#(set|update)_except" do
11
11
  end
12
12
  @c.strict_param_setting = false
13
13
  @o1 = @c.new
14
- MODEL_DB.reset
14
+ DB.reset
15
15
  end
16
16
 
17
17
  it "should raise errors if not all hash fields can be set and strict_param_setting is true" do
@@ -31,9 +31,9 @@ describe Sequel::Model, "#(set|update)_except" do
31
31
 
32
32
  it "#update_except should not update given attributes" do
33
33
  @o1.update_except({:x => 1, :y => 2, :z=>3, :id=>4}, [:y, :z])
34
- MODEL_DB.sqls.should == ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
34
+ DB.sqls.should == ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
35
35
  @c.new.update_except({:x => 1, :y => 2, :z=>3, :id=>4}, :y, :z)
36
- MODEL_DB.sqls.should == ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
36
+ DB.sqls.should == ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
37
37
  end
38
38
  end
39
39
 
@@ -67,7 +67,7 @@ describe Sequel::Model, ".restricted_columns " do
67
67
  i = @c.new
68
68
  i.update(:x => 7, :z => 9)
69
69
  i.values.should == {:x => 7}
70
- MODEL_DB.sqls.should == ["INSERT INTO blahblah (x) VALUES (7)", "SELECT * FROM blahblah WHERE (id = 10) LIMIT 1"]
70
+ DB.sqls.should == ["INSERT INTO blahblah (x) VALUES (7)", "SELECT * FROM blahblah WHERE (id = 10) LIMIT 1"]
71
71
  end
72
72
 
73
73
  it "should have allowed take precedence over restricted" do
@@ -82,6 +82,6 @@ describe Sequel::Model, ".restricted_columns " do
82
82
  i = @c.new
83
83
  i.update(:y => 7, :z => 9)
84
84
  i.values.should == {:y => 7}
85
- MODEL_DB.sqls.should == ["INSERT INTO blahblah (y) VALUES (7)", "SELECT * FROM blahblah WHERE (id = 10) LIMIT 1"]
85
+ DB.sqls.should == ["INSERT INTO blahblah (y) VALUES (7)", "SELECT * FROM blahblah WHERE (id = 10) LIMIT 1"]
86
86
  end
87
87
  end
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
2
2
 
3
+ Sequel.extension :blank
4
+
3
5
  describe "Object#blank?" do
4
6
  specify "it should be true if the object responds true to empty?" do
5
7
  [].blank?.should == true
@@ -24,7 +24,7 @@ describe "class_table_inheritance plugin" do
24
24
  end
25
25
  end
26
26
  class ::Employee < Sequel::Model(@db)
27
- def _refresh(x); @values[:id] = 1 end
27
+ def _save_refresh; @values[:id] = 1 end
28
28
  def self.columns
29
29
  dataset.columns
30
30
  end
@@ -204,7 +204,7 @@ describe "class_table_inheritance plugin" do
204
204
  it "should handle many_to_one relationships correctly" do
205
205
  Manager.dataset._fetch = {:id=>3, :name=>'E', :kind=>'Executive', :num_managers=>3}
206
206
  Staff.load(:manager_id=>3).manager.should == Executive.load(:id=>3, :name=>'E', :kind=>'Executive', :num_managers=>3)
207
- @db.sqls.should == ['SELECT * FROM employees INNER JOIN managers USING (id) WHERE (managers.id = 3) LIMIT 1']
207
+ @db.sqls.should == ['SELECT * FROM employees INNER JOIN managers USING (id) WHERE (id = 3) LIMIT 1']
208
208
  end
209
209
 
210
210
  it "should handle one_to_many relationships correctly" do
@@ -1,33 +1,11 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
2
2
 
3
- describe "Sequel::Dataset.introspect_all_columns" do
4
- before do
5
- @db = MODEL_DB
6
- @ds = @db[:a]
7
- class Sequel::Dataset
8
- # Handle case where introspect_all_columns has already been called
9
- alias columns columns_without_introspection unless instance_methods(false).map{|x| x.to_s}.include?('columns')
10
- end
11
- end
12
- after do
13
- class Sequel::Dataset
14
- alias columns columns_without_introspection
15
- end
16
- end
17
-
18
- qspecify "should turn on column introspection by default" do
19
- Sequel::Dataset.introspect_all_columns
20
- @db.reset
21
- @ds.select(:x).columns.should == [:x]
22
- @db.sqls.length.should == 0
23
- end
24
- end
3
+ Sequel.extension :columns_introspection
25
4
 
26
5
  describe "columns_introspection extension" do
27
6
  before do
28
- @db = Sequel.mock
7
+ @db = Sequel.mock.extension(:columns_introspection)
29
8
  @ds = @db[:a]
30
- @ds.extend(Sequel::ColumnsIntrospection.dup) # dup to allow multiple places in class hierarchy
31
9
  @db.sqls
32
10
  end
33
11
 
@@ -109,9 +87,4 @@ describe "columns_introspection extension" do
109
87
  @ds.select(1).columns
110
88
  @db.sqls.length.should == 1
111
89
  end
112
-
113
- specify "should not have column introspection on by default" do
114
- @db[:a].select(:x).columns
115
- @db.sqls.length.should == 1
116
- end
117
90
  end
@@ -6,7 +6,7 @@ describe "Composition plugin" do
6
6
  @c.plugin :composition
7
7
  @c.columns :id, :year, :month, :day
8
8
  @o = @c.load(:id=>1, :year=>1, :month=>2, :day=>3)
9
- MODEL_DB.reset
9
+ DB.reset
10
10
  end
11
11
 
12
12
  it ".composition should add compositions" do
@@ -48,7 +48,7 @@ describe "Composition plugin" do
48
48
  @c.composition :date, :composer=>proc{Date.new(year+1, month+2, day+3)}, :decomposer=>proc{[:year, :month, :day].each{|s| self.send("#{s}=", date.send(s) * 2)}}
49
49
  @o.date.should == Date.new(2, 4, 6)
50
50
  @o.save
51
- sql = MODEL_DB.sqls.last
51
+ sql = DB.sqls.last
52
52
  sql.should include("year = 4")
53
53
  sql.should include("month = 8")
54
54
  sql.should include("day = 12")
@@ -90,13 +90,6 @@ describe "Composition plugin" do
90
90
  called.should == true
91
91
  end
92
92
 
93
- it "should clear compositions cache when using set_values" do
94
- @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
95
- @o.date = Date.new(3, 4, 5)
96
- @o.set_values(:id=>1)
97
- @o.compositions.should == {}
98
- end
99
-
100
93
  it "should clear compositions cache when refreshing" do
101
94
  @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
102
95
  @o.date = Date.new(3, 4, 5)
@@ -104,16 +97,16 @@ describe "Composition plugin" do
104
97
  @o.compositions.should == {}
105
98
  end
106
99
 
107
- it "should clear compositions cache when refreshing after save" do
100
+ it "should not clear compositions cache when refreshing after save" do
108
101
  @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
109
- @c.create(:date=>Date.new(3, 4, 5)).compositions.should == {}
102
+ @c.create(:date=>Date.new(3, 4, 5)).compositions.should == {:date=>Date.new(3, 4, 5)}
110
103
  end
111
104
 
112
- it "should clear compositions cache when saving with insert_select" do
105
+ it "should not clear compositions cache when saving with insert_select" do
113
106
  def (@c.instance_dataset).supports_insert_select?() true end
114
107
  def (@c.instance_dataset).insert_select(*) {:id=>1} end
115
108
  @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
116
- @c.create(:date=>Date.new(3, 4, 5)).compositions.should == {}
109
+ @c.create(:date=>Date.new(3, 4, 5)).compositions.should == {:date=>Date.new(3, 4, 5)}
117
110
  end
118
111
 
119
112
  it "should instantiate compositions lazily" do
@@ -159,7 +152,7 @@ describe "Composition plugin" do
159
152
  @o.date.month.should == 6
160
153
  @o.date = c.new(3, 4)
161
154
  @o.save
162
- sql = MODEL_DB.sqls.last
155
+ sql = DB.sqls.last
163
156
  sql.should include("year = 6")
164
157
  sql.should include("month = 12")
165
158
  end
@@ -181,7 +174,7 @@ describe "Composition plugin" do
181
174
  @o.date.m.should == 6
182
175
  @o.date = c.new(3, 4)
183
176
  @o.save
184
- sql = MODEL_DB.sqls.last
177
+ sql = DB.sqls.last
185
178
  sql.should include("year = 6")
186
179
  sql.should include("month = 12")
187
180
  end
@@ -195,7 +188,7 @@ describe "Composition plugin" do
195
188
  @c.composition :date, :mapping=>[:year, :month, :day]
196
189
  @o.date = nil
197
190
  @o.save
198
- sql = MODEL_DB.sqls.last
191
+ sql = DB.sqls.last
199
192
  sql.should include("year = NULL")
200
193
  sql.should include("month = NULL")
201
194
  sql.should include("day = NULL")
@@ -214,7 +207,7 @@ describe "Composition plugin" do
214
207
  o = c.load(:id=>1, :year=>1, :month=>2, :day=>3)
215
208
  o.date.should == Date.new(1, 2, 3)
216
209
  o.save
217
- sql = MODEL_DB.sqls.last
210
+ sql = DB.sqls.last
218
211
  sql.should include("year = 1")
219
212
  sql.should include("month = 2")
220
213
  sql.should include("day = 3")
@@ -1,6 +1,7 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
2
 
3
3
  if RUBY_VERSION >= '2.0.0'
4
+ Sequel.extension :core_refinements, :pg_array, :pg_hstore, :pg_row, :pg_range, :pg_row_ops, :pg_range_ops, :pg_array_ops, :pg_hstore_ops, :pg_json, :pg_json_ops
4
5
  using Sequel::CoreRefinements
5
6
 
6
7
  describe "Core refinements" do
@@ -451,7 +452,6 @@ end
451
452
  describe "Postgres extensions integration" do
452
453
  before do
453
454
  @db = Sequel.mock
454
- Sequel.extension(:pg_array, :pg_array_ops, :pg_hstore, :pg_hstore_ops, :pg_json, :pg_range, :pg_range_ops, :pg_row, :pg_row_ops)
455
455
  end
456
456
 
457
457
  it "Symbol#pg_array should return an ArrayOp" do
@@ -466,6 +466,10 @@ describe "Postgres extensions integration" do
466
466
  @db.literal(:a.hstore['a']).should == "(a -> 'a')"
467
467
  end
468
468
 
469
+ it "Symbol#pg_json should return an JSONOp" do
470
+ @db.literal(:a.pg_json[%w'a b']).should == "(a #> ARRAY['a','b'])"
471
+ end
472
+
469
473
  it "Symbol#pg_range should return a RangeOp" do
470
474
  @db.literal(:a.pg_range.lower).should == "lower(a)"
471
475
  end
@@ -23,11 +23,15 @@ describe "Sequel::Plugins::DatasetAssociations" do
23
23
  @Tag.columns :id, :name
24
24
 
25
25
  @Artist.plugin :many_through_many
26
+ @Artist.plugin :pg_array_associations
27
+ @Tag.plugin :pg_array_associations
26
28
  @Artist.one_to_many :albums, :class=>@Album
27
29
  @Artist.one_to_one :first_album, :class=>@Album
28
30
  @Album.many_to_one :artist, :class=>@Artist
29
31
  @Album.many_to_many :tags, :class=>@Tag
30
32
  @Tag.many_to_many :albums, :class=>@Album
33
+ @Artist.pg_array_to_many :artist_tags, :class=>@Tag, :key=>:tag_ids
34
+ @Tag.many_to_pg_array :artists, :class=>@Artist
31
35
  @Artist.many_through_many :tags, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :class=>@Tag
32
36
  end
33
37
 
@@ -66,6 +70,20 @@ describe "Sequel::Plugins::DatasetAssociations" do
66
70
  ds.sql.should == "SELECT tags.* FROM tags WHERE (tags.id IN (SELECT albums_tags.tag_id FROM artists INNER JOIN albums ON (albums.artist_id = artists.id) INNER JOIN albums_tags ON (albums_tags.album_id = albums.id)))"
67
71
  end
68
72
 
73
+ it "should work for pg_array_to_many associations" do
74
+ ds = @Artist.artist_tags
75
+ ds.should be_a_kind_of(Sequel::Dataset)
76
+ ds.model.should == @Tag
77
+ ds.sql.should == "SELECT * FROM tags WHERE (id IN (SELECT unnest(artists.tag_ids) FROM artists))"
78
+ end
79
+
80
+ it "should work for many_to_pg_array associations" do
81
+ ds = @Tag.artists
82
+ ds.should be_a_kind_of(Sequel::Dataset)
83
+ ds.model.should == @Artist
84
+ ds.sql.should == "SELECT * FROM artists WHERE coalesce((tag_ids && (SELECT array_agg(tags.id) FROM tags)), 'f')"
85
+ end
86
+
69
87
  it "should have an associated method that takes an association symbol" do
70
88
  ds = @Album.associated(:artist)
71
89
  ds.should be_a_kind_of(Sequel::Dataset)
@@ -142,9 +142,9 @@ describe "date_arithmetic extension" do
142
142
  db.literal(Sequel.date_add(:a, @h2)).should == "(CAST(a AS timestamp) + 1 years + 1 months + 1 days + 1 hours + 1 minutes + 1 seconds)"
143
143
  end
144
144
 
145
- qspecify "should raise error if literalizing on an unsupported database" do
145
+ specify "should raise error if literalizing on an unsupported database" do
146
146
  db = Sequel.mock
147
147
  db.extension :date_arithmetic
148
- lambda{db.literal(Sequel.date_add(:a, @h0))}.should raise_error(Sequel::NotImplemented)
148
+ lambda{db.literal(Sequel.date_add(:a, @h0))}.should raise_error(Sequel::Error)
149
149
  end
150
150
  end
@@ -15,7 +15,7 @@ describe "Sequel::Plugins::DefaultsSetter" do
15
15
  end
16
16
 
17
17
  it "should set default value upon initialization" do
18
- @pr.call(2).new.values.should == {:a=>2}
18
+ @pr.call(2).new.a.should == 2
19
19
  end
20
20
 
21
21
  it "should not mark the column as modified" do
@@ -23,11 +23,11 @@ describe "Sequel::Plugins::DefaultsSetter" do
23
23
  end
24
24
 
25
25
  it "should not set a default of nil" do
26
- @pr.call(nil).new.values.should == {}
26
+ @pr.call(nil).new.class.default_values.should == {}
27
27
  end
28
28
 
29
29
  it "should set a default of false" do
30
- @pr.call(false).new.values.should == {:a=>false}
30
+ @pr.call(false).new.a.should == false
31
31
  end
32
32
 
33
33
  it "should handle Sequel::CURRENT_DATE default by using the current Date" do
@@ -49,12 +49,12 @@ describe "Sequel::Plugins::DefaultsSetter" do
49
49
 
50
50
  it "should not override a given value" do
51
51
  @pr.call(2)
52
- @c.new('a'=>3).values.should == {:a=>3}
53
- @c.new('a'=>nil).values.should == {:a=>nil}
52
+ @c.new('a'=>3).a.should == 3
53
+ @c.new('a'=>nil).a.should == nil
54
54
  end
55
55
 
56
56
  it "should work correctly when subclassing" do
57
- Class.new(@pr.call(2)).new.values.should == {:a=>2}
57
+ Class.new(@pr.call(2)).new.a.should == 2
58
58
  end
59
59
 
60
60
  it "should contain the default values in default_values" do
@@ -65,19 +65,19 @@ describe "Sequel::Plugins::DefaultsSetter" do
65
65
  it "should allow modifications of default values" do
66
66
  @pr.call(2)
67
67
  @c.default_values[:a] = 3
68
- @c.new.values.should == {:a => 3}
68
+ @c.new.a.should == 3
69
69
  end
70
70
 
71
71
  it "should allow proc default values" do
72
72
  @pr.call(2)
73
73
  @c.default_values[:a] = proc{3}
74
- @c.new.values.should == {:a => 3}
74
+ @c.new.a.should == 3
75
75
  end
76
76
 
77
77
  it "should have procs that set default values set them to nil" do
78
78
  @pr.call(2)
79
79
  @c.default_values[:a] = proc{nil}
80
- @c.new.values.should == {:a => nil}
80
+ @c.new.a.should == nil
81
81
  end
82
82
 
83
83
  it "should work correctly on a model without a dataset" do
@@ -88,11 +88,6 @@ describe "Sequel::Plugins::Dirty" do
88
88
  @o.values.has_key?(:missing_changed).should == false
89
89
  end
90
90
 
91
- it "set_values should clear the cached initial values" do
92
- @o.set_values(:id=>1)
93
- @o.column_changes.should == {}
94
- end
95
-
96
91
  it "refresh should clear the cached initial values" do
97
92
  @o.refresh
98
93
  @o.column_changes.should == {}
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
2
 
3
+ Sequel.extension :eval_inspect
4
+
3
5
  describe "eval_inspect extension" do
4
6
  before do
5
7
  @ds = Sequel.mock.dataset
@@ -83,7 +83,7 @@ describe "force_encoding plugin" do
83
83
 
84
84
  specify "should work when saving new model instances" do
85
85
  o = @c.new
86
- ds = MODEL_DB[:a]
86
+ ds = DB[:a]
87
87
  def ds.first
88
88
  s = 'blah'
89
89
  s.force_encoding('US-ASCII')
@@ -97,7 +97,7 @@ describe "force_encoding plugin" do
97
97
 
98
98
  specify "should work when refreshing model instances" do
99
99
  o = @c.load(:id=>1, :x=>'as')
100
- ds = MODEL_DB[:a]
100
+ ds = DB[:a]
101
101
  def ds.first
102
102
  s = 'blah'
103
103
  s.force_encoding('US-ASCII')
@@ -108,22 +108,6 @@ describe "force_encoding plugin" do
108
108
  o.x.should == 'blah'
109
109
  o.x.encoding.should == @e1
110
110
  end
111
-
112
- specify "should work when used with the identity_map plugin if the identity_map plugin is setup first" do
113
- @c = Class.new(Sequel::Model) do
114
- end
115
- @c.columns :id, :x
116
- @c.plugin :identity_map
117
- @c.plugin :force_encoding, 'UTF-8'
118
- @c.with_identity_map do
119
- o = @c.load(:id=>1)
120
- s = 'blah'
121
- s.force_encoding('US-ASCII')
122
- @c.load(:id=>1, :x=>s)
123
- o.x.should == 'blah'
124
- o.x.encoding.should == @e1
125
- end
126
- end
127
111
  end
128
112
  else
129
113
  skip_warn "force_encoding plugin: only works on ruby 1.9+"
@@ -9,8 +9,16 @@ describe "hash_aliases extension" do
9
9
  @ds.from(:a=>:b).sql.should == "SELECT * FROM a AS b"
10
10
  end
11
11
 
12
+ it "should not affect other arguments to from" do
13
+ @ds.from(:a, :b).sql.should == "SELECT * FROM a, b"
14
+ end
15
+
12
16
  it "should make select treat hash arguments as alias specifiers" do
13
17
  @ds.select(:a=>:b).sql.should == "SELECT a AS b"
14
18
  @ds.select{{:a=>:b}}.sql.should == "SELECT a AS b"
15
19
  end
20
+
21
+ it "should not affect other arguments to select" do
22
+ @ds.select(:a, :b).sql.should == "SELECT a, b"
23
+ end
16
24
  end
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  describe Sequel::Model, "hook_class_methods plugin" do
11
11
  before do
12
- MODEL_DB.reset
12
+ DB.reset
13
13
  end
14
14
 
15
15
  specify "should be definable using a block" do
@@ -164,165 +164,146 @@ describe Sequel::Model, "hook_class_methods plugin" do
164
164
  end
165
165
  end
166
166
 
167
- describe "Model#after_initialize" do
168
- qspecify "should be called after initialization" do
169
- values1 = nil
170
- reached_after_initialized = false
171
-
172
- a = model_class.call Sequel::Model do
173
- columns :x, :y
174
- after_initialize do
175
- values1 = @values.clone
176
- reached_after_initialized = true
177
- end
178
- end
179
-
180
- a.new(:x => 1, :y => 2)
181
- values1.should == {:x => 1, :y => 2}
182
- reached_after_initialized.should == true
183
- end
184
- end
185
-
186
167
  describe "Model#before_create && Model#after_create" do
187
168
  before do
188
- MODEL_DB.reset
169
+ DB.reset
189
170
 
190
171
  @c = model_class.call Sequel::Model(:items) do
191
172
  columns :x
192
173
  no_primary_key
193
174
 
194
- after_create {MODEL_DB << "BLAH after"}
175
+ after_create {DB << "BLAH after"}
195
176
  end
196
177
  end
197
178
 
198
179
  specify "should be called around new record creation" do
199
- @c.before_create {MODEL_DB << "BLAH before"}
180
+ @c.before_create {DB << "BLAH before"}
200
181
  @c.create(:x => 2)
201
- MODEL_DB.sqls.should == ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after']
182
+ DB.sqls.should == ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after']
202
183
  end
203
184
 
204
185
  specify ".create should cancel the save and raise an error if before_create returns false and raise_on_save_failure is true" do
205
186
  @c.before_create{false}
206
187
  proc{@c.load(:id => 2233).save}.should_not raise_error(Sequel::ValidationFailed)
207
188
  proc{@c.create(:x => 2)}.should raise_error(Sequel::BeforeHookFailed)
208
- MODEL_DB.sqls.should == []
189
+ DB.sqls.should == []
209
190
  end
210
191
 
211
192
  specify ".create should cancel the save and return nil if before_create returns false and raise_on_save_failure is false" do
212
193
  @c.before_create{false}
213
194
  @c.raise_on_save_failure = false
214
195
  @c.create(:x => 2).should == nil
215
- MODEL_DB.sqls.should == []
196
+ DB.sqls.should == []
216
197
  end
217
198
  end
218
199
 
219
200
  describe "Model#before_update && Model#after_update" do
220
201
  before do
221
- MODEL_DB.reset
202
+ DB.reset
222
203
 
223
204
  @c = model_class.call(Sequel::Model(:items)) do
224
- after_update {MODEL_DB << "BLAH after"}
205
+ after_update {DB << "BLAH after"}
225
206
  end
226
207
  end
227
208
 
228
209
  specify "should be called around record update" do
229
- @c.before_update {MODEL_DB << "BLAH before"}
210
+ @c.before_update {DB << "BLAH before"}
230
211
  m = @c.load(:id => 2233, :x=>123)
231
212
  m.save
232
- MODEL_DB.sqls.should == ['BLAH before', 'UPDATE items SET x = 123 WHERE (id = 2233)', 'BLAH after']
213
+ DB.sqls.should == ['BLAH before', 'UPDATE items SET x = 123 WHERE (id = 2233)', 'BLAH after']
233
214
  end
234
215
 
235
216
  specify "#save should cancel the save and raise an error if before_update returns false and raise_on_save_failure is true" do
236
217
  @c.before_update{false}
237
218
  proc{@c.load(:id => 2233).save}.should_not raise_error(Sequel::ValidationFailed)
238
219
  proc{@c.load(:id => 2233).save}.should raise_error(Sequel::BeforeHookFailed)
239
- MODEL_DB.sqls.should == []
220
+ DB.sqls.should == []
240
221
  end
241
222
 
242
223
  specify "#save should cancel the save and return nil if before_update returns false and raise_on_save_failure is false" do
243
224
  @c.before_update{false}
244
225
  @c.raise_on_save_failure = false
245
226
  @c.load(:id => 2233).save.should == nil
246
- MODEL_DB.sqls.should == []
227
+ DB.sqls.should == []
247
228
  end
248
229
  end
249
230
 
250
231
  describe "Model#before_save && Model#after_save" do
251
232
  before do
252
- MODEL_DB.reset
233
+ DB.reset
253
234
 
254
235
  @c = model_class.call(Sequel::Model(:items)) do
255
236
  columns :x
256
- after_save {MODEL_DB << "BLAH after"}
237
+ after_save {DB << "BLAH after"}
257
238
  end
258
239
  end
259
240
 
260
241
  specify "should be called around record update" do
261
- @c.before_save {MODEL_DB << "BLAH before"}
242
+ @c.before_save {DB << "BLAH before"}
262
243
  m = @c.load(:id => 2233, :x=>123)
263
244
  m.save
264
- MODEL_DB.sqls.should == ['BLAH before', 'UPDATE items SET x = 123 WHERE (id = 2233)', 'BLAH after']
245
+ DB.sqls.should == ['BLAH before', 'UPDATE items SET x = 123 WHERE (id = 2233)', 'BLAH after']
265
246
  end
266
247
 
267
248
  specify "should be called around record creation" do
268
- @c.before_save {MODEL_DB << "BLAH before"}
249
+ @c.before_save {DB << "BLAH before"}
269
250
  @c.no_primary_key
270
251
  @c.create(:x => 2)
271
- MODEL_DB.sqls.should == ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after']
252
+ DB.sqls.should == ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after']
272
253
  end
273
254
 
274
255
  specify "#save should cancel the save and raise an error if before_save returns false and raise_on_save_failure is true" do
275
256
  @c.before_save{false}
276
257
  proc{@c.load(:id => 2233).save}.should_not raise_error(Sequel::ValidationFailed)
277
258
  proc{@c.load(:id => 2233).save}.should raise_error(Sequel::BeforeHookFailed)
278
- MODEL_DB.sqls.should == []
259
+ DB.sqls.should == []
279
260
  end
280
261
 
281
262
  specify "#save should cancel the save and return nil if before_save returns false and raise_on_save_failure is false" do
282
263
  @c.before_save{false}
283
264
  @c.raise_on_save_failure = false
284
265
  @c.load(:id => 2233).save.should == nil
285
- MODEL_DB.sqls.should == []
266
+ DB.sqls.should == []
286
267
  end
287
268
  end
288
269
 
289
270
  describe "Model#before_destroy && Model#after_destroy" do
290
271
  before do
291
- MODEL_DB.reset
272
+ DB.reset
292
273
 
293
274
  @c = model_class.call(Sequel::Model(:items)) do
294
- after_destroy {MODEL_DB << "BLAH after"}
275
+ after_destroy {DB << "BLAH after"}
295
276
  end
296
277
  end
297
278
 
298
279
  specify "should be called around record destruction" do
299
- @c.before_destroy {MODEL_DB << "BLAH before"}
280
+ @c.before_destroy {DB << "BLAH before"}
300
281
  m = @c.load(:id => 2233)
301
282
  m.destroy
302
- MODEL_DB.sqls.should == ['BLAH before', "DELETE FROM items WHERE id = 2233", 'BLAH after']
283
+ DB.sqls.should == ['BLAH before', "DELETE FROM items WHERE id = 2233", 'BLAH after']
303
284
  end
304
285
 
305
286
  specify "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_save_failure is true" do
306
287
  @c.before_destroy{false}
307
288
  proc{@c.load(:id => 2233).destroy}.should raise_error(Sequel::BeforeHookFailed)
308
- MODEL_DB.sqls.should == []
289
+ DB.sqls.should == []
309
290
  end
310
291
 
311
292
  specify "#destroy should cancel the destroy and return nil if before_destroy returns false and raise_on_save_failure is false" do
312
293
  @c.before_destroy{false}
313
294
  @c.raise_on_save_failure = false
314
295
  @c.load(:id => 2233).destroy.should == nil
315
- MODEL_DB.sqls.should == []
296
+ DB.sqls.should == []
316
297
  end
317
298
  end
318
299
 
319
300
  describe "Model#before_validation && Model#after_validation" do
320
301
  before do
321
- MODEL_DB.reset
302
+ DB.reset
322
303
 
323
304
  @c = model_class.call(Sequel::Model(:items)) do
324
305
  plugin :validation_class_methods
325
- after_validation{MODEL_DB << "BLAH after"}
306
+ after_validation{DB << "BLAH after"}
326
307
 
327
308
  def self.validate(o)
328
309
  o.errors.add(:id, 'not valid') unless o[:id] == 2233
@@ -332,42 +313,42 @@ describe "Model#before_validation && Model#after_validation" do
332
313
  end
333
314
 
334
315
  specify "should be called around validation" do
335
- @c.before_validation{MODEL_DB << "BLAH before"}
316
+ @c.before_validation{DB << "BLAH before"}
336
317
  m = @c.load(:id => 2233)
337
318
  m.should be_valid
338
- MODEL_DB.sqls.should == ['BLAH before', 'BLAH after']
319
+ DB.sqls.should == ['BLAH before', 'BLAH after']
339
320
 
340
- MODEL_DB.sqls.clear
321
+ DB.sqls.clear
341
322
  m = @c.load(:id => 22)
342
323
  m.should_not be_valid
343
- MODEL_DB.sqls.should == ['BLAH before', 'BLAH after']
324
+ DB.sqls.should == ['BLAH before', 'BLAH after']
344
325
  end
345
326
 
346
327
  specify "should be called when calling save" do
347
- @c.before_validation{MODEL_DB << "BLAH before"}
328
+ @c.before_validation{DB << "BLAH before"}
348
329
  m = @c.load(:id => 2233, :x=>123)
349
330
  m.save.should == m
350
- MODEL_DB.sqls.should == ['BLAH before', 'BLAH after', 'UPDATE items SET x = 123 WHERE (id = 2233)']
331
+ DB.sqls.should == ['BLAH before', 'BLAH after', 'UPDATE items SET x = 123 WHERE (id = 2233)']
351
332
 
352
- MODEL_DB.sqls.clear
333
+ DB.sqls.clear
353
334
  m = @c.load(:id => 22)
354
335
  m.raise_on_save_failure = false
355
336
  m.save.should == nil
356
- MODEL_DB.sqls.should == ['BLAH before', 'BLAH after']
337
+ DB.sqls.should == ['BLAH before', 'BLAH after']
357
338
  end
358
339
 
359
340
  specify "#save should cancel the save and raise an error if before_validation returns false and raise_on_save_failure is true" do
360
341
  @c.before_validation{false}
361
342
  proc{@c.load(:id => 2233).save}.should_not raise_error(Sequel::ValidationFailed)
362
343
  proc{@c.load(:id => 2233).save}.should raise_error(Sequel::BeforeHookFailed)
363
- MODEL_DB.sqls.should == []
344
+ DB.sqls.should == []
364
345
  end
365
346
 
366
347
  specify "#save should cancel the save and return nil if before_validation returns false and raise_on_save_failure is false" do
367
348
  @c.before_validation{false}
368
349
  @c.raise_on_save_failure = false
369
350
  @c.load(:id => 2233).save.should == nil
370
- MODEL_DB.sqls.should == []
351
+ DB.sqls.should == []
371
352
  end
372
353
  end
373
354