sequel 4.49.0 → 5.0.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 (477) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +70 -0
  3. data/README.rdoc +195 -136
  4. data/Rakefile +26 -42
  5. data/bin/sequel +3 -5
  6. data/doc/advanced_associations.rdoc +86 -163
  7. data/doc/association_basics.rdoc +197 -274
  8. data/doc/bin_sequel.rdoc +5 -3
  9. data/doc/cheat_sheet.rdoc +66 -43
  10. data/doc/code_order.rdoc +1 -8
  11. data/doc/core_extensions.rdoc +81 -56
  12. data/doc/dataset_basics.rdoc +8 -17
  13. data/doc/dataset_filtering.rdoc +81 -86
  14. data/doc/extensions.rdoc +3 -10
  15. data/doc/mass_assignment.rdoc +73 -30
  16. data/doc/migration.rdoc +19 -36
  17. data/doc/model_dataset_method_design.rdoc +14 -17
  18. data/doc/model_hooks.rdoc +15 -25
  19. data/doc/model_plugins.rdoc +10 -10
  20. data/doc/mssql_stored_procedures.rdoc +3 -3
  21. data/doc/object_model.rdoc +52 -70
  22. data/doc/opening_databases.rdoc +39 -32
  23. data/doc/postgresql.rdoc +48 -38
  24. data/doc/prepared_statements.rdoc +27 -22
  25. data/doc/querying.rdoc +173 -150
  26. data/doc/reflection.rdoc +5 -6
  27. data/doc/release_notes/5.0.0.txt +159 -0
  28. data/doc/schema_modification.rdoc +63 -60
  29. data/doc/security.rdoc +97 -88
  30. data/doc/sharding.rdoc +43 -30
  31. data/doc/sql.rdoc +53 -65
  32. data/doc/testing.rdoc +3 -5
  33. data/doc/thread_safety.rdoc +2 -4
  34. data/doc/transactions.rdoc +18 -17
  35. data/doc/validations.rdoc +48 -45
  36. data/doc/virtual_rows.rdoc +87 -115
  37. data/lib/sequel.rb +1 -1
  38. data/lib/sequel/adapters/ado.rb +9 -25
  39. data/lib/sequel/adapters/ado/access.rb +7 -13
  40. data/lib/sequel/adapters/ado/mssql.rb +2 -9
  41. data/lib/sequel/adapters/amalgalite.rb +3 -18
  42. data/lib/sequel/adapters/ibmdb.rb +9 -45
  43. data/lib/sequel/adapters/jdbc.rb +13 -73
  44. data/lib/sequel/adapters/jdbc/db2.rb +8 -37
  45. data/lib/sequel/adapters/jdbc/derby.rb +4 -50
  46. data/lib/sequel/adapters/jdbc/h2.rb +4 -25
  47. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -26
  48. data/lib/sequel/adapters/jdbc/jtds.rb +2 -9
  49. data/lib/sequel/adapters/jdbc/mssql.rb +1 -11
  50. data/lib/sequel/adapters/jdbc/mysql.rb +1 -15
  51. data/lib/sequel/adapters/jdbc/oracle.rb +4 -26
  52. data/lib/sequel/adapters/jdbc/postgresql.rb +2 -31
  53. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +4 -17
  54. data/lib/sequel/adapters/jdbc/sqlite.rb +1 -7
  55. data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -13
  56. data/lib/sequel/adapters/jdbc/transactions.rb +1 -14
  57. data/lib/sequel/adapters/mock.rb +4 -30
  58. data/lib/sequel/adapters/mysql.rb +7 -44
  59. data/lib/sequel/adapters/mysql2.rb +5 -23
  60. data/lib/sequel/adapters/odbc.rb +0 -19
  61. data/lib/sequel/adapters/odbc/db2.rb +1 -1
  62. data/lib/sequel/adapters/odbc/mssql.rb +4 -12
  63. data/lib/sequel/adapters/odbc/oracle.rb +1 -1
  64. data/lib/sequel/adapters/oracle.rb +7 -13
  65. data/lib/sequel/adapters/postgres.rb +13 -57
  66. data/lib/sequel/adapters/postgresql.rb +1 -1
  67. data/lib/sequel/adapters/shared/access.rb +11 -51
  68. data/lib/sequel/adapters/shared/db2.rb +3 -61
  69. data/lib/sequel/adapters/shared/mssql.rb +21 -157
  70. data/lib/sequel/adapters/shared/mysql.rb +23 -224
  71. data/lib/sequel/adapters/shared/oracle.rb +13 -41
  72. data/lib/sequel/adapters/shared/postgres.rb +44 -259
  73. data/lib/sequel/adapters/shared/sqlanywhere.rb +4 -96
  74. data/lib/sequel/adapters/shared/sqlite.rb +12 -101
  75. data/lib/sequel/adapters/sqlanywhere.rb +4 -23
  76. data/lib/sequel/adapters/sqlite.rb +2 -19
  77. data/lib/sequel/adapters/tinytds.rb +5 -15
  78. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +1 -1
  79. data/lib/sequel/adapters/utils/mysql_mysql2.rb +2 -4
  80. data/lib/sequel/adapters/utils/mysql_prepared_statements.rb +3 -6
  81. data/lib/sequel/adapters/utils/replace.rb +0 -5
  82. data/lib/sequel/adapters/utils/stored_procedures.rb +0 -2
  83. data/lib/sequel/adapters/utils/unmodified_identifiers.rb +2 -0
  84. data/lib/sequel/ast_transformer.rb +3 -94
  85. data/lib/sequel/connection_pool.rb +26 -28
  86. data/lib/sequel/connection_pool/sharded_single.rb +1 -4
  87. data/lib/sequel/connection_pool/sharded_threaded.rb +97 -95
  88. data/lib/sequel/connection_pool/single.rb +0 -2
  89. data/lib/sequel/connection_pool/threaded.rb +94 -110
  90. data/lib/sequel/core.rb +42 -101
  91. data/lib/sequel/database.rb +12 -2
  92. data/lib/sequel/database/connecting.rb +23 -60
  93. data/lib/sequel/database/dataset.rb +6 -9
  94. data/lib/sequel/database/dataset_defaults.rb +4 -48
  95. data/lib/sequel/database/features.rb +5 -4
  96. data/lib/sequel/database/logging.rb +2 -9
  97. data/lib/sequel/database/misc.rb +23 -55
  98. data/lib/sequel/database/query.rb +8 -13
  99. data/lib/sequel/database/schema_generator.rb +89 -64
  100. data/lib/sequel/database/schema_methods.rb +61 -79
  101. data/lib/sequel/database/transactions.rb +4 -24
  102. data/lib/sequel/dataset.rb +18 -10
  103. data/lib/sequel/dataset/actions.rb +53 -107
  104. data/lib/sequel/dataset/dataset_module.rb +3 -15
  105. data/lib/sequel/dataset/features.rb +30 -30
  106. data/lib/sequel/dataset/graph.rb +40 -49
  107. data/lib/sequel/dataset/misc.rb +12 -37
  108. data/lib/sequel/dataset/placeholder_literalizer.rb +4 -4
  109. data/lib/sequel/dataset/prepared_statements.rb +23 -51
  110. data/lib/sequel/dataset/query.rb +71 -155
  111. data/lib/sequel/dataset/sql.rb +30 -225
  112. data/lib/sequel/deprecated.rb +18 -27
  113. data/lib/sequel/exceptions.rb +1 -17
  114. data/lib/sequel/extensions/_model_pg_row.rb +0 -7
  115. data/lib/sequel/extensions/_pretty_table.rb +1 -3
  116. data/lib/sequel/extensions/arbitrary_servers.rb +10 -10
  117. data/lib/sequel/extensions/connection_expiration.rb +1 -1
  118. data/lib/sequel/extensions/connection_validator.rb +1 -1
  119. data/lib/sequel/extensions/constraint_validations.rb +11 -11
  120. data/lib/sequel/extensions/core_extensions.rb +39 -49
  121. data/lib/sequel/extensions/core_refinements.rb +39 -45
  122. data/lib/sequel/extensions/current_datetime_timestamp.rb +0 -4
  123. data/lib/sequel/extensions/date_arithmetic.rb +7 -7
  124. data/lib/sequel/extensions/duplicate_columns_handler.rb +12 -9
  125. data/lib/sequel/extensions/empty_array_consider_nulls.rb +2 -2
  126. data/lib/sequel/extensions/eval_inspect.rb +4 -11
  127. data/lib/sequel/extensions/freeze_datasets.rb +1 -69
  128. data/lib/sequel/extensions/from_block.rb +1 -35
  129. data/lib/sequel/extensions/graph_each.rb +2 -2
  130. data/lib/sequel/extensions/identifier_mangling.rb +9 -19
  131. data/lib/sequel/extensions/implicit_subquery.rb +2 -2
  132. data/lib/sequel/extensions/inflector.rb +4 -4
  133. data/lib/sequel/extensions/migration.rb +23 -40
  134. data/lib/sequel/extensions/no_auto_literal_strings.rb +2 -84
  135. data/lib/sequel/extensions/null_dataset.rb +2 -8
  136. data/lib/sequel/extensions/pagination.rb +1 -17
  137. data/lib/sequel/extensions/pg_array.rb +20 -189
  138. data/lib/sequel/extensions/pg_hstore.rb +11 -50
  139. data/lib/sequel/extensions/pg_hstore_ops.rb +2 -2
  140. data/lib/sequel/extensions/pg_inet.rb +2 -15
  141. data/lib/sequel/extensions/pg_interval.rb +1 -20
  142. data/lib/sequel/extensions/pg_json.rb +7 -27
  143. data/lib/sequel/extensions/pg_loose_count.rb +1 -1
  144. data/lib/sequel/extensions/pg_range.rb +6 -121
  145. data/lib/sequel/extensions/pg_range_ops.rb +1 -3
  146. data/lib/sequel/extensions/pg_row.rb +5 -77
  147. data/lib/sequel/extensions/pg_row_ops.rb +2 -13
  148. data/lib/sequel/extensions/query.rb +3 -4
  149. data/lib/sequel/extensions/round_timestamps.rb +0 -6
  150. data/lib/sequel/extensions/schema_dumper.rb +13 -13
  151. data/lib/sequel/extensions/select_remove.rb +3 -3
  152. data/lib/sequel/extensions/split_array_nil.rb +2 -2
  153. data/lib/sequel/extensions/sql_comments.rb +2 -2
  154. data/lib/sequel/extensions/string_agg.rb +11 -8
  155. data/lib/sequel/extensions/symbol_aref.rb +6 -20
  156. data/lib/sequel/model.rb +27 -62
  157. data/lib/sequel/model/associations.rb +128 -131
  158. data/lib/sequel/model/base.rb +171 -711
  159. data/lib/sequel/model/default_inflections.rb +1 -1
  160. data/lib/sequel/model/errors.rb +0 -3
  161. data/lib/sequel/model/exceptions.rb +2 -6
  162. data/lib/sequel/model/inflections.rb +1 -26
  163. data/lib/sequel/model/plugins.rb +1 -0
  164. data/lib/sequel/plugins/active_model.rb +2 -5
  165. data/lib/sequel/plugins/association_dependencies.rb +15 -15
  166. data/lib/sequel/plugins/association_pks.rb +14 -28
  167. data/lib/sequel/plugins/association_proxies.rb +6 -7
  168. data/lib/sequel/plugins/auto_validations.rb +4 -4
  169. data/lib/sequel/plugins/before_after_save.rb +0 -43
  170. data/lib/sequel/plugins/blacklist_security.rb +9 -8
  171. data/lib/sequel/plugins/boolean_readers.rb +3 -3
  172. data/lib/sequel/plugins/boolean_subsets.rb +2 -2
  173. data/lib/sequel/plugins/caching.rb +5 -5
  174. data/lib/sequel/plugins/class_table_inheritance.rb +71 -102
  175. data/lib/sequel/plugins/column_conflicts.rb +2 -2
  176. data/lib/sequel/plugins/column_select.rb +2 -2
  177. data/lib/sequel/plugins/composition.rb +15 -24
  178. data/lib/sequel/plugins/constraint_validations.rb +4 -3
  179. data/lib/sequel/plugins/csv_serializer.rb +13 -20
  180. data/lib/sequel/plugins/dataset_associations.rb +2 -2
  181. data/lib/sequel/plugins/def_dataset_method.rb +5 -5
  182. data/lib/sequel/plugins/defaults_setter.rb +1 -1
  183. data/lib/sequel/plugins/delay_add_association.rb +1 -1
  184. data/lib/sequel/plugins/finder.rb +16 -10
  185. data/lib/sequel/plugins/force_encoding.rb +1 -7
  186. data/lib/sequel/plugins/hook_class_methods.rb +4 -106
  187. data/lib/sequel/plugins/input_transformer.rb +10 -11
  188. data/lib/sequel/plugins/insert_returning_select.rb +1 -9
  189. data/lib/sequel/plugins/instance_filters.rb +5 -5
  190. data/lib/sequel/plugins/instance_hooks.rb +7 -52
  191. data/lib/sequel/plugins/inverted_subsets.rb +3 -1
  192. data/lib/sequel/plugins/json_serializer.rb +19 -19
  193. data/lib/sequel/plugins/lazy_attributes.rb +1 -10
  194. data/lib/sequel/plugins/list.rb +6 -6
  195. data/lib/sequel/plugins/many_through_many.rb +11 -8
  196. data/lib/sequel/plugins/mssql_optimistic_locking.rb +3 -3
  197. data/lib/sequel/plugins/nested_attributes.rb +18 -31
  198. data/lib/sequel/plugins/optimistic_locking.rb +3 -3
  199. data/lib/sequel/plugins/pg_array_associations.rb +8 -2
  200. data/lib/sequel/plugins/pg_row.rb +2 -11
  201. data/lib/sequel/plugins/prepared_statements.rb +13 -66
  202. data/lib/sequel/plugins/prepared_statements_safe.rb +1 -1
  203. data/lib/sequel/plugins/rcte_tree.rb +7 -7
  204. data/lib/sequel/plugins/serialization.rb +15 -33
  205. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  206. data/lib/sequel/plugins/sharding.rb +2 -8
  207. data/lib/sequel/plugins/single_table_inheritance.rb +10 -13
  208. data/lib/sequel/plugins/skip_create_refresh.rb +3 -3
  209. data/lib/sequel/plugins/static_cache.rb +8 -9
  210. data/lib/sequel/plugins/string_stripper.rb +3 -3
  211. data/lib/sequel/plugins/subclasses.rb +1 -1
  212. data/lib/sequel/plugins/subset_conditions.rb +2 -2
  213. data/lib/sequel/plugins/table_select.rb +2 -2
  214. data/lib/sequel/plugins/tactical_eager_loading.rb +4 -4
  215. data/lib/sequel/plugins/timestamps.rb +6 -7
  216. data/lib/sequel/plugins/touch.rb +4 -8
  217. data/lib/sequel/plugins/tree.rb +3 -3
  218. data/lib/sequel/plugins/typecast_on_load.rb +2 -2
  219. data/lib/sequel/plugins/unlimited_update.rb +1 -7
  220. data/lib/sequel/plugins/update_or_create.rb +3 -3
  221. data/lib/sequel/plugins/update_refresh.rb +3 -3
  222. data/lib/sequel/plugins/uuid.rb +7 -11
  223. data/lib/sequel/plugins/validation_class_methods.rb +10 -9
  224. data/lib/sequel/plugins/validation_contexts.rb +4 -4
  225. data/lib/sequel/plugins/validation_helpers.rb +26 -25
  226. data/lib/sequel/plugins/whitelist_security.rb +13 -9
  227. data/lib/sequel/plugins/xml_serializer.rb +24 -25
  228. data/lib/sequel/sql.rb +145 -276
  229. data/lib/sequel/timezones.rb +8 -22
  230. data/lib/sequel/version.rb +2 -2
  231. data/spec/adapter_spec.rb +1 -1
  232. data/spec/adapters/db2_spec.rb +2 -103
  233. data/spec/adapters/mssql_spec.rb +89 -68
  234. data/spec/adapters/mysql_spec.rb +101 -480
  235. data/spec/adapters/oracle_spec.rb +1 -9
  236. data/spec/adapters/postgres_spec.rb +312 -565
  237. data/spec/adapters/spec_helper.rb +12 -31
  238. data/spec/adapters/sqlanywhere_spec.rb +2 -77
  239. data/spec/adapters/sqlite_spec.rb +8 -146
  240. data/spec/bin_spec.rb +11 -16
  241. data/spec/core/connection_pool_spec.rb +173 -74
  242. data/spec/core/database_spec.rb +64 -244
  243. data/spec/core/dataset_spec.rb +81 -415
  244. data/spec/core/deprecated_spec.rb +3 -3
  245. data/spec/core/expression_filters_spec.rb +37 -144
  246. data/spec/core/mock_adapter_spec.rb +176 -4
  247. data/spec/core/object_graph_spec.rb +11 -60
  248. data/spec/core/placeholder_literalizer_spec.rb +1 -14
  249. data/spec/core/schema_generator_spec.rb +51 -40
  250. data/spec/core/schema_spec.rb +74 -77
  251. data/spec/core/spec_helper.rb +6 -24
  252. data/spec/core/version_spec.rb +1 -1
  253. data/spec/core_extensions_spec.rb +7 -83
  254. data/spec/core_model_spec.rb +2 -2
  255. data/spec/deprecation_helper.rb +2 -14
  256. data/spec/extensions/accessed_columns_spec.rb +1 -1
  257. data/spec/extensions/active_model_spec.rb +3 -3
  258. data/spec/extensions/after_initialize_spec.rb +1 -1
  259. data/spec/extensions/arbitrary_servers_spec.rb +2 -2
  260. data/spec/extensions/association_dependencies_spec.rb +1 -1
  261. data/spec/extensions/association_pks_spec.rb +4 -59
  262. data/spec/extensions/association_proxies_spec.rb +1 -1
  263. data/spec/extensions/auto_literal_strings_spec.rb +1 -12
  264. data/spec/extensions/auto_validations_spec.rb +1 -1
  265. data/spec/extensions/blacklist_security_spec.rb +1 -1
  266. data/spec/extensions/blank_spec.rb +1 -1
  267. data/spec/extensions/boolean_readers_spec.rb +1 -1
  268. data/spec/extensions/boolean_subsets_spec.rb +1 -1
  269. data/spec/extensions/caching_spec.rb +1 -1
  270. data/spec/extensions/class_table_inheritance_spec.rb +35 -1086
  271. data/spec/extensions/column_conflicts_spec.rb +1 -1
  272. data/spec/extensions/column_select_spec.rb +4 -4
  273. data/spec/extensions/columns_introspection_spec.rb +1 -1
  274. data/spec/extensions/columns_updated_spec.rb +1 -1
  275. data/spec/extensions/composition_spec.rb +1 -7
  276. data/spec/extensions/connection_expiration_spec.rb +3 -3
  277. data/spec/extensions/connection_validator_spec.rb +3 -3
  278. data/spec/extensions/constraint_validations_plugin_spec.rb +1 -1
  279. data/spec/extensions/constraint_validations_spec.rb +1 -1
  280. data/spec/extensions/core_refinements_spec.rb +1 -3
  281. data/spec/extensions/csv_serializer_spec.rb +4 -9
  282. data/spec/extensions/current_datetime_timestamp_spec.rb +1 -1
  283. data/spec/extensions/dataset_associations_spec.rb +2 -1
  284. data/spec/extensions/dataset_source_alias_spec.rb +1 -1
  285. data/spec/extensions/date_arithmetic_spec.rb +3 -3
  286. data/spec/extensions/def_dataset_method_spec.rb +1 -1
  287. data/spec/extensions/defaults_setter_spec.rb +2 -2
  288. data/spec/extensions/delay_add_association_spec.rb +8 -9
  289. data/spec/extensions/dirty_spec.rb +1 -1
  290. data/spec/extensions/duplicate_columns_handler_spec.rb +1 -1
  291. data/spec/extensions/eager_each_spec.rb +2 -2
  292. data/spec/extensions/empty_array_consider_nulls_spec.rb +1 -1
  293. data/spec/extensions/error_splitter_spec.rb +1 -1
  294. data/spec/extensions/error_sql_spec.rb +1 -1
  295. data/spec/extensions/eval_inspect_spec.rb +1 -1
  296. data/spec/extensions/finder_spec.rb +1 -1
  297. data/spec/extensions/force_encoding_spec.rb +2 -5
  298. data/spec/extensions/freeze_datasets_spec.rb +1 -1
  299. data/spec/extensions/graph_each_spec.rb +5 -5
  300. data/spec/extensions/hook_class_methods_spec.rb +1 -194
  301. data/spec/extensions/identifier_mangling_spec.rb +17 -170
  302. data/spec/extensions/implicit_subquery_spec.rb +1 -5
  303. data/spec/extensions/inflector_spec.rb +1 -1
  304. data/spec/extensions/input_transformer_spec.rb +7 -2
  305. data/spec/extensions/insert_returning_select_spec.rb +1 -1
  306. data/spec/extensions/instance_filters_spec.rb +1 -1
  307. data/spec/extensions/instance_hooks_spec.rb +1 -95
  308. data/spec/extensions/inverted_subsets_spec.rb +1 -1
  309. data/spec/extensions/json_serializer_spec.rb +1 -1
  310. data/spec/extensions/lazy_attributes_spec.rb +1 -7
  311. data/spec/extensions/list_spec.rb +1 -1
  312. data/spec/extensions/looser_typecasting_spec.rb +1 -1
  313. data/spec/extensions/many_through_many_spec.rb +1 -1
  314. data/spec/extensions/migration_spec.rb +2 -2
  315. data/spec/extensions/modification_detection_spec.rb +1 -1
  316. data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
  317. data/spec/extensions/named_timezones_spec.rb +3 -3
  318. data/spec/extensions/nested_attributes_spec.rb +1 -29
  319. data/spec/extensions/null_dataset_spec.rb +1 -11
  320. data/spec/extensions/optimistic_locking_spec.rb +1 -1
  321. data/spec/extensions/pagination_spec.rb +1 -1
  322. data/spec/extensions/pg_array_associations_spec.rb +4 -1
  323. data/spec/extensions/pg_array_ops_spec.rb +1 -1
  324. data/spec/extensions/pg_array_spec.rb +3 -48
  325. data/spec/extensions/pg_enum_spec.rb +1 -1
  326. data/spec/extensions/pg_hstore_ops_spec.rb +1 -1
  327. data/spec/extensions/pg_hstore_spec.rb +23 -32
  328. data/spec/extensions/pg_inet_ops_spec.rb +1 -1
  329. data/spec/extensions/pg_inet_spec.rb +1 -14
  330. data/spec/extensions/pg_interval_spec.rb +3 -13
  331. data/spec/extensions/pg_json_ops_spec.rb +1 -1
  332. data/spec/extensions/pg_json_spec.rb +1 -13
  333. data/spec/extensions/pg_loose_count_spec.rb +1 -1
  334. data/spec/extensions/pg_range_ops_spec.rb +1 -1
  335. data/spec/extensions/pg_range_spec.rb +3 -88
  336. data/spec/extensions/pg_row_ops_spec.rb +1 -1
  337. data/spec/extensions/pg_row_plugin_spec.rb +1 -1
  338. data/spec/extensions/pg_row_spec.rb +1 -44
  339. data/spec/extensions/pg_static_cache_updater_spec.rb +1 -1
  340. data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
  341. data/spec/extensions/prepared_statements_spec.rb +13 -48
  342. data/spec/extensions/pretty_table_spec.rb +1 -1
  343. data/spec/extensions/query_spec.rb +1 -12
  344. data/spec/extensions/rcte_tree_spec.rb +1 -1
  345. data/spec/extensions/round_timestamps_spec.rb +1 -5
  346. data/spec/extensions/s_spec.rb +1 -1
  347. data/spec/extensions/schema_caching_spec.rb +1 -1
  348. data/spec/extensions/schema_dumper_spec.rb +1 -1
  349. data/spec/extensions/select_remove_spec.rb +1 -1
  350. data/spec/extensions/sequel_4_dataset_methods_spec.rb +1 -1
  351. data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
  352. data/spec/extensions/serialization_spec.rb +2 -14
  353. data/spec/extensions/server_block_spec.rb +1 -1
  354. data/spec/extensions/server_logging_spec.rb +2 -2
  355. data/spec/extensions/sharding_spec.rb +1 -1
  356. data/spec/extensions/shared_caching_spec.rb +1 -28
  357. data/spec/extensions/single_table_inheritance_spec.rb +2 -5
  358. data/spec/extensions/singular_table_names_spec.rb +1 -1
  359. data/spec/extensions/skip_create_refresh_spec.rb +1 -1
  360. data/spec/extensions/spec_helper.rb +5 -27
  361. data/spec/extensions/split_array_nil_spec.rb +1 -1
  362. data/spec/extensions/split_values_spec.rb +1 -1
  363. data/spec/extensions/sql_comments_spec.rb +1 -1
  364. data/spec/extensions/sql_expr_spec.rb +1 -1
  365. data/spec/extensions/static_cache_spec.rb +1 -1
  366. data/spec/extensions/string_agg_spec.rb +2 -2
  367. data/spec/extensions/string_date_time_spec.rb +1 -1
  368. data/spec/extensions/string_stripper_spec.rb +1 -1
  369. data/spec/extensions/subclasses_spec.rb +1 -1
  370. data/spec/extensions/subset_conditions_spec.rb +1 -1
  371. data/spec/extensions/symbol_aref_refinement_spec.rb +1 -1
  372. data/spec/extensions/symbol_as_refinement_spec.rb +1 -1
  373. data/spec/extensions/table_select_spec.rb +4 -4
  374. data/spec/extensions/tactical_eager_loading_spec.rb +1 -6
  375. data/spec/extensions/thread_local_timezones_spec.rb +1 -1
  376. data/spec/extensions/timestamps_spec.rb +3 -3
  377. data/spec/extensions/to_dot_spec.rb +1 -1
  378. data/spec/extensions/touch_spec.rb +1 -1
  379. data/spec/extensions/tree_spec.rb +1 -1
  380. data/spec/extensions/typecast_on_load_spec.rb +1 -1
  381. data/spec/extensions/unlimited_update_spec.rb +1 -1
  382. data/spec/extensions/update_or_create_spec.rb +1 -1
  383. data/spec/extensions/update_primary_key_spec.rb +4 -3
  384. data/spec/extensions/update_refresh_spec.rb +1 -1
  385. data/spec/extensions/uuid_spec.rb +10 -12
  386. data/spec/extensions/validate_associated_spec.rb +1 -1
  387. data/spec/extensions/validation_class_methods_spec.rb +3 -3
  388. data/spec/extensions/validation_contexts_spec.rb +1 -1
  389. data/spec/extensions/validation_helpers_spec.rb +10 -44
  390. data/spec/extensions/whitelist_security_spec.rb +5 -5
  391. data/spec/extensions/xml_serializer_spec.rb +3 -3
  392. data/spec/guards_helper.rb +2 -1
  393. data/spec/integration/associations_test.rb +1 -23
  394. data/spec/integration/database_test.rb +7 -7
  395. data/spec/integration/dataset_test.rb +5 -47
  396. data/spec/integration/eager_loader_test.rb +1 -1
  397. data/spec/integration/migrator_test.rb +1 -1
  398. data/spec/integration/model_test.rb +4 -82
  399. data/spec/integration/plugin_test.rb +6 -22
  400. data/spec/integration/prepared_statement_test.rb +8 -88
  401. data/spec/integration/schema_test.rb +6 -6
  402. data/spec/integration/spec_helper.rb +13 -21
  403. data/spec/integration/timezone_test.rb +5 -5
  404. data/spec/integration/transaction_test.rb +3 -55
  405. data/spec/integration/type_test.rb +9 -9
  406. data/spec/model/association_reflection_spec.rb +24 -9
  407. data/spec/model/associations_spec.rb +124 -303
  408. data/spec/model/base_spec.rb +18 -137
  409. data/spec/model/class_dataset_methods_spec.rb +2 -20
  410. data/spec/model/dataset_methods_spec.rb +1 -20
  411. data/spec/model/eager_loading_spec.rb +17 -11
  412. data/spec/model/hooks_spec.rb +5 -300
  413. data/spec/model/inflector_spec.rb +1 -1
  414. data/spec/model/model_spec.rb +15 -320
  415. data/spec/model/plugins_spec.rb +2 -16
  416. data/spec/model/record_spec.rb +29 -121
  417. data/spec/model/spec_helper.rb +5 -15
  418. data/spec/model/validations_spec.rb +1 -1
  419. data/spec/sequel_warning.rb +1 -12
  420. metadata +8 -64
  421. data/doc/active_record.rdoc +0 -927
  422. data/lib/sequel/adapters/cubrid.rb +0 -160
  423. data/lib/sequel/adapters/do.rb +0 -166
  424. data/lib/sequel/adapters/do/mysql.rb +0 -69
  425. data/lib/sequel/adapters/do/postgres.rb +0 -46
  426. data/lib/sequel/adapters/do/sqlite3.rb +0 -41
  427. data/lib/sequel/adapters/jdbc/as400.rb +0 -92
  428. data/lib/sequel/adapters/jdbc/cubrid.rb +0 -65
  429. data/lib/sequel/adapters/jdbc/firebirdsql.rb +0 -37
  430. data/lib/sequel/adapters/jdbc/informix-sqli.rb +0 -34
  431. data/lib/sequel/adapters/jdbc/jdbcprogress.rb +0 -34
  432. data/lib/sequel/adapters/odbc/progress.rb +0 -12
  433. data/lib/sequel/adapters/shared/cubrid.rb +0 -245
  434. data/lib/sequel/adapters/shared/firebird.rb +0 -261
  435. data/lib/sequel/adapters/shared/informix.rb +0 -63
  436. data/lib/sequel/adapters/shared/progress.rb +0 -40
  437. data/lib/sequel/adapters/swift.rb +0 -169
  438. data/lib/sequel/adapters/swift/mysql.rb +0 -50
  439. data/lib/sequel/adapters/swift/postgres.rb +0 -49
  440. data/lib/sequel/adapters/swift/sqlite.rb +0 -48
  441. data/lib/sequel/adapters/utils/pg_types.rb +0 -4
  442. data/lib/sequel/dataset/mutation.rb +0 -98
  443. data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +0 -117
  444. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +0 -8
  445. data/lib/sequel/extensions/filter_having.rb +0 -65
  446. data/lib/sequel/extensions/hash_aliases.rb +0 -51
  447. data/lib/sequel/extensions/meta_def.rb +0 -37
  448. data/lib/sequel/extensions/query_literals.rb +0 -86
  449. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +0 -26
  450. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +0 -133
  451. data/lib/sequel/extensions/set_overrides.rb +0 -82
  452. data/lib/sequel/no_core_ext.rb +0 -4
  453. data/lib/sequel/plugins/association_autoreloading.rb +0 -11
  454. data/lib/sequel/plugins/identifier_columns.rb +0 -49
  455. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +0 -11
  456. data/lib/sequel/plugins/pg_typecast_on_load.rb +0 -90
  457. data/lib/sequel/plugins/prepared_statements_associations.rb +0 -137
  458. data/lib/sequel/plugins/prepared_statements_with_pk.rb +0 -71
  459. data/lib/sequel/plugins/schema.rb +0 -84
  460. data/lib/sequel/plugins/scissors.rb +0 -37
  461. data/spec/core/dataset_mutation_spec.rb +0 -253
  462. data/spec/extensions/_deprecated_identifier_mangling_spec.rb +0 -314
  463. data/spec/extensions/before_after_save_spec.rb +0 -40
  464. data/spec/extensions/filter_having_spec.rb +0 -42
  465. data/spec/extensions/from_block_spec.rb +0 -21
  466. data/spec/extensions/hash_aliases_spec.rb +0 -26
  467. data/spec/extensions/identifier_columns_spec.rb +0 -19
  468. data/spec/extensions/meta_def_spec.rb +0 -35
  469. data/spec/extensions/no_auto_literal_strings_spec.rb +0 -69
  470. data/spec/extensions/pg_typecast_on_load_spec.rb +0 -70
  471. data/spec/extensions/prepared_statements_associations_spec.rb +0 -212
  472. data/spec/extensions/prepared_statements_with_pk_spec.rb +0 -40
  473. data/spec/extensions/query_literals_spec.rb +0 -185
  474. data/spec/extensions/schema_spec.rb +0 -123
  475. data/spec/extensions/scissors_spec.rb +0 -27
  476. data/spec/extensions/sequel_3_dataset_methods_spec.rb +0 -118
  477. data/spec/extensions/set_overrides_spec.rb +0 -75
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
1
+ require_relative "spec_helper"
2
2
 
