sequel 4.49.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,6 +1,6 @@
1
1
  SEQUEL_ADAPTER_TEST = :oracle
2
2
 
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
3
+ require_relative 'spec_helper'
4
4
 
5
5
  unless DB.opts[:autosequence]
6
6
  warn "Running oracle adapter specs without :autosequence Database option results in many errors, use the :autosequence Database option when testing"
@@ -310,12 +310,4 @@ describe "An Oracle database" do
310
310
 
311
311
  DB[:books].select(:title).group_by(:title).count.must_equal 2
312
312
  end
313
-
314
- it "#for_update should use FOR UPDATE" do
315
- DB[:books].for_update.sql.must_equal 'SELECT * FROM "BOOKS" FOR UPDATE'
316
- end
317
-
318
- it "#lock_style should accept symbols" do
319
- DB[:books].lock_style(:update).sql.must_equal 'SELECT * FROM "BOOKS" FOR UPDATE'
320
- end
321
313
  end
@@ -1,31 +1,21 @@
1
1
  SEQUEL_ADAPTER_TEST = :postgres
2
2
 
3
- require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
3
+ require_relative 'spec_helper'
4
4
 
5
5
  uses_pg = Sequel::Postgres::USES_PG if DB.adapter_scheme == :postgres
6
6
  uses_pg_or_jdbc = uses_pg || DB.adapter_scheme == :jdbc
7
- # SEQUEL5: Remove native handling
8
7
 
9
- def DB.sqls
10
- (@sqls ||= [])
11
- end
12
- logger = Object.new
13
- def logger.method_missing(m, msg)
14
- DB.sqls << msg
15
- end
16
- DB.loggers << logger
17
-
18
- DB.extension :pg_array, :pg_hstore, :pg_range, :pg_row, :pg_inet, :pg_json, :pg_enum
8
+ DB.extension :pg_array, :pg_range, :pg_row, :pg_inet, :pg_json, :pg_enum
19
9
  begin
20
10
  DB.extension :pg_interval
21
11
  rescue LoadError
22
12
  end
13
+ DB.extension :pg_hstore if DB.type_supported?('hstore')
23
14
 
24
15
  describe "PostgreSQL", '#create_table' do
25
16
  before do
26
17
  @db = DB
27
18
  @db.test_connection
28
- DB.sqls.clear
29
19
  end
30
20
  after do
31
21
  @db.drop_table?(:tmp_dolls, :unlogged_dolls)
@@ -33,9 +23,9 @@ describe "PostgreSQL", '#create_table' do
33
23
 
34
24
  it "should create a temporary table" do
35
25
  @db.create_table(:tmp_dolls, :temp => true){text :name}
36
- check_sqls do
37
- @db.sqls.must_equal ['CREATE TEMPORARY TABLE "tmp_dolls" ("name" text)']
38
- end
26
+ @db.table_exists?(:tmp_dolls).must_equal true
27
+ @db.disconnect
28
+ @db.table_exists?(:tmp_dolls).must_equal false
39
29
  end
40
30
 
41
31
  it "temporary table should support :on_commit option" do
@@ -80,9 +70,6 @@ describe "PostgreSQL", '#create_table' do
80
70
 
81
71
  it "should create an unlogged table" do
82
72
  @db.create_table(:unlogged_dolls, :unlogged => true){text :name}
83
- check_sqls do
84
- @db.sqls.must_equal ['CREATE UNLOGGED TABLE "unlogged_dolls" ("name" text)']
85
- end
86
73
  end
87
74
 
88
75
  it "should create a table inheriting from another table" do
@@ -340,7 +327,7 @@ describe "A PostgreSQL database" do
340
327
  @db.get(Sequel.cast('10 20', :int2vector)).wont_equal 10
341
328
  end
342
329
 
343
- cspecify "should not typecast the money type incorrectly", [:do] do
330
+ it "should not typecast the money type incorrectly" do
344
331
  @db.get(Sequel.cast('10.01', :money)).wont_equal 0
345
332
  end
346
333
 
@@ -407,7 +394,6 @@ describe "A PostgreSQL dataset" do
407
394
  end
408
395
  before do
409
396
  @d.delete
410
- @db.sqls.clear
411
397
  end
412
398
  after do
413
399
  @db.drop_table?(:atest)
@@ -416,35 +402,6 @@ describe "A PostgreSQL dataset" do
416
402
  @db.drop_table?(:test)
417
403
  end
418
404
 
419
- it "should quote columns and tables using double quotes if quoting identifiers" do
420
- check_sqls do
421
- @d.select(:name).sql.must_equal 'SELECT "name" FROM "test"'
422
- @d.select(Sequel.lit('COUNT(*)')).sql.must_equal 'SELECT COUNT(*) FROM "test"'
423
- @d.select(Sequel.function(:max, :value)).sql.must_equal 'SELECT max("value") FROM "test"'
424
- @d.select(Sequel.function(:NOW)).sql.must_equal 'SELECT NOW() FROM "test"'
425
- @d.select(Sequel.function(:max, Sequel[:items][:value])).sql.must_equal 'SELECT max("items"."value") FROM "test"'
426
- @d.order(Sequel.desc(:name)).sql.must_equal 'SELECT * FROM "test" ORDER BY "name" DESC'
427
- @d.select(Sequel.lit('test.name AS item_name')).sql.must_equal 'SELECT test.name AS item_name FROM "test"'
428
- @d.select(Sequel.lit('"name"')).sql.must_equal 'SELECT "name" FROM "test"'
429
- @d.select(Sequel.lit('max(test."name") AS "max_name"')).sql.must_equal 'SELECT max(test."name") AS "max_name" FROM "test"'
430
- @d.insert_sql(:x => :y).must_match(/\AINSERT INTO "test" \("x"\) VALUES \("y"\)( RETURNING NULL)?\z/)
431
-
432
- @d.select(Sequel.function(:test, :abc, 'hello')).sql.must_equal "SELECT test(\"abc\", 'hello') FROM \"test\""
433
- @d.select(Sequel.function(:test, Sequel[:abc][:def], 'hello')).sql.must_equal "SELECT test(\"abc\".\"def\", 'hello') FROM \"test\""
434
- @d.select(Sequel.function(:test, Sequel[:abc][:def], 'hello').as(:x2)).sql.must_equal "SELECT test(\"abc\".\"def\", 'hello') AS \"x2\" FROM \"test\""
435
- @d.insert_sql(:value => 333).must_match(/\AINSERT INTO "test" \("value"\) VALUES \(333\)( RETURNING NULL)?\z/)
436
- end
437
- end
438
-
439
- it "should quote fields correctly when reversing the order if quoting identifiers" do
440
- check_sqls do
441
- @d.reverse_order(:name).sql.must_equal 'SELECT * FROM "test" ORDER BY "name" DESC'
442
- @d.reverse_order(Sequel.desc(:name)).sql.must_equal 'SELECT * FROM "test" ORDER BY "name" ASC'
443
- @d.reverse_order(:name, Sequel.desc(:test)).sql.must_equal 'SELECT * FROM "test" ORDER BY "name" DESC, "test" ASC'
444
- @d.reverse_order(Sequel.desc(:name), :test).sql.must_equal 'SELECT * FROM "test" ORDER BY "name" ASC, "test" DESC'
445
- end
446
- end
447
-
448
405
  it "should support regexps" do
449
406
  @d.insert(:name => 'abc', :value => 1)
450
407
  @d.insert(:name => 'bcd', :value => 2)
@@ -591,27 +548,13 @@ describe "A PostgreSQL dataset" do
591
548
  @db.transaction(:synchronous=>true){}
592
549
  @db.transaction(:synchronous=>:off){}
593
550
  @db.transaction(:synchronous=>false){}
594
- @db.sqls.grep(/synchronous/).must_equal ["SET LOCAL synchronous_commit = on", "SET LOCAL synchronous_commit = on", "SET LOCAL synchronous_commit = off", "SET LOCAL synchronous_commit = off"]
595
551
 
596
- @db.sqls.clear
597
552
  @db.transaction(:synchronous=>nil){}
598
- check_sqls do
599
- @db.sqls.must_equal ['BEGIN', 'COMMIT']
600
- end
601
-
602
553
  if @db.server_version >= 90100
603
- @db.sqls.clear
604
554
  @db.transaction(:synchronous=>:local){}
605
- check_sqls do
606
- @db.sqls.grep(/synchronous/).must_equal ["SET LOCAL synchronous_commit = local"]
607
- end
608
555
 
609
556
  if @db.server_version >= 90200
610
- @db.sqls.clear
611
557
  @db.transaction(:synchronous=>:remote_write){}
612
- check_sqls do
613
- @db.sqls.grep(/synchronous/).must_equal ["SET LOCAL synchronous_commit = remote_write"]
614
- end
615
558
  end
616
559
  end
617
560
  end
@@ -621,7 +564,6 @@ describe "A PostgreSQL dataset" do
621
564
  @db.transaction(:read_only=>false){}
622
565
  @db.transaction(:isolation=>:serializable, :read_only=>true){}
623
566
  @db.transaction(:isolation=>:serializable, :read_only=>false){}
624
- @db.sqls.grep(/READ/).must_equal ["SET TRANSACTION READ ONLY", "SET TRANSACTION READ WRITE", "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY", "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE"]
625
567
  end
626
568
 
627
569
  it "should have #transaction support deferrable transactions" do
@@ -631,43 +573,38 @@ describe "A PostgreSQL dataset" do
631
573
  @db.transaction(:deferrable=>false, :read_only=>false){}
632
574
  @db.transaction(:isolation=>:serializable, :deferrable=>true, :read_only=>true){}
633
575
  @db.transaction(:isolation=>:serializable, :deferrable=>false, :read_only=>false){}
634
- @db.sqls.grep(/DEF/).must_equal ["SET TRANSACTION DEFERRABLE", "SET TRANSACTION NOT DEFERRABLE", "SET TRANSACTION READ ONLY DEFERRABLE", "SET TRANSACTION READ WRITE NOT DEFERRABLE", "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE", "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE NOT DEFERRABLE"]
635
576
  end if DB.server_version >= 90100
636
577
 
637
578
  it "should support creating indexes concurrently" do
638
579
  @db.add_index :test, [:name, :value], :concurrently=>true
