sequel 4.26.0 → 5.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (692) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG +405 -5656
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +232 -157
  5. data/bin/sequel +32 -9
  6. data/doc/advanced_associations.rdoc +252 -188
  7. data/doc/association_basics.rdoc +231 -273
  8. data/doc/bin_sequel.rdoc +5 -3
  9. data/doc/cheat_sheet.rdoc +75 -48
  10. data/doc/code_order.rdoc +28 -10
  11. data/doc/core_extensions.rdoc +104 -63
  12. data/doc/dataset_basics.rdoc +12 -21
  13. data/doc/dataset_filtering.rdoc +99 -86
  14. data/doc/extensions.rdoc +3 -10
  15. data/doc/mass_assignment.rdoc +74 -31
  16. data/doc/migration.rdoc +72 -46
  17. data/doc/model_dataset_method_design.rdoc +129 -0
  18. data/doc/model_hooks.rdoc +15 -25
  19. data/doc/model_plugins.rdoc +12 -12
  20. data/doc/mssql_stored_procedures.rdoc +3 -3
  21. data/doc/object_model.rdoc +59 -69
  22. data/doc/opening_databases.rdoc +84 -94
  23. data/doc/postgresql.rdoc +268 -38
  24. data/doc/prepared_statements.rdoc +29 -24
  25. data/doc/querying.rdoc +184 -164
  26. data/doc/reflection.rdoc +5 -6
  27. data/doc/release_notes/5.0.0.txt +159 -0
  28. data/doc/release_notes/5.1.0.txt +31 -0
  29. data/doc/release_notes/5.10.0.txt +84 -0
  30. data/doc/release_notes/5.11.0.txt +83 -0
  31. data/doc/release_notes/5.12.0.txt +141 -0
  32. data/doc/release_notes/5.13.0.txt +27 -0
  33. data/doc/release_notes/5.14.0.txt +63 -0
  34. data/doc/release_notes/5.15.0.txt +39 -0
  35. data/doc/release_notes/5.16.0.txt +110 -0
  36. data/doc/release_notes/5.17.0.txt +31 -0
  37. data/doc/release_notes/5.18.0.txt +69 -0
  38. data/doc/release_notes/5.19.0.txt +28 -0
  39. data/doc/release_notes/5.2.0.txt +33 -0
  40. data/doc/release_notes/5.20.0.txt +89 -0
  41. data/doc/release_notes/5.21.0.txt +87 -0
  42. data/doc/release_notes/5.22.0.txt +48 -0
  43. data/doc/release_notes/5.23.0.txt +56 -0
  44. data/doc/release_notes/5.24.0.txt +56 -0
  45. data/doc/release_notes/5.25.0.txt +32 -0
  46. data/doc/release_notes/5.26.0.txt +35 -0
  47. data/doc/release_notes/5.27.0.txt +21 -0
  48. data/doc/release_notes/5.28.0.txt +16 -0
  49. data/doc/release_notes/5.29.0.txt +22 -0
  50. data/doc/release_notes/5.3.0.txt +121 -0
  51. data/doc/release_notes/5.30.0.txt +20 -0
  52. data/doc/release_notes/5.31.0.txt +148 -0
  53. data/doc/release_notes/5.32.0.txt +46 -0
  54. data/doc/release_notes/5.33.0.txt +24 -0
  55. data/doc/release_notes/5.34.0.txt +40 -0
  56. data/doc/release_notes/5.35.0.txt +56 -0
  57. data/doc/release_notes/5.36.0.txt +60 -0
  58. data/doc/release_notes/5.37.0.txt +30 -0
  59. data/doc/release_notes/5.4.0.txt +80 -0
  60. data/doc/release_notes/5.5.0.txt +61 -0
  61. data/doc/release_notes/5.6.0.txt +31 -0
  62. data/doc/release_notes/5.7.0.txt +108 -0
  63. data/doc/release_notes/5.8.0.txt +170 -0
  64. data/doc/release_notes/5.9.0.txt +99 -0
  65. data/doc/schema_modification.rdoc +102 -77
  66. data/doc/security.rdoc +160 -87
  67. data/doc/sharding.rdoc +74 -47
  68. data/doc/sql.rdoc +135 -122
  69. data/doc/testing.rdoc +34 -18
  70. data/doc/thread_safety.rdoc +2 -4
  71. data/doc/transactions.rdoc +101 -19
  72. data/doc/validations.rdoc +64 -51
  73. data/doc/virtual_rows.rdoc +90 -109
  74. data/lib/sequel.rb +3 -1
  75. data/lib/sequel/adapters/ado.rb +154 -22
  76. data/lib/sequel/adapters/ado/access.rb +21 -21
  77. data/lib/sequel/adapters/ado/mssql.rb +8 -15
  78. data/lib/sequel/adapters/amalgalite.rb +17 -25
  79. data/lib/sequel/adapters/ibmdb.rb +52 -58
  80. data/lib/sequel/adapters/jdbc.rb +149 -127
  81. data/lib/sequel/adapters/jdbc/db2.rb +32 -40
  82. data/lib/sequel/adapters/jdbc/derby.rb +56 -58
  83. data/lib/sequel/adapters/jdbc/h2.rb +40 -30
  84. data/lib/sequel/adapters/jdbc/hsqldb.rb +22 -33
  85. data/lib/sequel/adapters/jdbc/jtds.rb +4 -10
  86. data/lib/sequel/adapters/jdbc/mssql.rb +6 -12
  87. data/lib/sequel/adapters/jdbc/mysql.rb +17 -18
  88. data/lib/sequel/adapters/jdbc/oracle.rb +25 -19
  89. data/lib/sequel/adapters/jdbc/postgresql.rb +90 -69
  90. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +14 -24
  91. data/lib/sequel/adapters/jdbc/sqlite.rb +50 -12
  92. data/lib/sequel/adapters/jdbc/sqlserver.rb +36 -9
  93. data/lib/sequel/adapters/jdbc/transactions.rb +25 -39
  94. data/lib/sequel/adapters/mock.rb +104 -113
  95. data/lib/sequel/adapters/mysql.rb +42 -61
  96. data/lib/sequel/adapters/mysql2.rb +126 -35
  97. data/lib/sequel/adapters/odbc.rb +21 -28
  98. data/lib/sequel/adapters/odbc/db2.rb +3 -1
  99. data/lib/sequel/adapters/odbc/mssql.rb +11 -15
  100. data/lib/sequel/adapters/odbc/oracle.rb +11 -0
  101. data/lib/sequel/adapters/oracle.rb +62 -68
  102. data/lib/sequel/adapters/postgres.rb +257 -311
  103. data/lib/sequel/adapters/postgresql.rb +3 -1
  104. data/lib/sequel/adapters/shared/access.rb +75 -79
  105. data/lib/sequel/adapters/shared/db2.rb +96 -74
  106. data/lib/sequel/adapters/shared/mssql.rb +258 -213
  107. data/lib/sequel/adapters/shared/mysql.rb +284 -216
  108. data/lib/sequel/adapters/shared/oracle.rb +175 -60
  109. data/lib/sequel/adapters/shared/postgres.rb +829 -383
  110. data/lib/sequel/adapters/shared/sqlanywhere.rb +105 -127
  111. data/lib/sequel/adapters/shared/sqlite.rb +382 -159
  112. data/lib/sequel/adapters/sqlanywhere.rb +53 -38
  113. data/lib/sequel/adapters/sqlite.rb +111 -105
  114. data/lib/sequel/adapters/tinytds.rb +38 -46
  115. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +8 -9
  116. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +7 -5
  117. data/lib/sequel/adapters/utils/mysql_mysql2.rb +87 -0
  118. data/lib/sequel/adapters/utils/mysql_prepared_statements.rb +56 -0
  119. data/lib/sequel/adapters/utils/replace.rb +3 -4
  120. data/lib/sequel/adapters/utils/split_alter_table.rb +2 -0
  121. data/lib/sequel/adapters/utils/stored_procedures.rb +9 -22
  122. data/lib/sequel/adapters/utils/unmodified_identifiers.rb +28 -0
  123. data/lib/sequel/ast_transformer.rb +13 -89
  124. data/lib/sequel/connection_pool.rb +54 -26
  125. data/lib/sequel/connection_pool/sharded_single.rb +19 -12
  126. data/lib/sequel/connection_pool/sharded_threaded.rb +160 -111
  127. data/lib/sequel/connection_pool/single.rb +21 -12
  128. data/lib/sequel/connection_pool/threaded.rb +137 -119
  129. data/lib/sequel/core.rb +352 -320
  130. data/lib/sequel/database.rb +19 -2
  131. data/lib/sequel/database/connecting.rb +70 -55
  132. data/lib/sequel/database/dataset.rb +15 -5
  133. data/lib/sequel/database/dataset_defaults.rb +20 -102
  134. data/lib/sequel/database/features.rb +20 -4
  135. data/lib/sequel/database/logging.rb +25 -7
  136. data/lib/sequel/database/misc.rb +132 -118
  137. data/lib/sequel/database/query.rb +51 -28
  138. data/lib/sequel/database/schema_generator.rb +188 -75
  139. data/lib/sequel/database/schema_methods.rb +161 -92
  140. data/lib/sequel/database/transactions.rb +260 -58
  141. data/lib/sequel/dataset.rb +28 -12
  142. data/lib/sequel/dataset/actions.rb +354 -170
  143. data/lib/sequel/dataset/dataset_module.rb +46 -0
  144. data/lib/sequel/dataset/features.rb +81 -34
  145. data/lib/sequel/dataset/graph.rb +82 -58
  146. data/lib/sequel/dataset/misc.rb +139 -47
  147. data/lib/sequel/dataset/placeholder_literalizer.rb +66 -26
  148. data/lib/sequel/dataset/prepared_statements.rb +188 -85
  149. data/lib/sequel/dataset/query.rb +428 -214
  150. data/lib/sequel/dataset/sql.rb +446 -339
  151. data/lib/sequel/deprecated.rb +14 -2
  152. data/lib/sequel/exceptions.rb +48 -16
  153. data/lib/sequel/extensions/_model_constraint_validations.rb +16 -0
  154. data/lib/sequel/extensions/_model_pg_row.rb +43 -0
  155. data/lib/sequel/extensions/_pretty_table.rb +10 -9
  156. data/lib/sequel/extensions/any_not_empty.rb +45 -0
  157. data/lib/sequel/extensions/arbitrary_servers.rb +15 -11
  158. data/lib/sequel/extensions/auto_literal_strings.rb +74 -0
  159. data/lib/sequel/extensions/blank.rb +2 -0
  160. data/lib/sequel/extensions/caller_logging.rb +79 -0
  161. data/lib/sequel/extensions/columns_introspection.rb +9 -4
  162. data/lib/sequel/extensions/connection_expiration.rb +99 -0
  163. data/lib/sequel/extensions/connection_validator.rb +26 -13
  164. data/lib/sequel/extensions/constant_sql_override.rb +65 -0
  165. data/lib/sequel/extensions/constraint_validations.rb +93 -38
  166. data/lib/sequel/extensions/core_extensions.rb +45 -53
  167. data/lib/sequel/extensions/core_refinements.rb +44 -46
  168. data/lib/sequel/extensions/current_datetime_timestamp.rb +5 -4
  169. data/lib/sequel/extensions/dataset_source_alias.rb +4 -0
  170. data/lib/sequel/extensions/date_arithmetic.rb +42 -16
  171. data/lib/sequel/extensions/datetime_parse_to_time.rb +37 -0
  172. data/lib/sequel/extensions/duplicate_columns_handler.rb +94 -0
  173. data/lib/sequel/extensions/empty_array_consider_nulls.rb +7 -3
  174. data/lib/sequel/extensions/error_sql.rb +7 -3
  175. data/lib/sequel/extensions/escaped_like.rb +100 -0
  176. data/lib/sequel/extensions/eval_inspect.rb +14 -15
  177. data/lib/sequel/extensions/exclude_or_null.rb +68 -0
  178. data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
  179. data/lib/sequel/extensions/freeze_datasets.rb +3 -0
  180. data/lib/sequel/extensions/from_block.rb +2 -31
  181. data/lib/sequel/extensions/graph_each.rb +19 -6
  182. data/lib/sequel/extensions/identifier_mangling.rb +180 -0
  183. data/lib/sequel/extensions/implicit_subquery.rb +48 -0
  184. data/lib/sequel/extensions/index_caching.rb +109 -0
  185. data/lib/sequel/extensions/inflector.rb +8 -4
  186. data/lib/sequel/extensions/integer64.rb +32 -0
  187. data/lib/sequel/extensions/looser_typecasting.rb +19 -9
  188. data/lib/sequel/extensions/migration.rb +132 -80
  189. data/lib/sequel/extensions/mssql_emulate_lateral_with_apply.rb +4 -0
  190. data/lib/sequel/extensions/named_timezones.rb +88 -23
  191. data/lib/sequel/extensions/no_auto_literal_strings.rb +4 -0
  192. data/lib/sequel/extensions/null_dataset.rb +12 -8
  193. data/lib/sequel/extensions/pagination.rb +35 -28
  194. data/lib/sequel/extensions/pg_array.rb +227 -316
  195. data/lib/sequel/extensions/pg_array_ops.rb +19 -7
  196. data/lib/sequel/extensions/pg_enum.rb +69 -24
  197. data/lib/sequel/extensions/pg_extended_date_support.rb +250 -0
  198. data/lib/sequel/extensions/pg_hstore.rb +50 -59
  199. data/lib/sequel/extensions/pg_hstore_ops.rb +9 -3
  200. data/lib/sequel/extensions/pg_inet.rb +34 -15
  201. data/lib/sequel/extensions/pg_inet_ops.rb +5 -1
  202. data/lib/sequel/extensions/pg_interval.rb +26 -26
  203. data/lib/sequel/extensions/pg_json.rb +422 -141
  204. data/lib/sequel/extensions/pg_json_ops.rb +248 -9
  205. data/lib/sequel/extensions/pg_loose_count.rb +5 -1
  206. data/lib/sequel/extensions/pg_range.rb +162 -146
  207. data/lib/sequel/extensions/pg_range_ops.rb +10 -5
  208. data/lib/sequel/extensions/pg_row.rb +53 -87
  209. data/lib/sequel/extensions/pg_row_ops.rb +36 -13
  210. data/lib/sequel/extensions/pg_static_cache_updater.rb +6 -2
  211. data/lib/sequel/extensions/pg_timestamptz.rb +28 -0
  212. data/lib/sequel/extensions/pretty_table.rb +4 -0
  213. data/lib/sequel/extensions/query.rb +12 -7
  214. data/lib/sequel/extensions/round_timestamps.rb +6 -9
  215. data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
  216. data/lib/sequel/extensions/s.rb +59 -0
  217. data/lib/sequel/extensions/schema_caching.rb +14 -1
  218. data/lib/sequel/extensions/schema_dumper.rb +83 -55
  219. data/lib/sequel/extensions/select_remove.rb +8 -4
  220. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +85 -0
  221. data/lib/sequel/extensions/server_block.rb +50 -17
  222. data/lib/sequel/extensions/server_logging.rb +61 -0
  223. data/lib/sequel/extensions/split_array_nil.rb +8 -4
  224. data/lib/sequel/extensions/sql_comments.rb +96 -0
  225. data/lib/sequel/extensions/sql_expr.rb +4 -1
  226. data/lib/sequel/extensions/string_agg.rb +181 -0
  227. data/lib/sequel/extensions/string_date_time.rb +2 -0
  228. data/lib/sequel/extensions/symbol_aref.rb +53 -0
  229. data/lib/sequel/extensions/symbol_aref_refinement.rb +43 -0
  230. data/lib/sequel/extensions/symbol_as.rb +23 -0
  231. data/lib/sequel/extensions/symbol_as_refinement.rb +37 -0
  232. data/lib/sequel/extensions/synchronize_sql.rb +45 -0
  233. data/lib/sequel/extensions/thread_local_timezones.rb +4 -0
  234. data/lib/sequel/extensions/to_dot.rb +15 -5
  235. data/lib/sequel/extensions/virtual_row_method_block.rb +44 -0
  236. data/lib/sequel/model.rb +36 -126
  237. data/lib/sequel/model/associations.rb +850 -257
  238. data/lib/sequel/model/base.rb +652 -764
  239. data/lib/sequel/model/dataset_module.rb +13 -10
  240. data/lib/sequel/model/default_inflections.rb +3 -1
  241. data/lib/sequel/model/errors.rb +3 -3
  242. data/lib/sequel/model/exceptions.rb +12 -12
  243. data/lib/sequel/model/inflections.rb +8 -19
  244. data/lib/sequel/model/plugins.rb +111 -0
  245. data/lib/sequel/plugins/accessed_columns.rb +2 -0
  246. data/lib/sequel/plugins/active_model.rb +32 -7
  247. data/lib/sequel/plugins/after_initialize.rb +3 -1
  248. data/lib/sequel/plugins/association_dependencies.rb +27 -18
  249. data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
  250. data/lib/sequel/plugins/association_multi_add_remove.rb +85 -0
  251. data/lib/sequel/plugins/association_pks.rb +181 -83
  252. data/lib/sequel/plugins/association_proxies.rb +33 -9
  253. data/lib/sequel/plugins/auto_validations.rb +58 -23
  254. data/lib/sequel/plugins/before_after_save.rb +8 -0
  255. data/lib/sequel/plugins/blacklist_security.rb +23 -12
  256. data/lib/sequel/plugins/boolean_readers.rb +9 -6
  257. data/lib/sequel/plugins/boolean_subsets.rb +64 -0
  258. data/lib/sequel/plugins/caching.rb +27 -16
  259. data/lib/sequel/plugins/class_table_inheritance.rb +192 -94
  260. data/lib/sequel/plugins/column_conflicts.rb +18 -3
  261. data/lib/sequel/plugins/column_select.rb +9 -5
  262. data/lib/sequel/plugins/columns_updated.rb +42 -0
  263. data/lib/sequel/plugins/composition.rb +36 -24
  264. data/lib/sequel/plugins/constraint_validations.rb +37 -16
  265. data/lib/sequel/plugins/csv_serializer.rb +58 -35
  266. data/lib/sequel/plugins/dataset_associations.rb +60 -18
  267. data/lib/sequel/plugins/def_dataset_method.rb +90 -0
  268. data/lib/sequel/plugins/defaults_setter.rb +74 -13
  269. data/lib/sequel/plugins/delay_add_association.rb +4 -1
  270. data/lib/sequel/plugins/dirty.rb +65 -24
  271. data/lib/sequel/plugins/eager_each.rb +27 -3
  272. data/lib/sequel/plugins/eager_graph_eager.rb +139 -0
  273. data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
  274. data/lib/sequel/plugins/error_splitter.rb +19 -12
  275. data/lib/sequel/plugins/finder.rb +246 -0
  276. data/lib/sequel/plugins/forbid_lazy_load.rb +216 -0
  277. data/lib/sequel/plugins/force_encoding.rb +9 -12
  278. data/lib/sequel/plugins/hook_class_methods.rb +39 -54
  279. data/lib/sequel/plugins/input_transformer.rb +20 -10
  280. data/lib/sequel/plugins/insert_conflict.rb +72 -0
  281. data/lib/sequel/plugins/insert_returning_select.rb +4 -2
  282. data/lib/sequel/plugins/instance_filters.rb +12 -8
  283. data/lib/sequel/plugins/instance_hooks.rb +36 -17
  284. data/lib/sequel/plugins/instance_specific_default.rb +113 -0
  285. data/lib/sequel/plugins/inverted_subsets.rb +24 -13
  286. data/lib/sequel/plugins/json_serializer.rb +123 -47
  287. data/lib/sequel/plugins/lazy_attributes.rb +20 -14
  288. data/lib/sequel/plugins/list.rb +40 -26
  289. data/lib/sequel/plugins/many_through_many.rb +28 -12
  290. data/lib/sequel/plugins/modification_detection.rb +17 -5
  291. data/lib/sequel/plugins/mssql_optimistic_locking.rb +8 -5
  292. data/lib/sequel/plugins/nested_attributes.rb +55 -28
  293. data/lib/sequel/plugins/optimistic_locking.rb +5 -3
  294. data/lib/sequel/plugins/pg_array_associations.rb +52 -18
  295. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +348 -0
  296. data/lib/sequel/plugins/pg_row.rb +7 -51
  297. data/lib/sequel/plugins/prepared_statements.rb +53 -72
  298. data/lib/sequel/plugins/prepared_statements_safe.rb +13 -5
  299. data/lib/sequel/plugins/rcte_tree.rb +43 -63
  300. data/lib/sequel/plugins/serialization.rb +37 -44
  301. data/lib/sequel/plugins/serialization_modification_detection.rb +3 -1
  302. data/lib/sequel/plugins/sharding.rb +17 -10
  303. data/lib/sequel/plugins/single_table_inheritance.rb +62 -28
  304. data/lib/sequel/plugins/singular_table_names.rb +2 -0
  305. data/lib/sequel/plugins/skip_create_refresh.rb +5 -3
  306. data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
  307. data/lib/sequel/plugins/split_values.rb +13 -6
  308. data/lib/sequel/plugins/static_cache.rb +79 -53
  309. data/lib/sequel/plugins/static_cache_cache.rb +53 -0
  310. data/lib/sequel/plugins/string_stripper.rb +5 -3
  311. data/lib/sequel/plugins/subclasses.rb +20 -2
  312. data/lib/sequel/plugins/subset_conditions.rb +48 -0
  313. data/lib/sequel/plugins/table_select.rb +4 -2
  314. data/lib/sequel/plugins/tactical_eager_loading.rb +120 -6
  315. data/lib/sequel/plugins/throw_failures.rb +110 -0
  316. data/lib/sequel/plugins/timestamps.rb +22 -8
  317. data/lib/sequel/plugins/touch.rb +21 -8
  318. data/lib/sequel/plugins/tree.rb +57 -30
  319. data/lib/sequel/plugins/typecast_on_load.rb +14 -4
  320. data/lib/sequel/plugins/unlimited_update.rb +3 -7
  321. data/lib/sequel/plugins/update_or_create.rb +6 -4
  322. data/lib/sequel/plugins/update_primary_key.rb +3 -1
  323. data/lib/sequel/plugins/update_refresh.rb +28 -15
  324. data/lib/sequel/plugins/uuid.rb +70 -0
  325. data/lib/sequel/plugins/validate_associated.rb +20 -0
  326. data/lib/sequel/plugins/validation_class_methods.rb +40 -19
  327. data/lib/sequel/plugins/validation_contexts.rb +49 -0
  328. data/lib/sequel/plugins/validation_helpers.rb +49 -31
  329. data/lib/sequel/plugins/whitelist_security.rb +122 -0
  330. data/lib/sequel/plugins/xml_serializer.rb +31 -30
  331. data/lib/sequel/sql.rb +479 -329
  332. data/lib/sequel/timezones.rb +62 -32
  333. data/lib/sequel/version.rb +10 -3
  334. metadata +177 -477
  335. data/Rakefile +0 -165
  336. data/doc/active_record.rdoc +0 -912
  337. data/doc/release_notes/1.0.txt +0 -38
  338. data/doc/release_notes/1.1.txt +0 -143
  339. data/doc/release_notes/1.3.txt +0 -101
  340. data/doc/release_notes/1.4.0.txt +0 -53
  341. data/doc/release_notes/1.5.0.txt +0 -155
  342. data/doc/release_notes/2.0.0.txt +0 -298
  343. data/doc/release_notes/2.1.0.txt +0 -271
  344. data/doc/release_notes/2.10.0.txt +0 -328
  345. data/doc/release_notes/2.11.0.txt +0 -215
  346. data/doc/release_notes/2.12.0.txt +0 -534
  347. data/doc/release_notes/2.2.0.txt +0 -253
  348. data/doc/release_notes/2.3.0.txt +0 -88
  349. data/doc/release_notes/2.4.0.txt +0 -106
  350. data/doc/release_notes/2.5.0.txt +0 -137
  351. data/doc/release_notes/2.6.0.txt +0 -157
  352. data/doc/release_notes/2.7.0.txt +0 -166
  353. data/doc/release_notes/2.8.0.txt +0 -171
  354. data/doc/release_notes/2.9.0.txt +0 -97
  355. data/doc/release_notes/3.0.0.txt +0 -221
  356. data/doc/release_notes/3.1.0.txt +0 -406
  357. data/doc/release_notes/3.10.0.txt +0 -286
  358. data/doc/release_notes/3.11.0.txt +0 -254
  359. data/doc/release_notes/3.12.0.txt +0 -304
  360. data/doc/release_notes/3.13.0.txt +0 -210
  361. data/doc/release_notes/3.14.0.txt +0 -118
  362. data/doc/release_notes/3.15.0.txt +0 -78
  363. data/doc/release_notes/3.16.0.txt +0 -45
  364. data/doc/release_notes/3.17.0.txt +0 -58
  365. data/doc/release_notes/3.18.0.txt +0 -120
  366. data/doc/release_notes/3.19.0.txt +0 -67
  367. data/doc/release_notes/3.2.0.txt +0 -268
  368. data/doc/release_notes/3.20.0.txt +0 -41
  369. data/doc/release_notes/3.21.0.txt +0 -87
  370. data/doc/release_notes/3.22.0.txt +0 -39
  371. data/doc/release_notes/3.23.0.txt +0 -172
  372. data/doc/release_notes/3.24.0.txt +0 -420
  373. data/doc/release_notes/3.25.0.txt +0 -88
  374. data/doc/release_notes/3.26.0.txt +0 -88
  375. data/doc/release_notes/3.27.0.txt +0 -82
  376. data/doc/release_notes/3.28.0.txt +0 -304
  377. data/doc/release_notes/3.29.0.txt +0 -459
  378. data/doc/release_notes/3.3.0.txt +0 -192
  379. data/doc/release_notes/3.30.0.txt +0 -135
  380. data/doc/release_notes/3.31.0.txt +0 -146
  381. data/doc/release_notes/3.32.0.txt +0 -202
  382. data/doc/release_notes/3.33.0.txt +0 -157
  383. data/doc/release_notes/3.34.0.txt +0 -671
  384. data/doc/release_notes/3.35.0.txt +0 -144
  385. data/doc/release_notes/3.36.0.txt +0 -245
  386. data/doc/release_notes/3.37.0.txt +0 -338
  387. data/doc/release_notes/3.38.0.txt +0 -234
  388. data/doc/release_notes/3.39.0.txt +0 -237
  389. data/doc/release_notes/3.4.0.txt +0 -325
  390. data/doc/release_notes/3.40.0.txt +0 -73
  391. data/doc/release_notes/3.41.0.txt +0 -155
  392. data/doc/release_notes/3.42.0.txt +0 -74
  393. data/doc/release_notes/3.43.0.txt +0 -105
  394. data/doc/release_notes/3.44.0.txt +0 -152
  395. data/doc/release_notes/3.45.0.txt +0 -179
  396. data/doc/release_notes/3.46.0.txt +0 -122
  397. data/doc/release_notes/3.47.0.txt +0 -270
  398. data/doc/release_notes/3.48.0.txt +0 -477
  399. data/doc/release_notes/3.5.0.txt +0 -510
  400. data/doc/release_notes/3.6.0.txt +0 -366
  401. data/doc/release_notes/3.7.0.txt +0 -179
  402. data/doc/release_notes/3.8.0.txt +0 -151
  403. data/doc/release_notes/3.9.0.txt +0 -233
  404. data/doc/release_notes/4.0.0.txt +0 -262
  405. data/doc/release_notes/4.1.0.txt +0 -85
  406. data/doc/release_notes/4.10.0.txt +0 -226
  407. data/doc/release_notes/4.11.0.txt +0 -147
  408. data/doc/release_notes/4.12.0.txt +0 -105
  409. data/doc/release_notes/4.13.0.txt +0 -169
  410. data/doc/release_notes/4.14.0.txt +0 -68
  411. data/doc/release_notes/4.15.0.txt +0 -56
  412. data/doc/release_notes/4.16.0.txt +0 -36
  413. data/doc/release_notes/4.17.0.txt +0 -38
  414. data/doc/release_notes/4.18.0.txt +0 -36
  415. data/doc/release_notes/4.19.0.txt +0 -45
  416. data/doc/release_notes/4.2.0.txt +0 -129
  417. data/doc/release_notes/4.20.0.txt +0 -79
  418. data/doc/release_notes/4.21.0.txt +0 -94
  419. data/doc/release_notes/4.22.0.txt +0 -72
  420. data/doc/release_notes/4.23.0.txt +0 -65
  421. data/doc/release_notes/4.24.0.txt +0 -99
  422. data/doc/release_notes/4.25.0.txt +0 -181
  423. data/doc/release_notes/4.26.0.txt +0 -44
  424. data/doc/release_notes/4.3.0.txt +0 -40
  425. data/doc/release_notes/4.4.0.txt +0 -92
  426. data/doc/release_notes/4.5.0.txt +0 -34
  427. data/doc/release_notes/4.6.0.txt +0 -30
  428. data/doc/release_notes/4.7.0.txt +0 -103
  429. data/doc/release_notes/4.8.0.txt +0 -175
  430. data/doc/release_notes/4.9.0.txt +0 -190
  431. data/lib/sequel/adapters/cubrid.rb +0 -142
  432. data/lib/sequel/adapters/do.rb +0 -156
  433. data/lib/sequel/adapters/do/mysql.rb +0 -64
  434. data/lib/sequel/adapters/do/postgres.rb +0 -42
  435. data/lib/sequel/adapters/do/sqlite3.rb +0 -40
  436. data/lib/sequel/adapters/jdbc/as400.rb +0 -82
  437. data/lib/sequel/adapters/jdbc/cubrid.rb +0 -62
  438. data/lib/sequel/adapters/jdbc/firebirdsql.rb +0 -34
  439. data/lib/sequel/adapters/jdbc/informix-sqli.rb +0 -31
  440. data/lib/sequel/adapters/jdbc/jdbcprogress.rb +0 -31
  441. data/lib/sequel/adapters/odbc/progress.rb +0 -8
  442. data/lib/sequel/adapters/shared/cubrid.rb +0 -243
  443. data/lib/sequel/adapters/shared/firebird.rb +0 -245
  444. data/lib/sequel/adapters/shared/informix.rb +0 -52
  445. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +0 -150
  446. data/lib/sequel/adapters/shared/progress.rb +0 -38
  447. data/lib/sequel/adapters/swift.rb +0 -158
  448. data/lib/sequel/adapters/swift/mysql.rb +0 -47
  449. data/lib/sequel/adapters/swift/postgres.rb +0 -45
  450. data/lib/sequel/adapters/swift/sqlite.rb +0 -47
  451. data/lib/sequel/adapters/utils/pg_types.rb +0 -68
  452. data/lib/sequel/dataset/mutation.rb +0 -109
  453. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +0 -3
  454. data/lib/sequel/extensions/filter_having.rb +0 -59
  455. data/lib/sequel/extensions/hash_aliases.rb +0 -45
  456. data/lib/sequel/extensions/meta_def.rb +0 -31
  457. data/lib/sequel/extensions/query_literals.rb +0 -80
  458. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +0 -22
  459. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +0 -118
  460. data/lib/sequel/extensions/set_overrides.rb +0 -72
  461. data/lib/sequel/no_core_ext.rb +0 -1
  462. data/lib/sequel/plugins/association_autoreloading.rb +0 -7
  463. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +0 -7
  464. data/lib/sequel/plugins/pg_typecast_on_load.rb +0 -78
  465. data/lib/sequel/plugins/prepared_statements_associations.rb +0 -117
  466. data/lib/sequel/plugins/prepared_statements_with_pk.rb +0 -59
  467. data/lib/sequel/plugins/schema.rb +0 -80
  468. data/lib/sequel/plugins/scissors.rb +0 -33
  469. data/spec/adapters/db2_spec.rb +0 -160
  470. data/spec/adapters/firebird_spec.rb +0 -411
  471. data/spec/adapters/informix_spec.rb +0 -100
  472. data/spec/adapters/mssql_spec.rb +0 -706
  473. data/spec/adapters/mysql_spec.rb +0 -1287
  474. data/spec/adapters/oracle_spec.rb +0 -313
  475. data/spec/adapters/postgres_spec.rb +0 -3725
  476. data/spec/adapters/spec_helper.rb +0 -43
  477. data/spec/adapters/sqlanywhere_spec.rb +0 -170
  478. data/spec/adapters/sqlite_spec.rb +0 -653
  479. data/spec/bin_spec.rb +0 -254
  480. data/spec/core/connection_pool_spec.rb +0 -1016
  481. data/spec/core/database_spec.rb +0 -2531
  482. data/spec/core/dataset_spec.rb +0 -5098
  483. data/spec/core/deprecated_spec.rb +0 -70
  484. data/spec/core/expression_filters_spec.rb +0 -1243
  485. data/spec/core/mock_adapter_spec.rb +0 -462
  486. data/spec/core/object_graph_spec.rb +0 -303
  487. data/spec/core/placeholder_literalizer_spec.rb +0 -163
  488. data/spec/core/schema_generator_spec.rb +0 -179
  489. data/spec/core/schema_spec.rb +0 -1659
  490. data/spec/core/spec_helper.rb +0 -34
  491. data/spec/core/version_spec.rb +0 -7
  492. data/spec/core_extensions_spec.rb +0 -699
  493. data/spec/extensions/accessed_columns_spec.rb +0 -51
  494. data/spec/extensions/active_model_spec.rb +0 -123
  495. data/spec/extensions/after_initialize_spec.rb +0 -24
  496. data/spec/extensions/arbitrary_servers_spec.rb +0 -109
  497. data/spec/extensions/association_dependencies_spec.rb +0 -117
  498. data/spec/extensions/association_pks_spec.rb +0 -365
  499. data/spec/extensions/association_proxies_spec.rb +0 -86
  500. data/spec/extensions/auto_validations_spec.rb +0 -192
  501. data/spec/extensions/blacklist_security_spec.rb +0 -88
  502. data/spec/extensions/blank_spec.rb +0 -69
  503. data/spec/extensions/boolean_readers_spec.rb +0 -93
  504. data/spec/extensions/caching_spec.rb +0 -270
  505. data/spec/extensions/class_table_inheritance_spec.rb +0 -420
  506. data/spec/extensions/column_conflicts_spec.rb +0 -60
  507. data/spec/extensions/column_select_spec.rb +0 -108
  508. data/spec/extensions/columns_introspection_spec.rb +0 -91
  509. data/spec/extensions/composition_spec.rb +0 -242
  510. data/spec/extensions/connection_validator_spec.rb +0 -120
  511. data/spec/extensions/constraint_validations_plugin_spec.rb +0 -274
  512. data/spec/extensions/constraint_validations_spec.rb +0 -325
  513. data/spec/extensions/core_refinements_spec.rb +0 -519
  514. data/spec/extensions/csv_serializer_spec.rb +0 -173
  515. data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
  516. data/spec/extensions/dataset_associations_spec.rb +0 -311
  517. data/spec/extensions/dataset_source_alias_spec.rb +0 -51
  518. data/spec/extensions/date_arithmetic_spec.rb +0 -150
  519. data/spec/extensions/defaults_setter_spec.rb +0 -101
  520. data/spec/extensions/delay_add_association_spec.rb +0 -52
  521. data/spec/extensions/dirty_spec.rb +0 -180
  522. data/spec/extensions/eager_each_spec.rb +0 -42
  523. data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
  524. data/spec/extensions/error_splitter_spec.rb +0 -18
  525. data/spec/extensions/error_sql_spec.rb +0 -20
  526. data/spec/extensions/eval_inspect_spec.rb +0 -73
  527. data/spec/extensions/filter_having_spec.rb +0 -40
  528. data/spec/extensions/force_encoding_spec.rb +0 -114
  529. data/spec/extensions/from_block_spec.rb +0 -21
  530. data/spec/extensions/graph_each_spec.rb +0 -109
  531. data/spec/extensions/hash_aliases_spec.rb +0 -24
  532. data/spec/extensions/hook_class_methods_spec.rb +0 -429
  533. data/spec/extensions/inflector_spec.rb +0 -183
  534. data/spec/extensions/input_transformer_spec.rb +0 -54
  535. data/spec/extensions/insert_returning_select_spec.rb +0 -46
  536. data/spec/extensions/instance_filters_spec.rb +0 -79
  537. data/spec/extensions/instance_hooks_spec.rb +0 -276
  538. data/spec/extensions/inverted_subsets_spec.rb +0 -33
  539. data/spec/extensions/json_serializer_spec.rb +0 -291
  540. data/spec/extensions/lazy_attributes_spec.rb +0 -170
  541. data/spec/extensions/list_spec.rb +0 -267
  542. data/spec/extensions/looser_typecasting_spec.rb +0 -43
  543. data/spec/extensions/many_through_many_spec.rb +0 -2172
  544. data/spec/extensions/meta_def_spec.rb +0 -21
  545. data/spec/extensions/migration_spec.rb +0 -712
  546. data/spec/extensions/modification_detection_spec.rb +0 -80
  547. data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -91
  548. data/spec/extensions/named_timezones_spec.rb +0 -108
  549. data/spec/extensions/nested_attributes_spec.rb +0 -697
  550. data/spec/extensions/null_dataset_spec.rb +0 -85
  551. data/spec/extensions/optimistic_locking_spec.rb +0 -128
  552. data/spec/extensions/pagination_spec.rb +0 -118
  553. data/spec/extensions/pg_array_associations_spec.rb +0 -736
  554. data/spec/extensions/pg_array_ops_spec.rb +0 -143
  555. data/spec/extensions/pg_array_spec.rb +0 -395
  556. data/spec/extensions/pg_enum_spec.rb +0 -92
  557. data/spec/extensions/pg_hstore_ops_spec.rb +0 -236
  558. data/spec/extensions/pg_hstore_spec.rb +0 -206
  559. data/spec/extensions/pg_inet_ops_spec.rb +0 -101
  560. data/spec/extensions/pg_inet_spec.rb +0 -52
  561. data/spec/extensions/pg_interval_spec.rb +0 -76
  562. data/spec/extensions/pg_json_ops_spec.rb +0 -229
  563. data/spec/extensions/pg_json_spec.rb +0 -218
  564. data/spec/extensions/pg_loose_count_spec.rb +0 -17
  565. data/spec/extensions/pg_range_ops_spec.rb +0 -58
  566. data/spec/extensions/pg_range_spec.rb +0 -404
  567. data/spec/extensions/pg_row_ops_spec.rb +0 -60
  568. data/spec/extensions/pg_row_plugin_spec.rb +0 -62
  569. data/spec/extensions/pg_row_spec.rb +0 -360
  570. data/spec/extensions/pg_static_cache_updater_spec.rb +0 -92
  571. data/spec/extensions/pg_typecast_on_load_spec.rb +0 -63
  572. data/spec/extensions/prepared_statements_associations_spec.rb +0 -159
  573. data/spec/extensions/prepared_statements_safe_spec.rb +0 -61
  574. data/spec/extensions/prepared_statements_spec.rb +0 -103
  575. data/spec/extensions/prepared_statements_with_pk_spec.rb +0 -31
  576. data/spec/extensions/pretty_table_spec.rb +0 -92
  577. data/spec/extensions/query_literals_spec.rb +0 -183
  578. data/spec/extensions/query_spec.rb +0 -102
  579. data/spec/extensions/rcte_tree_spec.rb +0 -392
  580. data/spec/extensions/round_timestamps_spec.rb +0 -43
  581. data/spec/extensions/schema_caching_spec.rb +0 -41
  582. data/spec/extensions/schema_dumper_spec.rb +0 -789
  583. data/spec/extensions/schema_spec.rb +0 -117
  584. data/spec/extensions/scissors_spec.rb +0 -26
  585. data/spec/extensions/select_remove_spec.rb +0 -38
  586. data/spec/extensions/sequel_3_dataset_methods_spec.rb +0 -101
  587. data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
  588. data/spec/extensions/serialization_spec.rb +0 -362
  589. data/spec/extensions/server_block_spec.rb +0 -90
  590. data/spec/extensions/set_overrides_spec.rb +0 -61
  591. data/spec/extensions/sharding_spec.rb +0 -198
  592. data/spec/extensions/shared_caching_spec.rb +0 -175
  593. data/spec/extensions/single_table_inheritance_spec.rb +0 -297
  594. data/spec/extensions/singular_table_names_spec.rb +0 -22
  595. data/spec/extensions/skip_create_refresh_spec.rb +0 -17
  596. data/spec/extensions/spec_helper.rb +0 -71
  597. data/spec/extensions/split_array_nil_spec.rb +0 -24
  598. data/spec/extensions/split_values_spec.rb +0 -22
  599. data/spec/extensions/sql_expr_spec.rb +0 -60
  600. data/spec/extensions/static_cache_spec.rb +0 -361
  601. data/spec/extensions/string_date_time_spec.rb +0 -95
  602. data/spec/extensions/string_stripper_spec.rb +0 -68
  603. data/spec/extensions/subclasses_spec.rb +0 -66
  604. data/spec/extensions/table_select_spec.rb +0 -71
  605. data/spec/extensions/tactical_eager_loading_spec.rb +0 -82
  606. data/spec/extensions/thread_local_timezones_spec.rb +0 -67
  607. data/spec/extensions/timestamps_spec.rb +0 -175
  608. data/spec/extensions/to_dot_spec.rb +0 -154
  609. data/spec/extensions/touch_spec.rb +0 -203
  610. data/spec/extensions/tree_spec.rb +0 -274
  611. data/spec/extensions/typecast_on_load_spec.rb +0 -80
  612. data/spec/extensions/unlimited_update_spec.rb +0 -20
  613. data/spec/extensions/update_or_create_spec.rb +0 -87
  614. data/spec/extensions/update_primary_key_spec.rb +0 -100
  615. data/spec/extensions/update_refresh_spec.rb +0 -53
  616. data/spec/extensions/validate_associated_spec.rb +0 -52
  617. data/spec/extensions/validation_class_methods_spec.rb +0 -1027
  618. data/spec/extensions/validation_helpers_spec.rb +0 -541
  619. data/spec/extensions/xml_serializer_spec.rb +0 -207
  620. data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
  621. data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
  622. data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  623. data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  624. data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
  625. data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
  626. data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
  627. data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
  628. data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
  629. data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
  630. data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
  631. data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
  632. data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
  633. data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
  634. data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  635. data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
  636. data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
  637. data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
  638. data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
  639. data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
  640. data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  641. data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
  642. data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  643. data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
  644. data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  645. data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
  646. data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
  647. data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  648. data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  649. data/spec/files/reversible_migrations/001_reversible.rb +0 -5
  650. data/spec/files/reversible_migrations/002_reversible.rb +0 -5
  651. data/spec/files/reversible_migrations/003_reversible.rb +0 -5
  652. data/spec/files/reversible_migrations/004_reversible.rb +0 -5
  653. data/spec/files/reversible_migrations/005_reversible.rb +0 -10
  654. data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
  655. data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
  656. data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
  657. data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
  658. data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
  659. data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
  660. data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
  661. data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
  662. data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
  663. data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
  664. data/spec/guards_helper.rb +0 -55
  665. data/spec/integration/associations_test.rb +0 -2454
  666. data/spec/integration/database_test.rb +0 -113
  667. data/spec/integration/dataset_test.rb +0 -1808
  668. data/spec/integration/eager_loader_test.rb +0 -687
  669. data/spec/integration/migrator_test.rb +0 -240
  670. data/spec/integration/model_test.rb +0 -226
  671. data/spec/integration/plugin_test.rb +0 -2240
  672. data/spec/integration/prepared_statement_test.rb +0 -467
  673. data/spec/integration/schema_test.rb +0 -817
  674. data/spec/integration/spec_helper.rb +0 -48
  675. data/spec/integration/timezone_test.rb +0 -86
  676. data/spec/integration/transaction_test.rb +0 -374
  677. data/spec/integration/type_test.rb +0 -133
  678. data/spec/model/association_reflection_spec.rb +0 -525
  679. data/spec/model/associations_spec.rb +0 -4426
  680. data/spec/model/base_spec.rb +0 -759
  681. data/spec/model/class_dataset_methods_spec.rb +0 -146
  682. data/spec/model/dataset_methods_spec.rb +0 -149
  683. data/spec/model/eager_loading_spec.rb +0 -2137
  684. data/spec/model/hooks_spec.rb +0 -604
  685. data/spec/model/inflector_spec.rb +0 -26
  686. data/spec/model/model_spec.rb +0 -982
  687. data/spec/model/plugins_spec.rb +0 -299
  688. data/spec/model/record_spec.rb +0 -2147
  689. data/spec/model/spec_helper.rb +0 -46
  690. data/spec/model/validations_spec.rb +0 -193
  691. data/spec/sequel_coverage.rb +0 -15
  692. data/spec/spec_config.rb +0 -10