3
3
  describe "Database transactions" do
4
4
  before(:all) do
@@ -192,7 +192,6 @@ describe "Database transactions" do
192
192
  c = Class.new(Sequel::Model(@d))
193
193
  c.set_primary_key :name
194
194
  c.unrestrict_primary_key
195
- c.use_after_commit_rollback = false
196
195
  @db.transaction(:prepare=>'XYZ'){c.create(:name => '1'); c.create(:name => '2').destroy}
197
196
  @db.commit_prepared_transaction('XYZ')
198
197
  @d.select_order_map(:name).must_equal ['1']
@@ -315,57 +314,6 @@ describe "Database transactions" do
315
314
  end
316
315
  end
317
316
 
318
- if (! defined?(RUBY_ENGINE) or RUBY_ENGINE == 'ruby') and RUBY_VERSION < '1.9'
319
- describe "Database transactions and Thread#kill" do
320
- before do
321
- @db = DB
322
- @db.create_table!(:items, :engine=>'InnoDB'){String :name; Integer :value}
323
- @d = @db[:items]
324
- end
325
- after do
326
- @db.drop_table?(:items)
327
- end
328
-
329
- it "should handle transactions inside threads" do
330
- q = Queue.new
331
- q1 = Queue.new
332
- t = Thread.new do
333
- @db.transaction do
334
- @d.insert(:name => 'abc', :value => 1)
335
- q1.push nil
336
- q.pop
337
- @d.insert(:name => 'def', :value => 2)
338
- end
339
- end
340
- q1.pop
341
- t.kill
342
- @d.count.must_equal 0
343
- end
344
-
345
- if DB.supports_savepoints?
346
- it "should handle transactions with savepoints inside threads" do
347
- q = Queue.new
348
- q1 = Queue.new
349
- t = Thread.new do
350
- @db.transaction do
351
- @d.insert(:name => 'abc', :value => 1)
352
- @db.transaction(:savepoint=>true) do
353
- @d.insert(:name => 'def', :value => 2)
354
- q1.push nil
355
- q.pop
356
- @d.insert(:name => 'ghi', :value => 3)
357
- end
358
- @d.insert(:name => 'jkl', :value => 4)
359
- end
360
- end
361
- q1.pop
362
- t.kill
363
- @d.count.must_equal 0
364
- end
365
- end
366
- end
367
- end
368
-
369
317
  describe "Database transaction retrying" do