639
- check_sqls do
640
- @db.sqls.must_equal ['CREATE INDEX CONCURRENTLY "test_name_value_index" ON "test" ("name", "value")']
641
- end
642
580
  end
643
581
 
644
582
  it "should support dropping indexes only if they already exist" do
583
+ proc{@db.drop_index :test, [:name, :value], :name=>'tnv1'}.must_raise Sequel::DatabaseError
584
+ @db.drop_index :test, [:name, :value], :if_exists=>true, :name=>'tnv1'
645
585
  @db.add_index :test, [:name, :value], :name=>'tnv1'
646
- @db.sqls.clear
647
586
  @db.drop_index :test, [:name, :value], :if_exists=>true, :name=>'tnv1'
648
- check_sqls do
649
- @db.sqls.must_equal ['DROP INDEX IF EXISTS "tnv1"']
650
- end
651
587
  end
652
588
 
653
589
  it "should support CASCADE when dropping indexes" do
654
- @db.add_index :test, [:name, :value], :name=>'tnv2'
655
- @db.sqls.clear
590
+ @db.add_index :test, [:name, :value], :name=>'tnv2', :unique=>true
591
+ @db.create_table(:atest){text :name; integer :value; foreign_key [:name, :value], :test, :key=>[:name, :value]}
592
+ @db.foreign_key_list(:atest).length.must_equal 1
656
593
  @db.drop_index :test, [:name, :value], :cascade=>true, :name=>'tnv2'
657
- check_sqls do
658
- @db.sqls.must_equal ['DROP INDEX "tnv2" CASCADE']
659
- end
594
+ @db.foreign_key_list(:atest).length.must_equal 0
660
595
  end
661
596
 
662
597
  it "should support dropping indexes concurrently" do
663
598
  @db.add_index :test, [:name, :value], :name=>'tnv2'
664
- @db.sqls.clear
665
599
  @db.drop_index :test, [:name, :value], :concurrently=>true, :name=>'tnv2'
666
- check_sqls do
667
- @db.sqls.must_equal ['DROP INDEX CONCURRENTLY "tnv2"']
668
- end
669
600
  end if DB.server_version >= 90200
670
601
 
602
+ it "should support creating indexes only if they do not exist" do
603
+ @db.add_index :test, [:name, :value], :name=>'tnv3'
604
+ proc{@db.add_index :test, [:name, :value], :name=>'tnv3'}.must_raise Sequel::DatabaseError
605
+ @db.add_index :test, [:name, :value], :if_not_exists=>true, :name=>'tnv3'
606
+ end if DB.server_version >= 90500
607
+
671
608
  it "#lock should lock table if inside a transaction" do
672
609
  @db.transaction{@d.lock('EXCLUSIVE'); @d.insert(:name=>'a')}
673
610
  end
@@ -801,7 +738,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
801
738
  @db.drop_table?(:test3)
802
739
  end
803
740
 
804
- cspecify "should store milliseconds in time fields for Time objects", [:do], [:swift] do
741
+ it "should store milliseconds in time fields for Time objects" do
805
742
  t = Time.now
806
743
  @d.insert(:time=>t)
807
744
  t2 = @d.get(:time)
@@ -810,7 +747,7 @@ describe "A PostgreSQL dataset with a timestamp field" do
810
747
  (t2.is_a?(Time) ? t2.usec : t2.strftime('%N').to_i/1000).must_equal t.usec
811
748
  end
812
749
 
813
- cspecify "should store milliseconds in time fields for DateTime objects", [:do], [:swift] do
750
+ it "should store milliseconds in time fields for DateTime objects" do
814
751
  t = DateTime.now
815
752
  @d.insert(:time=>t)
816
753
  t2 = @d.get(:time)
@@ -837,13 +774,11 @@ describe "A PostgreSQL dataset with a timestamp field" do
837
774
  @db.convert_infinite_timestamps = 't'
838
775
  @db[:test3].get(:time).must_equal 1.0/0.0
839
776
  @db.convert_infinite_timestamps = 'f'
840
- if RUBY_VERSION >= '1.9'
841
- proc{@db[:test3].get(:time)}.must_raise ArgumentError, Sequel::InvalidValue
842
- @db.convert_infinite_timestamps = nil
843
- proc{@db[:test3].get(:time)}.must_raise ArgumentError, Sequel::InvalidValue
844
- @db.convert_infinite_timestamps = false
845
- proc{@db[:test3].get(:time)}.must_raise ArgumentError, Sequel::InvalidValue
846
- end
777
+ proc{@db[:test3].get(:time)}.must_raise ArgumentError, Sequel::InvalidValue
778
+ @db.convert_infinite_timestamps = nil
779
+ proc{@db[:test3].get(:time)}.must_raise ArgumentError, Sequel::InvalidValue
780
+ @db.convert_infinite_timestamps = false
781
+ proc{@db[:test3].get(:time)}.must_raise ArgumentError, Sequel::InvalidValue
847
782
 
848
783
  @d.update(:time=>Sequel.cast('-infinity', DateTime))
849
784
  @db.convert_infinite_timestamps = :nil
@@ -952,7 +887,6 @@ describe "A PostgreSQL database" do
952
887
  before do
953
888
  @db = DB
954
889
  @db.drop_table?(:posts)
955
- @db.sqls.clear
956
890
  end
957
891
  after do
958
892
  @db.drop_table?(:posts)
@@ -985,12 +919,7 @@ describe "A PostgreSQL database" do
985
919
 
986
920
  it "should support opclass specification" do
987
921
  @db.create_table(:posts){text :title; text :body; integer :user_id; index(:user_id, :opclass => :int4_ops, :type => :btree)}
988
- check_sqls do
989
- @db.sqls.must_equal [
990
- 'CREATE TABLE "posts" ("title" text, "body" text, "user_id" integer)',
991
- 'CREATE INDEX "posts_user_id_index" ON "posts" USING btree ("user_id" int4_ops)'
992
- ]
993
- end
922
+ proc{@db.create_table(:posts){text :title; text :body; integer :user_id; index(:user_id, :opclass => :bogus_opclass, :type => :btree)}}.must_raise Sequel::DatabaseError
994
923
  end
995
924
 
996
925
  it "should support fulltext indexes and searching" do
@@ -1035,52 +964,25 @@ describe "A PostgreSQL database" do
1035
964
 
1036
965
  it "should support spatial indexes" do
1037
966
  @db.create_table(:posts){box :geom; spatial_index [:geom]}
1038
- check_sqls do
1039
- @db.sqls.must_equal [
1040
- 'CREATE TABLE "posts" ("geom" box)',
1041
- 'CREATE INDEX "posts_geom_index" ON "posts" USING gist ("geom")'
1042
- ]
1043
- end
1044
967
  end
1045
968
 
1046
969
  it "should support indexes with index type" do
1047
970
  @db.create_table(:posts){point :p; index :p, :type => 'gist'}
1048
- check_sqls do
1049
- @db.sqls.must_equal [
1050
- 'CREATE TABLE "posts" ("p" point)',
1051
- 'CREATE INDEX "posts_p_index" ON "posts" USING gist ("p")'
1052
- ]
1053
- end
1054
971
  end
1055
972
 
1056
973
  it "should support unique indexes with index type" do
1057
- @db.create_table(:posts){varchar :title, :size => 5; index :title, :type => 'btree', :unique => true}
1058
- check_sqls do
1059
- @db.sqls.must_equal [
1060
- 'CREATE TABLE "posts" ("title" varchar(5))',
1061
- 'CREATE UNIQUE INDEX "posts_title_index" ON "posts" USING btree ("title")'
1062
- ]
1063
- end
974
+ @db.create_table(:posts){varchar :title, :size => 5; index :title, :type => 'btree', :unique => true, :name=>:post_index_foo}
975
+ @db.indexes(:posts).length.must_equal 1
976
+ @db.indexes(:posts)[:post_index_foo][:unique].must_equal true
1064
977
  end
1065
978
 
1066
979
  it "should support partial indexes" do
1067
980
  @db.create_table(:posts){varchar :title, :size => 5; index :title, :where => {:title => '5'}}
1068
- check_sqls do
1069
- @db.sqls.must_equal [
1070
- 'CREATE TABLE "posts" ("title" varchar(5))',
1071
- 'CREATE INDEX "posts_title_index" ON "posts" ("title") WHERE ("title" = \'5\')'
1072
- ]
1073
- end
1074
981
  end
1075
982
 
1076
- it "should support identifiers for table names in indicies" do
1077
- @db.create_table(Sequel::SQL::Identifier.new(:posts)){varchar :title, :size => 5; index :title, :where => {:title => '5'}}
1078
- check_sqls do
1079
- @db.sqls.must_equal [
1080
- 'CREATE TABLE "posts" ("title" varchar(5))',
1081
- 'CREATE INDEX "posts_title_index" ON "posts" ("title") WHERE ("title" = \'5\')'
1082
- ]
1083
- end
983
+ it "should support identifiers for table names when creating indexes" do
984
+ @db.create_table(Sequel::SQL::Identifier.new(:posts)){varchar :title, :size => 5; index :title}
985
+ @db.indexes(:posts).length.must_equal 1
1084
986
  end
1085
987
 
1086
988
  it "should support renaming tables" do
@@ -1100,7 +1002,6 @@ describe "Postgres::Dataset#import" do
1100
1002
  before do
1101
1003
  @db = DB
1102
1004
  @db.create_table!(:test){primary_key :x; Integer :y}
1103
- @db.sqls.clear
1104
1005
  @ds = @db[:test]
1105
1006
  end
1106
1007
  after do
@@ -1109,9 +1010,6 @@ describe "Postgres::Dataset#import" do
1109
1010
 
1110
1011
  it "#import should a single insert statement" do
1111
1012
  @ds.import([:x, :y], [[1, 2], [3, 4]])
1112
- check_sqls do
1113
- @db.sqls.must_equal ['BEGIN', 'INSERT INTO "test" ("x", "y") VALUES (1, 2), (3, 4)', 'COMMIT']
1114
- end
1115
1013
  @ds.all.must_equal [{:x=>1, :y=>2}, {:x=>3, :y=>4}]
1116
1014
  end
1117
1015
 
@@ -1135,7 +1033,6 @@ describe "Postgres::Dataset#insert" do
1135
1033
  before do
1136
1034
  @db = DB
1137
1035
  @db.create_table!(:test5){primary_key :xid; Integer :value}