@@ -1,299 +0,0 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
-
3
- describe Sequel::Model, ".plugin" do
4
- before do
5
- module Sequel::Plugins
6
- module Timestamped
7
- module InstanceMethods
8
- def get_stamp(*args); @values[:stamp] end
9
- def abc; 123; end
10
- end
11
-
12
- module ClassMethods
13
- def def; 234; end
14
- end
15
-
16
- module DatasetMethods
17
- def ghi; 345; end
18
- end
19
- end
20
- end
21
- @c = Class.new(Sequel::Model(:items))
22
- @t = Sequel::Plugins::Timestamped
23
- end
24
- after do
25
- Sequel::Plugins.send(:remove_const, :Timestamped)
26
- end
27
-
28
- it "should raise LoadError if the plugin is not found" do
29
- proc{@c.plugin :something_or_other}.must_raise(LoadError)
30
- end
31
-
32
- it "should store the plugin in .plugins" do
33
- @c.plugins.wont_include(@t)
34
- @c.plugin @t
35
- @c.plugins.must_include(@t)
36
- end
37
-
38
- it "should be inherited in subclasses" do
39
- @c.plugins.wont_include(@t)
40
- c1 = Class.new(@c)
41
- @c.plugin @t
42
- c2 = Class.new(@c)
43
- @c.plugins.must_include(@t)
44
- c1.plugins.wont_include(@t)
45
- c2.plugins.must_include(@t)
46
- end
47
-
48
- it "should accept a symbol and load the module from the Sequel::Plugins namespace" do
49
- @c.plugin :timestamped
50
- @c.plugins.must_include(@t)
51
- end
52
-
53
- it "should accept a module" do
54
- m = Module.new
55
- @c.plugin m
56
- @c.plugins.must_include(m)
57
- end
58
-
59
- it "should not attempt to load a plugin twice" do
60
- @c.plugins.wont_include(@t)
61
- @c.plugin @t
62
- @c.plugins.reject{|m| m != @t}.length.must_equal 1
63
- @c.plugin @t
64
- @c.plugins.reject{|m| m != @t}.length.must_equal 1
65
- end
66
-
67
- it "should call apply and configure if the plugin responds to it, with the args and block used" do
68
- m = Module.new do
69
- def self.args; @args; end
70
- def self.block; @block; end
71
- def self.block_call; @block.call; end
72
- def self.args2; @args2; end
73
- def self.block2; @block2; end
74
- def self.block2_call; @block2.call; end
75
- def self.apply(model, *args, &block)
76
- @args = args
77
- @block = block
78
- model.send(:define_method, :blah){43}
79
- end
80
- def self.configure(model, *args, &block)
81
- @args2 = args
82
- @block2 = block
83
- model.send(:define_method, :blag){44}
84
- end
85
- end
86
- b = lambda{42}
87
- @c.plugin(m, 123, 1=>2, &b)
88
-
89
- m.args.must_equal [123, {1=>2}]
90
- m.block.must_equal b
91
- m.block_call.must_equal 42
92
- @c.new.blah.must_equal 43
93
-
94
- m.args2.must_equal [123, {1=>2}]
95
- m.block2.must_equal b
96
- m.block2_call.must_equal 42
97
- @c.new.blag.must_equal 44
98
- end
99
-
100
- it "should call configure even if the plugin has already been loaded" do
101
- m = Module.new do
102
- @args = []
103
- def self.args; @args; end
104
- def self.configure(model, *args, &block)
105
- @args << [block, *args]
106
- end
107
- end
108
-
109
- b = lambda{42}
110
- @c.plugin(m, 123, 1=>2, &b)
111
- m.args.must_equal [[b, 123, {1=>2}]]
112
-
113
- b2 = lambda{44}
114
- @c.plugin(m, 234, 2=>3, &b2)
115
- m.args.must_equal [[b, 123, {1=>2}], [b2, 234, {2=>3}]]
116
- end
117
-
118
- it "should call things in the following order: apply, ClassMethods, InstanceMethods, DatasetMethods, configure" do
119
- m = Module.new do
120
- @args = []
121
- def self.args; @args; end
122
- def self.apply(model, *args, &block)
123
- @args << :apply
124
- end
125
- def self.configure(model, *args, &block)
126
- @args << :configure
127
- end
128
- self::InstanceMethods = Module.new do
129
- def self.included(model)
130
- model.plugins.last.args << :im
131
- end
132
- end
133
- self::ClassMethods = Module.new do
134
- def self.extended(model)
135
- model.plugins.last.args << :cm
136
- end
137
- end
138
- self::DatasetMethods = Module.new do
139
- def self.extended(dataset)
140
- dataset.model.plugins.last.args << :dm
141
- end
142
- end
143
- end
144
-
145
- b = lambda{44}
146
- @c.plugin(m, 123, 1=>2, &b)
147
- m.args.must_equal [:apply, :cm, :im, :dm, :configure]
148
- @c.plugin(m, 234, 2=>3, &b)
149
- m.args.must_equal [:apply, :cm, :im, :dm, :configure, :configure]
150
- end
151
-
152
- it "should include an InstanceMethods module in the class if the plugin includes it" do
153
- @c.plugin @t
154
- m = @c.new
155
- m.must_respond_to(:get_stamp)
156
- m.must_respond_to(:abc)
157
- m.abc.must_equal 123
158
- t = Time.now
159
- m[:stamp] = t
160
- m.get_stamp.must_equal t
161
- end
162
-
163
- it "should extend the class with a ClassMethods module if the plugin includes it" do
164
- @c.plugin @t
165
- @c.def.must_equal 234
166
- end
167
-
168
- it "should extend the class's dataset with a DatasetMethods module if the plugin includes it" do
169
- @c.plugin @t
170
- @c.dataset.ghi.must_equal 345
171
- end
172
-
173
- it "should save the DatasetMethods module and apply it later if the class doesn't have a dataset" do
174
- c = Class.new(Sequel::Model)
175
- c.plugin @t
176
- c.dataset = DB[:i]
177
- c.dataset.ghi.must_equal 345
178
- end
179
-
180
- it "should save the DatasetMethods module and apply it later if the class has a dataset" do
181
- @c.plugin @t
182
- @c.dataset = DB[:i]
183
- @c.dataset.ghi.must_equal 345
184
- end
185
-
186
- it "should not define class methods for private instance methods in DatasetMethod" do
187
- m = Module.new do
188
- self::DatasetMethods = Module.new do
189
- def b; 2; end
190
- private
191
- def a; 1; end
192
- end
193
- end
194
- @c.plugin m
195
- @c.dataset.b.must_equal 2
196
- lambda{@c.dataset.a}.must_raise(NoMethodError)
197
- @c.dataset.send(:a).must_equal 1
198
- lambda{@c.a}.must_raise(NoMethodError)
199
- lambda{@c.send(:a)}.must_raise(NoMethodError)
200
- end
201
-
202
- it "should not raise an error if the DatasetMethod module has no public instance methods" do
203
- m = Module.new do
204
- self::DatasetMethods = Module.new do
205
- private
206
- def a; 1; end
207
- end
208
- end
209
- @c.plugin m
210
- end
211
-
212
- it "should not raise an error if plugin submodule names exist higher up in the namespace hierarchy" do
213
- class ::ClassMethods; end
214
- @c.plugin(m = Module.new)
215
- Object.send(:remove_const, :ClassMethods)
216
- @c.plugins.must_include(m)
217
-
218
- class ::InstanceMethods; end
219
- @c.plugin(m = Module.new)
220
- Object.send(:remove_const, :InstanceMethods)
221
- @c.plugins.must_include(m)
222
-
223
- class ::DatasetMethods; end
224
- @c.plugin(m = Module.new)
225
- Object.send(:remove_const, :DatasetMethods)
226
- @c.plugins.must_include(m)
227
- end
228
- end
229
-
230
- describe Sequel::Plugins do
231
- before do
232
- @c = Class.new(Sequel::Model(:items))
233
- end
234
-
235
- it "should have def_dataset_methods define methods that call methods on the dataset" do
236
- m = Module.new do
237
- module self::ClassMethods
238
- Sequel::Plugins.def_dataset_methods(self, :one)
239
- end
240
- module self::DatasetMethods
241
- def one
242
- 1
243
- end
244
- end
245
- end
246
- @c.plugin m
247
- @c.one.must_equal 1
248
- end
249
-
250
- it "should have def_dataset_methods accept an array with multiple methods" do
251
- m = Module.new do
252
- module self::ClassMethods
253
- Sequel::Plugins.def_dataset_methods(self, [:one, :two])
254
- end
255
- module self::DatasetMethods
256
- def one
257
- 1
258
- end
259
- def two
260
- 2
261
- end
262
- end
263
- end
264
- @c.plugin m
265
- @c.one.must_equal 1
266
- @c.two.must_equal 2
267
- end
268
-
269
- it "should have inherited_instance_variables add instance variables to copy into the subclass" do
270
- m = Module.new do
271
- def self.apply(model)
272
- model.instance_variable_set(:@one, 1)
273
- end
274
- module self::ClassMethods
275
- attr_reader :one
276
- Sequel::Plugins.inherited_instance_variables(self, :@one=>nil)
277
- end
278
- end
279
- @c.plugin m
280
- Class.new(@c).one.must_equal 1
281
- end
282
-
283
- it "should have after_set_dataset add a method to call after set_dataset" do
284
- m = Module.new do
285
- module self::ClassMethods
286
- Sequel::Plugins.after_set_dataset(self, :one)
287
- private
288
- def one
289
- dataset.opts[:foo] = 1
290
- end
291
- end
292
- end
293
- @c.plugin m
294
- @c.dataset.opts[:foo].must_equal nil
295
- @c.set_dataset :blah
296
- @c.dataset.opts[:foo].must_equal 1
297
- end
298
- end
299
-
@@ -1,2147 +0,0 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
-
3
- describe "Model#values" do
4
- before do
5
- @c = Class.new(Sequel::Model(:items))
6
- end
7
-
8
- it "should return the hash of model values" do
9
- hash = {:x=>1}
10
- @c.load(hash).values.must_be_same_as(hash)
11
- end
12
-
13
- it "should be aliased as to_hash" do
14
- hash = {:x=>1}
15
- @c.load(hash).to_hash.must_be_same_as(hash)
16
- end
17
- end
18
-
19
- describe "Model#get_column_value and set_column_value" do
20
- before do
21
- @c = Class.new(Sequel::Model(:items))
22
- @c.columns :x
23
- @o = @c.load(:x=>1)
24
- end
25
-
26
- it "should get and set column values" do
27
- @o.get_column_value(:x).must_equal 1
28
- @o.set_column_value(:x=, 2)
29
- @o.get_column_value(:x).must_equal 2
30
- @o.x.must_equal 2
31
- end
32
- end
33
-
34
- describe "Model#save server use" do
35
- before do
36
- @db = Sequel.mock(:autoid=>proc{|sql| 10}, :fetch=>{:x=>1, :id=>10}, :servers=>{:blah=>{}, :read_only=>{}})
37
- @c = Class.new(Sequel::Model(@db[:items]))
38
- @c.columns :id, :x, :y
39
- @c.dataset.columns(:id, :x, :y)
40
- @db.sqls
41
- end
42
-
43
- it "should use the :default server if the model doesn't have one already specified" do
44
- @c.new(:x=>1).save.must_equal @c.load(:x=>1, :id=>10)
45
- @db.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", 'SELECT * FROM items WHERE (id = 10) LIMIT 1']
46
- end
47
-
48
- it "should use the model's server if the model has one already specified" do
49
- @c.dataset = @c.dataset.server(:blah)
50
- @c.new(:x=>1).save.must_equal @c.load(:x=>1, :id=>10)
51
- @db.sqls.must_equal ["INSERT INTO items (x) VALUES (1) -- blah", 'SELECT * FROM items WHERE (id = 10) LIMIT 1 -- blah']
52
- end
53
- end
54
-
55
- describe "Model#save" do
56
- before do
57
- @c = Class.new(Sequel::Model(:items)) do
58
- columns :id, :x, :y
59
- end
60
- @c.instance_dataset.autoid = @c.dataset.autoid = 13
61
- DB.reset
62
- end
63
-
64
- it "should insert a record for a new model instance" do
65
- o = @c.new(:x => 1)
66
- o.save
67
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 13) LIMIT 1"]
68
- end
69
-
70
- it "should use dataset's insert_select method if present" do
71
- ds = @c.instance_dataset
72
- ds._fetch = {:y=>2}
73
- def ds.supports_insert_select?() true end
74
- def ds.insert_select(hash)
75
- with_sql_first("INSERT INTO items (y) VALUES (2) RETURNING *")
76
- end
77
- o = @c.new(:x => 1)
78
- o.save
79
-
80
- o.values.must_equal(:y=>2)
81
- DB.sqls.must_equal ["INSERT INTO items (y) VALUES (2) RETURNING *"]
82
- end
83
-
84
- it "should not use dataset's insert_select method if specific columns are selected" do
85
- ds = @c.dataset = @c.dataset.select(:y)
86
- def ds.insert_select(*) raise; end
87
- @c.new(:x => 1).save
88
- end
89
-
90
- it "should use dataset's insert_select method if the dataset uses returning, even if specific columns are selected" do
91
- def (@c.dataset).supports_returning?(_) true end
92
- ds = @c.dataset = @c.dataset.select(:y).returning(:y)
93
- DB.reset
94
- ds = @c.instance_dataset
95
- ds._fetch = {:y=>2}
96
- def ds.supports_insert_select?() true end
97
- def ds.insert_select(hash)
98
- with_sql_first("INSERT INTO items (y) VALUES (2) RETURNING y")
99
- end
100
- o = @c.new(:x => 1)
101
- o.save
102
-
103
- o.values.must_equal(:y=>2)
104
- DB.sqls.must_equal ["INSERT INTO items (y) VALUES (2) RETURNING y"]
105
- end
106
-
107
- it "should use value returned by insert as the primary key and refresh the object" do
108
- o = @c.new(:x => 11)
109
- o.save
110
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (11)",
111
- "SELECT * FROM items WHERE (id = 13) LIMIT 1"]
112
- end
113
-
114
- it "should allow you to skip refreshing by overridding _save_refresh" do
115
- @c.send(:define_method, :_save_refresh){}
116
- @c.create(:x => 11)
117
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (11)"]
118
- end
119
-
120
- it "should work correctly for inserting a record without a primary key" do
121
- @c.no_primary_key
122
- o = @c.new(:x => 11)
123
- o.save
124
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (11)"]
125
- end
126
-
127
- it "should set the autoincrementing_primary_key value to the value returned by insert" do
128
- @c.unrestrict_primary_key
129
- @c.set_primary_key [:x, :y]
130
- o = @c.new(:x => 11)
131
- def o.autoincrementing_primary_key() :y end
132
- o.save
133
- sqls = DB.sqls
134
- sqls.length.must_equal 2
135
- sqls.first.must_equal "INSERT INTO items (x) VALUES (11)"
136
- sqls.last.must_match %r{SELECT \* FROM items WHERE \(\([xy] = 1[13]\) AND \([xy] = 1[13]\)\) LIMIT 1}
137
- end
138
-
139
- it "should update a record for an existing model instance" do
140
- o = @c.load(:id => 3, :x => 1)
141
- o.save
142
- DB.sqls.must_equal ["UPDATE items SET x = 1 WHERE (id = 3)"]
143
- end
144
-
145
- it "should raise a NoExistingObject exception if the dataset update call doesn't return 1, unless require_modification is false" do
146
- o = @c.load(:id => 3, :x => 1)
147
- t = o.this
148
- t.numrows = 0
149
- proc{o.save}.must_raise(Sequel::NoExistingObject)
150
- t.numrows = 2
151
- proc{o.save}.must_raise(Sequel::NoExistingObject)
152
- t.numrows = 1
153
- o.save
154
-
155
- o.require_modification = false
156
- t.numrows = 0
157
- o.save
158
- t.numrows = 2
159
- o.save
160
- end
161
-
162
- it "should respect the :columns option to specify the columns to save" do
163
- o = @c.load(:id => 3, :x => 1, :y => nil)
164
- o.save(:columns=>:y)
165
- DB.sqls.first.must_equal "UPDATE items SET y = NULL WHERE (id = 3)"
166
- end
167
-
168
- it "should mark saved columns as not changed" do
169
- o = @c.load(:id => 3, :x => 1, :y => nil)
170
- o[:y] = 4
171
- o.changed_columns.must_equal [:y]
172
- o.save(:columns=>:x)
173
- o.changed_columns.must_equal [:y]
174
- o.save(:columns=>:y)
175
- o.changed_columns.must_equal []
176
- end
177
-
178
- it "should mark all columns as not changed if this is a new record" do
179
- o = @c.new(:x => 1, :y => nil)
180
- o.x = 4
181
- o.changed_columns.must_equal [:x]
182
- o.save
183
- o.changed_columns.must_equal []
184
- end
185
-
186
- it "should mark all columns as not changed if this is a new record and insert_select was used" do
187
- def (@c.dataset).insert_select(h) h.merge(:id=>1) end
188
- o = @c.new(:x => 1, :y => nil)
189
- o.x = 4
190
- o.changed_columns.must_equal [:x]
191
- o.save
192
- o.changed_columns.must_equal []
193
- end
194
-
195
- 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
196
- res = nil
197
- @c.send(:define_method, :after_save){ res = [@columns_updated, @was_new]}
198
- o = @c.new(:x => 1, :y => nil)
199
- o[:x] = 2
200
- o.save
201
- res.must_equal [nil, true]
202
- o.after_save
203
- res.must_equal [nil, nil]
204
-
205
- res = nil
206
- o = @c.load(:id => 23,:x => 1, :y => nil)
207
- o[:x] = 2
208
- o.save
209
- res.must_equal [{:x => 2, :y => nil}, nil]
210
- o.after_save
211
- res.must_equal [nil, nil]
212
-
213
- res = nil
214
- o = @c.load(:id => 23,:x => 2, :y => nil)
215
- o[:x] = 2
216
- o[:y] = 22
217
- o.save(:columns=>:x)
218
- res.must_equal [{:x=>2},nil]
219
- o.after_save
220
- res.must_equal [nil, nil]
221
- end
222
-
223
- it "should use Model's use_transactions setting by default" do
224
- @c.use_transactions = true
225
- @c.load(:id => 3, :x => 1, :y => nil).save(:columns=>:y)
226
- DB.sqls.must_equal ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
227
- @c.use_transactions = false
228
- @c.load(:id => 3, :x => 1, :y => nil).save(:columns=>:y)
229
- DB.sqls.must_equal ["UPDATE items SET y = NULL WHERE (id = 3)"]
230
- end
231
-
232
- it "should inherit Model's use_transactions setting" do
233
- @c.use_transactions = true
234
- Class.new(@c).load(:id => 3, :x => 1, :y => nil).save(:columns=>:y)
235
- DB.sqls.must_equal ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
236
- @c.use_transactions = false
237
- Class.new(@c).load(:id => 3, :x => 1, :y => nil).save(:columns=>:y)
238
- DB.sqls.must_equal ["UPDATE items SET y = NULL WHERE (id = 3)"]
239
- end
240
-
241
- it "should use object's use_transactions setting" do
242
- o = @c.load(:id => 3, :x => 1, :y => nil)
243
- o.use_transactions = false
244
- @c.use_transactions = true
245
- o.save(:columns=>:y)
246
- DB.sqls.must_equal ["UPDATE items SET y = NULL WHERE (id = 3)"]
247
- o = @c.load(:id => 3, :x => 1, :y => nil)
248
- o.use_transactions = true
249
- @c.use_transactions = false
250
- o.save(:columns=>:y)
251
- DB.sqls.must_equal ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
252
- end
253
-
254
- it "should use :transaction option if given" do
255
- o = @c.load(:id => 3, :x => 1, :y => nil)
256
- o.use_transactions = true
257
- o.save(:columns=>:y, :transaction=>false)
258
- DB.sqls.must_equal ["UPDATE items SET y = NULL WHERE (id = 3)"]
259
- o = @c.load(:id => 3, :x => 1, :y => nil)
260
- o.use_transactions = false
261
- o.save(:columns=>:y, :transaction=>true)
262
- DB.sqls.must_equal ["BEGIN", "UPDATE items SET y = NULL WHERE (id = 3)", "COMMIT"]
263
- end
264
-
265
- it "should rollback if before_save returns false and raise_on_save_failure = true" do
266
- o = @c.load(:id => 3, :x => 1, :y => nil)
267
- o.use_transactions = true
268
- o.raise_on_save_failure = true
269
- def o.before_save
270
- false
271
- end
272
- proc { o.save(:columns=>:y) }.must_raise(Sequel::HookFailed)
273
- DB.sqls.must_equal ["BEGIN", "ROLLBACK"]
274
- end
275
-
276
- it "should rollback if before_save calls cancel_action and raise_on_save_failure = true" do
277
- o = @c.load(:id => 3, :x => 1, :y => nil)
278
- o.use_transactions = true
279
- o.raise_on_save_failure = true
280
- def o.before_save
281
- cancel_action
282
- end
283
- proc { o.save(:columns=>:y) }.must_raise(Sequel::HookFailed)
284
- DB.sqls.must_equal ["BEGIN", "ROLLBACK"]
285
- end
286
-
287
- it "should rollback if before_save returns false and :raise_on_failure option is true" do
288
- o = @c.load(:id => 3, :x => 1, :y => nil)
289
- o.use_transactions = true
290
- o.raise_on_save_failure = false
291
- def o.before_save
292
- false
293
- end
294
- proc { o.save(:columns=>:y, :raise_on_failure => true) }.must_raise(Sequel::HookFailed)
295
- DB.sqls.must_equal ["BEGIN", "ROLLBACK"]
296
- end
297
-
298
- it "should not rollback outer transactions if before_save returns false and raise_on_save_failure = false" do
299
- o = @c.load(:id => 3, :x => 1, :y => nil)
300
- o.use_transactions = true
301
- o.raise_on_save_failure = false
302
- def o.before_save
303
- false
304
- end
305
- DB.transaction do
306
- o.save(:columns=>:y).must_equal nil
307
- DB.run "BLAH"
308
- end
309
- DB.sqls.must_equal ["BEGIN", "BLAH", "COMMIT"]
310
- end
311
-
312
- it "should rollback if before_save returns false and raise_on_save_failure = false" do
313
- o = @c.load(:id => 3, :x => 1, :y => nil)
314
- o.use_transactions = true
315
- o.raise_on_save_failure = false
316
- def o.before_save
317
- false
318
- end
319
- o.save(:columns=>:y).must_equal nil
320
- DB.sqls.must_equal ["BEGIN", "ROLLBACK"]
321
- end
322
-
323
- it "should not rollback if before_save throws Rollback and use_transactions = false" do
324
- o = @c.load(:id => 3, :x => 1, :y => nil)
325
- o.use_transactions = false
326
- def o.before_save
327
- raise Sequel::Rollback
328
- end
329
- proc { o.save(:columns=>:y) }.must_raise(Sequel::Rollback)
330
- DB.sqls.must_equal []
331
- end
332
-
333
- it "should support a :server option to set the server/shard to use" do
334
- db = Sequel.mock(:fetch=>{:id=>13, :x=>1}, :autoid=>proc{13}, :numrows=>1, :servers=>{:s1=>{}})
335
- c = Class.new(Sequel::Model(db[:items]))
336
- c.columns :id, :x
337
- db.sqls
338
- o = c.new(:x => 1)
339
- o.save(:server=>:s1)
340
- db.sqls.must_equal ["INSERT INTO items (x) VALUES (1) -- s1", "SELECT * FROM items WHERE (id = 13) LIMIT 1 -- s1"]
341
- o.save(:server=>:s1, :transaction=>true)
342
- db.sqls.must_equal ["BEGIN -- s1", "UPDATE items SET x = 1 WHERE (id = 13) -- s1", 'COMMIT -- s1']
343
- end
344
- end
345
-
346
- describe "Model#set_server" do
347
- before do
348
- @db = Sequel.mock(:fetch=>{:id=>13, :x=>1}, :autoid=>proc{13}, :numrows=>1, :servers=>{:s1=>{}})
349
- @c = Class.new(Sequel::Model(@db[:items])) do
350
- columns :id, :x
351
- end
352
- @db.sqls
353
- end
354
-
355
- it "should set the server to use when inserting" do
356
- @c.new(:x => 1).set_server(:s1).save
357
- @db.sqls.must_equal ["INSERT INTO items (x) VALUES (1) -- s1", "SELECT * FROM items WHERE (id = 13) LIMIT 1 -- s1"]
358
- end
359
-
360
- it "should set the server to use when updating" do
361
- @c.load(:id=>13, :x => 1).set_server(:s1).save
362
- @db.sqls.must_equal ["UPDATE items SET x = 1 WHERE (id = 13) -- s1"]
363
- end
364
-
365
- it "should set the server to use for transactions when saving" do
366
- @c.load(:id=>13, :x => 1).set_server(:s1).save(:transaction=>true)
367
- @db.sqls.must_equal ["BEGIN -- s1", "UPDATE items SET x = 1 WHERE (id = 13) -- s1", 'COMMIT -- s1']
368
- end
369
-
370
- it "should set the server to use when deleting" do
371
- @c.load(:id=>13).set_server(:s1).delete
372
- @db.sqls.must_equal ["DELETE FROM items WHERE (id = 13) -- s1"]
373
- end
374
-
375
- it "should set the server to use when deleting when using optimized delete" do
376
- @c.set_primary_key :id
377
- @c.load(:id=>13).set_server(:s1).delete
378
- @db.sqls.must_equal ["DELETE FROM items WHERE id = 13 -- s1"]
379
- end
380
-
381
- it "should set the server to use for transactions when destroying" do
382
- o = @c.load(:id=>13).set_server(:s1)
383
- o.use_transactions = true
384
- o.destroy
385
- @db.sqls.must_equal ["BEGIN -- s1", "DELETE FROM items WHERE (id = 13) -- s1", 'COMMIT -- s1']
386
- end
387
-
388
- it "should set the server on this if this is already loaded" do
389
- o = @c.load(:id=>13, :x => 1)
390
- o.this
391
- o.set_server(:s1)
392
- o.this.opts[:server].must_equal :s1
393
- end
394
-
395
- it "should set the server on this if this is not already loaded" do
396
- @c.load(:id=>13, :x => 1).set_server(:s1).this.opts[:server].must_equal :s1
397
- end
398
- end
399
-
400
- describe "Model#freeze" do
401
- before do
402
- class ::Album < Sequel::Model
403
- columns :id
404
- class B < Sequel::Model
405
- columns :id, :album_id
406
- end
407
- end
408
- @o = Album.load(:id=>1).freeze
409
- DB.sqls
410
- end
411
- after do
412
- Object.send(:remove_const, :Album)
413
- end
414
-
415
- it "should freeze the object" do
416
- @o.frozen?.must_equal true
417
- end
418
-
419
- it "should freeze the object if the model doesn't have a primary key" do
420
- Album.no_primary_key
421
- @o = Album.load(:id=>1).freeze
422
- @o.frozen?.must_equal true
423
- end
424
-
425
- it "should freeze the object's values, associations, changed_columns, errors, and this" do
426
- @o.values.frozen?.must_equal true
427
- @o.changed_columns.frozen?.must_equal true
428
- @o.errors.frozen?.must_equal true
429
- @o.this.frozen?.must_equal true
430
- end
431
-
432
- it "should still have working class attr overriddable methods" do
433
- Sequel::Model::BOOLEAN_SETTINGS.each{|m| @o.send(m) == Album.send(m)}
434
- end
435
-
436
- it "should have working new? method" do
437
- @o.new?.must_equal false
438
- Album.new.freeze.new?.must_equal true
439
- end
440
-
441
- it "should have working valid? method" do
442
- @o.valid?.must_equal true
443
- o = Album.new
444
- def o.validate() errors.add(:foo, '') end
445
- o.freeze
446
- o.valid?.must_equal false
447
- end
448
-
449
- it "should not call validate if errors is already frozen" do
450
- @o.valid?.must_equal true
451
- o = Album.new
452
- o.errors.freeze
453
- def o.validate() errors.add(:foo, '') end
454
- o.freeze
455
- o.valid?.must_equal true
456
- end
457
-
458
- it "should raise an Error if trying to save/destroy/delete/refresh" do
459
- proc{@o.save}.must_raise(Sequel::Error)
460
- proc{@o.destroy}.must_raise(Sequel::Error)
461
- proc{@o.delete}.must_raise(Sequel::Error)
462
- proc{@o.refresh}.must_raise(Sequel::Error)
463
- @o.db.sqls.must_equal []
464
- end
465
- end
466
-
467
- describe "Model#dup" do
468
- before do
469
- @Album = Class.new(Sequel::Model(:albums))
470
- @o = @Album.load(:id=>1)
471
- DB.sqls
472
- end
473
-
474
- it "should be equal to existing object" do
475
- @o.dup.must_equal @o
476
- @o.dup.values.must_equal @o.values
477
- @o.dup.changed_columns.must_equal @o.changed_columns
478
- @o.dup.errors.must_equal @o.errors
479
- @o.dup.this.must_equal @o.this
480
- end
481
-
482
- it "should not use identical structures" do
483
- @o.dup.wont_be_same_as(@o)
484
- @o.dup.values.wont_be_same_as(@o.values)
485
- @o.dup.changed_columns.wont_be_same_as(@o.changed_columns)
486
- @o.dup.errors.wont_be_same_as(@o.errors)
487
- @o.dup.this.wont_be_same_as(@o.this)
488
- end
489
-
490
- it "should keep new status" do
491
- @o.dup.new?.must_equal false
492
- @Album.new.dup.new?.must_equal true
493
- end
494
-
495
- it "should not copy frozen status" do
496
- @o.freeze.dup.wont_be :frozen?
497
- @o.freeze.dup.values.wont_be :frozen?
498
- @o.freeze.dup.changed_columns.wont_be :frozen?
499
- @o.freeze.dup.errors.wont_be :frozen?
500
- @o.freeze.dup.this.wont_be :frozen?
501
- end
502
- end
503
-
504
- describe "Model#clone" do
505
- before do
506
- @Album = Class.new(Sequel::Model(:albums))
507
- @o = @Album.load(:id=>1)
508
- DB.sqls
509
- end
510
-
511
- it "should be equal to existing object" do
512
- @o.clone.must_equal @o
513
- @o.clone.values.must_equal @o.values
514
- @o.clone.changed_columns.must_equal @o.changed_columns
515
- @o.clone.errors.must_equal @o.errors
516
- @o.clone.this.must_equal @o.this
517
- end
518
-
519
- it "should not use identical structures" do
520
- @o.clone.wont_be_same_as(@o)
521
- @o.clone.values.wont_be_same_as(@o.values)
522
- @o.clone.changed_columns.wont_be_same_as(@o.changed_columns)
523
- @o.clone.errors.wont_be_same_as(@o.errors)
524
- @o.clone.this.wont_be_same_as(@o.this)
525
- end
526
-
527
- it "should keep new status" do
528
- @o.clone.new?.must_equal false
529
- @Album.new.clone.new?.must_equal true
530
- end
531
-
532
- it "should copy frozen status" do
533
- @o.freeze.clone.must_be :frozen?
534
- @o.freeze.clone.values.must_be :frozen?
535
- @o.freeze.clone.changed_columns.must_be :frozen?
536
- @o.freeze.clone.errors.must_be :frozen?
537
- @o.freeze.clone.this.must_be :frozen?
538
- end
539
- end
540
-
541
- describe "Model#marshallable" do
542
- before do
543
- class ::Album < Sequel::Model
544
- columns :id, :x
545
- end
546
- end
547
- after do
548
- Object.send(:remove_const, :Album)
549
- end
550
-
551
- it "should make an object marshallable" do
552
- i = Album.new(:x=>2)
553
- s = nil
554
- i2 = nil
555
- i.marshallable!
556
- s = Marshal.dump(i)
557
- i2 = Marshal.load(s)
558
- i2.must_equal i
559
-
560
- i.save
561
- i.marshallable!
562
- s = Marshal.dump(i)
563
- i2 = Marshal.load(s)
564
- i2.must_equal i
565
-
566
- i.save
567
- i.marshallable!
568
- s = Marshal.dump(i)
569
- i2 = Marshal.load(s)
570
- i2.must_equal i
571
- end
572
- end
573
-
574
- describe "Model#modified?" do
575
- before do
576
- @c = Class.new(Sequel::Model(:items))
577
- @c.class_eval do
578
- columns :id, :x
579
- @db_schema = {:x => {:type => :integer}}
580
- end
581
- DB.reset
582
- end
583
-
584
- it "should be true if the object is new" do
585
- @c.new.modified?.must_equal true
586
- end
587
-
588
- it "should be false if the object has not been modified" do
589
- @c.load(:id=>1).modified?.must_equal false
590
- end
591
-
592
- it "should be true if the object has been modified" do
593
- o = @c.load(:id=>1, :x=>2)
594
- o.x = 3
595
- o.modified?.must_equal true
596
- end
597
-
598
- it "should be true if the object is marked modified!" do
599
- o = @c.load(:id=>1, :x=>2)
600
- o.modified!
601
- o.modified?.must_equal true
602
- end
603
-
604
- it "should be false if the object is marked modified! after saving until modified! again" do
605
- o = @c.load(:id=>1, :x=>2)
606
- o.modified!
607
- o.save
608
- o.modified?.must_equal false
609
- o.modified!
610
- o.modified?.must_equal true
611
- end
612
-
613
- it "should be false if a column value is set that is the same as the current value after typecasting" do
614
- o = @c.load(:id=>1, :x=>2)
615
- o.x = '2'
616
- o.modified?.must_equal false
617
- end
618
-
619
- it "should be true if a column value is set that is the different as the current value after typecasting" do
620
- o = @c.load(:id=>1, :x=>'2')
621
- o.x = '2'
622
- o.modified?.must_equal true
623
- end
624
-
625
- it "should be true if given a column argument and the column has been changed" do
626
- o = @c.new
627
- o.modified?(:id).must_equal false
628
- o.id = 1
629
- o.modified?(:id).must_equal true
630
- end
631
- end
632
-
633
- describe "Model#modified!" do
634
- before do
635
- @c = Class.new(Sequel::Model(:items))
636
- @c.class_eval do
637
- columns :id, :x
638
- end
639
- DB.reset
640
- end
641
-
642
- it "should mark the object as modified so that save_changes still runs the callbacks" do
643
- o = @c.load(:id=>1, :x=>2)
644
- def o.after_save
645
- values[:x] = 3
646
- end
647
- o.update({})
648
- o.x.must_equal 2
649
-
650
- o.modified!
651
- o.update({})
652
- o.x.must_equal 3
653
- o.db.sqls.must_equal []
654
- end
655
-
656
- it "should mark given column argument as modified" do
657
- o = @c.load(:id=>1, :x=>2)
658
- o.modified!(:x)
659
- o.changed_columns.must_equal [:x]
660
- o.save
661
- o.db.sqls.must_equal ["UPDATE items SET x = 2 WHERE (id = 1)"]
662
- end
663
- end
664
-
665
- describe "Model#save_changes" do
666
- before do
667
- @c = Class.new(Sequel::Model(:items)) do
668
- unrestrict_primary_key
669
- columns :id, :x, :y
670
- end
671
- DB.reset
672
- end
673
-
674
- it "should always save if the object is new" do
675
- o = @c.new(:x => 1)
676
- o.save_changes
677
- DB.sqls.first.must_equal "INSERT INTO items (x) VALUES (1)"
678
- end
679
-
680
- it "should take options passed to save" do
681
- o = @c.new(:x => 1)
682
- def o.before_validation; false; end
683
- proc{o.save_changes}.must_raise(Sequel::HookFailed)
684
- DB.sqls.must_equal []
685
- o.save_changes(:validate=>false)
686
- DB.sqls.first.must_equal "INSERT INTO items (x) VALUES (1)"
687
- end
688
-
689
- it "should do nothing if no changed columns" do
690
- o = @c.load(:id => 3, :x => 1, :y => nil)
691
- o.save_changes
692
- DB.sqls.must_equal []
693
- end
694
-
695
- it "should do nothing if modified? is false" do
696
- o = @c.load(:id => 3, :x => 1, :y => nil)
697
- def o.modified?; false; end
698
- o.save_changes
699
- DB.sqls.must_equal []
700
- end
701
-
702
- it "should update only changed columns" do
703
- o = @c.load(:id => 3, :x => 1, :y => nil)
704
- o.x = 2
705
-
706
- o.save_changes
707
- DB.sqls.must_equal ["UPDATE items SET x = 2 WHERE (id = 3)"]
708
- o.save_changes
709
- o.save_changes
710
- DB.sqls.must_equal []
711
-
712
- o.y = 4
713
- o.save_changes
714
- DB.sqls.must_equal ["UPDATE items SET y = 4 WHERE (id = 3)"]
715
- o.save_changes
716
- o.save_changes
717
- DB.sqls.must_equal []
718
- end
719
-
720
- it "should not consider columns changed if the values did not change" do
721
- o = @c.load(:id => 3, :x => 1, :y => nil)
722
- o.x = 1
723
-
724
- o.save_changes
725
- DB.sqls.must_equal []
726
- o.x = 3
727
- o.save_changes
728
- DB.sqls.must_equal ["UPDATE items SET x = 3 WHERE (id = 3)"]
729
-
730
- o[:y] = nil
731
- o.save_changes
732
- DB.sqls.must_equal []
733
- o[:y] = 4
734
- o.save_changes
735
- DB.sqls.must_equal ["UPDATE items SET y = 4 WHERE (id = 3)"]
736
- end
737
-
738
- it "should clear changed_columns" do
739
- o = @c.load(:id => 3, :x => 1, :y => nil)
740
- o.x = 4
741
- o.changed_columns.must_equal [:x]
742
- o.save_changes
743
- o.changed_columns.must_equal []
744
- end
745
-
746
- it "should update columns changed in a before_update hook" do
747
- o = @c.load(:id => 3, :x => 1, :y => nil)
748
- @c.send(:define_method, :before_update){self.x += 1}
749
- o.save_changes
750
- DB.sqls.must_equal []
751
- o.x = 2
752
- o.save_changes
753
- DB.sqls.must_equal ["UPDATE items SET x = 3 WHERE (id = 3)"]
754
- o.save_changes
755
- DB.sqls.must_equal []
756
- o.x = 4
757
- o.save_changes
758
- DB.sqls.must_equal ["UPDATE items SET x = 5 WHERE (id = 3)"]
759
- end
760
-
761
- it "should update columns changed in a before_save hook" do
762
- o = @c.load(:id => 3, :x => 1, :y => nil)
763
- @c.send(:define_method, :before_update){self.x += 1}
764
- o.save_changes
765
- DB.sqls.must_equal []
766
- o.x = 2
767
- o.save_changes
768
- DB.sqls.must_equal ["UPDATE items SET x = 3 WHERE (id = 3)"]
769
- o.save_changes
770
- DB.sqls.must_equal []
771
- o.x = 4
772
- o.save_changes
773
- DB.sqls.must_equal ["UPDATE items SET x = 5 WHERE (id = 3)"]
774
- end
775
- end
776
-
777
- describe "Model#new?" do
778
- before do
779
- @c = Class.new(Sequel::Model(:items)) do
780
- unrestrict_primary_key
781
- columns :x
782
- end
783
- DB.reset
784
- end
785
-
786
- it "should be true for a new instance" do
787
- n = @c.new(:x => 1)
788
- n.must_be :new?
789
- end
790
-
791
- it "should be false after saving" do
792
- n = @c.new(:x => 1)
793
- n.save
794
- n.wont_be :new?
795
- end
796
- end
797
-
798
- describe Sequel::Model, "with a primary key" do
799
- it "should default to :id" do
800
- model_a = Class.new Sequel::Model
801
- model_a.primary_key.must_equal :id
802
- end
803
-
804
- it "should be changed through 'set_primary_key'" do
805
- model_a = Class.new(Sequel::Model){ set_primary_key :a }
806
- model_a.primary_key.must_equal :a
807
- end
808
-
809
- it "should accept single argument composite keys" do
810
- model_a = Class.new(Sequel::Model){ set_primary_key [:a, :b] }
811
- model_a.primary_key.must_equal [:a, :b]
812
- end
813
- end
814
-
815
- describe Sequel::Model, "without a primary key" do
816
- it "should return nil for primary key" do
817
- Class.new(Sequel::Model){no_primary_key}.primary_key.must_equal nil
818
- end
819
-
820
- it "should raise a Sequel::Error on 'this'" do
821
- instance = Class.new(Sequel::Model){no_primary_key}.new
822
- proc{instance.this}.must_raise(Sequel::Error)
823
- end
824
- end
825
-
826
- describe Sequel::Model, "#this" do
827
- before do
828
- @example = Class.new(Sequel::Model(:examples))
829
- @example.columns :id, :a, :x, :y
830
- end
831
-
832
- it "should return a dataset identifying the record" do
833
- instance = @example.load(:id => 3)
834
- instance.this.sql.must_equal "SELECT * FROM examples WHERE (id = 3) LIMIT 1"
835
- end
836
-
837
- it "should support arbitary primary keys" do
838
- @example.set_primary_key :a
839
-
840
- instance = @example.load(:a => 3)
841
- instance.this.sql.must_equal "SELECT * FROM examples WHERE (a = 3) LIMIT 1"
842
- end
843
-
844
- it "should use a qualified primary key if the dataset is joined" do
845
- @example.dataset = @example.dataset.cross_join(:a)
846
- instance = @example.load(:id => 3)
847
- instance.this.sql.must_equal "SELECT * FROM examples CROSS JOIN a WHERE (examples.id = 3) LIMIT 1"
848
- end
849
-
850
- it "should support composite primary keys" do
851
- @example.set_primary_key [:x, :y]
852
- instance = @example.load(:x => 4, :y => 5)
853
- instance.this.sql.must_match(/SELECT \* FROM examples WHERE \(\([xy] = [45]\) AND \([xy] = [45]\)\) LIMIT 1/)
854
- end
855
- end
856
-
857
- describe "Model#pk" do
858
- before do
859
- @m = Class.new(Sequel::Model)
860
- @m.columns :id, :x, :y
861
- end
862
-
863
- it "should by default return the value of the :id column" do
864
- m = @m.load(:id => 111, :x => 2, :y => 3)
865
- m.pk.must_equal 111
866
- end
867
-
868
- it "should return the primary key value for custom primary key" do
869
- @m.set_primary_key :x
870
- m = @m.load(:id => 111, :x => 2, :y => 3)
871
- m.pk.must_equal 2
872
- end
873
-
874
- it "should return the primary key value for composite primary key" do
875
- @m.set_primary_key [:y, :x]
876
- m = @m.load(:id => 111, :x => 2, :y => 3)
877
- m.pk.must_equal [3, 2]
878
- end
879
-
880
- it "should raise if no primary key" do
881
- @m.set_primary_key nil
882
- m = @m.new(:id => 111, :x => 2, :y => 3)
883
- proc {m.pk}.must_raise(Sequel::Error)
884
-
885
- @m.no_primary_key
886
- m = @m.new(:id => 111, :x => 2, :y => 3)
887
- proc {m.pk}.must_raise(Sequel::Error)
888
- end
889
- end
890
-
891
- describe "Model#pk_hash" do
892
- before do
893
- @m = Class.new(Sequel::Model)
894
- @m.columns :id, :x, :y
895
- end
896
-
897
- it "should by default return a hash with the value of the :id column" do
898
- m = @m.load(:id => 111, :x => 2, :y => 3)
899
- m.pk_hash.must_equal(:id => 111)
900
- end
901
-
902
- it "should return a hash with the primary key value for custom primary key" do
903
- @m.set_primary_key :x
904
- m = @m.load(:id => 111, :x => 2, :y => 3)
905
- m.pk_hash.must_equal(:x => 2)
906
- end
907
-
908
- it "should return a hash with the primary key values for composite primary key" do
909
- @m.set_primary_key [:y, :x]
910
- m = @m.load(:id => 111, :x => 2, :y => 3)
911
- m.pk_hash.must_equal(:y => 3, :x => 2)
912
- end
913
-
914
- it "should raise if no primary key" do
915
- @m.set_primary_key nil
916
- m = @m.new(:id => 111, :x => 2, :y => 3)
917
- proc{m.pk_hash}.must_raise(Sequel::Error)
918
-
919
- @m.no_primary_key
920
- m = @m.new(:id => 111, :x => 2, :y => 3)
921
- proc{m.pk_hash}.must_raise(Sequel::Error)
922
- end
923
- end
924
-
925
- describe "Model#qualified_pk_hash" do
926
- before do
927
- @m = Class.new(Sequel::Model(:items))
928
- @m.columns :id, :x, :y
929
- end
930
-
931
- it "should by default return a hash with the value of the :id column" do
932
- m = @m.load(:id => 111, :x => 2, :y => 3)
933
- m.qualified_pk_hash.must_equal(Sequel.qualify(:items, :id) => 111)
934
- end
935
-
936
- it "should accept a custom qualifier" do
937
- m = @m.load(:id => 111, :x => 2, :y => 3)
938
- m.qualified_pk_hash(:foo).must_equal(Sequel.qualify(:foo, :id) => 111)
939
- end
940
-
941
- it "should return a hash with the primary key value for custom primary key" do
942
- @m.set_primary_key :x
943
- m = @m.load(:id => 111, :x => 2, :y => 3)
944
- m.qualified_pk_hash.must_equal(Sequel.qualify(:items, :x) => 2)
945
- end
946
-
947
- it "should return a hash with the primary key values for composite primary key" do
948
- @m.set_primary_key [:y, :x]
949
- m = @m.load(:id => 111, :x => 2, :y => 3)
950
- m.qualified_pk_hash.must_equal(Sequel.qualify(:items, :y) => 3, Sequel.qualify(:items, :x) => 2)
951
- end
952
-
953
- it "should raise if no primary key" do
954
- @m.set_primary_key nil
955
- m = @m.new(:id => 111, :x => 2, :y => 3)
956
- proc{m.qualified_pk_hash}.must_raise(Sequel::Error)
957
-
958
- @m.no_primary_key
959
- m = @m.new(:id => 111, :x => 2, :y => 3)
960
- proc{m.qualified_pk_hash}.must_raise(Sequel::Error)
961
- end
962
- end
963
-
964
- describe Sequel::Model, "#set" do
965
- before do
966
- @c = Class.new(Sequel::Model(:items)) do
967
- set_primary_key :id
968
- columns :x, :y, :id
969
- end
970
- @c.strict_param_setting = false
971
- @o1 = @c.new
972
- @o2 = @c.load(:id => 5)
973
- DB.reset
974
- end
975
-
976
- it "should filter the given params using the model columns" do
977
- @o1.set(:x => 1, :z => 2)
978
- @o1.values.must_equal(:x => 1)
979
- DB.sqls.must_equal []
980
-
981
- @o2.set(:y => 1, :abc => 2)
982
- @o2.values.must_equal(:y => 1, :id=> 5)
983
- DB.sqls.must_equal []
984
- end
985
-
986
- it "should work with both strings and symbols" do
987
- @o1.set('x'=> 1, 'z'=> 2)
988
- @o1.values.must_equal(:x => 1)
989
- DB.sqls.must_equal []
990
-
991
- @o2.set('y'=> 1, 'abc'=> 2)
992
- @o2.values.must_equal(:y => 1, :id=> 5)
993
- DB.sqls.must_equal []
994
- end
995
-
996
- it "should support virtual attributes" do
997
- @c.send(:define_method, :blah=){|v| self.x = v}
998
- @o1.set(:blah => 333)
999
- @o1.values.must_equal(:x => 333)
1000
- DB.sqls.must_equal []
1001
- @o1.set('blah'=> 334)
1002
- @o1.values.must_equal(:x => 334)
1003
- DB.sqls.must_equal []
1004
- end
1005
-
1006
- it "should not modify the primary key" do
1007
- @o1.set(:x => 1, :id => 2)
1008
- @o1.values.must_equal(:x => 1)
1009
- DB.sqls.must_equal []
1010
- @o2.set('y'=> 1, 'id'=> 2)
1011
- @o2.values.must_equal(:y => 1, :id=> 5)
1012
- DB.sqls.must_equal []
1013
- end
1014
-
1015
- it "should return self" do
1016
- returned_value = @o1.set(:x => 1, :z => 2)
1017
- returned_value.must_equal @o1
1018
- DB.sqls.must_equal []
1019
- end
1020
-
1021
- it "should raise error if strict_param_setting is true and method does not exist" do
1022
- @o1.strict_param_setting = true
1023
- proc{@o1.set('foo' => 1)}.must_raise(Sequel::MassAssignmentRestriction)
1024
- end
1025
-
1026
- it "should raise error if strict_param_setting is true and column is a primary key" do
1027
- @o1.strict_param_setting = true
1028
- proc{@o1.set('id' => 1)}.must_raise(Sequel::MassAssignmentRestriction)
1029
- end
1030
-
1031
- it "should raise error if strict_param_setting is true and column is restricted" do
1032
- @o1.strict_param_setting = true
1033
- @c.set_allowed_columns
1034
- proc{@o1.set('x' => 1)}.must_raise(Sequel::MassAssignmentRestriction)
1035
- end
1036
-
1037
- it "should not create a symbol if strict_param_setting is true and string is given" do
1038
- @o1.strict_param_setting = true
1039
- proc{@o1.set('sadojafdso' => 1)}.must_raise(Sequel::MassAssignmentRestriction)
1040
- Symbol.all_symbols.map(&:to_s).wont_include('sadojafdso')
1041
- end
1042
-
1043
- it "#set should correctly handle cases where an instance method is added to the class" do
1044
- @o1.set(:x => 1)
1045
- @o1.values.must_equal(:x => 1)
1046
-
1047
- @c.class_eval do
1048
- def z=(v)
1049
- self[:z] = v
1050
- end
1051
- end
1052
- @o1.set(:x => 2, :z => 3)
1053
- @o1.values.must_equal(:x => 2, :z=>3)
1054
- end
1055
-
1056
- it "#set should correctly handle cases where a singleton method is added to the object" do
1057
- @o1.set(:x => 1)
1058
- @o1.values.must_equal(:x => 1)
1059
-
1060
- def @o1.z=(v)
1061
- self[:z] = v
1062
- end
1063
- @o1.set(:x => 2, :z => 3)
1064
- @o1.values.must_equal(:x => 2, :z=>3)
1065
- end
1066
-
1067
- it "#set should correctly handle cases where a module with a setter method is included in the class" do
1068
- @o1.set(:x => 1)
1069
- @o1.values.must_equal(:x => 1)
1070
-
1071
- @c.send(:include, Module.new do
1072
- def z=(v)
1073
- self[:z] = v
1074
- end
1075
- end)
1076
- @o1.set(:x => 2, :z => 3)
1077
- @o1.values.must_equal(:x => 2, :z=>3)
1078
- end
1079
-
1080
- it "#set should correctly handle cases where the object extends a module with a setter method " do
1081
- @o1.set(:x => 1)
1082
- @o1.values.must_equal(:x => 1)
1083
-
1084
- @o1.extend(Module.new do
1085
- def z=(v)
1086
- self[:z] = v
1087
- end
1088
- end)
1089
- @o1.set(:x => 2, :z => 3)
1090
- @o1.values.must_equal(:x => 2, :z=>3)
1091
- end
1092
- end
1093
-
1094
- describe Sequel::Model, "#update" do
1095
- before do
1096
- @c = Class.new(Sequel::Model(:items)) do
1097
- set_primary_key :id
1098
- columns :x, :y, :id
1099
- end
1100
- @c.strict_param_setting = false
1101
- @o1 = @c.new
1102
- @o2 = @c.load(:id => 5)
1103
- DB.reset
1104
- end
1105
-
1106
- it "should filter the given params using the model columns" do
1107
- @o1.update(:x => 1, :z => 2)
1108
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1109
-
1110
- DB.reset
1111
- @o2.update(:y => 1, :abc => 2)
1112
- DB.sqls.must_equal ["UPDATE items SET y = 1 WHERE (id = 5)"]
1113
- end
1114
-
1115
- it "should support virtual attributes" do
1116
- @c.send(:define_method, :blah=){|v| self.x = v}
1117
- @o1.update(:blah => 333)
1118
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (333)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1119
- end
1120
-
1121
- it "should not modify the primary key" do
1122
- @o1.update(:x => 1, :id => 2)
1123
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1124
- DB.reset
1125
- @o2.update('y'=> 1, 'id'=> 2)
1126
- @o2.values.must_equal(:y => 1, :id=> 5)
1127
- DB.sqls.must_equal ["UPDATE items SET y = 1 WHERE (id = 5)"]
1128
- end
1129
- end
1130
-
1131
- describe Sequel::Model, "#set_fields" do
1132
- before do
1133
- @c = Class.new(Sequel::Model(:items)) do
1134
- set_primary_key :id
1135
- columns :x, :y, :z, :id
1136
- end
1137
- @o1 = @c.new
1138
- DB.reset
1139
- end
1140
-
1141
- it "should set only the given fields" do
1142
- @o1.set_fields({:x => 1, :y => 2, :z=>3, :id=>4}, [:x, :y])
1143
- @o1.values.must_equal(:x => 1, :y => 2)
1144
- @o1.set_fields({:x => 9, :y => 8, :z=>6, :id=>7}, [:x, :y, :id])
1145
- @o1.values.must_equal(:x => 9, :y => 8, :id=>7)
1146
- DB.sqls.must_equal []
1147
- end
1148
-
1149
- it "should lookup into the hash without checking if the entry exists" do
1150
- @o1.set_fields({:x => 1}, [:x, :y])
1151
- @o1.values.must_equal(:x => 1, :y => nil)
1152
- @o1.set_fields(Hash.new(2), [:x, :y])
1153
- @o1.values.must_equal(:x => 2, :y => 2)
1154
- end
1155
-
1156
- it "should skip missing fields if :missing=>:skip option is used" do
1157
- @o1.set_fields({:x => 3}, [:x, :y], :missing=>:skip)
1158
- @o1.values.must_equal(:x => 3)
1159
- @o1.set_fields({"x" => 4}, [:x, :y], :missing=>:skip)
1160
- @o1.values.must_equal(:x => 4)
1161
- @o1.set_fields(Hash.new(2).merge(:x=>2), [:x, :y], :missing=>:skip)
1162
- @o1.values.must_equal(:x => 2)
1163
- @o1.set_fields({:x => 1, :y => 2, :z=>3, :id=>4}, [:x, :y], :missing=>:skip)
1164
- @o1.values.must_equal(:x => 1, :y => 2)
1165
- end
1166
-
1167
- it "should raise for missing fields if :missing=>:raise option is used" do
1168
- proc{@o1.set_fields({:x => 1}, [:x, :y], :missing=>:raise)}.must_raise(Sequel::Error)
1169
- proc{@o1.set_fields(Hash.new(2).merge(:x=>2), [:x, :y], :missing=>:raise)}.must_raise(Sequel::Error)
1170
- proc{@o1.set_fields({"x" => 1}, [:x, :y], :missing=>:raise)}.must_raise(Sequel::Error)
1171
- @o1.set_fields({:x => 5, "y"=>2}, [:x, :y], :missing=>:raise)
1172
- @o1.values.must_equal(:x => 5, :y => 2)
1173
- @o1.set_fields({:x => 1, :y => 3, :z=>3, :id=>4}, [:x, :y], :missing=>:raise)
1174
- @o1.values.must_equal(:x => 1, :y => 3)
1175
- end
1176
-
1177
- it "should use default behavior for an unrecognized :missing option" do
1178
- @o1.set_fields({:x => 1, :y => 2, :z=>3, :id=>4}, [:x, :y], :missing=>:foo)
1179
- @o1.values.must_equal(:x => 1, :y => 2)
1180
- @o1.set_fields({:x => 9, :y => 8, :z=>6, :id=>7}, [:x, :y, :id], :missing=>:foo)
1181
- @o1.values.must_equal(:x => 9, :y => 8, :id=>7)
1182
- DB.sqls.must_equal []
1183
- end
1184
-
1185
- it "should respect model's default_set_fields_options" do
1186
- @c.default_set_fields_options = {:missing=>:skip}
1187
- @o1.set_fields({:x => 3}, [:x, :y])
1188
- @o1.values.must_equal(:x => 3)
1189
- @o1.set_fields({:x => 4}, [:x, :y], {})
1190
- @o1.values.must_equal(:x => 4)
1191
- proc{@o1.set_fields({:x => 3}, [:x, :y], :missing=>:raise)}.must_raise(Sequel::Error)
1192
- @c.default_set_fields_options = {:missing=>:raise}
1193
- proc{@o1.set_fields({:x => 3}, [:x, :y])}.must_raise(Sequel::Error)
1194
- proc{@o1.set_fields({:x => 3}, [:x, :y], {})}.must_raise(Sequel::Error)
1195
- @o1.set_fields({:x => 5}, [:x, :y], :missing=>:skip)
1196
- @o1.values.must_equal(:x => 5)
1197
- @o1.set_fields({:x => 5}, [:x, :y], :missing=>nil)
1198
- @o1.values.must_equal(:x => 5, :y=>nil)
1199
- DB.sqls.must_equal []
1200
- end
1201
-
1202
- it "should respect model's default_set_fields_options in a subclass" do
1203
- @c.default_set_fields_options = {:missing=>:skip}
1204
- o = Class.new(@c).new
1205
- o.set_fields({:x => 3}, [:x, :y])
1206
- o.values.must_equal(:x => 3)
1207
- end
1208
-
1209
- it "should respect set_column_value" do
1210
- @c.class_eval do
1211
- def set_column_value(c, v)
1212
- if c.to_s == 'model='
1213
- self[:model] = v
1214
- else
1215
- send(c, v)
1216
- end
1217
- end
1218
- end
1219
- @o1.set_fields({:model=>2, :x=>3}, [:model, :x])
1220
- @o1[:model].must_equal 2
1221
- @o1.x.must_equal 3
1222
- end
1223
- end
1224
-
1225
- describe Sequel::Model, "#update_fields" do
1226
- before do
1227
- @c = Class.new(Sequel::Model(:items)) do
1228
- set_primary_key :id
1229
- columns :x, :y, :z, :id
1230
- end
1231
- @c.strict_param_setting = true
1232
- @o1 = @c.load(:id=>1)
1233
- DB.reset
1234
- end
1235
-
1236
- it "should set only the given fields, and then save the changes to the record" do
1237
- @o1.update_fields({:x => 1, :y => 2, :z=>3, :id=>4}, [:x, :y])
1238
- @o1.values.must_equal(:x => 1, :y => 2, :id=>1)
1239
- sqls = DB.sqls
1240
- sqls.pop.must_match(/UPDATE items SET [xy] = [12], [xy] = [12] WHERE \(id = 1\)/)
1241
- sqls.must_equal []
1242
-
1243
- @o1.update_fields({:x => 1, :y => 5, :z=>6, :id=>7}, [:x, :y])
1244
- @o1.values.must_equal(:x => 1, :y => 5, :id=>1)
1245
- DB.sqls.must_equal ["UPDATE items SET y = 5 WHERE (id = 1)"]
1246
- end
1247
-
1248
- it "should support :missing=>:skip option" do
1249
- @o1.update_fields({:x => 1, :z=>3, :id=>4}, [:x, :y], :missing=>:skip)
1250
- @o1.values.must_equal(:x => 1, :id=>1)
1251
- DB.sqls.must_equal ["UPDATE items SET x = 1 WHERE (id = 1)"]
1252
- end
1253
-
1254
- it "should support :missing=>:raise option" do
1255
- proc{@o1.update_fields({:x => 1}, [:x, :y], :missing=>:raise)}.must_raise(Sequel::Error)
1256
- end
1257
-
1258
- it "should respect model's default_set_fields_options" do
1259
- @c.default_set_fields_options = {:missing=>:skip}
1260
- @o1.update_fields({:x => 3}, [:x, :y])
1261
- @o1.values.must_equal(:x => 3, :id=>1)
1262
- DB.sqls.must_equal ["UPDATE items SET x = 3 WHERE (id = 1)"]
1263
-
1264
- @c.default_set_fields_options = {:missing=>:raise}
1265
- proc{@o1.update_fields({:x => 3}, [:x, :y])}.must_raise(Sequel::Error)
1266
- DB.sqls.must_equal []
1267
- end
1268
- end
1269
-
1270
- describe Sequel::Model, "#(set|update)_(all|only)" do
1271
- before do
1272
- @c = Class.new(Sequel::Model(:items)) do
1273
- set_primary_key :id
1274
- columns :x, :y, :z, :id
1275
- set_allowed_columns :x
1276
- end
1277
- @c.strict_param_setting = false
1278
- @o1 = @c.new
1279
- DB.reset
1280
- end
1281
-
1282
- it "should raise errors if not all hash fields can be set and strict_param_setting is true" do
1283
- @c.strict_param_setting = true
1284
-
1285
- proc{@c.new.set_all(:x => 1, :y => 2, :z=>3, :use_after_commit_rollback => false)}.must_raise(Sequel::MassAssignmentRestriction)
1286
- (o = @c.new).set_all(:x => 1, :y => 2, :z=>3)
1287
- o.values.must_equal(:x => 1, :y => 2, :z=>3)
1288
-
1289
- proc{@c.new.set_only({:x => 1, :y => 2, :z=>3, :id=>4}, :x, :y)}.must_raise(Sequel::MassAssignmentRestriction)
1290
- proc{@c.new.set_only({:x => 1, :y => 2, :z=>3}, :x, :y)}.must_raise(Sequel::MassAssignmentRestriction)
1291
- (o = @c.new).set_only({:x => 1, :y => 2}, :x, :y)
1292
- o.values.must_equal(:x => 1, :y => 2)
1293
- end
1294
-
1295
- it "#set_all should set all attributes including the primary key" do
1296
- @o1.set_all(:x => 1, :y => 2, :z=>3, :id=>4)
1297
- @o1.values.must_equal(:id =>4, :x => 1, :y => 2, :z=>3)
1298
- end
1299
-
1300
- it "#set_all should set not set restricted fields" do
1301
- @o1.set_all(:x => 1, :use_after_commit_rollback => false)
1302
- @o1.use_after_commit_rollback.must_equal true
1303
- @o1.values.must_equal(:x => 1)
1304
- end
1305
-
1306
- it "#set_only should only set given attributes" do
1307
- @o1.set_only({:x => 1, :y => 2, :z=>3, :id=>4}, [:x, :y])
1308
- @o1.values.must_equal(:x => 1, :y => 2)
1309
- @o1.set_only({:x => 4, :y => 5, :z=>6, :id=>7}, :x, :y)
1310
- @o1.values.must_equal(:x => 4, :y => 5)
1311
- @o1.set_only({:x => 9, :y => 8, :z=>6, :id=>7}, :x, :y, :id)
1312
- @o1.values.must_equal(:x => 9, :y => 8, :id=>7)
1313
- end
1314
-
1315
- it "#update_all should update all attributes" do
1316
- @c.new.update_all(:x => 1)
1317
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1318
- @c.new.update_all(:y => 1)
1319
- DB.sqls.must_equal ["INSERT INTO items (y) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1320
- @c.new.update_all(:z => 1)
1321
- DB.sqls.must_equal ["INSERT INTO items (z) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1322
- end
1323
-
1324
- it "#update_only should only update given attributes" do
1325
- @o1.update_only({:x => 1, :y => 2, :z=>3, :id=>4}, [:x])
1326
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1327
- @c.new.update_only({:x => 1, :y => 2, :z=>3, :id=>4}, :x)
1328
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (1)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1329
- end
1330
- end
1331
-
1332
- describe Sequel::Model, "#destroy with filtered dataset" do
1333
- before do
1334
- @model = Class.new(Sequel::Model(DB[:items].where(:a=>1)))
1335
- @model.columns :id, :a
1336
- @instance = @model.load(:id => 1234)
1337
- DB.reset
1338
- end
1339
-
1340
- it "should raise a NoExistingObject exception if the dataset delete call doesn't return 1" do
1341
- def (@instance.this).execute_dui(*a) 0 end
1342
- proc{@instance.delete}.must_raise(Sequel::NoExistingObject)
1343
- def (@instance.this).execute_dui(*a) 2 end
1344
- proc{@instance.delete}.must_raise(Sequel::NoExistingObject)
1345
- def (@instance.this).execute_dui(*a) 1 end
1346
- @instance.delete
1347
-
1348
- @instance.require_modification = false
1349
- def (@instance.this).execute_dui(*a) 0 end
1350
- @instance.delete
1351
- def (@instance.this).execute_dui(*a) 2 end
1352
- @instance.delete
1353
- end
1354
-
1355
- it "should include WHERE clause when deleting" do
1356
- @instance.destroy
1357
- DB.sqls.must_equal ["DELETE FROM items WHERE ((a = 1) AND (id = 1234))"]
1358
- end
1359
- end
1360
-
1361
- describe Sequel::Model, "#destroy" do
1362
- before do
1363
- @model = Class.new(Sequel::Model(:items))
1364
- @model.columns :id
1365
- @instance = @model.load(:id => 1234)
1366
- DB.reset
1367
- end
1368
-
1369
- it "should return self" do
1370
- @model.send(:define_method, :after_destroy){3}
1371
- @instance.destroy.must_equal @instance
1372
- end
1373
-
1374
- it "should raise a NoExistingObject exception if the dataset delete call doesn't return 1" do
1375
- def (@model.dataset).execute_dui(*a) 0 end
1376
- proc{@instance.delete}.must_raise(Sequel::NoExistingObject)
1377
- def (@model.dataset).execute_dui(*a) 2 end
1378
- proc{@instance.delete}.must_raise(Sequel::NoExistingObject)
1379
- def (@model.dataset).execute_dui(*a) 1 end
1380
- @instance.delete
1381
-
1382
- @instance.require_modification = false
1383
- def (@model.dataset).execute_dui(*a) 0 end
1384
- @instance.delete
1385
- def (@model.dataset).execute_dui(*a) 2 end
1386
- @instance.delete
1387
- end
1388
-
1389
- it "should run within a transaction if use_transactions is true" do
1390
- @instance.use_transactions = true
1391
- @instance.destroy
1392
- DB.sqls.must_equal ["BEGIN", "DELETE FROM items WHERE id = 1234", "COMMIT"]
1393
- end
1394
-
1395
- it "should not run within a transaction if use_transactions is false" do
1396
- @instance.use_transactions = false
1397
- @instance.destroy
1398
- DB.sqls.must_equal ["DELETE FROM items WHERE id = 1234"]
1399
- end
1400
-
1401
- it "should run within a transaction if :transaction option is true" do
1402
- @instance.use_transactions = false
1403
- @instance.destroy(:transaction => true)
1404
- DB.sqls.must_equal ["BEGIN", "DELETE FROM items WHERE id = 1234", "COMMIT"]
1405
- end
1406
-
1407
- it "should not run within a transaction if :transaction option is false" do
1408
- @instance.use_transactions = true
1409
- @instance.destroy(:transaction => false)
1410
- DB.sqls.must_equal ["DELETE FROM items WHERE id = 1234"]
1411
- end
1412
-
1413
- it "should run before_destroy and after_destroy hooks" do
1414
- @model.send(:define_method, :before_destroy){DB.execute('before blah')}
1415
- @model.send(:define_method, :after_destroy){DB.execute('after blah')}
1416
- @instance.destroy
1417
- DB.sqls.must_equal ["before blah", "DELETE FROM items WHERE id = 1234", "after blah"]
1418
- end
1419
- end
1420
-
1421
- describe Sequel::Model, "#exists?" do
1422
- before do
1423
- @model = Class.new(Sequel::Model(:items))
1424
- @model.instance_dataset._fetch = @model.dataset._fetch = proc{|sql| {:x=>1} if sql =~ /id = 1/}
1425
- DB.reset
1426
- end
1427
-
1428
- it "should do a query to check if the record exists" do
1429
- @model.load(:id=>1).exists?.must_equal true
1430
- DB.sqls.must_equal ['SELECT 1 AS one FROM items WHERE (id = 1) LIMIT 1']
1431
- end
1432
-
1433
- it "should return false when #this.count == 0" do
1434
- @model.load(:id=>2).exists?.must_equal false
1435
- DB.sqls.must_equal ['SELECT 1 AS one FROM items WHERE (id = 2) LIMIT 1']
1436
- end
1437
-
1438
- it "should return false without issuing a query if the model object is new" do
1439
- @model.new.exists?.must_equal false
1440
- DB.sqls.must_equal []
1441
- end
1442
- end
1443
-
1444
- describe Sequel::Model, "#each" do
1445
- before do
1446
- @model = Class.new(Sequel::Model(:items))
1447
- @model.columns :a, :b, :id
1448
- @m = @model.load(:a => 1, :b => 2, :id => 4444)
1449
- end
1450
-
1451
- it "should iterate over the values" do
1452
- h = {}
1453
- @m.each{|k, v| h[k] = v}
1454
- h.must_equal(:a => 1, :b => 2, :id => 4444)
1455
- end
1456
- end
1457
-
1458
- describe Sequel::Model, "#keys" do
1459
- before do
1460
- @model = Class.new(Sequel::Model(:items))
1461
- @model.columns :a, :b, :id
1462
- @m = @model.load(:a => 1, :b => 2, :id => 4444)
1463
- end
1464
-
1465
- it "should return the value keys" do
1466
- @m.keys.sort_by{|k| k.to_s}.must_equal [:a, :b, :id]
1467
- @model.new.keys.must_equal []
1468
- end
1469
- end
1470
-
1471
- describe Sequel::Model, "#==" do
1472
- it "should compare instances by values" do
1473
- z = Class.new(Sequel::Model)
1474
- z.columns :id, :x
1475
- a = z.load(:id => 1, :x => 3)
1476
- b = z.load(:id => 1, :x => 4)
1477
- c = z.load(:id => 1, :x => 3)
1478
-
1479
- a.wont_equal b
1480
- a.must_equal c
1481
- b.wont_equal c
1482
- end
1483
-
1484
- it "should be aliased to #eql?" do
1485
- z = Class.new(Sequel::Model)
1486
- z.columns :id, :x
1487
- a = z.load(:id => 1, :x => 3)
1488
- b = z.load(:id => 1, :x => 4)
1489
- c = z.load(:id => 1, :x => 3)
1490
-
1491
- a.eql?(b).must_equal false
1492
- a.eql?(c).must_equal true
1493
- b.eql?(c).must_equal false
1494
- end
1495
- end
1496
-
1497
- describe Sequel::Model, "#===" do
1498
- it "should compare instances by class and pk if pk is not nil" do
1499
- z = Class.new(Sequel::Model)
1500
- z.columns :id, :x
1501
- y = Class.new(Sequel::Model)
1502
- y.columns :id, :x
1503
- a = z.load(:id => 1, :x => 3)
1504
- b = z.load(:id => 1, :x => 4)
1505
- c = z.load(:id => 2, :x => 3)
1506
- d = y.load(:id => 1, :x => 3)
1507
-
1508
- a.must_be :===, b
1509
- a.wont_be :===, c
1510
- a.wont_be :===, d
1511
- end
1512
-
1513
- it "should always be false if the primary key is nil" do
1514
- z = Class.new(Sequel::Model)
1515
- z.columns :id, :x
1516
- y = Class.new(Sequel::Model)
1517
- y.columns :id, :x
1518
- a = z.new(:x => 3)
1519
- b = z.new(:x => 4)
1520
- c = z.new(:x => 3)
1521
- d = y.new(:x => 3)
1522
-
1523
- a.wont_be :===, b
1524
- a.wont_be :===, c
1525
- a.wont_be :===, d
1526
- end
1527
- end
1528
-
1529
- describe Sequel::Model, "#hash" do
1530
- it "should be the same only for objects with the same class and pk if the pk is not nil" do
1531
- z = Class.new(Sequel::Model)
1532
- z.columns :id, :x
1533
- y = Class.new(Sequel::Model)
1534
- y.columns :id, :x
1535
- a = z.load(:id => 1, :x => 3)
1536
-
1537
- a.hash.must_equal z.load(:id => 1, :x => 4).hash
1538
- a.hash.wont_equal z.load(:id => 2, :x => 3).hash
1539
- a.hash.wont_equal y.load(:id => 1, :x => 3).hash
1540
- end
1541
-
1542
- it "should be the same only for objects with the same class and values if the pk is nil" do
1543
- z = Class.new(Sequel::Model)
1544
- z.columns :id, :x
1545
- y = Class.new(Sequel::Model)
1546
- y.columns :id, :x
1547
- a = z.new(:x => 3)
1548
-
1549
- a.hash.wont_equal z.new(:x => 4).hash
1550
- a.hash.must_equal z.new(:x => 3).hash
1551
- a.hash.wont_equal y.new(:x => 3).hash
1552
- end
1553
-
1554
- it "should be the same only for objects with the same class and pk if pk is composite and all values are non-NULL" do
1555
- z = Class.new(Sequel::Model)
1556
- z.columns :id, :id2, :x
1557
- z.set_primary_key([:id, :id2])
1558
- y = Class.new(Sequel::Model)
1559
- y.columns :id, :id2, :x
1560
- y.set_primary_key([:id, :id2])
1561
- a = z.load(:id => 1, :id2=>2, :x => 3)
1562
-
1563
- a.hash.must_equal z.load(:id => 1, :id2=>2, :x => 4).hash
1564
- a.hash.wont_equal z.load(:id => 2, :id2=>1, :x => 3).hash
1565
- a.hash.wont_equal y.load(:id => 1, :id2=>1, :x => 3).hash
1566
- end
1567
-
1568
- it "should be the same only for objects with the same class and value if pk is composite and one values is NULL" do
1569
- z = Class.new(Sequel::Model)
1570
- z.columns :id, :id2, :x
1571
- z.set_primary_key([:id, :id2])
1572
- y = Class.new(Sequel::Model)
1573
- y.columns :id, :id2, :x
1574
- y.set_primary_key([:id, :id2])
1575
-
1576
- a = z.load(:id => 1, :id2 => nil, :x => 3)
1577
- a.hash.must_equal z.load(:id => 1, :id2=>nil, :x => 3).hash
1578
- a.hash.wont_equal z.load(:id => 1, :id2=>nil, :x => 4).hash
1579
- a.hash.wont_equal y.load(:id => 1, :id2=>nil, :x => 3).hash
1580
-
1581
- a = z.load(:id =>nil, :id2 => nil, :x => 3)
1582
- a.hash.must_equal z.load(:id => nil, :id2=>nil, :x => 3).hash
1583
- a.hash.wont_equal z.load(:id => nil, :id2=>nil, :x => 4).hash
1584
- a.hash.wont_equal y.load(:id => nil, :id2=>nil, :x => 3).hash
1585
-
1586
- a = z.load(:id => 1, :x => 3)
1587
- a.hash.must_equal z.load(:id => 1, :x => 3).hash
1588
- a.hash.wont_equal z.load(:id => 1, :id2=>nil, :x => 3).hash
1589
- a.hash.wont_equal z.load(:id => 1, :x => 4).hash
1590
- a.hash.wont_equal y.load(:id => 1, :x => 3).hash
1591
-
1592
- a = z.load(:x => 3)
1593
- a.hash.must_equal z.load(:x => 3).hash
1594
- a.hash.wont_equal z.load(:id => nil, :id2=>nil, :x => 3).hash
1595
- a.hash.wont_equal z.load(:x => 4).hash
1596
- a.hash.wont_equal y.load(:x => 3).hash
1597
- end
1598
-
1599
- it "should be the same only for objects with the same class and values if the no primary key" do
1600
- z = Class.new(Sequel::Model)
1601
- z.columns :id, :x
1602
- z.no_primary_key
1603
- y = Class.new(Sequel::Model)
1604
- y.columns :id, :x
1605
- y.no_primary_key
1606
- a = z.new(:x => 3)
1607
-
1608
- a.hash.wont_equal z.new(:x => 4).hash
1609
- a.hash.must_equal z.new(:x => 3).hash
1610
- a.hash.wont_equal y.new(:x => 3).hash
1611
- end
1612
-
1613
- end
1614
-
1615
- describe Sequel::Model, "#initialize" do
1616
- before do
1617
- @c = Class.new(Sequel::Model) do
1618
- columns :id, :x
1619
- end
1620
- @c.strict_param_setting = false
1621
- end
1622
-
1623
- it "should accept values" do
1624
- m = @c.new(:x => 2)
1625
- m.values.must_equal(:x => 2)
1626
- end
1627
-
1628
- it "should not modify the primary key" do
1629
- m = @c.new(:id => 1, :x => 2)
1630
- m.values.must_equal(:x => 2)
1631
- end
1632
-
1633
- it "should accept no values" do
1634
- m = @c.new
1635
- m.values.must_equal({})
1636
- end
1637
-
1638
- it "should accept a block to execute" do
1639
- m = @c.new {|o| o[:id] = 1234}
1640
- m.id.must_equal 1234
1641
- end
1642
-
1643
- it "should accept virtual attributes" do
1644
- @c.send(:define_method, :blah=){|x| @blah = x}
1645
- @c.send(:define_method, :blah){@blah}
1646
-
1647
- m = @c.new(:x => 2, :blah => 3)
1648
- m.values.must_equal(:x => 2)
1649
- m.blah.must_equal 3
1650
- end
1651
-
1652
- it "should convert string keys into symbol keys" do
1653
- m = @c.new('x' => 2)
1654
- m.values.must_equal(:x => 2)
1655
- end
1656
- end
1657
-
1658
- describe Sequel::Model, "#initialize_set" do
1659
- before do
1660
- @c = Class.new(Sequel::Model){columns :id, :x, :y}
1661
- end
1662
-
1663
- it "should be called by initialize to set the column values" do
1664
- @c.send(:define_method, :initialize_set){|h| set(:y => 3)}
1665
- @c.new(:x => 2).values.must_equal(:y => 3)
1666
- end
1667
-
1668
- it "should be called with the hash given to initialize " do
1669
- x = nil
1670
- @c.send(:define_method, :initialize_set){|y| x = y}
1671
- @c.new(:x => 2)
1672
- x.must_equal(:x => 2)
1673
- end
1674
-
1675
- it "should not cause columns modified by the method to be considered as changed" do
1676
- @c.send(:define_method, :initialize_set){|h| set(:y => 3)}
1677
- @c.new(:x => 2).changed_columns.must_equal []
1678
- end
1679
- end
1680
-
1681
- describe Sequel::Model, ".create" do
1682
- before do
1683
- DB.reset
1684
- @c = Class.new(Sequel::Model(:items)) do
1685
- unrestrict_primary_key
1686
- columns :x
1687
- end
1688
- end
1689
-
1690
- it "should be able to create rows in the associated table" do
1691
- o = @c.create(:x => 1)
1692
- o.class.must_equal @c
1693
- DB.sqls.must_equal ['INSERT INTO items (x) VALUES (1)', "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1694
- end
1695
-
1696
- it "should be able to create rows without any values specified" do
1697
- o = @c.create
1698
- o.class.must_equal @c
1699
- DB.sqls.must_equal ["INSERT INTO items DEFAULT VALUES", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1700
- end
1701
-
1702
- it "should accept a block and call it" do
1703
- o1, o2, o3 = nil, nil, nil
1704
- o = @c.create {|o4| o1 = o4; o3 = o4; o2 = :blah; o3.x = 333}
1705
- o.class.must_equal @c
1706
- o1.must_be :===, o
1707
- o3.must_be :===, o
1708
- o2.must_equal :blah
1709
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (333)", "SELECT * FROM items WHERE (id = 10) LIMIT 1"]
1710
- end
1711
-
1712
- it "should create a row for a model with custom primary key" do
1713
- @c.set_primary_key :x
1714
- o = @c.create(:x => 30)
1715
- o.class.must_equal @c
1716
- DB.sqls.must_equal ["INSERT INTO items (x) VALUES (30)", "SELECT * FROM items WHERE (x = 30) LIMIT 1"]
1717
- end
1718
- end
1719
-
1720
- describe Sequel::Model, "#refresh" do
1721
- before do
1722
- @c = Class.new(Sequel::Model(:items)) do
1723
- unrestrict_primary_key
1724
- columns :id, :x
1725
- end
1726
- DB.reset
1727
- end
1728
-
1729
- it "should reload the instance values from the database" do
1730
- @m = @c.new(:id => 555)
1731
- @m[:x] = 'blah'
1732
- @c.instance_dataset._fetch = @c.dataset._fetch = {:x => 'kaboom', :id => 555}
1733
- @m.refresh
1734
- @m[:x].must_equal 'kaboom'
1735
- DB.sqls.must_equal ["SELECT * FROM items WHERE (id = 555) LIMIT 1"]
1736
- end
1737
-
1738
- it "should raise if the instance is not found" do
1739
- @m = @c.new(:id => 555)
1740
- @c.instance_dataset._fetch =@c.dataset._fetch = []
1741
- proc {@m.refresh}.must_raise(Sequel::Error)
1742
- DB.sqls.must_equal ["SELECT * FROM items WHERE (id = 555) LIMIT 1"]
1743
- end
1744
-
1745
- it "should be aliased by #reload" do
1746
- @m = @c.new(:id => 555)
1747
- @c.instance_dataset._fetch =@c.dataset._fetch = {:x => 'kaboom', :id => 555}
1748
- @m.reload
1749
- @m[:x].must_equal 'kaboom'
1750
- DB.sqls.must_equal ["SELECT * FROM items WHERE (id = 555) LIMIT 1"]
1751
- end
1752
- end
1753
-
1754
- describe Sequel::Model, "typecasting" do
1755
- before do
1756
- @c = Class.new(Sequel::Model(:items)) do
1757
- columns :x
1758
- end
1759
- @c.db_schema = {:x=>{:type=>:integer}}
1760
- @c.raise_on_typecast_failure = true
1761
- DB.reset
1762
- end
1763
-
1764
- after do
1765
- Sequel.datetime_class = Time
1766
- end
1767
-
1768
- it "should not convert if typecasting is turned off" do
1769
- @c.typecast_on_assignment = false
1770
- m = @c.new
1771
- m.x = '1'
1772
- m.x.must_equal '1'
1773
- end
1774
-
1775
- it "should convert to integer for an integer field" do
1776
- @c.db_schema = {:x=>{:type=>:integer}}
1777
- m = @c.new
1778
- m.x = '1'
1779
- m.x.must_equal 1
1780
- m.x = 1
1781
- m.x.must_equal 1
1782
- m.x = 1.3
1783
- m.x.must_equal 1
1784
- end
1785
-
1786
- it "should typecast '' to nil unless type is string or blob" do
1787
- [:integer, :float, :decimal, :boolean, :date, :time, :datetime].each do |x|
1788
- @c.db_schema = {:x=>{:type=>x}}
1789
- m = @c.new
1790
- m.x = ''
1791
- m.x.must_equal nil
1792
- end
1793
- [:string, :blob].each do |x|
1794
- @c.db_schema = {:x=>{:type=>x}}
1795
- m = @c.new
1796
- m.x = ''
1797
- m.x.must_equal ''
1798
- end
1799
- end
1800
-
1801
- it "should not typecast '' to nil if typecast_empty_string_to_nil is false" do
1802
- m = @c.new
1803
- m.typecast_empty_string_to_nil = false
1804
- proc{m.x = ''}.must_raise Sequel::InvalidValue
1805
- @c.typecast_empty_string_to_nil = false
1806
- proc{@c.new.x = ''}.must_raise Sequel::InvalidValue
1807
- end
1808
-
1809
- it "should handle typecasting where == raises an error on the object" do
1810
- m = @c.new
1811
- o = Object.new
1812
- def o.==(v) raise ArgumentError end
1813
- def o.to_i() 4 end
1814
- m.x = o
1815
- m.x.must_equal 4
1816
- end
1817
-
1818
- it "should not typecast nil if NULLs are allowed" do
1819
- @c.db_schema[:x][:allow_null] = true
1820
- m = @c.new
1821
- m.x = nil
1822
- m.x.must_equal nil
1823
- end
1824
-
1825
- it "should raise an error if attempting to typecast nil and NULLs are not allowed" do
1826
- @c.db_schema[:x][:allow_null] = false
1827
- proc{@c.new.x = nil}.must_raise(Sequel::InvalidValue)
1828
- proc{@c.new.x = ''}.must_raise(Sequel::InvalidValue)
1829
- end
1830
-
1831
- it "should not raise an error if NULLs are not allowed and typecasting is turned off" do
1832
- @c.typecast_on_assignment = false
1833
- @c.db_schema[:x][:allow_null] = false
1834
- m = @c.new
1835
- m.x = nil
1836
- m.x.must_equal nil
1837
- end
1838
-
1839
- it "should not raise when typecasting nil to NOT NULL column but raise_on_typecast_failure is off" do
1840
- @c.raise_on_typecast_failure = false
1841
- @c.typecast_on_assignment = true
1842
- m = @c.new
1843
- m.x = ''
1844
- m.x.must_equal nil
1845
- m.x = nil
1846
- m.x.must_equal nil
1847
- end
1848
-
1849
- it "should raise an error if invalid data is used in an integer field" do
1850
- proc{@c.new.x = 'a'}.must_raise(Sequel::InvalidValue)
1851
- end
1852
-
1853
- it "should assign value if raise_on_typecast_failure is off and assigning invalid integer" do
1854
- @c.raise_on_typecast_failure = false
1855
- model = @c.new
1856
- model.x = '1d'
1857
- model.x.must_equal '1d'
1858
- end
1859
-
1860
- it "should convert to float for a float field" do
1861
- @c.db_schema = {:x=>{:type=>:float}}
1862
- m = @c.new
1863
- m.x = '1.3'
1864
- m.x.must_equal 1.3
1865
- m.x = 1
1866
- m.x.must_equal 1.0
1867
- m.x = 1.3
1868
- m.x.must_equal 1.3
1869
- end
1870
-
1871
- it "should raise an error if invalid data is used in an float field" do
1872
- @c.db_schema = {:x=>{:type=>:float}}
1873
- proc{@c.new.x = 'a'}.must_raise(Sequel::InvalidValue)
1874
- end
1875
-
1876
- it "should assign value if raise_on_typecast_failure is off and assigning invalid float" do
1877
- @c.raise_on_typecast_failure = false
1878
- @c.db_schema = {:x=>{:type=>:float}}
1879
- model = @c.new
1880
- model.x = '1d'
1881
- model.x.must_equal '1d'
1882
- end
1883
-
1884
- it "should convert to BigDecimal for a decimal field" do
1885
- @c.db_schema = {:x=>{:type=>:decimal}}
1886
- m = @c.new
1887
- bd = BigDecimal.new('1.0')
1888
- m.x = '1.0'
1889
- m.x.must_equal bd
1890
- m.x = 1.0
1891
- m.x.must_equal bd
1892
- m.x = 1
1893
- m.x.must_equal bd
1894
- m.x = bd
1895
- m.x.must_equal bd
1896
- m.x = '0'
1897
- m.x.must_equal 0
1898
- end
1899
-
1900
- it "should raise an error if invalid data is used in an decimal field" do
1901
- @c.db_schema = {:x=>{:type=>:decimal}}
1902
- proc{@c.new.x = Date.today}.must_raise(Sequel::InvalidValue)
1903
- proc{@c.new.x = 'foo'}.must_raise(Sequel::InvalidValue)
1904
- end
1905
-
1906
- it "should assign value if raise_on_typecast_failure is off and assigning invalid decimal" do
1907
- @c.raise_on_typecast_failure = false
1908
- @c.db_schema = {:x=>{:type=>:decimal}}
1909
- model = @c.new
1910
- time = Time.now
1911
- model.x = time
1912
- model.x.must_equal time
1913
- end
1914
-
1915
- it "should convert to string for a string field" do
1916
- @c.db_schema = {:x=>{:type=>:string}}
1917
- m = @c.new
1918
- m.x = '1.3'
1919
- m.x.must_equal '1.3'
1920
- m.x = 1
1921
- m.x.must_equal '1'
1922
- m.x = 1.3
1923
- m.x.must_equal '1.3'
1924
- end
1925
-
1926
- it "should convert to boolean for a boolean field" do
1927
- @c.db_schema = {:x=>{:type=>:boolean}}
1928
- m = @c.new
1929
- m.x = '1.3'
1930
- m.x.must_equal true
1931
- m.x = 1
1932
- m.x.must_equal true
1933
- m.x = 1.3
1934
- m.x.must_equal true
1935
- m.x = 't'
1936
- m.x.must_equal true
1937
- m.x = 'T'
1938
- m.x.must_equal true
1939
- m.x = 'y'
1940
- m.x.must_equal true
1941
- m.x = 'Y'
1942
- m.x.must_equal true
1943
- m.x = true
1944
- m.x.must_equal true
1945
- m.x = nil
1946
- m.x.must_equal nil
1947
- m.x = ''
1948
- m.x.must_equal nil
1949
- m.x = []
1950
- m.x.must_equal nil
1951
- m.x = 'f'
1952
- m.x.must_equal false
1953
- m.x = 'F'
1954
- m.x.must_equal false
1955
- m.x = 'false'
1956
- m.x.must_equal false
1957
- m.x = 'FALSE'
1958
- m.x.must_equal false
1959
- m.x = 'n'
1960
- m.x.must_equal false
1961
- m.x = 'N'
1962
- m.x.must_equal false
1963
- m.x = 'no'
1964
- m.x.must_equal false
1965
- m.x = 'NO'
1966
- m.x.must_equal false
1967
- m.x = '0'
1968
- m.x.must_equal false
1969
- m.x = 0
1970
- m.x.must_equal false
1971
- m.x = false
1972
- m.x.must_equal false
1973
- end
1974
-
1975
- it "should convert to date for a date field" do
1976
- @c.db_schema = {:x=>{:type=>:date}}
1977
- m = @c.new
1978
- y = Date.new(2007,10,21)
1979
- m.x = '2007-10-21'
1980
- m.x.must_equal y
1981
- m.x = Date.parse('2007-10-21')
1982
- m.x.must_equal y
1983
- m.x = Time.parse('2007-10-21')
1984
- m.x.must_equal y
1985
- m.x = DateTime.parse('2007-10-21')
1986
- m.x.must_equal y
1987
- end
1988
-
1989
- it "should accept a hash with symbol or string keys for a date field" do
1990
- @c.db_schema = {:x=>{:type=>:date}}
1991
- m = @c.new
1992
- y = Date.new(2007,10,21)
1993
- m.x = {:year=>2007, :month=>10, :day=>21}
1994
- m.x.must_equal y
1995
- m.x = {'year'=>'2007', 'month'=>'10', 'day'=>'21'}
1996
- m.x.must_equal y
1997
- end
1998
-
1999
- it "should raise an error if invalid data is used in a date field" do
2000
- @c.db_schema = {:x=>{:type=>:date}}
2001
- proc{@c.new.x = 'a'}.must_raise(Sequel::InvalidValue)
2002
- proc{@c.new.x = 100}.must_raise(Sequel::InvalidValue)
2003
- end
2004
-
2005
- it "should assign value if raise_on_typecast_failure is off and assigning invalid date" do
2006
- @c.raise_on_typecast_failure = false
2007
- @c.db_schema = {:x=>{:type=>:date}}
2008
- model = @c.new
2009
- model.x = 4
2010
- model.x.must_equal 4
2011
- end
2012
-
2013
- it "should convert to Sequel::SQLTime for a time field" do
2014
- @c.db_schema = {:x=>{:type=>:time}}
2015
- m = @c.new
2016
- x = '10:20:30'
2017
- y = Sequel::SQLTime.parse(x)
2018
- m.x = x
2019
- m.x.must_equal y
2020
- m.x = y
2021
- m.x.must_equal y
2022
- m.x.must_be_kind_of(Sequel::SQLTime)
2023
- end
2024
-
2025
- it "should accept a hash with symbol or string keys for a time field" do
2026
- @c.db_schema = {:x=>{:type=>:time}}
2027
- m = @c.new
2028
- y = Time.parse('10:20:30')
2029
- m.x = {:hour=>10, :minute=>20, :second=>30}
2030
- m.x.must_equal y
2031
- m.x = {'hour'=>'10', 'minute'=>'20', 'second'=>'30'}
2032
- m.x.must_equal y
2033
- end
2034
-
2035
- it "should raise an error if invalid data is used in a time field" do
2036
- @c.db_schema = {:x=>{:type=>:time}}
2037
- proc{@c.new.x = '0000'}.must_raise(Sequel::InvalidValue)
2038
- proc{@c.new.x = Date.parse('2008-10-21')}.must_raise(Sequel::InvalidValue)
2039
- proc{@c.new.x = DateTime.parse('2008-10-21')}.must_raise(Sequel::InvalidValue)
2040
- end
2041
-
2042
- it "should assign value if raise_on_typecast_failure is off and assigning invalid time" do
2043
- @c.raise_on_typecast_failure = false
2044
- @c.db_schema = {:x=>{:type=>:time}}
2045
- model = @c.new
2046
- model.x = '0000'
2047
- model.x.must_equal '0000'
2048
- end
2049
-
2050
- it "should convert to the Sequel.datetime_class for a datetime field" do
2051
- @c.db_schema = {:x=>{:type=>:datetime}}
2052
- m = @c.new
2053
- x = '2007-10-21T10:20:30-07:00'
2054
- y = Time.parse(x)
2055
- m.x = x
2056
- m.x.must_equal y
2057
- m.x = DateTime.parse(x)
2058
- m.x.must_equal y
2059
- m.x = Time.parse(x)
2060
- m.x.must_equal y
2061
- m.x = Date.parse('2007-10-21')
2062
- m.x.must_equal Time.parse('2007-10-21')
2063
- Sequel.datetime_class = DateTime
2064
- y = DateTime.parse(x)
2065
- m.x = x
2066
- m.x.must_equal y
2067
- m.x = DateTime.parse(x)
2068
- m.x.must_equal y
2069
- m.x = Time.parse(x)
2070
- m.x.must_equal y
2071
- m.x = Date.parse('2007-10-21')
2072
- m.x.must_equal DateTime.parse('2007-10-21')
2073
- end
2074
-
2075
- it "should accept a hash with symbol or string keys for a datetime field" do
2076
- @c.db_schema = {:x=>{:type=>:datetime}}
2077
- m = @c.new
2078
- y = Time.parse('2007-10-21 10:20:30')
2079
- m.x = {:year=>2007, :month=>10, :day=>21, :hour=>10, :minute=>20, :second=>30}
2080
- m.x.must_equal y
2081
- m.x = {'year'=>'2007', 'month'=>'10', 'day'=>'21', 'hour'=>'10', 'minute'=>'20', 'second'=>'30'}
2082
- m.x.must_equal y
2083
- Sequel.datetime_class = DateTime
2084
- y = DateTime.parse('2007-10-21 10:20:30')
2085
- m.x = {:year=>2007, :month=>10, :day=>21, :hour=>10, :minute=>20, :second=>30}
2086
- m.x.must_equal y
2087
- m.x = {'year'=>'2007', 'month'=>'10', 'day'=>'21', 'hour'=>'10', 'minute'=>'20', 'second'=>'30'}
2088
- m.x.must_equal y
2089
- end
2090
-
2091
- it "should raise an error if invalid data is used in a datetime field" do
2092
- @c.db_schema = {:x=>{:type=>:datetime}}
2093
- proc{@c.new.x = '0000'}.must_raise(Sequel::InvalidValue)
2094
- Sequel.datetime_class = DateTime
2095
- proc{@c.new.x = '0000'}.must_raise(Sequel::InvalidValue)
2096
- proc{@c.new.x = 'a'}.must_raise(Sequel::InvalidValue)
2097
- end
2098
-
2099
- it "should assign value if raise_on_typecast_failure is off and assigning invalid datetime" do
2100
- @c.raise_on_typecast_failure = false
2101
- @c.db_schema = {:x=>{:type=>:datetime}}
2102
- model = @c.new
2103
- model.x = '0000'
2104
- model.x.must_equal '0000'
2105
- Sequel.datetime_class = DateTime
2106
- model = @c.new
2107
- model.x = '0000'
2108
- model.x.must_equal '0000'
2109
- model.x = 'a'
2110
- model.x.must_equal 'a'
2111
- end
2112
- end
2113
-
2114
- describe "Model#lock!" do
2115
- before do
2116
- @c = Class.new(Sequel::Model(:items)) do
2117
- columns :id
2118
- end
2119
- @c.dataset._fetch = {:id=>1}
2120
- DB.reset
2121
- end
2122
-
2123
- it "should do nothing if the record is a new record" do
2124
- o = @c.new
2125
- def o._refresh(x) raise Sequel::Error; super(x) end
2126
- x = o.lock!
2127
- x.must_equal o
2128
- DB.sqls.must_equal []
2129
- end
2130
-
2131
- it "should refresh the record using for_update if it is not a new record" do
2132
- o = @c.load(:id => 1)
2133
- def o._refresh(x) instance_variable_set(:@a, 1); super(x) end
2134
- x = o.lock!
2135
- x.must_equal o
2136
- o.instance_variable_get(:@a).must_equal 1
2137
- DB.sqls.must_equal ["SELECT * FROM items WHERE (id = 1) LIMIT 1 FOR UPDATE"]
2138
- end
2139
- end
2140
-
2141
- describe "Model#schema_type_class" do
2142
- it "should return the class or array of classes for the given type symbol" do
2143
- @c = Class.new(Sequel::Model(:items))
2144
- @c.class_eval{@db_schema = {:id=>{:type=>:integer}}}
2145
- @c.new.send(:schema_type_class, :id).must_equal Integer
2146
- end
2147
- end