370
318
  before(:all) do
371
319
  @db = DB
@@ -379,7 +327,7 @@ describe "Database transaction retrying" do
379
327
  @db.drop_table?(:items)
380
328
  end
381
329
 
382
- cspecify "should be supported using the :retry_on option", [:db2] do
330
+ it "should be supported using the :retry_on option" do
383
331
  @d.insert('b')
384
332
  @d.insert('c')
385
333
  s = 'a'
@@ -390,7 +338,7 @@ describe "Database transaction retrying" do
390
338
  @d.select_order_map(:a).must_equal %w'b c d'
391
339
  end
392
340
 
393
- cspecify "should limit number of retries via the :num_retries option", [:db2] do
341
+ it "should limit number of retries via the :num_retries option" do
394
342
  @d.insert('b')
395
343
  @d.insert('c')
396
344
  s = 'a'
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
1
+ require_relative "spec_helper"
2
2
 
3
3
  describe "Supported types" do
4
4
  def create_items_table_with_column(name, type, opts={})
@@ -37,13 +37,13 @@ describe "Supported types" do
37
37
  ds.all.must_equal [{:number=>2**34}]
38
38
  end
39
39
 
40
- cspecify "should support generic float type", [:swift, :sqlite] do
40
+ it "should support generic float type" do
41
41
  ds = create_items_table_with_column(:number, Float)
42
42
  ds.insert(:number => 2.1)