1138
- @db.sqls.clear
1139
1036
  @ds = @db[:test5]
1140
1037
  end
1141
1038
  after do
@@ -1153,11 +1050,8 @@ describe "Postgres::Dataset#insert" do
1153
1050
  @ds.all.must_equal [{:xid=>1, :value=>10}]
1154
1051
  end
1155
1052
 
1156
- it "should use INSERT RETURNING" do
1053
+ it "should have insert return primary key value" do
1157
1054
  @ds.insert(:value=>10).must_equal 1
1158
- check_sqls do
1159
- @db.sqls.last.must_equal 'INSERT INTO "test5" ("value") VALUES (10) RETURNING "xid"'
1160
- end
1161
1055
  end
1162
1056
 
1163
1057
  it "should have insert_select insert the record and return the inserted record" do
@@ -1234,7 +1128,7 @@ describe "Postgres::Database schema qualified tables" do
1234
1128
  @db.create_table(Sequel[:schema_test][:domains]){integer :i}
1235
1129
  sch = @db.schema(Sequel[:schema_test][:domains])
1236
1130
  cs = sch.map{|x| x.first}
1237
- cs.must_include(:i)
1131
+ cs.first.must_equal :i
1238
1132
  cs.wont_include(:data_type)
1239
1133
  end
1240
1134
 
@@ -1243,7 +1137,7 @@ describe "Postgres::Database schema qualified tables" do
1243
1137
  @db.create_table(Sequel[:schema_test][:domains]){integer :i}
1244
1138
  sch = @db.schema(:domains, :schema=>:schema_test)
1245
1139
  cs = sch.map{|x| x.first}
1246
- cs.must_include(:i)
1140
+ cs.first.must_equal :i
1247
1141
  cs.wont_include(:d)
1248
1142
  @db.drop_table(:domains)
1249
1143
  end
@@ -1519,19 +1413,19 @@ if DB.server_version >= 80300
1519
1413
  it "should search by indexed column" do
1520
1414
  record = {:title => "oopsla conference", :body => "test"}
1521
1415
  @ds.insert(record)
1522
- @ds.full_text_search(:title, "oopsla").all.must_include(record)
1416
+ @ds.full_text_search(:title, "oopsla").all.must_equal [record]
1523
1417
  end
1524
1418
 
1525
1419
  it "should join multiple coumns with spaces to search by last words in row" do
1526
1420
  record = {:title => "multiple words", :body => "are easy to search"}
1527
1421
  @ds.insert(record)
1528
- @ds.full_text_search([:title, :body], "words").all.must_include(record)
1422
+ @ds.full_text_search([:title, :body], "words").all.must_equal [record]
1529
1423
  end
1530
1424
 
1531
1425
  it "should return rows with a NULL in one column if a match in another column" do
1532
1426
  record = {:title => "multiple words", :body =>nil}
1533
1427
  @ds.insert(record)
1534
- @ds.full_text_search([:title, :body], "words").all.must_include(record)
1428
+ @ds.full_text_search([:title, :body], "words").all.must_equal [record]
1535
1429
  end
1536
1430
  end
1537
1431
  end
@@ -1663,7 +1557,6 @@ if DB.adapter_scheme == :postgres
1663
1557
  before(:all) do
1664
1558
  @db = DB
1665
1559
  @db.create_table!(:test_cursor){Integer :x}
1666
- @db.sqls.clear
1667
1560
  @ds = @db[:test_cursor]
1668
1561
  @db.transaction{1001.times{|i| @ds.insert(i)}}
1669
1562
  end
@@ -1687,23 +1580,19 @@ if DB.adapter_scheme == :postgres
1687
1580
  end
1688
1581
 
1689
1582
  it "should respect the :rows_per_fetch option" do
1690
- @db.sqls.clear
1583
+ i = 0
1584
+ @ds = @ds.with_extend{define_method(:execute){|*a, &block| i+=1; super(*a, &block);}}
1691
1585
  @ds.use_cursor.all
1692
- check_sqls do
1693
- @db.sqls.length.must_equal 6
1694
- @db.sqls.clear
1695
- end
1586
+ i.must_equal 2
1587
+
1588
+ i = 0
1696
1589
  @ds.use_cursor(:rows_per_fetch=>100).all
1697
- check_sqls do
1698
- @db.sqls.length.must_equal 15
1699
- end
1590
+ i.must_equal 11
1700
1591
  end
1701
1592
 
1702
1593
  it "should respect the :hold=>true option for creating the cursor WITH HOLD and not using a transaction" do
1703
1594
  @ds.use_cursor.each{@db.in_transaction?.must_equal true}
1704
- check_sqls{@db.sqls.any?{|s| s =~ /WITH HOLD/}.must_equal false}
1705
1595
  @ds.use_cursor(:hold=>true).each{@db.in_transaction?.must_equal false}
1706
- check_sqls{@db.sqls.any?{|s| s =~ /WITH HOLD/}.must_equal true}
1707
1596
  end
1708
1597
 
1709
1598
  it "should support updating individual rows based on a cursor" do
@@ -1777,39 +1666,6 @@ if DB.adapter_scheme == :postgres
1777
1666
  @db[:foo].get(:bar).must_equal 'foo'.reverse
1778
1667
  end
1779
1668
  end
1780
-
1781
- describe "Postgres::PG_NAMED_TYPES" do
1782
- before(:all) do
1783
- deprecated do
1784
- @db = DB
1785
- @cp = @db.conversion_procs.dup
1786
- @db.conversion_procs.delete(1013)
1787
- Sequel::Postgres::PG_NAMED_TYPES[:oidvector] = lambda{|v| v.reverse}
1788
- @db.reset_conversion_procs
1789
- @db.register_array_type('oidvector')
1790
- end
1791
- end
1792
- after(:all) do
1793
- deprecated do
1794
- Sequel::Postgres::PG_NAMED_TYPES.delete(:oidvector)
1795
- @db.conversion_procs.replace(@cp)
1796
- @db.drop_table?(:foo)
1797
- @db.drop_enum(:foo_enum) rescue nil
1798
- end
1799
- end
1800
-
1801
- deprecated "should look up conversion procs by name" do
1802
- @db.create_table!(:foo){oidvector :bar}
1803
- @db[:foo].insert(Sequel.cast('21', :oidvector))
1804
- @db[:foo].get(:bar).must_equal '12'
1805
- end
1806
-
1807
- deprecated "should handle array types of named types" do
1808
- @db.create_table!(:foo){column :bar, 'oidvector[]'}
1809
- @db[:foo].insert(Sequel.pg_array(['21'], :oidvector))
1810
- @db[:foo].get(:bar).must_equal ['12']
1811
- end
1812
- end
1813
1669
  end
1814
1670
 
1815
1671
  if uses_pg_or_jdbc && DB.server_version >= 90000
@@ -2076,56 +1932,35 @@ describe 'PostgreSQL special float handling' do
2076
1932
  before do
2077
1933
  @db = DB
2078
1934
  @db.create_table!(:test5){Float :value}
2079
- @db.sqls.clear
2080
1935
  @ds = @db[:test5]
2081
1936
  end
2082
1937
  after do
2083
1938
  @db.drop_table?(:test5)
2084
1939
  end
2085
1940
 
2086
- check_sqls do
2087
- it 'should quote NaN' do
2088
- nan = 0.0/0.0
2089
- @ds.insert_sql(:value => nan).must_equal %q{INSERT INTO "test5" ("value") VALUES ('NaN')}
2090
- end
2091
-
2092
- it 'should quote +Infinity' do
2093
- inf = 1.0/0.0
2094
- @ds.insert_sql(:value => inf).must_equal %q{INSERT INTO "test5" ("value") VALUES ('Infinity')}
2095
- end
2096
-
2097
- it 'should quote -Infinity' do
2098
- inf = -1.0/0.0
2099
- @ds.insert_sql(:value => inf).must_equal %q{INSERT INTO "test5" ("value") VALUES ('-Infinity')}
2100
- end
1941
+ it 'inserts NaN' do
1942
+ nan = 0.0/0.0
1943
+ @ds.insert(:value=>nan)
1944
+ @ds.all[0][:value].nan?.must_equal true
2101
1945
  end
2102
1946
 
2103
- if DB.adapter_scheme == :postgres
2104
- it 'inserts NaN' do
2105
- nan = 0.0/0.0
2106
- @ds.insert(:value=>nan)
2107
- @ds.all[0][:value].nan?.must_equal true
2108
- end
2109
-
2110
- it 'inserts +Infinity' do
2111
- inf = 1.0/0.0
2112
- @ds.insert(:value=>inf)
2113
- @ds.all[0][:value].infinite?.must_be :>, 0
2114
- end
1947
+ it 'inserts +Infinity' do
1948
+ inf = 1.0/0.0
1949
+ @ds.insert(:value=>inf)
1950
+ @ds.all[0][:value].infinite?.must_be :>, 0
1951
+ end
2115
1952
 
2116
- it 'inserts -Infinity' do
2117
- inf = -1.0/0.0
2118
- @ds.insert(:value=>inf)
2119
- @ds.all[0][:value].infinite?.must_be :<, 0
2120
- end
1953
+ it 'inserts -Infinity' do
1954
+ inf = -1.0/0.0
1955
+ @ds.insert(:value=>inf)
1956
+ @ds.all[0][:value].infinite?.must_be :<, 0
2121
1957
  end
2122
- end
1958
+ end if DB.adapter_scheme == :postgres
2123
1959
 
2124
1960
  describe 'PostgreSQL array handling' do
2125
1961
  before(:all) do
2126
1962
  @db = DB
2127
1963
  @ds = @db[:items]
2128
- @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
2129
1964
  @tp = lambda{@db.schema(:items).map{|a| a.last[:type]}}
2130
1965
  end
2131
1966
  after do
@@ -2144,27 +1979,23 @@ describe 'PostgreSQL array handling' do
2144
1979
  @ds.insert(Sequel.pg_array([1], :int2), Sequel.pg_array([nil, 2], :int4), Sequel.pg_array([3, nil], :int8), Sequel.pg_array([4, nil, 4.5], :real), Sequel.pg_array([5, nil, 5.5], "double precision"))
2145
1980
  @ds.count.must_equal 1
2146
1981
  rs = @ds.all
2147
- if @native
2148
- rs.must_equal [{:i2=>[1], :i4=>[nil, 2], :i8=>[3, nil], :r=>[4.0, nil, 4.5], :dp=>[5.0, nil, 5.5]}]
2149
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2150
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2151
- @ds.delete
2152
- @ds.insert(rs.first)
2153
- @ds.all.must_equal rs
2154
- end
1982
+ rs.must_equal [{:i2=>[1], :i4=>[nil, 2], :i8=>[3, nil], :r=>[4.0, nil, 4.5], :dp=>[5.0, nil, 5.5]}]
1983
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
1984
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
1985
+ @ds.delete
1986
+ @ds.insert(rs.first)
1987
+ @ds.all.must_equal rs
2155
1988
 
2156
1989
  @ds.delete
2157
1990
  @ds.insert(Sequel.pg_array([[1], [2]], :int2), Sequel.pg_array([[nil, 2], [3, 4]], :int4), Sequel.pg_array([[3, nil], [nil, nil]], :int8), Sequel.pg_array([[4, nil], [nil, 4.5]], :real), Sequel.pg_array([[5, nil], [nil, 5.5]], "double precision"))
2158
1991
 
2159
1992
  rs = @ds.all
2160
- if @native
2161
- rs.must_equal [{:i2=>[[1], [2]], :i4=>[[nil, 2], [3, 4]], :i8=>[[3, nil], [nil, nil]], :r=>[[4, nil], [nil, 4.5]], :dp=>[[5, nil], [nil, 5.5]]}]
2162
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2163
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2164
- @ds.delete
2165
- @ds.insert(rs.first)
2166
- @ds.all.must_equal rs
2167
- end
1993
+ rs.must_equal [{:i2=>[[1], [2]], :i4=>[[nil, 2], [3, 4]], :i8=>[[3, nil], [nil, nil]], :r=>[[4, nil], [nil, 4.5]], :dp=>[[5, nil], [nil, 5.5]]}]
1994
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
1995
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
1996
+ @ds.delete
1997
+ @ds.insert(rs.first)
1998
+ @ds.all.must_equal rs
2168
1999
  end
2169
2000
 
2170
2001
  it 'insert and retrieve decimal arrays' do
@@ -2175,26 +2006,22 @@ describe 'PostgreSQL array handling' do
2175
2006
  @ds.insert(Sequel.pg_array([BigDecimal.new('1.000000000000000000001'), nil, BigDecimal.new('1')], :numeric))
2176
2007
  @ds.count.must_equal 1
2177
2008
  rs = @ds.all
2178
- if @native
2179
- rs.must_equal [{:n=>[BigDecimal.new('1.000000000000000000001'), nil, BigDecimal.new('1')]}]
2180
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2181
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2182
- @ds.delete
2183
- @ds.insert(rs.first)
2184
- @ds.all.must_equal rs
2185
- end
2009
+ rs.must_equal [{:n=>[BigDecimal.new('1.000000000000000000001'), nil, BigDecimal.new('1')]}]
2010
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2011
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2012
+ @ds.delete
2013
+ @ds.insert(rs.first)
2014
+ @ds.all.must_equal rs
2186
2015
 
2187
2016
  @ds.delete
2188
2017
  @ds.insert(Sequel.pg_array([[BigDecimal.new('1.0000000000000000000000000000001'), nil], [nil, BigDecimal.new('1')]], :numeric))
2189
2018
  rs = @ds.all
2190
- if @native
2191
- rs.must_equal [{:n=>[[BigDecimal.new('1.0000000000000000000000000000001'), nil], [nil, BigDecimal.new('1')]]}]
2192
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2193
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2194
- @ds.delete
2195
- @ds.insert(rs.first)
2196
- @ds.all.must_equal rs
2197
- end
2019
+ rs.must_equal [{:n=>[[BigDecimal.new('1.0000000000000000000000000000001'), nil], [nil, BigDecimal.new('1')]]}]
2020
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2021
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2022
+ @ds.delete
2023
+ @ds.insert(rs.first)
2024
+ @ds.all.must_equal rs
2198
2025
  end
2199
2026
 
2200
2027
  it 'insert and retrieve string arrays' do
@@ -2207,26 +2034,22 @@ describe 'PostgreSQL array handling' do
2207
2034
  @ds.insert(Sequel.pg_array(['a', nil, 'NULL', 'b"\'c'], 'char(4)'), Sequel.pg_array(['a', nil, 'NULL', 'b"\'c', '', ''], :varchar), Sequel.pg_array(['a', nil, 'NULL', 'b"\'c'], :text))
2208
2035
  @ds.count.must_equal 1
2209
2036
  rs = @ds.all
2210
- if @native
2211
- rs.must_equal [{:c=>['a ', nil, 'NULL', 'b"\'c'], :vc=>['a', nil, 'NULL', 'b"\'c', '', ''], :t=>['a', nil, 'NULL', 'b"\'c']}]
2212
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2213
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2214
- @ds.delete
2215
- @ds.insert(rs.first)
2216
- @ds.all.must_equal rs
2217
- end
2037
+ rs.must_equal [{:c=>['a ', nil, 'NULL', 'b"\'c'], :vc=>['a', nil, 'NULL', 'b"\'c', '', ''], :t=>['a', nil, 'NULL', 'b"\'c']}]
2038
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2039
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2040
+ @ds.delete
2041
+ @ds.insert(rs.first)
2042
+ @ds.all.must_equal rs
2218
2043
 
2219
2044
  @ds.delete
2220
2045
  @ds.insert(Sequel.pg_array([[['a'], [nil]], [['NULL'], ['b"\'c']]], 'char(4)'), Sequel.pg_array([[['a[],\\[\\]\\,\\""NULL",'], ['']], [['NULL'], ['b"\'c']]], :varchar), Sequel.pg_array([[['a'], [nil]], [['NULL'], ['b"\'c']]], :text))
2221
2046
  rs = @ds.all
2222
- if @native
2223
- rs.must_equal [{:c=>[[['a '], [nil]], [['NULL'], ['b"\'c']]], :vc=>[[['a[],\\[\\]\\,\\""NULL",'], ['']], [['NULL'], ['b"\'c']]], :t=>[[['a'], [nil]], [['NULL'], ['b"\'c']]]}]
2224
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2225
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2226
- @ds.delete
2227
- @ds.insert(rs.first)
2228
- @ds.all.must_equal rs
2229
- end
2047
+ rs.must_equal [{:c=>[[['a '], [nil]], [['NULL'], ['b"\'c']]], :vc=>[[['a[],\\[\\]\\,\\""NULL",'], ['']], [['NULL'], ['b"\'c']]], :t=>[[['a'], [nil]], [['NULL'], ['b"\'c']]]}]
2048
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2049
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2050
+ @ds.delete
2051
+ @ds.insert(rs.first)
2052
+ @ds.all.must_equal rs
2230
2053
  end
2231
2054
 
2232
2055
  it 'insert and retrieve arrays of other types' do
@@ -2246,14 +2069,12 @@ describe 'PostgreSQL array handling' do
2246
2069
  @ds.insert(Sequel.pg_array([true, false], :bool), Sequel.pg_array([d, nil], :date), Sequel.pg_array([t, nil], :time), Sequel.pg_array([ts, nil], :timestamp), Sequel.pg_array([ts, nil], :timestamptz))
2247
2070
  @ds.count.must_equal 1
2248
2071
  rs = @ds.all
2249
- if @native
2250
- rs.must_equal [{:b=>[true, false], :d=>[d, nil], :t=>[t, nil], :ts=>[ts, nil], :tstz=>[ts, nil]}]
2251
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2252
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2253
- @ds.delete
2254
- @ds.insert(rs.first)
2255
- @ds.all.must_equal rs
2256
- end
2072
+ rs.must_equal [{:b=>[true, false], :d=>[d, nil], :t=>[t, nil], :ts=>[ts, nil], :tstz=>[ts, nil]}]
2073
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2074
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2075
+ @ds.delete
2076
+ @ds.insert(rs.first)
2077
+ @ds.all.must_equal rs
2257
2078
 
2258
2079
  @db.create_table!(:items) do
2259
2080
  column :ba, 'bytea[]'
@@ -2263,15 +2084,13 @@ describe 'PostgreSQL array handling' do
2263
2084
  @tp.call.must_equal [:blob_array, :time_timezone_array, :oid_array]
2264
2085
  @ds.insert(Sequel.pg_array([Sequel.blob("a\0"), nil], :bytea), Sequel.pg_array([t, nil], :timetz), Sequel.pg_array([1, 2, 3], :oid))
2265
2086
  @ds.count.must_equal 1
2266
- if @native
2267
- rs = @ds.all
2268
- rs.must_equal [{:ba=>[Sequel.blob("a\0"), nil], :tz=>[t, nil], :o=>[1, 2, 3]}]
2269
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2270
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2271
- @ds.delete
2272
- @ds.insert(rs.first)
2273
- @ds.all.must_equal rs
2274
- end
2087
+ rs = @ds.all
2088
+ rs.must_equal [{:ba=>[Sequel.blob("a\0"), nil], :tz=>[t, nil], :o=>[1, 2, 3]}]
2089
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2090
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2091
+ @ds.delete
2092
+ @ds.insert(rs.first)
2093
+ @ds.all.must_equal rs
2275
2094
 
2276
2095
  @db.create_table!(:items) do
2277
2096
  column :x, 'xml[]'
@@ -2295,21 +2114,19 @@ describe 'PostgreSQL array handling' do
2295
2114
  Sequel.pg_array(['N'], :name),
2296
2115
  Sequel.pg_array(['1 2'], :oidvector))
2297
2116
  @ds.count.must_equal 1