43
43
  ds.all.must_equal [{:number=>2.1}]
44
44
  end
45
45
 
46
- cspecify "should support generic numeric type", [:odbc, :mssql], [:swift, :sqlite] do
46
+ cspecify "should support generic numeric type", [:odbc, :mssql] do
47
47
  ds = create_items_table_with_column(:number, Numeric, :size=>[15, 10])
48
48
  ds.insert(:number => BigDecimal.new('2.123456789'))
49
49
  ds.all.must_equal [{:number=>BigDecimal.new('2.123456789')}]
@@ -67,7 +67,7 @@ describe "Supported types" do
67
67
  ds.all.must_equal [{:name=>'Test User'*100}]
68
68
  end
69
69
 
70
- cspecify "should support generic date type", [:do, :sqlite], [:jdbc, :sqlite], [:tinytds], [:jdbc, :mssql], :oracle do
70
+ cspecify "should support generic date type", [:jdbc, :sqlite], [:tinytds], [:jdbc, :mssql], :oracle do
71
71
  ds = create_items_table_with_column(:dat, Date)
72
72
  d = Date.today
73
73
  ds.insert(:dat => d)
@@ -75,7 +75,7 @@ describe "Supported types" do
75
75
  ds.first[:dat].to_s.must_equal d.to_s
76
76
  end
77
77
 
78
- cspecify "should support generic time type", [:do], [:swift], [:odbc], [:jdbc, :mssql], [:jdbc, :sqlite], [:mysql2], [:tinytds], :oracle, [:ado] do
78
+ cspecify "should support generic time type", [:odbc], [:jdbc, :mssql], [:jdbc, :sqlite], [:mysql2], [:tinytds], :oracle, [:ado] do
79
79
  ds = create_items_table_with_column(:tim, Time, :only_time=>true)
80
80
  t = Sequel::SQLTime.now
81
81
  ds.insert(:tim => t)
@@ -89,7 +89,7 @@ describe "Supported types" do
89
89
  v2.must_be_kind_of(Sequel::SQLTime)
90
90
  end
91
91
 
92
- cspecify "should support generic datetime type", [:do, :sqlite], [:jdbc, :sqlite] do
92
+ cspecify "should support generic datetime type", [:jdbc, :sqlite] do
93
93
  ds = create_items_table_with_column(:tim, DateTime)
94
94
  t = DateTime.now
95
95
  ds.insert(:tim => t)
@@ -100,14 +100,14 @@ describe "Supported types" do
100
100
  ds.first[:tim].strftime('%Y%m%d%H%M%S').must_equal t.strftime('%Y%m%d%H%M%S')
101
101
  end
102
102
 
103
- cspecify "should support generic file type", [:do], [:odbc, :mssql], [:mysql2], [:tinytds] do
103
+ cspecify "should support generic file type", [:odbc, :mssql], [:mysql2], [:tinytds] do
104
104
  ds = create_items_table_with_column(:name, File)
105
105
  ds.insert(:name =>Sequel.blob("a\0"*300))
106
106
  ds.all.must_equal [{:name=>Sequel.blob("a\0"*300)}]
107
107
  ds.first[:name].must_be_kind_of(::Sequel::SQL::Blob)
108
108
  end
109
109
 
110
- cspecify "should support generic boolean type", [:do, :sqlite], [:jdbc, :sqlite], [:jdbc, :db2], :oracle do
110
+ cspecify "should support generic boolean type", [:jdbc, :sqlite], [:jdbc, :db2], :oracle do
111
111
  ds = create_items_table_with_column(:number, TrueClass)
112
112
  ds.insert(:number => true)
113
113
  ds.all.must_equal [{:number=>true}]
@@ -116,7 +116,7 @@ describe "Supported types" do
116
116
  ds.all.must_equal [{:number=>true}]
117
117
  end
118
118
 
119
- cspecify "should support generic boolean type with defaults", [:do, :sqlite], [:jdbc, :sqlite], [:jdbc, :db2], :oracle do
119
+ cspecify "should support generic boolean type with defaults", [:jdbc, :sqlite], [:jdbc, :db2], :oracle do
120
120
  ds = create_items_table_with_column(:number, TrueClass, :default=>true)
121
121
  ds.insert
122
122
  ds.all.must_equal [{:number=>true}]
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
1
+ require_relative "spec_helper"
2
2
 
3
3
  describe Sequel::Model::Associations::AssociationReflection, "#associated_class" do
4
4
  before do
@@ -15,14 +15,34 @@ describe Sequel::Model::Associations::AssociationReflection, "#associated_class"
15
15
  @c.association_reflection(:c).associated_class.must_equal ParParent
16
16
  end
17
17
 
18
+ it "should use the :class value if present" do
19
+ @c.many_to_one :c, :class=>@c
20
+ @c.one_to_many :cs, :class=>@c
21
+ c = @c.association_reflection(:c)
22
+ cs = @c.association_reflection(:cs)
23
+
24
+ c.association_method.must_equal :c
25
+ c.dataset_method.must_equal :c_dataset
26
+ c.setter_method.must_equal :c=
27
+ c._setter_method.must_equal :_c=
28
+
29
+ cs.association_method.must_equal :cs
30
+ cs.dataset_method.must_equal :cs_dataset
31
+ cs.add_method.must_equal :add_c
32
+ cs._add_method.must_equal :_add_c
33
+ cs.remove_method.must_equal :remove_c
34
+ cs._remove_method.must_equal :_remove_c
35
+ cs.remove_all_method.must_equal :remove_all_cs
36
+ cs._remove_all_method.must_equal :_remove_all_cs
37
+ end
38
+
18
39
  it "should have inspect include association class and representation of association definition " do
19
40
  ParParent.many_to_one :c
20
41
  ParParent.association_reflection(:c).inspect.must_equal "#<Sequel::Model::Associations::ManyToOneAssociationReflection ParParent.many_to_one :c>"
21
42
  ParParent.many_to_one :c, :class=>ParParent
22
43
  ParParent.association_reflection(:c).inspect.must_equal "#<Sequel::Model::Associations::ManyToOneAssociationReflection ParParent.many_to_one :c, :class=>ParParent>"
23
44
  ParParent.many_to_one :c, :class=>ParParent, :key=>:c_id
24
- ["#<Sequel::Model::Associations::ManyToOneAssociationReflection ParParent.many_to_one :c, :key=>:c_id, :class=>ParParent>",
25
- "#<Sequel::Model::Associations::ManyToOneAssociationReflection ParParent.many_to_one :c, :class=>ParParent, :key=>:c_id>"].must_include ParParent.association_reflection(:c).inspect
45
+ ParParent.association_reflection(:c).inspect.must_equal "#<Sequel::Model::Associations::ManyToOneAssociationReflection ParParent.many_to_one :c, :key=>:c_id, :class=>ParParent>"
26
46
 
27
47
  @c.one_to_many :foos do |ds| ds end
28
48
  @c.association_reflection(:foos).inspect.must_equal "#<Sequel::Model::Associations::OneToManyAssociationReflection #{@c.to_s}.one_to_many :foos, :block=>#{@c.association_reflection(:foos)[:block].inspect}>"
@@ -286,11 +306,6 @@ describe Sequel::Model::Associations::AssociationReflection do
286
306
  def @c.name() "C" end
287
307
  end
288
308
 
289
- deprecated "#eager_loading_predicate_key should be an alias of predicate_key for backwards compatibility" do
290
- @c.one_to_many :cs, :class=>@c
291
- @c.dataset.literal(@c.association_reflection(:cs).eager_loading_predicate_key).must_equal 'foo.c_id'
292
- end
293
-
294
309
  it "one_to_many #qualified_primary_key should be a qualified version of the primary key" do
295
310
  @c.one_to_many :cs, :class=>@c
296
311
  @c.dataset.literal(@c.association_reflection(:cs).qualified_primary_key).must_equal 'foo.id'
@@ -516,7 +531,7 @@ describe Sequel::Model, " association reflection methods" do
516
531
  c.associate :many_to_one, :parent2, :class => @c1
517
532
  @c1.associations.must_equal [:parent]
518
533
  c.associations.sort_by{|x| x.to_s}.must_equal [:parent, :parent2]
519
- c.instance_methods.map{|x| x.to_s}.must_include('parent')
534
+ c.instance_methods.must_include(:parent)
520
535
  end
521
536
  end
522
537
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
1
+ require_relative "spec_helper"
2
2
 
3
3
  describe Sequel::Model, "associate" do
4
4
  it "should use explicit class if given a class, symbol, or string" do
@@ -449,12 +449,6 @@ describe Sequel::Model, "many_to_one" do
449
449
  d.associations[:parent] = 42
450
450
  d.parent(:reload=>true).wont_equal 42
451
451
  DB.sqls.must_equal ["SELECT * FROM nodes WHERE id = 234"]
452
- deprecated do
453
- d.parent(true).wont_equal 42
454
- DB.sqls.must_equal ["SELECT * FROM nodes WHERE id = 234"]
455
- d.parent(Object.new).wont_equal 42
456
- DB.sqls.must_equal ["SELECT * FROM nodes WHERE id = 234"]
457
- end
458
452
  end
459
453
 
460
454
  it "should use a callback if given one as the argument" do
@@ -571,31 +565,31 @@ describe Sequel::Model, "many_to_one" do
571
565
 
572
566
  it "should not create the setter method if :read_only option is used" do
573
567
  @c2.many_to_one :parent, :class => @c2, :read_only=>true
574
- @c2.instance_methods.collect{|x| x.to_s}.must_include('parent')
575
- @c2.instance_methods.collect{|x| x.to_s}.wont_include('parent=')
568
+ @c2.instance_methods.must_include(:parent)
569
+ @c2.instance_methods.wont_include(:parent=)
576
570
  end
577
571
 
578
572
  it "should not add associations methods directly to class" do
579
573
  @c2.many_to_one :parent, :class => @c2
580
- @c2.instance_methods.collect{|x| x.to_s}.must_include('parent')
581
- @c2.instance_methods.collect{|x| x.to_s}.must_include('parent=')
582
- @c2.instance_methods(false).collect{|x| x.to_s}.wont_include('parent')
583
- @c2.instance_methods(false).collect{|x| x.to_s}.wont_include('parent=')
574
+ @c2.instance_methods.must_include(:parent)
575
+ @c2.instance_methods.must_include(:parent=)
576
+ @c2.instance_methods(false).wont_include(:parent)
577
+ @c2.instance_methods(false).wont_include(:parent=)
584
578
  end
585
579
 
586
580
  it "should add associations methods to the :methods_module option" do
587
581
  m = Module.new
588
582
  @c2.many_to_one :parent, :class => @c2, :methods_module=>m
589
- m.instance_methods.collect{|x| x.to_s}.must_include('parent')
590
- m.instance_methods.collect{|x| x.to_s}.must_include('parent=')
591
- @c2.instance_methods.collect{|x| x.to_s}.wont_include('parent')
592
- @c2.instance_methods.collect{|x| x.to_s}.wont_include('parent=')
583
+ m.instance_methods.must_include(:parent)
584
+ m.instance_methods.must_include(:parent=)
585
+ @c2.instance_methods.wont_include(:parent)
586
+ @c2.instance_methods.wont_include(:parent=)
593
587
  end
594
588
 
595
589
  it "should add associations methods directly to class if :methods_module is the class itself" do
596
590
  @c2.many_to_one :parent, :class => @c2, :methods_module=>@c2
597
- @c2.instance_methods(false).collect{|x| x.to_s}.must_include('parent')
598
- @c2.instance_methods(false).collect{|x| x.to_s}.must_include('parent=')
591
+ @c2.instance_methods(false).must_include(:parent)
592
+ @c2.instance_methods(false).must_include(:parent=)
599
593
  end
600
594
 
601
595
  it "should raise an error if trying to set a model object that doesn't have a valid primary key" do
@@ -607,7 +601,7 @@ describe Sequel::Model, "many_to_one" do
607
601
 
608
602
  it "should make the change to the foreign_key value inside a _association= method" do
609
603
  @c2.many_to_one :parent, :class => @c2
610
- @c2.private_instance_methods.collect{|x| x.to_s}.sort.must_include("_parent=")
604
+ @c2.private_instance_methods.must_include(:_parent=)
611
605
  p = @c2.new
612
606
  c = @c2.load(:id=>123)
613
607
  def p._parent=(x)
@@ -679,21 +673,6 @@ describe Sequel::Model, "many_to_one" do
679
673
  p.associations[:parent].must_equal :foo
680
674
  end
681
675
 
682
- deprecated "should raise error and not call internal add or remove method if before callback returns false, even if raise_on_save_failure is false" do
683
- p = @c2.new
684
- c = @c2.load(:id=>123)
685
- p.raise_on_save_failure = false
686
- @c2.many_to_one :parent, :class => @c2, :before_set=>:bs
687
- def p.bs(x) false end
688
- def p._parent=; raise; end
689
- proc{p.parent = c}.must_raise(Sequel::HookFailed)
690
-
691
- p.parent.must_be_nil
692
- p.associations[:parent] = c
693
- p.parent.must_equal c
694
- proc{p.parent = nil}.must_raise(Sequel::HookFailed)
695
- end
696
-
697
676
  it "should raise error and not call internal add or remove method if before callback calls cancel_action, even if raise_on_save_failure is false" do
698
677
  p = @c2.new
699
678
  c = @c2.load(:id=>123)
@@ -751,9 +730,9 @@ describe Sequel::Model, "one_to_one" do
751
730
 
752
731
  it "should not add a setter method if the :read_only option is true" do
753
732
  @c2.one_to_one :attribute, :class => @c1, :read_only=>true
754
- im = @c2.instance_methods.collect{|x| x.to_s}
755
- im.must_include('attribute')
756
- im.wont_include('attribute=')
733
+ im = @c2.instance_methods
734
+ im.must_include(:attribute)
735
+ im.wont_include(:attribute=)
757
736
  end
758
737
 
759
738
  it "should add a setter method" do
@@ -761,10 +740,9 @@ describe Sequel::Model, "one_to_one" do
761
740
  attrib = @c1.new(:id=>3)
762
741
  @c1.dataset = @c1.dataset.with_fetch(:id=>3)
763
742
  @c2.new(:id => 1234).attribute = attrib
764
- sqls = DB.sqls
765
- ['INSERT INTO attributes (node_id, id) VALUES (1234, 3)',
766
- 'INSERT INTO attributes (id, node_id) VALUES (3, 1234)'].must_include(sqls.slice! 1)
767
- sqls.must_equal ['UPDATE attributes SET node_id = NULL WHERE (node_id = 1234)', "SELECT * FROM attributes WHERE id = 3"]
743
+ DB.sqls.must_equal ['UPDATE attributes SET node_id = NULL WHERE (node_id = 1234)',
744
+ 'INSERT INTO attributes (id, node_id) VALUES (3, 1234)',
745
+ "SELECT * FROM attributes WHERE id = 3"]
768
746
 
769
747
  @c2.new(:id => 1234).attribute.must_equal attrib
770
748
  attrib = @c1.load(:id=>3)
@@ -800,10 +778,9 @@ describe Sequel::Model, "one_to_one" do
800
778
  attrib = @c1.new(:id=>3)
801
779
  @c1.dataset = @c1.dataset.with_fetch(:id=>3)
802
780
  @c2.new(:id => 1234, :xxx=>5).attribute = attrib
803
- sqls = DB.sqls
804
- ['INSERT INTO attributes (node_id, id) VALUES (5, 3)',
805
- 'INSERT INTO attributes (id, node_id) VALUES (3, 5)'].must_include(sqls.slice! 1)
806
- sqls.must_equal ['UPDATE attributes SET node_id = NULL WHERE (node_id = 5)', "SELECT * FROM attributes WHERE id = 3"]
781
+ DB.sqls.must_equal ['UPDATE attributes SET node_id = NULL WHERE (node_id = 5)',
782
+ 'INSERT INTO attributes (id, node_id) VALUES (3, 5)',
783
+ "SELECT * FROM attributes WHERE id = 3"]
807
784
 
808
785
  @c2.new(:id => 321, :xxx=>5).attribute.must_equal attrib
809
786
  attrib = @c1.load(:id=>3)
@@ -818,10 +795,8 @@ describe Sequel::Model, "one_to_one" do
818
795
  attrib = @c1.load(:id=>3, :y=>6)
819
796
  @c1.dataset = @c1.dataset.with_fetch(:id=>3, :y=>6)
820
797
  @c2.load(:id => 1234, :x=>5).attribute = attrib
821
- sqls = DB.sqls
822
- sqls.last.must_match(/UPDATE attributes SET (node_id = 1234|y = 5), (node_id = 1234|y = 5) WHERE \(id = 3\)/)
823
- sqls.first.must_match(/UPDATE attributes SET (node_id|y) = NULL, (node_id|y) = NULL WHERE \(\(node_id = 1234\) AND \(y = 5\) AND \(id != 3\)\)/)
824
- sqls.length.must_equal 2
798
+ DB.sqls.must_equal ["UPDATE attributes SET node_id = NULL, y = NULL WHERE ((node_id = 1234) AND (y = 5) AND (id != 3))",
799
+ "UPDATE attributes SET y = 5, node_id = 1234 WHERE (id = 3)"]
825
800
  end
826
801
 
827
802
  it "should use implicit key if omitted" do
@@ -946,10 +921,9 @@ describe Sequel::Model, "one_to_one" do
946
921
  @c2.dataset = @c2.dataset.with_fetch(:id => 4321, :blah => 3)
947
922
  d.parent = e
948
923
  e.values.must_equal(:id => 4321, :blah => 3)
949
- sqls = DB.sqls
950
- ["INSERT INTO nodes (blah, id) VALUES (3, 4321)",
951
- "INSERT INTO nodes (id, blah) VALUES (4321, 3)"].must_include(sqls.slice! 1)
952
- sqls.must_equal ["UPDATE nodes SET blah = NULL WHERE (blah = 3)", "SELECT * FROM nodes WHERE id = 4321"]
924
+ DB.sqls.must_equal ["UPDATE nodes SET blah = NULL WHERE (blah = 3)",
925
+ "INSERT INTO nodes (id, blah) VALUES (4321, 3)",
926
+ "SELECT * FROM nodes WHERE id = 4321"]
953
927
  end
954
928
 
955
929
  it "should persist changes to associated object when the setter is called" do
@@ -999,10 +973,6 @@ describe Sequel::Model, "one_to_one" do
999
973
  d.associations[:parent] = [42]
1000
974
  d.parent(:reload=>true).wont_equal 42
1001
975
  DB.sqls.must_equal ["SELECT * FROM nodes WHERE (nodes.node_id = 1) LIMIT 1"]
1002
- deprecated do
1003
- d.parent(true).wont_equal 42
1004
- DB.sqls.must_equal ["SELECT * FROM nodes WHERE (nodes.node_id = 1) LIMIT 1"]
1005
- end
1006
976
  end
1007
977
 
1008
978
  it "should have the setter set the reciprocal many_to_one cached association" do
@@ -1054,10 +1024,10 @@ describe Sequel::Model, "one_to_one" do
1054
1024
 
1055
1025
  it "should not add associations methods directly to class" do
1056
1026
  @c2.one_to_one :parent, :class => @c2
1057
- @c2.instance_methods.collect{|x| x.to_s}.must_include('parent')
1058
- @c2.instance_methods.collect{|x| x.to_s}.must_include('parent=')
1059
- @c2.instance_methods(false).collect{|x| x.to_s}.wont_include('parent')
1060
- @c2.instance_methods(false).collect{|x| x.to_s}.wont_include('parent=')
1027
+ @c2.instance_methods.must_include(:parent)
1028
+ @c2.instance_methods.must_include(:parent=)
1029
+ @c2.instance_methods(false).wont_include(:parent)
1030
+ @c2.instance_methods(false).wont_include(:parent=)
1061
1031
  end
1062
1032
 
1063
1033
  it "should raise an error if the current model object that doesn't have a valid primary key" do
@@ -1069,7 +1039,7 @@ describe Sequel::Model, "one_to_one" do
1069
1039
 
1070
1040
  it "should make the change to the foreign_key value inside a _association= method" do
1071
1041
  @c2.one_to_one :parent, :class => @c2
1072
- @c2.private_instance_methods.collect{|x| x.to_s}.sort.must_include("_parent=")
1042
+ @c2.private_instance_methods.must_include(:_parent=)
1073
1043
  c = @c2.new
1074
1044
  p = @c2.load(:id=>123)
1075
1045
  def p._parent=(x)
@@ -1126,21 +1096,6 @@ describe Sequel::Model, "one_to_one" do
1126
1096
  parent.pk.must_equal 20
1127
1097
  end
1128
1098
 
1129
- deprecated "should raise error and not call internal add or remove method if before callback returns false, even if raise_on_save_failure is false" do
1130
- p = @c2.load(:id=>321)
1131
- c = @c2.load(:id=>123)
1132
- p.raise_on_save_failure = false
1133
- @c2.one_to_one :parent, :class => @c2, :before_set=>:bs
1134
- def p.bs(x) false end
1135
- def p._parent=; raise; end
1136
- proc{p.parent = c}.must_raise(Sequel::HookFailed)
1137
-
1138
- p.associations[:parent].must_be_nil
1139
- p.associations[:parent] = c
1140
- p.parent.must_equal c
1141
- proc{p.parent = nil}.must_raise(Sequel::HookFailed)
1142
- end
1143
-
1144
1099
  it "should raise error and not call internal add or remove method if before callback calls cancel_action, even if raise_on_save_failure is false" do
1145
1100
  p = @c2.load(:id=>321)
1146
1101
  c = @c2.load(:id=>123)
@@ -1253,15 +1208,6 @@ describe Sequel::Model, "one_to_many" do
1253
1208
  DB.sqls.must_equal ["SELECT * FROM attributes WHERE ((attributes.nodeid = 1234) AND (name > 'M'))"]
1254
1209
  end
1255
1210
 
1256
- deprecated "should use a callback if given one as the argument" do
1257
- @c2.one_to_many :attributes, :class => @c1, :key => :nodeid
1258
-
1259
- d = @c2.load(:id => 1234)
1260
- d.associations[:attributes] = []
1261
- d.attributes(proc{|ds| ds.filter{name > 'M'}}).wont_equal []
1262
- DB.sqls.must_equal ["SELECT * FROM attributes WHERE ((attributes.nodeid = 1234) AND (name > 'M'))"]
1263
- end
1264
-
1265
1211
  it "should use explicit key if given" do
1266
1212
  @c2.one_to_many :attributes, :class => @c1, :key => :nodeid
1267
1213
  @c2.new(:id => 1234).attributes_dataset.sql.must_equal 'SELECT * FROM attributes WHERE (attributes.nodeid = 1234)'
@@ -1303,9 +1249,8 @@ describe Sequel::Model, "one_to_many" do
1303
1249
  a = @c1.new(:id => 234)
1304
1250
  @c1.dataset = @c1.dataset.with_fetch(:id=>234, :node_id=>1234)
1305
1251
  a.must_equal n.add_attribute(a)
1306
- sqls = DB.sqls
1307
- sqls.shift.must_match(/INSERT INTO attributes \((node_)?id, (node_)?id\) VALUES \(1?234, 1?234\)/)
1308
- sqls.must_equal ["SELECT * FROM attributes WHERE id = 234"]
1252
+ DB.sqls.must_equal ["INSERT INTO attributes (id, node_id) VALUES (234, 1234)",
1253
+ "SELECT * FROM attributes WHERE id = 234"]
1309
1254
  a.values.must_equal(:node_id => 1234, :id => 234)
1310
1255
  end
1311
1256
 
@@ -1335,9 +1280,8 @@ describe Sequel::Model, "one_to_many" do
1335
1280
  DB.reset
1336
1281
  @c1.dataset = @c1.dataset.with_fetch(:node_id => 1234, :id => 234)
1337
1282
  n.add_attribute(:id => 234).must_equal @c1.load(:node_id => 1234, :id => 234)
1338
- sqls = DB.sqls
1339
- sqls.shift.must_match(/INSERT INTO attributes \((node_)?id, (node_)?id\) VALUES \(1?234, 1?234\)/)
1340
- sqls.must_equal ["SELECT * FROM attributes WHERE id = 234"]
1283
+ DB.sqls.must_equal ["INSERT INTO attributes (id, node_id) VALUES (234, 1234)",
1284
+ "SELECT * FROM attributes WHERE id = 234"]
1341
1285
  end