2298
- if @native
2299
- rs = @ds.all
2300
- r = rs.first
2301
- m = r.delete(:m)
2302
- m.class.must_equal(Sequel::Postgres::PGArray)
2303
- m.to_a.must_be_kind_of(Array)
2304
- m.first.must_be_kind_of(String)
2305
- r.must_be(:==, :x=>['<a></a>'], :b=>['1'], :vb=>['10'], :u=>['c0f24910-39e7-11e4-916c-0800200c9a66'], :xi=>['12'], :c=>['12'], :n=>['N'], :o=>['1 2'])
2306
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2307
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2308
- r[:m] = m
2309
- @ds.delete
2310
- @ds.insert(r)
2311
- @ds.all.must_equal rs
2312
- end
2117
+ rs = @ds.all
2118
+ r = rs.first
2119
+ m = r.delete(:m)
2120
+ m.class.must_equal(Sequel::Postgres::PGArray)
2121
+ m.to_a.must_be_kind_of(Array)
2122
+ m.first.must_be_kind_of(String)
2123
+ r.must_be(:==, :x=>['<a></a>'], :b=>['1'], :vb=>['10'], :u=>['c0f24910-39e7-11e4-916c-0800200c9a66'], :xi=>['12'], :c=>['12'], :n=>['N'], :o=>['1 2'])
2124
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2125
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2126
+ r[:m] = m
2127
+ @ds.delete
2128
+ @ds.insert(r)
2129
+ @ds.all.must_equal rs
2313
2130
  end
2314
2131
 
2315
2132
  it 'insert and retrieve empty arrays' do
@@ -2318,15 +2135,13 @@ describe 'PostgreSQL array handling' do
2318
2135
  end
2319
2136
  @ds.insert(:n=>Sequel.pg_array([], :integer))
2320
2137
  @ds.count.must_equal 1
2321
- if @native
2322
- rs = @ds.all
2323
- rs.must_equal [{:n=>[]}]
2324
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2325
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2326
- @ds.delete
2327
- @ds.insert(rs.first)
2328
- @ds.all.must_equal rs
2329
- end
2138
+ rs = @ds.all
2139
+ rs.must_equal [{:n=>[]}]
2140
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2141
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2142
+ @ds.delete
2143
+ @ds.insert(rs.first)
2144
+ @ds.all.must_equal rs
2330
2145
  end
2331
2146
 
2332
2147
  it 'convert ruby array :default values' do
@@ -2335,15 +2150,13 @@ describe 'PostgreSQL array handling' do
2335
2150
  end
2336
2151
  @ds.insert
2337
2152
  @ds.count.must_equal 1
2338
- if @native
2339
- rs = @ds.all
2340
- rs.must_equal [{:n=>[]}]
2341
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2342
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2343
- @ds.delete
2344
- @ds.insert(rs.first)
2345
- @ds.all.must_equal rs
2346
- end
2153
+ rs = @ds.all
2154
+ rs.must_equal [{:n=>[]}]
2155
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2156
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2157
+ @ds.delete
2158
+ @ds.insert(rs.first)
2159
+ @ds.all.must_equal rs
2347
2160
  end
2348
2161
 
2349
2162
  it 'insert and retrieve custom array types' do
@@ -2372,14 +2185,12 @@ describe 'PostgreSQL array handling' do
2372
2185
  @ds.insert(Sequel.pg_array([int2v], :int2vector))
2373
2186
  @ds.count.must_equal 1
2374
2187
  rs = @ds.all
2375
- if @native
2376
- rs.must_equal [{:b=>[int2v]}]
2377
- rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2378
- rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2379
- @ds.delete
2380
- @ds.insert(rs.first)
2381
- @ds.all.must_equal rs
2382
- end
2188
+ rs.must_equal [{:b=>[int2v]}]
2189
+ rs.first.values.each{|v| v.class.must_equal(Sequel::Postgres::PGArray)}
2190
+ rs.first.values.each{|v| v.to_a.must_be_kind_of(Array)}
2191
+ @ds.delete
2192
+ @ds.insert(rs.first)
2193
+ @ds.all.must_equal rs
2383
2194
  end
2384
2195
 
2385
2196
  it 'retrieve arrays with explicit bounds' do
@@ -2475,7 +2286,6 @@ describe 'PostgreSQL array handling' do
2475
2286
  column :t, 'text[]'
2476
2287
  end
2477
2288
  c = Class.new(Sequel::Model(@db[:items]))
2478
- c.plugin :pg_typecast_on_load, :i, :f, :d, :t unless @native
2479
2289
  h = {:i=>[1,2, nil], :f=>[[1, 2.5], [3, 4.5]], :d=>[1, BigDecimal.new('1.000000000000000000001')], :t=>[%w'a b c', ['NULL', nil, '1']]}
2480
2290
  o = c.create(h)
2481
2291
  o.i.must_equal [1, 2, nil]
@@ -2494,7 +2304,6 @@ describe 'PostgreSQL array handling' do
2494
2304
  column :t, 'varchar[]'
2495
2305
  end
2496
2306
  c = Class.new(Sequel::Model(@db[:items]))
2497
- c.plugin :pg_typecast_on_load, :i, :f, :d, :t unless @native
2498
2307
  o = c.create(:i=>[1,2, nil], :f=>[[1, 2.5], [3, 4.5]], :d=>[1, BigDecimal.new('1.000000000000000000001')], :t=>[%w'a b c', ['NULL', nil, '1']])
2499
2308
  o.i.must_equal [1, 2, nil]
2500
2309
  o.f.must_equal [[1, 2.5], [3, 4.5]]
@@ -2572,11 +2381,9 @@ describe 'PostgreSQL array handling' do
2572
2381
  @ds.from{Sequel.pg_array([1,2,3]).op.unnest([4,5,6], [7,8]).as(:t1, [:a, :b, :c])}.select_order_map([:a, :b, :c]).must_equal [[1, 4, 7], [2, 5, 8], [3, 6, nil]]
2573
2382
  end
2574
2383
 
2575
- if @native
2576
- @ds.get(Sequel.pg_array(:i).push(4)).must_equal [1, 2, 3, 4]
2577
- @ds.get(Sequel.pg_array(:i).unshift(4)).must_equal [4, 1, 2, 3]
2578
- @ds.get(Sequel.pg_array(:i).concat(:i2)).must_equal [1, 2, 3, 2, 1]
2579
- end
2384
+ @ds.get(Sequel.pg_array(:i).push(4)).must_equal [1, 2, 3, 4]
2385
+ @ds.get(Sequel.pg_array(:i).unshift(4)).must_equal [4, 1, 2, 3]
2386
+ @ds.get(Sequel.pg_array(:i).concat(:i2)).must_equal [1, 2, 3, 2, 1]
2580
2387
 
2581
2388
  if @db.type_supported?(:hstore)
2582
2389
  Sequel.extension :pg_hstore_ops
@@ -2591,7 +2398,6 @@ describe 'PostgreSQL hstore handling' do
2591
2398
  @db = DB
2592
2399
  @ds = @db[:items]
2593
2400
  @h = {'a'=>'b', 'c'=>nil, 'd'=>'NULL', 'e'=>'\\\\" \\\' ,=>'}
2594
- @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
2595
2401
  end
2596
2402
  after do
2597
2403
  @db.drop_table?(:items)
@@ -2603,17 +2409,15 @@ describe 'PostgreSQL hstore handling' do
2603
2409
  end
2604
2410
  @ds.insert(Sequel.hstore(@h))
2605
2411
  @ds.count.must_equal 1
2606
- if @native
2607
- rs = @ds.all
2608
- v = rs.first[:h]
2609
- v.must_equal @h
2610
- v.class.must_equal(Sequel::Postgres::HStore)
2611
- v.to_hash.must_be_kind_of(Hash)
2612
- v.to_hash.must_equal @h
2613
- @ds.delete
2614
- @ds.insert(rs.first)
2615
- @ds.all.must_equal rs
2616
- end
2412
+ rs = @ds.all
2413
+ v = rs.first[:h]
2414
+ v.must_equal @h
2415
+ v.class.must_equal(Sequel::Postgres::HStore)
2416
+ v.to_hash.must_be_kind_of(Hash)
2417
+ v.to_hash.must_equal @h
2418
+ @ds.delete
2419
+ @ds.insert(rs.first)
2420
+ @ds.all.must_equal rs
2617
2421
  end
2618
2422
 
2619
2423
  it 'insert and retrieve hstore[] values' do
@@ -2622,16 +2426,14 @@ describe 'PostgreSQL hstore handling' do
2622
2426
  end
2623
2427
  @ds.insert(Sequel.pg_array([Sequel.hstore(@h)], :hstore))
2624
2428
  @ds.count.must_equal 1
2625
- if @native
2626
- rs = @ds.all
2627
- v = rs.first[:h].first
2628
- v.class.must_equal(Sequel::Postgres::HStore)
2629
- v.to_hash.must_be_kind_of(Hash)
2630
- v.to_hash.must_equal @h
2631
- @ds.delete
2632
- @ds.insert(rs.first)
2633
- @ds.all.must_equal rs
2634
- end
2429
+ rs = @ds.all
2430
+ v = rs.first[:h].first
2431
+ v.class.must_equal(Sequel::Postgres::HStore)
2432
+ v.to_hash.must_be_kind_of(Hash)
2433
+ v.to_hash.must_equal @h
2434
+ @ds.delete
2435
+ @ds.insert(rs.first)
2436
+ @ds.all.must_equal rs
2635
2437
  end
2636
2438
 
2637
2439
  it 'use hstore in bound variables' do
@@ -2673,7 +2475,6 @@ describe 'PostgreSQL hstore handling' do
2673
2475
  end
2674
2476
  Sequel.extension :pg_hstore_ops
2675
2477
  c.plugin :many_through_many
2676
- c.plugin :pg_typecast_on_load, :h unless @native
2677
2478
 
2678
2479
  h = {'item_id'=>"2", 'left_item_id'=>"1"}
2679
2480
  o2 = c.create(:id=>2)
@@ -2836,7 +2637,6 @@ describe 'PostgreSQL json type' do
2836
2637
  @ds = @db[:items]
2837
2638
  @a = [1, 2, {'a'=>'b'}, 3.0]
2838
2639
  @h = {'a'=>'b', '1'=>[3, 4, 5]}
2839
- @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
2840
2640
  end
2841
2641
  after do
2842
2642
  @db.drop_table?(:items)
@@ -2855,32 +2655,28 @@ describe 'PostgreSQL json type' do
2855
2655
  @db.create_table!(:items){column :j, json_type}
2856
2656
  @ds.insert(pg_json.call(@h))
2857
2657
  @ds.count.must_equal 1