1342
1286
 
1343
1287
  it "should accept a primary key for the add_ method" do
@@ -1403,9 +1347,7 @@ describe Sequel::Model, "one_to_many" do
1403
1347
  n = @c2.load(:id => 1234, :x=>5)
1404
1348
  a = @c1.load(:id => 2345)
1405
1349
  n.add_attribute(a).must_equal a
1406
- sqls = DB.sqls
1407
- sqls.shift.must_match(/UPDATE attributes SET (node_id = 1234|y = 5), (node_id = 1234|y = 5) WHERE \(id = 2345\)/)
1408
- sqls.must_equal []
1350
+ DB.sqls.must_equal ["UPDATE attributes SET node_id = 1234, y = 5 WHERE (id = 2345)"]
1409
1351
  end
1410
1352
 
1411
1353
  it "should have add_ method accept a composite key" do
@@ -1416,10 +1358,8 @@ describe Sequel::Model, "one_to_many" do
1416
1358
  n = @c2.load(:id => 1234, :x=>5)
1417
1359
  a = @c1.load(:id => 2345, :z => 8, :node_id => 1234, :y=>5)
1418
1360
  n.add_attribute([2345, 8]).must_equal a
1419
- sqls = DB.sqls
1420
- sqls.shift.must_match(/SELECT \* FROM attributes WHERE \(\((id|z) = (2345|8)\) AND \((id|z) = (2345|8)\)\) LIMIT 1/)
1421
- sqls.shift.must_match(/UPDATE attributes SET (node_id|y) = (1234|5), (node_id|y) = (1234|5) WHERE \(\((id|z) = (2345|8)\) AND \((id|z) = (2345|8)\)\)/)
1422
- sqls.must_equal []
1361
+ DB.sqls.must_equal ["SELECT * FROM attributes WHERE ((id = 2345) AND (z = 8)) LIMIT 1",
1362
+ "UPDATE attributes SET node_id = 1234, y = 5 WHERE ((id = 2345) AND (z = 8))"]
1423
1363
  end
1424
1364
 
1425
1365
  it "should have remove_ method respect composite keys" do
@@ -1428,9 +1368,8 @@ describe Sequel::Model, "one_to_many" do
1428
1368
  n = @c2.load(:id => 1234, :x=>5)
1429
1369
  a = @c1.load(:id => 2345, :node_id=>1234, :y=>5)
1430
1370
  n.remove_attribute(a).must_equal a
1431
- sqls = DB.sqls
1432
- sqls.pop.must_match(/UPDATE attributes SET (node_id|y) = NULL, (node_id|y) = NULL WHERE \(id = 2345\)/)
1433
- sqls.must_equal ["SELECT 1 AS one FROM attributes WHERE ((attributes.node_id = 1234) AND (attributes.y = 5) AND (id = 2345)) LIMIT 1"]
1371
+ DB.sqls.must_equal ["SELECT 1 AS one FROM attributes WHERE ((attributes.node_id = 1234) AND (attributes.y = 5) AND (id = 2345)) LIMIT 1",
1372
+ "UPDATE attributes SET node_id = NULL, y = NULL WHERE (id = 2345)"]
1434
1373
  end
1435
1374
 
1436
1375
  it "should accept a array of composite primary key values for the remove_ method and remove an existing record" do
@@ -1439,10 +1378,8 @@ describe Sequel::Model, "one_to_many" do
1439
1378
  @c2.one_to_many :attributes, :class => @c1, :key=>:node_id, :primary_key=>:id
1440
1379
  n = @c2.new(:id => 123)
1441
1380
  n.remove_attribute([234, 5]).must_equal @c1.load(:node_id => nil, :y => 5, :id => 234)
1442
- sqls = DB.sqls
1443
- sqls.length.must_equal 2
1444
- sqls.first.must_match(/SELECT \* FROM attributes WHERE \(\(attributes.node_id = 123\) AND \(attributes\.(id|y) = (234|5)\) AND \(attributes\.(id|y) = (234|5)\)\) LIMIT 1/)
1445
- sqls.last.must_match(/UPDATE attributes SET node_id = NULL WHERE \(\((id|y) = (234|5)\) AND \((id|y) = (234|5)\)\)/)
1381
+ DB.sqls.must_equal ["SELECT * FROM attributes WHERE ((attributes.node_id = 123) AND (attributes.id = 234) AND (attributes.y = 5)) LIMIT 1",
1382
+ "UPDATE attributes SET node_id = NULL WHERE ((id = 234) AND (y = 5))"]
1446
1383
  end
1447
1384
 
1448
1385
  it "should raise an error in add_ and remove_ if the passed object returns false to save (is not valid)" do
@@ -1584,10 +1521,6 @@ describe Sequel::Model, "one_to_many" do
1584
1521
  n.associations[:attributes] = 42
1585
1522
  n.attributes(:reload=>true).wont_equal 42
1586
1523
  DB.sqls.must_equal ['SELECT * FROM attributes WHERE (attributes.node_id = 1234)']
1587
- deprecated do
1588
- n.attributes(true).wont_equal 42
1589
- DB.sqls.must_equal ['SELECT * FROM attributes WHERE (attributes.node_id = 1234)']
1590
- end
1591
1524
  end
1592
1525
 
1593
1526
  it "should add item to cache if it exists when calling add_" do
@@ -1635,28 +1568,28 @@ describe Sequel::Model, "one_to_many" do
1635
1568
 
1636
1569
  it "should not create the add_, remove_, or remove_all_ methods if :read_only option is used" do
1637
1570
  @c2.one_to_many :attributes, :class => @c1, :read_only=>true
1638
- im = @c2.instance_methods.collect{|x| x.to_s}
1639
- im.must_include('attributes')
1640
- im.must_include('attributes_dataset')
1641
- im.wont_include('add_attribute')
1642
- im.wont_include('remove_attribute')
1643
- im.wont_include('remove_all_attributes')
1571
+ im = @c2.instance_methods
1572
+ im.must_include(:attributes)
1573
+ im.must_include(:attributes_dataset)
1574
+ im.wont_include(:add_attribute)
1575
+ im.wont_include(:remove_attribute)
1576
+ im.wont_include(:remove_all_attributes)
1644
1577
  end
1645
1578
 
1646
1579
  it "should not add associations methods directly to class" do
1647
1580
  @c2.one_to_many :attributes, :class => @c1
1648
- im = @c2.instance_methods.collect{|x| x.to_s}
1649
- im.must_include('attributes')
1650
- im.must_include('attributes_dataset')
1651
- im.must_include('add_attribute')
1652
- im.must_include('remove_attribute')
1653
- im.must_include('remove_all_attributes')
1654
- im2 = @c2.instance_methods(false).collect{|x| x.to_s}
1655
- im2.wont_include('attributes')
1656
- im2.wont_include('attributes_dataset')
1657
- im2.wont_include('add_attribute')
1658
- im2.wont_include('remove_attribute')
1659
- im2.wont_include('remove_all_attributes')
1581
+ im = @c2.instance_methods
1582
+ im.must_include(:attributes)
1583
+ im.must_include(:attributes_dataset)
1584
+ im.must_include(:add_attribute)
1585
+ im.must_include(:remove_attribute)
1586
+ im.must_include(:remove_all_attributes)
1587
+ im2 = @c2.instance_methods(false)
1588
+ im2.wont_include(:attributes)
1589
+ im2.wont_include(:attributes_dataset)
1590
+ im2.wont_include(:add_attribute)
1591
+ im2.wont_include(:remove_attribute)
1592
+ im2.wont_include(:remove_all_attributes)
1660
1593
  end
1661
1594
 
1662
1595
  it "should populate the reciprocal many_to_one cache when loading the one_to_many association" do
@@ -1705,9 +1638,7 @@ describe Sequel::Model, "one_to_many" do
1705
1638
  it "should have the remove_all_ method respect composite keys" do
1706
1639
  @c2.one_to_many :attributes, :class => @c1, :key=>[:node_id, :y], :primary_key=>[:id, :x]
1707
1640
  @c2.new(:id => 1234, :x=>5).remove_all_attributes
1708
- sqls = DB.sqls
1709
- sqls.pop.must_match(/UPDATE attributes SET (node_id|y) = NULL, (node_id|y) = NULL WHERE \(\(node_id = 1234\) AND \(y = 5\)\)/)
1710
- sqls.must_equal []
1641
+ DB.sqls.must_equal ["UPDATE attributes SET node_id = NULL, y = NULL WHERE ((node_id = 1234) AND (y = 5))"]
1711
1642
  end
1712
1643
 
1713
1644
  it "remove_all should set the cache to []" do
@@ -1750,7 +1681,7 @@ describe Sequel::Model, "one_to_many" do
1750
1681
 
1751
1682
  it "should call an _add_ method internally to add attributes" do
1752
1683
  @c2.one_to_many :attributes, :class => @c1
1753
- @c2.private_instance_methods.collect{|x| x.to_s}.sort.must_include("_add_attribute")
1684
+ @c2.private_instance_methods.must_include(:_add_attribute)
1754
1685
  p = @c2.load(:id=>10)
1755
1686
  c = @c1.load(:id=>123)
1756
1687
  def p._add_attribute(x)
@@ -1786,7 +1717,7 @@ describe Sequel::Model, "one_to_many" do
1786
1717
 
1787
1718
  it "should call a _remove_ method internally to remove attributes" do
1788
1719
  @c2.one_to_many :attributes, :class => @c1
1789
- @c2.private_instance_methods.collect{|x| x.to_s}.sort.must_include("_remove_attribute")
1720
+ @c2.private_instance_methods.must_include(:_remove_attribute)
1790
1721
  p = @c2.load(:id=>10)
1791
1722
  c = @c1.load(:id=>123)
1792
1723
  def p._remove_attribute(x)
@@ -1834,7 +1765,7 @@ describe Sequel::Model, "one_to_many" do
1834
1765
 
1835
1766
  it "should call a _remove_all_ method internally to remove attributes" do
1836
1767
  @c2.one_to_many :attributes, :class => @c1
1837
- @c2.private_instance_methods.collect{|x| x.to_s}.sort.must_include("_remove_all_attributes")
1768
+ @c2.private_instance_methods.must_include(:_remove_all_attributes)
1838
1769
  p = @c2.load(:id=>10)
1839
1770
  def p._remove_all_attributes
1840
1771
  @x = :foo
@@ -1893,39 +1824,6 @@ describe Sequel::Model, "one_to_many" do
1893
1824
  attributes.collect{|a| a.pk}.must_equal [20, 30]
1894
1825
  end
1895
1826
 
1896
- deprecated "should raise error and not call internal add or remove method if before callback returns false if raise_on_save_failure is true" do
1897
- p = @c2.load(:id=>10)
1898
- c = @c1.load(:id=>123)
1899
- @c2.one_to_many :attributes, :class => @c1, :before_add=>:ba, :before_remove=>:br
1900
- def p.ba(c) false end
1901
- def p._add_attribute; raise; end
1902
- def p._remove_attribute; raise; end
1903
- p.associations[:attributes] = []
1904
- proc{p.add_attribute(c)}.must_raise(Sequel::HookFailed)
1905
- p.attributes.must_equal []
1906
- p.associations[:attributes] = [c]
1907
- def p.br(c) false end
1908
- proc{p.remove_attribute(c)}.must_raise(Sequel::HookFailed)
1909
- p.attributes.must_equal [c]
1910
- end
1911
-
1912
- deprecated "should return nil and not call internal add or remove method if before callback returns false if raise_on_save_failure is false" do
1913
- p = @c2.load(:id=>10)
1914
- c = @c1.load(:id=>123)
1915
- p.raise_on_save_failure = false
1916
- @c2.one_to_many :attributes, :class => @c1, :before_add=>:ba, :before_remove=>:br
1917
- def p.ba(c) false end
1918
- def p._add_attribute; raise; end
1919
- def p._remove_attribute; raise; end
1920
- p.associations[:attributes] = []
1921
- p.add_attribute(c).must_be_nil
1922
- p.attributes.must_equal []
1923
- p.associations[:attributes] = [c]
1924
- def p.br(c) false end
1925
- p.remove_attribute(c).must_be_nil
1926
- p.attributes.must_equal [c]
1927
- end
1928
-
1929
1827
  it "should raise error and not call internal add or remove method if before callback calls cancel_action if raise_on_save_failure is true" do
1930
1828
  p = @c2.load(:id=>10)
1931
1829
  c = @c1.load(:id=>123)
@@ -2066,11 +1964,6 @@ describe Sequel::Model, "many_to_many" do
2066
1964
  @c2.new(:id => 1234).attributes_dataset.sql.must_equal 'SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id = 1234)'
2067
1965
  end
2068
1966
 
2069
- deprecated "should respect :eager_loading_predicate_key when lazily loading" do
2070
- @c2.many_to_many :attributes, :class => @c1, :eager_loading_predicate_key=>Sequel.subscript(Sequel[:attributes_nodes][:node_id], 0)
2071
- @c2.new(:id => 1234).attributes_dataset.sql.must_equal 'SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id[0] = 1234)'
2072
- end
2073
-
2074
1967
  it "should respect :predicate_key when lazily loading" do
2075
1968
  @c2.many_to_many :attributes, :class => @c1, :predicate_key=>Sequel.subscript(Sequel[:attributes_nodes][:node_id], 0)
2076
1969
  @c2.new(:id => 1234).attributes_dataset.sql.must_equal 'SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id[0] = 1234)'
@@ -2206,12 +2099,9 @@ describe Sequel::Model, "many_to_many" do
2206
2099
  a.must_equal n.add_attribute(a)
2207
2100
  a.must_equal n.remove_attribute(a)
2208
2101
  n.remove_all_attributes
2209
- sqls = DB.sqls
2210
- ['INSERT INTO attribute2node (node_id, attribute_id) VALUES (1234, 2345)',
2211
- 'INSERT INTO attribute2node (attribute_id, node_id) VALUES (2345, 1234)'].must_include(sqls.shift)
2212
- ["DELETE FROM attribute2node WHERE ((node_id = 1234) AND (attribute_id = 2345))",
2213
- "DELETE FROM attribute2node WHERE ((attribute_id = 2345) AND (node_id = 1234))"].must_include(sqls.shift)
2214
- sqls.must_equal ["DELETE FROM attribute2node WHERE (node_id = 1234)"]
2102
+ DB.sqls.must_equal ["INSERT INTO attribute2node (node_id, attribute_id) VALUES (1234, 2345)",
2103
+ "DELETE FROM attribute2node WHERE ((node_id = 1234) AND (attribute_id = 2345))",
2104
+ "DELETE FROM attribute2node WHERE (node_id = 1234)"]
2215
2105
  end
2216
2106
 
2217
2107
  with_symbol_splitting "should handle an aliased symbol join table" do
@@ -2222,12 +2112,9 @@ describe Sequel::Model, "many_to_many" do
2222
2112
  a.must_equal n.add_attribute(a)
2223
2113
  a.must_equal n.remove_attribute(a)
2224
2114
  n.remove_all_attributes
2225
- sqls = DB.sqls
2226
- ['INSERT INTO attribute2node (node_id, attribute_id) VALUES (1234, 2345)',
2227
- 'INSERT INTO attribute2node (attribute_id, node_id) VALUES (2345, 1234)'].must_include(sqls.shift)
2228
- ["DELETE FROM attribute2node WHERE ((node_id = 1234) AND (attribute_id = 2345))",
2229
- "DELETE FROM attribute2node WHERE ((attribute_id = 2345) AND (node_id = 1234))"].must_include(sqls.shift)
2230
- sqls.must_equal ["DELETE FROM attribute2node WHERE (node_id = 1234)"]
2115
+ DB.sqls.must_equal ["INSERT INTO attribute2node (node_id, attribute_id) VALUES (1234, 2345)",
2116
+ "DELETE FROM attribute2node WHERE ((node_id = 1234) AND (attribute_id = 2345))",
2117
+ "DELETE FROM attribute2node WHERE (node_id = 1234)"]
2231
2118
  end
2232
2119
 
2233
2120
  it "should define an add_ method that works on existing records" do
@@ -2236,10 +2123,7 @@ describe Sequel::Model, "many_to_many" do
2236
2123
  n = @c2.load(:id => 1234)
2237
2124
  a = @c1.load(:id => 2345)
2238
2125
  n.add_attribute(a).must_equal a
2239
- sqls = DB.sqls
2240
- ['INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 2345)',
2241
- 'INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (2345, 1234)'].must_include(sqls.shift)
2242
- sqls.must_equal []
2126
+ DB.sqls.must_equal ["INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 2345)"]
2243
2127
  end
2244
2128
 
2245
2129
  it "should define an add_ method that works with a primary key" do
@@ -2249,10 +2133,8 @@ describe Sequel::Model, "many_to_many" do
2249
2133
  a = @c1.load(:id => 2345)
2250
2134
  @c1.dataset = @c1.dataset.with_fetch(:id=>2345)
2251
2135
  n.add_attribute(2345).must_equal a
2252
- sqls = DB.sqls
2253
- ['INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 2345)',
2254
- 'INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (2345, 1234)'].must_include(sqls.pop)
2255
- sqls.must_equal ["SELECT * FROM attributes WHERE id = 2345"]
2136
+ DB.sqls.must_equal ["SELECT * FROM attributes WHERE id = 2345",
2137
+ "INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 2345)"]
2256
2138
  end
2257
2139
 
2258
2140
  it "should raise an error if the primary key passed to the add_ method does not match an existing record" do
@@ -2270,11 +2152,9 @@ describe Sequel::Model, "many_to_many" do
2270
2152
  n = @c2.load(:id => 1234)
2271
2153
  @c1.dataset = @c1.dataset.with_fetch(:id=>1)
2272
2154
  n.add_attribute(:id => 1).must_equal @c1.load(:id => 1)
2273
- sqls = DB.sqls
2274
- ['INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 1)',
2275
- 'INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (1, 1234)'
2276
- ].must_include(sqls.pop)
2277
- sqls.must_equal ['INSERT INTO attributes (id) VALUES (1)', "SELECT * FROM attributes WHERE id = 1"]
2155
+ DB.sqls.must_equal ['INSERT INTO attributes (id) VALUES (1)',
2156
+ "SELECT * FROM attributes WHERE id = 1",
2157
+ "INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 1)"]
2278
2158
  end
2279
2159
 
2280
2160
  it "should define a remove_ method that works on existing records" do
@@ -2311,11 +2191,7 @@ describe Sequel::Model, "many_to_many" do
2311
2191
  n = @c2.load(:id => 1234).set(:xxx=>5)
2312
2192
  a = @c1.load(:id => 2345).set(:yyy=>8)
2313
2193
  n.add_attribute(a).must_equal a
2314
- sqls = DB.sqls
2315
- ['INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (5, 8)',
2316
- 'INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (8, 5)'
2317
- ].must_include(sqls.pop)
2318
- sqls.must_equal []
2194
+ DB.sqls.must_equal ["INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (5, 8)"]
2319
2195
  end
2320
2196
 
2321
2197
  it "should have add_ method not add the same object to the cached association array if the object is already in the array" do
@@ -2358,10 +2234,8 @@ describe Sequel::Model, "many_to_many" do
2358
2234
  n = @c2.load(:id => 1234, :x=>5)
2359
2235
  a = @c1.load(:id => 2345, :z=>8)
2360
2236
  n.add_attribute([2345, 8]).must_equal a
2361
- sqls = DB.sqls
2362
- sqls.shift.must_match(/SELECT \* FROM attributes WHERE \(\((id|z) = (8|2345)\) AND \((id|z) = (8|2345)\)\) LIMIT 1/)
2363
- sqls.pop.must_match(/INSERT INTO attributes_nodes \([lr][12], [lr][12], [lr][12], [lr][12]\) VALUES \((1234|5|2345|8), (1234|5|2345|8), (1234|5|2345|8), (1234|5|2345|8)\)/)
2364
- sqls.must_equal []
2237
+ DB.sqls.must_equal ["SELECT * FROM attributes WHERE ((id = 2345) AND (z = 8)) LIMIT 1",
2238
+ "INSERT INTO attributes_nodes (l1, l2, r1, r2) VALUES (1234, 5, 2345, 8)"]
2365
2239
  end
2366
2240
 
2367
2241
  it "should have the remove_ method respect the :left_primary_key and :right_primary_key options" do
@@ -2387,10 +2261,8 @@ describe Sequel::Model, "many_to_many" do
2387
2261
  @c2.many_to_many :attributes, :class => @c1
2388
2262
  n = @c2.new(:id => 1234)
2389
2263
  @c1.load(:id => 234, :y=>8).must_equal n.remove_attribute([234, 8])
2390
- sqls = DB.sqls
2391
- ["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE ((attributes_nodes.node_id = 1234) AND (attributes.id = 234) AND (attributes.y = 8)) LIMIT 1",
2392
- "SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE ((attributes_nodes.node_id = 1234) AND (attributes.y = 8) AND (attributes.id = 234)) LIMIT 1"].must_include(sqls.shift)
2393
- sqls.must_equal ["DELETE FROM attributes_nodes WHERE ((node_id = 1234) AND (attribute_id = 234))"]
2264
+ DB.sqls.must_equal ["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE ((attributes_nodes.node_id = 1234) AND (attributes.id = 234) AND (attributes.y = 8)) LIMIT 1",
2265
+ "DELETE FROM attributes_nodes WHERE ((node_id = 1234) AND (attribute_id = 234))"]
2394
2266
  end
2395
2267
 
2396
2268
  it "should raise an error if the model object doesn't have a valid primary key" do
@@ -2479,10 +2351,6 @@ describe Sequel::Model, "many_to_many" do
2479
2351
  n.associations[:attributes] = 42
2480
2352
  n.attributes(:reload=>true).wont_equal 42
2481
2353
  DB.sqls.must_equal ["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id = 1234)"]
2482
- deprecated do
2483
- n.attributes(true).wont_equal 42
2484
- DB.sqls.must_equal ["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id = 1234)"]
2485
- end
2486
2354
  end
2487
2355
 
2488
2356
  it "should add item to cache if it exists when calling add_" do
@@ -2531,28 +2399,28 @@ describe Sequel::Model, "many_to_many" do
2531
2399
 
2532
2400
  it "should not create the add_, remove_, or remove_all_ methods if :read_only option is used" do
2533
2401
  @c2.many_to_many :attributes, :class => @c1, :read_only=>true
2534
- im = @c2.instance_methods.collect{|x| x.to_s}
2535
- im.must_include('attributes')
2536
- im.must_include('attributes_dataset')
2537
- im.wont_include('add_attribute')
2538
- im.wont_include('remove_attribute')
2539
- im.wont_include('remove_all_attributes')
2402
+ im = @c2.instance_methods
2403
+ im.must_include(:attributes)
2404
+ im.must_include(:attributes_dataset)
2405
+ im.wont_include(:add_attribute)
2406
+ im.wont_include(:remove_attribute)
2407
+ im.wont_include(:remove_all_attributes)
2540
2408
  end
2541
2409
 
2542
2410
  it "should not add associations methods directly to class" do
2543
2411
  @c2.many_to_many :attributes, :class => @c1
2544
- im = @c2.instance_methods.collect{|x| x.to_s}
2545
- im.must_include('attributes')
2546
- im.must_include('attributes_dataset')
2547
- im.must_include('add_attribute')
2548
- im.must_include('remove_attribute')
2549
- im.must_include('remove_all_attributes')
2550
- im2 = @c2.instance_methods(false).collect{|x| x.to_s}
2551
- im2.wont_include('attributes')
2552
- im2.wont_include('attributes_dataset')
2553
- im2.wont_include('add_attribute')
2554
- im2.wont_include('remove_attribute')
2555
- im2.wont_include('remove_all_attributes')
2412
+ im = @c2.instance_methods
2413
+ im.must_include(:attributes)
2414
+ im.must_include(:attributes_dataset)
2415
+ im.must_include(:add_attribute)
2416
+ im.must_include(:remove_attribute)
2417
+ im.must_include(:remove_all_attributes)
2418
+ im2 = @c2.instance_methods(false)
2419
+ im2.wont_include(:attributes)
2420
+ im2.wont_include(:attributes_dataset)
2421
+ im2.wont_include(:add_attribute)
2422
+ im2.wont_include(:remove_attribute)
2423
+ im2.wont_include(:remove_all_attributes)
2556
2424
  end