2858
- if @native
2859
- rs = @ds.all
2860
- v = rs.first[:j]
2861
- v.class.must_equal(hash_class)
2862
- v.to_hash.must_be_kind_of(Hash)
2863
- v.must_equal @h
2864
- v.to_hash.must_equal @h
2865
- @ds.delete
2866
- @ds.insert(rs.first)
2867
- @ds.all.must_equal rs
2868
- end
2658
+ rs = @ds.all
2659
+ v = rs.first[:j]
2660
+ v.class.must_equal(hash_class)
2661
+ v.to_hash.must_be_kind_of(Hash)
2662
+ v.must_equal @h
2663
+ v.to_hash.must_equal @h
2664
+ @ds.delete
2665
+ @ds.insert(rs.first)
2666
+ @ds.all.must_equal rs
2869
2667
 
2870
2668
  @ds.delete
2871
2669
  @ds.insert(pg_json.call(@a))
2872
2670
  @ds.count.must_equal 1
2873
- if @native
2874
- rs = @ds.all
2875
- v = rs.first[:j]
2876
- v.class.must_equal(array_class)
2877
- v.to_a.must_be_kind_of(Array)
2878
- v.must_equal @a
2879
- v.to_a.must_equal @a
2880
- @ds.delete
2881
- @ds.insert(rs.first)
2882
- @ds.all.must_equal rs
2883
- end
2671
+ rs = @ds.all
2672
+ v = rs.first[:j]
2673
+ v.class.must_equal(array_class)
2674
+ v.to_a.must_be_kind_of(Array)
2675
+ v.must_equal @a
2676
+ v.to_a.must_equal @a
2677
+ @ds.delete
2678
+ @ds.insert(rs.first)
2679
+ @ds.all.must_equal rs
2884
2680
  end
2885
2681
 
2886
2682
  it 'insert and retrieve json[] values' do
@@ -2888,17 +2684,15 @@ describe 'PostgreSQL json type' do
2888
2684
  j = Sequel.pg_array([pg_json.call('a'=>1), pg_json.call(['b', 2])])
2889
2685
  @ds.insert(j)
2890
2686
  @ds.count.must_equal 1
2891
- if @native
2892
- rs = @ds.all
2893
- v = rs.first[:j]
2894
- v.class.must_equal(Sequel::Postgres::PGArray)
2895
- v.to_a.must_be_kind_of(Array)
2896
- v.must_equal j
2897
- v.to_a.must_equal j
2898
- @ds.delete
2899
- @ds.insert(rs.first)
2900
- @ds.all.must_equal rs
2901
- end
2687
+ rs = @ds.all
2688
+ v = rs.first[:j]
2689
+ v.class.must_equal(Sequel::Postgres::PGArray)
2690
+ v.to_a.must_be_kind_of(Array)
2691
+ v.must_equal j
2692
+ v.to_a.must_equal j
2693
+ @ds.delete
2694
+ @ds.insert(rs.first)
2695
+ @ds.all.must_equal rs
2902
2696
  end
2903
2697
 
2904
2698
  it 'with models' do
@@ -2907,7 +2701,6 @@ describe 'PostgreSQL json type' do
2907
2701
  column :h, json_type
2908
2702
  end
2909
2703
  c = Class.new(Sequel::Model(@db[:items]))
2910
- c.plugin :pg_typecast_on_load, :h unless @native
2911
2704
  c.create(:h=>pg_json.call(@h)).h.must_equal @h
2912
2705
  c.create(:h=>pg_json.call(@a)).h.must_equal @a
2913
2706
  end
@@ -3039,7 +2832,6 @@ describe 'PostgreSQL inet/cidr types' do
3039
2832
  @ipv6 = IPAddr.new(@v6)
3040
2833
  @ipv6nm = IPAddr.new(@v6nm)
3041
2834
  end
3042
- @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
3043
2835
  end
3044
2836
  after do
3045
2837
  @db.drop_table?(:items)
@@ -3049,51 +2841,45 @@ describe 'PostgreSQL inet/cidr types' do
3049
2841
  @db.create_table!(:items){inet :i; cidr :c}
3050
2842
  @ds.insert(@ipv4, @ipv4nm)
3051
2843
  @ds.count.must_equal 1
3052
- if @native
2844
+ rs = @ds.all
2845
+ rs.first[:i].must_equal @ipv4
2846
+ rs.first[:c].must_equal @ipv4nm
2847
+ rs.first[:i].must_be_kind_of(IPAddr)
2848
+ rs.first[:c].must_be_kind_of(IPAddr)
2849
+ @ds.delete
2850
+ @ds.insert(rs.first)
2851
+ @ds.all.must_equal rs
2852
+
2853
+ unless ipv6_broken
2854
+ @ds.delete
2855
+ @ds.insert(@ipv6, @ipv6nm)
2856
+ @ds.count.must_equal 1
3053
2857
  rs = @ds.all
3054
- rs.first[:i].must_equal @ipv4
3055
- rs.first[:c].must_equal @ipv4nm
2858
+ rs.first[:j]
2859
+ rs.first[:i].must_equal @ipv6
2860
+ rs.first[:c].must_equal @ipv6nm
3056
2861
  rs.first[:i].must_be_kind_of(IPAddr)
3057
2862
  rs.first[:c].must_be_kind_of(IPAddr)
3058
2863
  @ds.delete
3059
2864
  @ds.insert(rs.first)
3060
2865
  @ds.all.must_equal rs
3061
2866
  end
3062
-
3063
- unless ipv6_broken
3064
- @ds.delete
3065
- @ds.insert(@ipv6, @ipv6nm)
3066
- @ds.count.must_equal 1
3067
- if @native
3068
- rs = @ds.all
3069
- rs.first[:j]
3070
- rs.first[:i].must_equal @ipv6
3071
- rs.first[:c].must_equal @ipv6nm
3072
- rs.first[:i].must_be_kind_of(IPAddr)
3073
- rs.first[:c].must_be_kind_of(IPAddr)
3074
- @ds.delete
3075
- @ds.insert(rs.first)
3076
- @ds.all.must_equal rs
3077
- end
3078
- end
3079
2867
  end
3080
2868
 
3081
2869
  it 'insert and retrieve inet/cidr/macaddr array values' do
3082
2870
  @db.create_table!(:items){column :i, 'inet[]'; column :c, 'cidr[]'; column :m, 'macaddr[]'}
3083
2871
  @ds.insert(Sequel.pg_array([@ipv4], 'inet'), Sequel.pg_array([@ipv4nm], 'cidr'), Sequel.pg_array(['12:34:56:78:90:ab'], 'macaddr'))
3084
2872
  @ds.count.must_equal 1
3085
- if @native
3086
- rs = @ds.all
3087
- rs.first.values.all?{|c| c.is_a?(Sequel::Postgres::PGArray)}.must_equal true
3088
- rs.first[:i].first.must_equal @ipv4
3089
- rs.first[:c].first.must_equal @ipv4nm
3090
- rs.first[:m].first.must_equal '12:34:56:78:90:ab'
3091
- rs.first[:i].first.must_be_kind_of(IPAddr)
3092
- rs.first[:c].first.must_be_kind_of(IPAddr)
3093
- @ds.delete
3094
- @ds.insert(rs.first)
3095
- @ds.all.must_equal rs
3096
- end
2873
+ rs = @ds.all
2874
+ rs.first.values.all?{|c| c.is_a?(Sequel::Postgres::PGArray)}.must_equal true
2875
+ rs.first[:i].first.must_equal @ipv4
2876
+ rs.first[:c].first.must_equal @ipv4nm
2877
+ rs.first[:m].first.must_equal '12:34:56:78:90:ab'
2878
+ rs.first[:i].first.must_be_kind_of(IPAddr)
2879
+ rs.first[:c].first.must_be_kind_of(IPAddr)
2880
+ @ds.delete
2881
+ @ds.insert(rs.first)
2882
+ @ds.all.must_equal rs
3097
2883
  end
3098
2884
 
3099
2885
  it 'use ipaddr in bound variables' do
@@ -3129,7 +2915,6 @@ describe 'PostgreSQL inet/cidr types' do
3129
2915
  cidr :c
3130
2916
  end
3131
2917
  c = Class.new(Sequel::Model(@db[:items]))
3132
- c.plugin :pg_typecast_on_load, :i, :c unless @native
3133
2918
  c.create(:i=>@v4, :c=>@v4nm).values.values_at(:i, :c).must_equal [@ipv4, @ipv4nm]
3134
2919
  unless ipv6_broken
3135
2920
  c.create(:i=>@ipv6, :c=>@ipv6nm).values.values_at(:i, :c).must_equal [@ipv6, @ipv6nm]
@@ -3211,7 +2996,6 @@ describe 'PostgreSQL range types' do
3211
2996
  @r.each{|k, v| @ra[k] = Sequel.pg_array([v], @map[k])}
3212
2997
  @r.each{|k, v| @pgr[k] = Sequel.pg_range(v)}
3213
2998
  @r.each{|k, v| @pgra[k] = Sequel.pg_array([Sequel.pg_range(v)], @map[k])}
3214
- @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
3215
2999
  end
3216
3000
  after do
3217
3001
  @db.drop_table?(:items)
@@ -3224,19 +3008,17 @@ describe 'PostgreSQL range types' do
3224
3008
  input.each{|k, v| h[k] = Sequel.cast(v, @map[k])}
3225
3009
  @ds.insert(h)
3226
3010
  @ds.count.must_equal 1
3227
- if @native
3228
- rs = @ds.all
3229
- rs.first.each do |k, v|
3230
- v.class.must_equal(Sequel::Postgres::PGRange)
3231
- v.to_range.must_be_kind_of(Range)
3232
- v.must_be :==, @r[k]
3233
- v.to_range.must_equal @r[k]
3234
- end
3235
- @ds.delete
3236
- @ds.insert(rs.first)
3237
- @ds.all.must_equal rs
3011
+ rs = @ds.all
3012
+ rs.first.each do |k, v|
3013
+ v.class.must_equal(Sequel::Postgres::PGRange)
3014
+ v.to_range.must_be_kind_of(Range)
3015
+ v.must_be :==, @r[k]
3016
+ v.to_range.must_equal @r[k]
3238
3017
  end
3239
3018
  @ds.delete
3019
+ @ds.insert(rs.first)
3020
+ @ds.all.must_equal rs
3021
+ @ds.delete
3240
3022
  end
3241
3023
  end
3242
3024
 
@@ -3245,21 +3027,19 @@ describe 'PostgreSQL range types' do
3245
3027
  [@ra, @pgra].each do |input|
3246
3028
  @ds.insert(input)
3247
3029
  @ds.count.must_equal 1
3248
- if @native
3249
- rs = @ds.all
3250
- rs.first.each do |k, v|
3251
- v.class.must_equal(Sequel::Postgres::PGArray)
3252
- v.to_a.must_be_kind_of(Array)
3253
- v.first.class.must_equal(Sequel::Postgres::PGRange)
3254
- v.first.to_range.must_be_kind_of(Range)
3255
- v.must_be :==, @ra[k].to_a
3256
- v.first.must_be :==, @r[k]
3257
- end
3258
- @ds.delete
3259
- @ds.insert(rs.first)
3260
- @ds.all.must_equal rs
3030
+ rs = @ds.all
3031
+ rs.first.each do |k, v|
3032
+ v.class.must_equal(Sequel::Postgres::PGArray)
3033
+ v.to_a.must_be_kind_of(Array)
3034
+ v.first.class.must_equal(Sequel::Postgres::PGRange)
3035
+ v.first.to_range.must_be_kind_of(Range)
3036
+ v.must_be :==, @ra[k].to_a
3037
+ v.first.must_be :==, @r[k]
3261
3038
  end
3262
3039
  @ds.delete
3040
+ @ds.insert(rs.first)
3041
+ @ds.all.must_equal rs
3042
+ @ds.delete
3263
3043
  end
3264
3044
  end
3265
3045
 
@@ -3288,14 +3068,12 @@ describe 'PostgreSQL range types' do
3288
3068
  it 'with models' do
3289
3069
  @db.create_table!(:items){primary_key :id; int4range :i4; int8range :i8; numrange :n; daterange :d; tsrange :t; tstzrange :tz}
3290
3070
  c = Class.new(Sequel::Model(@db[:items]))
3291
- c.plugin :pg_typecast_on_load, :i4, :i8, :n, :d, :t, :tz unless @native
3292
3071
  v = c.create(@r).values
3293
3072
  v.delete(:id)
3294
3073
  v.must_be :==, @r
3295
3074
 
3296
3075
  @db.create_table!(:items){primary_key :id; column :i4, 'int4range[]'; column :i8, 'int8range[]'; column :n, 'numrange[]'; column :d, 'daterange[]'; column :t, 'tsrange[]'; column :tz, 'tstzrange[]'}
3297
3076
  c = Class.new(Sequel::Model(@db[:items]))
3298
- c.plugin :pg_typecast_on_load, :i4, :i8, :n, :d, :t, :tz unless @native
3299
3077
  v = c.create(@ra).values
3300
3078
  v.delete(:id)
3301
3079
  v.each{|k,v1| v1.must_be :==, @ra[k].to_a}
@@ -3304,10 +3082,8 @@ describe 'PostgreSQL range types' do
3304
3082
  it 'works with current_datetime_timestamp extension' do
3305
3083
  ds = @db.dataset.extension(:current_datetime_timestamp)
3306
3084
  tsr = ds.get(Sequel.pg_range(ds.current_datetime..ds.current_datetime, :tstzrange))
3307
- if @native
3308
- tsr.begin.must_be_kind_of Time
3309
- tsr.end.must_be_kind_of Time
3310
- end
3085
+ tsr.begin.must_be_kind_of Time
3086
+ tsr.end.must_be_kind_of Time
3311
3087
  end
3312
3088
 
3313
3089
  it 'operations/functions with pg_range_ops' do
@@ -3384,10 +3160,6 @@ describe 'PostgreSQL interval types' do
3384
3160
  before(:all) do
3385
3161
  @db = DB
3386
3162
  @ds = @db[:items]
3387
- @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
3388
- end
3389
- after(:all) do
3390
- Sequel::Postgres::PG__TYPES.delete(1186) # SEQUEL5: Remove
3391
3163
  end
3392
3164
  after do
3393
3165
  @db.drop_table?(:items)
@@ -3417,16 +3189,14 @@ describe 'PostgreSQL interval types' do
3417
3189
  ].each do |instr, outstr, value, parts|
3418
3190
  @ds.insert(instr)
3419
3191
  @ds.count.must_equal 1
3420
- if @native
3421
- @ds.get(Sequel.cast(:i, String)).must_equal outstr
3422
- rs = @ds.all
3423
- rs.first[:i].is_a?(ActiveSupport::Duration).must_equal true
3424
- rs.first[:i].must_equal ActiveSupport::Duration.new(value, parts)
3425
- rs.first[:i].parts.sort_by{|k,v| k.to_s}.reject{|k,v| v == 0}.must_equal parts.sort_by{|k,v| k.to_s}
3426
- @ds.delete
3427
- @ds.insert(rs.first)
3428
- @ds.all.must_equal rs
3429
- end
3192
+ @ds.get(Sequel.cast(:i, String)).must_equal outstr
3193
+ rs = @ds.all
3194
+ rs.first[:i].is_a?(ActiveSupport::Duration).must_equal true
3195
+ rs.first[:i].must_equal ActiveSupport::Duration.new(value, parts)
3196
+ rs.first[:i].parts.sort_by{|k,v| k.to_s}.reject{|k,v| v == 0}.must_equal parts.sort_by{|k,v| k.to_s}
3197
+ @ds.delete
3198
+ @ds.insert(rs.first)
3199
+ @ds.all.must_equal rs
3430
3200
  @ds.delete
3431
3201
  end
3432
3202
  end
@@ -3435,16 +3205,14 @@ describe 'PostgreSQL interval types' do
3435
3205
  @db.create_table!(:items){column :i, 'interval[]'}
3436
3206
  @ds.insert(Sequel.pg_array(['1 year 2 months 3 weeks 4 days 5 hours 6 minutes 7 seconds'], 'interval'))
3437
3207
  @ds.count.must_equal 1
3438
- if @native
3439
- rs = @ds.all
3440
- rs.first[:i].is_a?(Sequel::Postgres::PGArray).must_equal true
3441
- rs.first[:i].first.is_a?(ActiveSupport::Duration).must_equal true
3442
- rs.first[:i].first.must_equal ActiveSupport::Duration.new(31557600 + 2*86400*30 + 3*86400*7 + 4*86400 + 5*3600 + 6*60 + 7, [[:years, 1], [:months, 2], [:days, 25], [:seconds, 18367]])
3443
- rs.first[:i].first.parts.sort_by{|k,v| k.to_s}.must_equal [[:years, 1], [:months, 2], [:days, 25], [:seconds, 18367]].sort_by{|k,v| k.to_s}
3444
- @ds.delete
3445
- @ds.insert(rs.first)
3446
- @ds.all.must_equal rs
3447
- end
3208
+ rs = @ds.all
3209
+ rs.first[:i].is_a?(Sequel::Postgres::PGArray).must_equal true
3210
+ rs.first[:i].first.is_a?(ActiveSupport::Duration).must_equal true
3211
+ rs.first[:i].first.must_equal ActiveSupport::Duration.new(31557600 + 2*86400*30 + 3*86400*7 + 4*86400 + 5*3600 + 6*60 + 7, [[:years, 1], [:months, 2], [:days, 25], [:seconds, 18367]])
3212
+ rs.first[:i].first.parts.sort_by{|k,v| k.to_s}.must_equal [[:years, 1], [:months, 2], [:days, 25], [:seconds, 18367]].sort_by{|k,v| k.to_s}
3213
+ @ds.delete
3214
+ @ds.insert(rs.first)
3215
+ @ds.all.must_equal rs
3448
3216
  end
3449
3217
 
3450
3218
  it 'use intervals in bound variables' do
@@ -3472,7 +3240,6 @@ describe 'PostgreSQL interval types' do
3472
3240
  interval :i
3473
3241
  end
3474
3242
  c = Class.new(Sequel::Model(@db[:items]))
3475
- c.plugin :pg_typecast_on_load, :i, :c unless @native
3476
3243
  v = c.create(:i=>'1 year 2 mons 25 days 05:06:07').i
3477
3244
  v.is_a?(ActiveSupport::Duration).must_equal true
3478
3245
  v.must_equal ActiveSupport::Duration.new(31557600 + 2*86400*30 + 3*86400*7 + 4*86400 + 5*3600 + 6*60 + 7, [[:years, 1], [:months, 2], [:days, 25], [:seconds, 18367]])
@@ -3504,8 +3271,6 @@ describe 'PostgreSQL row-valued/composite types' do
3504
3271
  @db.register_row_type(Sequel.qualify(:public, :person))
3505
3272
  @db.register_row_type(Sequel[:public][:company])
3506
3273
  @new_oids = @db.conversion_procs.keys - oids
3507
-
3508
- @native = DB.adapter_scheme == :postgres || DB.adapter_scheme == :jdbc
3509
3274
  end
3510
3275
  after(:all) do
3511
3276
  @new_oids.each{|oid| @db.conversion_procs.delete(oid)}
@@ -3519,22 +3284,20 @@ describe 'PostgreSQL row-valued/composite types' do
3519
3284
  it 'insert and retrieve row types' do