2557
2425
 
2558
2426
  it "should have an remove_all_ method that removes all associations" do
@@ -2625,7 +2493,7 @@ describe Sequel::Model, "many_to_many" do
2625
2493
 
2626
2494
  it "should call an _add_ method internally to add attributes" do
2627
2495
  @c2.many_to_many :attributes, :class => @c1
2628
- @c2.private_instance_methods.collect{|x| x.to_s}.sort.must_include("_add_attribute")
2496
+ @c2.private_instance_methods.must_include(:_add_attribute)
2629
2497
  p = @c2.load(:id=>10)
2630
2498
  c = @c1.load(:id=>123)
2631
2499
  def p._add_attribute(x)
@@ -2660,7 +2528,7 @@ describe Sequel::Model, "many_to_many" do
2660
2528
 
2661
2529
  it "should call a _remove_ method internally to remove attributes" do
2662
2530
  @c2.many_to_many :attributes, :class => @c1
2663
- @c2.private_instance_methods.collect{|x| x.to_s}.sort.must_include("_remove_attribute")
2531
+ @c2.private_instance_methods.must_include(:_remove_attribute)
2664
2532
  p = @c2.load(:id=>10)
2665
2533
  c = @c1.load(:id=>123)
2666
2534
  def p._remove_attribute(x)
@@ -2705,7 +2573,7 @@ describe Sequel::Model, "many_to_many" do
2705
2573
 
2706
2574
  it "should call a _remove_all_ method internally to remove attributes" do
2707
2575
  @c2.many_to_many :attributes, :class => @c1
2708
- @c2.private_instance_methods.collect{|x| x.to_s}.sort.must_include("_remove_all_attributes")
2576
+ @c2.private_instance_methods.must_include(:_remove_all_attributes)
2709
2577
  p = @c2.load(:id=>10)
2710
2578
  def p._remove_all_attributes
2711
2579
  @x = :foo
@@ -2766,40 +2634,6 @@ describe Sequel::Model, "many_to_many" do
2766
2634
  attributes.collect{|a| a.pk}.must_equal [20, 30]
2767
2635
  end
2768
2636
 
2769
- deprecated "should raise error and not call internal add or remove method if before callback returns false if raise_on_save_failure is true" do
2770
- p = @c2.load(:id=>10)
2771
- c = @c1.load(:id=>123)
2772
- @c2.many_to_many :attributes, :class => @c1, :before_add=>:ba, :before_remove=>:br
2773
- def p.ba(c) false end
2774
- def p._add_attribute; raise; end
2775
- def p._remove_attribute; raise; end
2776
- p.associations[:attributes] = []
2777
- p.raise_on_save_failure = true
2778
- proc{p.add_attribute(c)}.must_raise(Sequel::HookFailed)
2779
- p.attributes.must_equal []
2780
- p.associations[:attributes] = [c]
2781
- def p.br(c) false end
2782
- proc{p.remove_attribute(c)}.must_raise(Sequel::HookFailed)
2783
- p.attributes.must_equal [c]
2784
- end
2785
-
2786
- deprecated "should return nil and not call internal add or remove method if before callback returns false if raise_on_save_failure is false" do
2787
- p = @c2.load(:id=>10)
2788
- c = @c1.load(:id=>123)
2789
- p.raise_on_save_failure = false
2790
- @c2.many_to_many :attributes, :class => @c1, :before_add=>:ba, :before_remove=>:br
2791
- def p.ba(c) false end
2792
- def p._add_attribute; raise; end
2793
- def p._remove_attribute; raise; end
2794
- p.associations[:attributes] = []
2795
- p.add_attribute(c).must_be_nil
2796
- p.attributes.must_equal []
2797
- p.associations[:attributes] = [c]
2798
- def p.br(c) false end
2799
- p.remove_attribute(c).must_be_nil
2800
- p.attributes.must_equal [c]
2801
- end
2802
-
2803
2637
  it "should raise error and not call internal add or remove method if before callback calls cancel_action if raise_on_save_failure is true" do
2804
2638
  p = @c2.load(:id=>10)
2805
2639
  c = @c1.load(:id=>123)
@@ -3077,20 +2911,16 @@ describe Sequel::Model, "one_through_one" do
3077
2911
  n.associations[:attribute] = 42
3078
2912
  n.attribute(:reload=>true).wont_equal 42
3079
2913
  DB.sqls.must_equal ["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id = 1234) LIMIT 1"]
3080
- deprecated do
3081
- n.attribute(true).wont_equal 42
3082
- DB.sqls.must_equal ["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE (attributes_nodes.node_id = 1234) LIMIT 1"]
3083
- end
3084
2914
  end
3085
2915
 
3086
2916
  it "should not add associations methods directly to class" do
3087
2917
  @c2.one_through_one :attribute, :class => @c1
3088
- im = @c2.instance_methods.collect{|x| x.to_s}
3089
- im.must_include('attribute')
3090
- im.must_include('attribute_dataset')
3091
- im2 = @c2.instance_methods(false).collect{|x| x.to_s}
3092
- im2.wont_include('attribute')
3093
- im2.wont_include('attribute_dataset')
2918
+ im = @c2.instance_methods
2919
+ im.must_include(:attribute)
2920
+ im.must_include(:attribute_dataset)
2921
+ im2 = @c2.instance_methods(false)
2922
+ im2.wont_include(:attribute)
2923
+ im2.wont_include(:attribute_dataset)
3094
2924
  end
3095
2925
 
3096
2926
  it "should support after_load association callback" do
@@ -3116,9 +2946,9 @@ describe Sequel::Model, "one_through_one" do
3116
2946
 
3117
2947
  it "should not add a setter method if the :read_only option is true" do
3118
2948
  @c2.one_through_one :attribute, :class => @c1, :read_only=>true
3119
- im = @c2.instance_methods.collect{|x| x.to_s}
3120
- im.must_include('attribute')
3121
- im.wont_include('attribute=')
2949
+ im = @c2.instance_methods
2950
+ im.must_include(:attribute)
2951
+ im.wont_include(:attribute=)
3122
2952
  end
3123
2953
 
3124
2954
  it "should add a setter method" do
@@ -3130,10 +2960,8 @@ describe Sequel::Model, "one_through_one" do
3130
2960
  DB.sqls.must_equal ["SELECT * FROM attributes_nodes WHERE (node_id = 1234) LIMIT 1"]
3131
2961
 
3132
2962
  o.attribute = attrib
3133
- sqls = DB.sqls
3134
- ["INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (3, 1234)",
3135
- "INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 3)"].must_include(sqls.slice! 1)
3136
- sqls.must_equal ["SELECT * FROM attributes_nodes WHERE (node_id = 1234) LIMIT 1"]
2963
+ DB.sqls.must_equal ["SELECT * FROM attributes_nodes WHERE (node_id = 1234) LIMIT 1",
2964
+ "INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (3, 1234)"]
3137
2965
 
3138
2966
  DB.fetch = {:node_id=>1234, :attribute_id=>5}
3139
2967
  o.attribute = nil
@@ -3168,10 +2996,8 @@ describe Sequel::Model, "one_through_one" do
3168
2996
  DB.sqls.must_equal ["SELECT * FROM attributes_nodes WHERE (a AND (node_id = 1234)) LIMIT 1"]
3169
2997
 
3170
2998
  o.attribute = attrib
3171
- sqls = DB.sqls
3172
- ["INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (3, 1234)",
3173
- "INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 3)"].must_include(sqls.slice! 1)
3174
- sqls.must_equal ["SELECT * FROM attributes_nodes WHERE (a AND (node_id = 1234)) LIMIT 1"]
2999
+ DB.sqls.must_equal ["SELECT * FROM attributes_nodes WHERE (a AND (node_id = 1234)) LIMIT 1",
3000
+ "INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (3, 1234)"]
3175
3001
 
3176
3002
  DB.fetch = {:node_id=>1234, :attribute_id=>5}
3177
3003
  o.attribute = nil
@@ -3192,10 +3018,8 @@ describe Sequel::Model, "one_through_one" do
3192
3018
  DB.sqls.must_equal ["SELECT * FROM attributes_nodes WHERE (node_id = 5) LIMIT 1"]
3193
3019
 
3194
3020
  o.attribute = attrib
3195
- sqls = DB.sqls
3196
- ["INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (7, 5)",
3197
- "INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (5, 7)"].must_include(sqls.slice! 1)
3198
- sqls.must_equal ["SELECT * FROM attributes_nodes WHERE (node_id = 5) LIMIT 1"]
3021
+ DB.sqls.must_equal ["SELECT * FROM attributes_nodes WHERE (node_id = 5) LIMIT 1",
3022
+ "INSERT INTO attributes_nodes (attribute_id, node_id) VALUES (7, 5)"]
3199
3023
 
3200
3024
  DB.fetch = {:node_id=>1234, :attribute_id=>9}
3201
3025
  o.attribute = nil
@@ -3217,9 +3041,8 @@ describe Sequel::Model, "one_through_one" do
3217
3041
  DB.sqls.must_equal ["SELECT * FROM attributes_nodes WHERE ((node_id = 1234) AND (y = 5)) LIMIT 1"]
3218
3042
 
3219
3043
  o.attribute = attrib
3220
- sqls = DB.sqls
3221
- sqls.slice!(1).must_match(/\AINSERT INTO attributes_nodes \((attribute_id|z|node_id|y), (attribute_id|z|node_id|y), (attribute_id|z|node_id|y), (attribute_id|z|node_id|y)\) VALUES \((3|7|1234|5), (3|7|1234|5), (3|7|1234|5), (3|7|1234|5)\)\z/)
3222
- sqls.must_equal ["SELECT * FROM attributes_nodes WHERE ((node_id = 1234) AND (y = 5)) LIMIT 1"]
3044
+ DB.sqls.must_equal ["SELECT * FROM attributes_nodes WHERE ((node_id = 1234) AND (y = 5)) LIMIT 1",
3045
+ "INSERT INTO attributes_nodes (attribute_id, z, node_id, y) VALUES (3, 7, 1234, 5)"]
3223
3046
 
3224
3047
  DB.fetch = {:node_id=>1234, :attribute_id=>10, :y=>6, :z=>8}
3225
3048
  o.attribute = nil
@@ -3227,10 +3050,8 @@ describe Sequel::Model, "one_through_one" do
3227
3050
  "DELETE FROM attributes_nodes WHERE ((node_id = 1234) AND (y = 5) AND (attribute_id = 10) AND (z = 8))"]
3228
3051
 
3229
3052
  o.attribute = attrib
3230
- sqls = DB.sqls
3231
- ["UPDATE attributes_nodes SET attribute_id = 3, z = 7 WHERE ((node_id = 1234) AND (y = 5) AND (attribute_id = 10) AND (z = 8))",
3232
- "UPDATE attributes_nodes SET z = 7, attribute_id = 3 WHERE ((node_id = 1234) AND (y = 5) AND (attribute_id = 10) AND (z = 8))"].must_include(sqls.slice!(1))
3233
- sqls.must_equal ["SELECT * FROM attributes_nodes WHERE ((node_id = 1234) AND (y = 5)) LIMIT 1"]
3053
+ DB.sqls.must_equal ["SELECT * FROM attributes_nodes WHERE ((node_id = 1234) AND (y = 5)) LIMIT 1",
3054
+ "UPDATE attributes_nodes SET attribute_id = 3, z = 7 WHERE ((node_id = 1234) AND (y = 5) AND (attribute_id = 10) AND (z = 8))"]
3234
3055
  end
3235
3056
 
3236
3057
  it "should raise an error if the current model object that doesn't have a valid primary key" do
@@ -3249,7 +3070,7 @@ describe Sequel::Model, "one_through_one" do
3249
3070
 
3250
3071
  it "should make the change to the foreign_key value inside a _association= method" do
3251
3072
  @c2.one_through_one :attribute, :class => @c1
3252
- @c2.private_instance_methods.collect{|x| x.to_s}.sort.must_include("_attribute=")
3073
+ @c2.private_instance_methods.must_include(:_attribute=)
3253
3074
  attrib = @c1.new(:id=>3)
3254
3075
  o = @c2.new(:id => 1234)
3255
3076
  def o._attribute=(x)