3520
3285
  @ds.insert(:id=>1, :address=>Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345']))
3521
3286
  @ds.count.must_equal 1
3522
- if @native
3523
- # Single row valued type
3524
- rs = @ds.all
3525
- v = rs.first[:address]
3526
- v.class.superclass.must_equal(Sequel::Postgres::PGRow::HashRow)
3527
- v.to_hash.must_be_kind_of(Hash)
3528
- v.to_hash.must_equal(:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345')
3529
- @ds.delete
3530
- @ds.insert(rs.first)
3531
- @ds.all.must_equal rs
3287
+ # Single row valued type
3288
+ rs = @ds.all
3289
+ v = rs.first[:address]
3290
+ v.class.superclass.must_equal(Sequel::Postgres::PGRow::HashRow)
3291
+ v.to_hash.must_be_kind_of(Hash)
3292
+ v.to_hash.must_equal(:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345')
3293
+ @ds.delete
3294
+ @ds.insert(rs.first)
3295
+ @ds.all.must_equal rs
3532
3296
 
3533
- # Nested row value type
3534
- p = @ds.get(:person)
3535
- p[:id].must_equal 1
3536
- p[:address].must_equal v
3537
- end
3297
+ # Nested row value type
3298
+ p = @ds.get(:person)
3299
+ p[:id].must_equal 1
3300
+ p[:address].must_equal v
3538
3301
  end
3539
3302
 
3540
3303
  it 'insert and retrieve row types containing domains' do
@@ -3559,19 +3322,17 @@ describe 'PostgreSQL row-valued/composite types' do
3559
3322
  @ds = @db[:company]
3560
3323
  @ds.insert(:id=>1, :employees=>Sequel.pg_array([@db.row_type(:person, [1, Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345'])])]))
3561
3324
  @ds.count.must_equal 1
3562
- if @native
3563
- v = @ds.get(:company)
3564
- v.class.superclass.must_equal(Sequel::Postgres::PGRow::HashRow)
3565
- v.to_hash.must_be_kind_of(Hash)
3566
- v[:id].must_equal 1
3567
- employees = v[:employees]
3568
- employees.class.must_equal(Sequel::Postgres::PGArray)
3569
- employees.to_a.must_be_kind_of(Array)
3570
- employees.must_equal [{:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}}]
3571
- @ds.delete
3572
- @ds.insert(v[:id], v[:employees])
3573
- @ds.get(:company).must_equal v
3574
- end
3325
+ v = @ds.get(:company)
3326
+ v.class.superclass.must_equal(Sequel::Postgres::PGRow::HashRow)
3327
+ v.to_hash.must_be_kind_of(Hash)
3328
+ v[:id].must_equal 1
3329
+ employees = v[:employees]
3330
+ employees.class.must_equal(Sequel::Postgres::PGArray)
3331
+ employees.to_a.must_be_kind_of(Array)
3332
+ employees.must_equal [{:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}}]
3333
+ @ds.delete
3334
+ @ds.insert(v[:id], v[:employees])
3335
+ @ds.get(:company).must_equal v
3575
3336
  end
3576
3337
 
3577
3338
  it 'use row types in bound variables' do
@@ -3606,11 +3367,9 @@ describe 'PostgreSQL row-valued/composite types' do
3606
3367
  @ds = @db[:company]
3607
3368
  @ds.insert(:id=>1, :employees=>Sequel.pg_array([@db.row_type(:person, [1, Sequel.pg_row(['123 Sesame St', 'Somewhere', '12345'])])]))
3608
3369
  @ds.get(Sequel.pg_row(:company)[:id]).must_equal 1
3609
- if @native
3610
- @ds.get(Sequel.pg_row(:company)[:employees]).must_equal [{:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}}]
3611
- @ds.get(Sequel.pg_row(:company)[:employees][1]).must_equal(:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'})
3612
- @ds.get(Sequel.pg_row(:company)[:employees][1][:address]).must_equal(:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345')
3613
- end
3370
+ @ds.get(Sequel.pg_row(:company)[:employees]).must_equal [{:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}}]
3371
+ @ds.get(Sequel.pg_row(:company)[:employees][1]).must_equal(:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'})
3372
+ @ds.get(Sequel.pg_row(:company)[:employees][1][:address]).must_equal(:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345')
3614
3373
  @ds.get(Sequel.pg_row(:company)[:employees][1][:id]).must_equal 1
3615
3374
  @ds.get(Sequel.pg_row(:company)[:employees][1][:address][:street]).must_equal '123 Sesame St'
3616
3375
  @ds.get(Sequel.pg_row(:company)[:employees][1][:address][:city]).must_equal 'Somewhere'
@@ -3635,22 +3394,18 @@ describe 'PostgreSQL row-valued/composite types' do
3635
3394
  @db[:b].select(Sequel.pg_row(:b)[:a]).first.must_equal(:a=>2)
3636
3395
  @db[:b].select(Sequel.pg_row(:b).splat[:a]).first.must_equal(:a=>1)
3637
3396
 
3638
- if @native
3639
- @db[:b].select(:b).first.must_equal(:b=>{:a=>2})
3640
- @db[:b].select(Sequel.pg_row(:b).splat).first.must_equal(:a=>1, :b=>{:a=>2})
3641
- @db[:b].select(Sequel.pg_row(:b).splat(:b)).first.must_equal(:b=>{:a=>1, :b=>{:a=>2}})
3642
- end
3397
+ @db[:b].select(:b).first.must_equal(:b=>{:a=>2})
3398
+ @db[:b].select(Sequel.pg_row(:b).splat).first.must_equal(:a=>1, :b=>{:a=>2})
3399
+ @db[:b].select(Sequel.pg_row(:b).splat(:b)).first.must_equal(:b=>{:a=>1, :b=>{:a=>2}})
3643
3400
  end
3644
3401
 
3645
3402
  it "* should expand the table type into separate columns" do
3646
3403
  ds = @db[:b].select(Sequel.pg_row(:b).splat(:b)).from_self(:alias=>:t)
3647
- if @native
3648
- ds.first.must_equal(:b=>{:a=>1, :b=>{:a=>2}})
3649
- ds.select(Sequel.pg_row(:b).*).first.must_equal(:a=>1, :b=>{:a=>2})
3650
- ds.select(Sequel.pg_row(:b)[:b]).first.must_equal(:b=>{:a=>2})
3651
- ds.select(Sequel.pg_row(Sequel[:t][:b]).*).first.must_equal(:a=>1, :b=>{:a=>2})
3652
- ds.select(Sequel.pg_row(Sequel[:t][:b])[:b]).first.must_equal(:b=>{:a=>2})
3653
- end
3404
+ ds.first.must_equal(:b=>{:a=>1, :b=>{:a=>2}})
3405
+ ds.select(Sequel.pg_row(:b).*).first.must_equal(:a=>1, :b=>{:a=>2})
3406
+ ds.select(Sequel.pg_row(:b)[:b]).first.must_equal(:b=>{:a=>2})
3407
+ ds.select(Sequel.pg_row(Sequel[:t][:b]).*).first.must_equal(:a=>1, :b=>{:a=>2})
3408
+ ds.select(Sequel.pg_row(Sequel[:t][:b])[:b]).first.must_equal(:b=>{:a=>2})
3654
3409
  ds.select(Sequel.pg_row(:b)[:a]).first.must_equal(:a=>1)
3655
3410
  ds.select(Sequel.pg_row(Sequel[:t][:b])[:a]).first.must_equal(:a=>1)
3656
3411
  end
@@ -3679,41 +3434,37 @@ describe 'PostgreSQL row-valued/composite types' do
3679
3434
  it 'insert and retrieve row types as model objects' do
3680
3435
  @ds.insert(:id=>1, :address=>@a)
3681
3436
  @ds.count.must_equal 1
3682
- if @native
3683
- # Single row valued type
3684
- rs = @ds.all
3685
- v = rs.first[:address]
3686
- v.must_be_kind_of(Address)
3687
- v.must_equal @a
3688
- @ds.delete
3689
- @ds.insert(rs.first)
3690
- @ds.all.must_equal rs
3691
-
3692
- # Nested row value type
3693
- p = @ds.get(:person)
3694
- p.must_be_kind_of(Person)
3695
- p.id.must_equal 1
3696
- p.address.must_be_kind_of(Address)
3697
- p.address.must_equal @a
3698
- end
3437
+ # Single row valued type
3438
+ rs = @ds.all
3439
+ v = rs.first[:address]
3440
+ v.must_be_kind_of(Address)
3441
+ v.must_equal @a
3442
+ @ds.delete
3443
+ @ds.insert(rs.first)
3444
+ @ds.all.must_equal rs
3445
+
3446
+ # Nested row value type
3447
+ p = @ds.get(:person)
3448
+ p.must_be_kind_of(Person)
3449
+ p.id.must_equal 1
3450
+ p.address.must_be_kind_of(Address)
3451
+ p.address.must_equal @a
3699
3452
  end
3700
3453
 
3701
3454
  it 'insert and retrieve arrays of row types as model objects' do
3702
3455
  @ds = @db[:company]
3703
3456
  @ds.insert(:id=>1, :employees=>@es)
3704
3457
  @ds.count.must_equal 1
3705
- if @native
3706
- v = @ds.get(:company)
3707
- v.must_be_kind_of(Company)
3708
- v.id.must_equal 1
3709
- employees = v[:employees]
3710
- employees.class.must_equal(Sequel::Postgres::PGArray)
3711
- employees.to_a.must_be_kind_of(Array)
3712
- employees.must_equal @es
3713
- @ds.delete
3714
- @ds.insert(v.id, v.employees)
3715
- @ds.get(:company).must_equal v
3716
- end
3458
+ v = @ds.get(:company)
3459
+ v.must_be_kind_of(Company)
3460
+ v.id.must_equal 1
3461
+ employees = v[:employees]
3462
+ employees.class.must_equal(Sequel::Postgres::PGArray)
3463
+ employees.to_a.must_be_kind_of(Array)
3464
+ employees.must_equal @es
3465
+ @ds.delete
3466
+ @ds.insert(v.id, v.employees)
3467
+ @ds.get(:company).must_equal v
3717
3468
  end
3718
3469
 
3719
3470
  it 'use model objects in bound variables' do
@@ -3732,7 +3483,6 @@ describe 'PostgreSQL row-valued/composite types' do
3732
3483
  end if uses_pg_or_jdbc
3733
3484
 
3734
3485
  it 'model typecasting' do
3735
- Person.plugin :pg_typecast_on_load, :address unless @native
3736
3486
  a = Address.new(:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345')
3737
3487
  o = Person.create(:id=>1, :address=>['123 Sesame St', 'Somewhere', '12345'])
3738
3488
  o.address.must_equal a
@@ -3741,7 +3491,6 @@ describe 'PostgreSQL row-valued/composite types' do
3741
3491
  o = Person.create(:id=>1, :address=>a)
3742
3492
  o.address.must_equal a
3743
3493
 
3744
- Company.plugin :pg_typecast_on_load, :employees unless @native
3745
3494
  e = Person.new(:id=>1, :address=>a)
3746
3495
  o = Company.create(:id=>1, :employees=>[{:id=>1, :address=>{:street=>'123 Sesame St', :city=>'Somewhere', :zip=>'12345'}}])
3747
3496
  o.employees.must_equal [e]
@@ -3838,8 +3587,6 @@ end
3838
3587
 
3839
3588
  describe "PostgreSQL stored procedures for datasets" do
3840
3589
  before do
3841
- require 'sequel/adapters/utils/stored_procedures'
3842
-
3843
3590
  @db = DB
3844
3591
  @db.create_table!(:items) do
3845
3592
  primary_key :id