sequel 5.29.0 → 5.34.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 (387) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +70 -1922
  3. data/README.rdoc +1 -1
  4. data/doc/advanced_associations.rdoc +4 -4
  5. data/doc/association_basics.rdoc +3 -3
  6. data/doc/code_order.rdoc +12 -2
  7. data/doc/model_dataset_method_design.rdoc +1 -1
  8. data/doc/postgresql.rdoc +71 -0
  9. data/doc/release_notes/5.30.0.txt +20 -0
  10. data/doc/release_notes/5.31.0.txt +148 -0
  11. data/doc/release_notes/5.32.0.txt +46 -0
  12. data/doc/release_notes/5.33.0.txt +24 -0
  13. data/doc/release_notes/5.34.0.txt +40 -0
  14. data/doc/testing.rdoc +1 -1
  15. data/lib/sequel/adapters/shared/access.rb +6 -6
  16. data/lib/sequel/adapters/shared/mssql.rb +5 -5
  17. data/lib/sequel/adapters/shared/mysql.rb +9 -9
  18. data/lib/sequel/adapters/shared/oracle.rb +16 -16
  19. data/lib/sequel/adapters/shared/postgres.rb +169 -14
  20. data/lib/sequel/adapters/shared/sqlanywhere.rb +9 -9
  21. data/lib/sequel/adapters/shared/sqlite.rb +32 -5
  22. data/lib/sequel/connection_pool/sharded_single.rb +4 -1
  23. data/lib/sequel/connection_pool/sharded_threaded.rb +12 -12
  24. data/lib/sequel/connection_pool/single.rb +1 -1
  25. data/lib/sequel/connection_pool/threaded.rb +2 -2
  26. data/lib/sequel/core.rb +318 -314
  27. data/lib/sequel/database/connecting.rb +1 -1
  28. data/lib/sequel/database/misc.rb +16 -10
  29. data/lib/sequel/database/query.rb +3 -1
  30. data/lib/sequel/database/schema_generator.rb +0 -1
  31. data/lib/sequel/database/schema_methods.rb +15 -16
  32. data/lib/sequel/database/transactions.rb +12 -13
  33. data/lib/sequel/dataset/placeholder_literalizer.rb +3 -7
  34. data/lib/sequel/dataset/query.rb +4 -3
  35. data/lib/sequel/deprecated.rb +2 -0
  36. data/lib/sequel/exceptions.rb +2 -0
  37. data/lib/sequel/extensions/connection_expiration.rb +2 -2
  38. data/lib/sequel/extensions/connection_validator.rb +2 -2
  39. data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
  40. data/lib/sequel/extensions/index_caching.rb +9 -7
  41. data/lib/sequel/extensions/integer64.rb +2 -0
  42. data/lib/sequel/extensions/migration.rb +1 -1
  43. data/lib/sequel/extensions/pg_enum.rb +5 -2
  44. data/lib/sequel/extensions/pg_hstore.rb +6 -0
  45. data/lib/sequel/extensions/pg_inet.rb +13 -5
  46. data/lib/sequel/extensions/pg_interval.rb +2 -0
  47. data/lib/sequel/extensions/pg_range.rb +2 -0
  48. data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
  49. data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
  50. data/lib/sequel/extensions/schema_dumper.rb +10 -4
  51. data/lib/sequel/extensions/server_block.rb +3 -3
  52. data/lib/sequel/model.rb +2 -0
  53. data/lib/sequel/model/associations.rb +30 -18
  54. data/lib/sequel/model/base.rb +64 -55
  55. data/lib/sequel/model/plugins.rb +3 -3
  56. data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
  57. data/lib/sequel/plugins/association_multi_add_remove.rb +2 -0
  58. data/lib/sequel/plugins/association_pks.rb +57 -16
  59. data/lib/sequel/plugins/association_proxies.rb +2 -0
  60. data/lib/sequel/plugins/boolean_subsets.rb +4 -1
  61. data/lib/sequel/plugins/class_table_inheritance.rb +26 -26
  62. data/lib/sequel/plugins/dirty.rb +13 -13
  63. data/lib/sequel/plugins/forbid_lazy_load.rb +214 -0
  64. data/lib/sequel/plugins/json_serializer.rb +3 -7
  65. data/lib/sequel/plugins/rcte_tree.rb +2 -2
  66. data/lib/sequel/plugins/single_table_inheritance.rb +15 -15
  67. data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
  68. data/lib/sequel/plugins/subclasses.rb +2 -0
  69. data/lib/sequel/timezones.rb +6 -4
  70. data/lib/sequel/version.rb +1 -1
  71. metadata +17 -368
  72. data/Rakefile +0 -151
  73. data/doc/release_notes/4.0.0.txt +0 -262
  74. data/doc/release_notes/4.1.0.txt +0 -85
  75. data/doc/release_notes/4.10.0.txt +0 -226
  76. data/doc/release_notes/4.11.0.txt +0 -147
  77. data/doc/release_notes/4.12.0.txt +0 -105
  78. data/doc/release_notes/4.13.0.txt +0 -169
  79. data/doc/release_notes/4.14.0.txt +0 -68
  80. data/doc/release_notes/4.15.0.txt +0 -56
  81. data/doc/release_notes/4.16.0.txt +0 -36
  82. data/doc/release_notes/4.17.0.txt +0 -38
  83. data/doc/release_notes/4.18.0.txt +0 -36
  84. data/doc/release_notes/4.19.0.txt +0 -45
  85. data/doc/release_notes/4.2.0.txt +0 -129
  86. data/doc/release_notes/4.20.0.txt +0 -79
  87. data/doc/release_notes/4.21.0.txt +0 -94
  88. data/doc/release_notes/4.22.0.txt +0 -72
  89. data/doc/release_notes/4.23.0.txt +0 -65
  90. data/doc/release_notes/4.24.0.txt +0 -99
  91. data/doc/release_notes/4.25.0.txt +0 -181
  92. data/doc/release_notes/4.26.0.txt +0 -44
  93. data/doc/release_notes/4.27.0.txt +0 -78
  94. data/doc/release_notes/4.28.0.txt +0 -57
  95. data/doc/release_notes/4.29.0.txt +0 -41
  96. data/doc/release_notes/4.3.0.txt +0 -40
  97. data/doc/release_notes/4.30.0.txt +0 -37
  98. data/doc/release_notes/4.31.0.txt +0 -57
  99. data/doc/release_notes/4.32.0.txt +0 -132
  100. data/doc/release_notes/4.33.0.txt +0 -88
  101. data/doc/release_notes/4.34.0.txt +0 -86
  102. data/doc/release_notes/4.35.0.txt +0 -130
  103. data/doc/release_notes/4.36.0.txt +0 -116
  104. data/doc/release_notes/4.37.0.txt +0 -50
  105. data/doc/release_notes/4.38.0.txt +0 -67
  106. data/doc/release_notes/4.39.0.txt +0 -127
  107. data/doc/release_notes/4.4.0.txt +0 -92
  108. data/doc/release_notes/4.40.0.txt +0 -179
  109. data/doc/release_notes/4.41.0.txt +0 -77
  110. data/doc/release_notes/4.42.0.txt +0 -221
  111. data/doc/release_notes/4.43.0.txt +0 -87
  112. data/doc/release_notes/4.44.0.txt +0 -125
  113. data/doc/release_notes/4.45.0.txt +0 -370
  114. data/doc/release_notes/4.46.0.txt +0 -404
  115. data/doc/release_notes/4.47.0.txt +0 -56
  116. data/doc/release_notes/4.48.0.txt +0 -293
  117. data/doc/release_notes/4.49.0.txt +0 -222
  118. data/doc/release_notes/4.5.0.txt +0 -34
  119. data/doc/release_notes/4.6.0.txt +0 -30
  120. data/doc/release_notes/4.7.0.txt +0 -103
  121. data/doc/release_notes/4.8.0.txt +0 -175
  122. data/doc/release_notes/4.9.0.txt +0 -190
  123. data/spec/adapter_spec.rb +0 -4
  124. data/spec/adapters/db2_spec.rb +0 -170
  125. data/spec/adapters/mssql_spec.rb +0 -828
  126. data/spec/adapters/mysql_spec.rb +0 -1060
  127. data/spec/adapters/oracle_spec.rb +0 -371
  128. data/spec/adapters/postgres_spec.rb +0 -4476
  129. data/spec/adapters/spec_helper.rb +0 -44
  130. data/spec/adapters/sqlanywhere_spec.rb +0 -97
  131. data/spec/adapters/sqlite_spec.rb +0 -652
  132. data/spec/bin_spec.rb +0 -278
  133. data/spec/core/connection_pool_spec.rb +0 -1250
  134. data/spec/core/database_spec.rb +0 -2915
  135. data/spec/core/dataset_spec.rb +0 -5544
  136. data/spec/core/deprecated_spec.rb +0 -70
  137. data/spec/core/expression_filters_spec.rb +0 -1498
  138. data/spec/core/mock_adapter_spec.rb +0 -722
  139. data/spec/core/object_graph_spec.rb +0 -336
  140. data/spec/core/placeholder_literalizer_spec.rb +0 -166
  141. data/spec/core/schema_generator_spec.rb +0 -214
  142. data/spec/core/schema_spec.rb +0 -1844
  143. data/spec/core/spec_helper.rb +0 -24
  144. data/spec/core/version_spec.rb +0 -14
  145. data/spec/core_extensions_spec.rb +0 -763
  146. data/spec/core_model_spec.rb +0 -2
  147. data/spec/core_spec.rb +0 -1
  148. data/spec/deprecation_helper.rb +0 -30
  149. data/spec/extensions/accessed_columns_spec.rb +0 -51
  150. data/spec/extensions/active_model_spec.rb +0 -99
  151. data/spec/extensions/after_initialize_spec.rb +0 -28
  152. data/spec/extensions/any_not_empty_spec.rb +0 -23
  153. data/spec/extensions/arbitrary_servers_spec.rb +0 -109
  154. data/spec/extensions/association_dependencies_spec.rb +0 -125
  155. data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
  156. data/spec/extensions/association_pks_spec.rb +0 -423
  157. data/spec/extensions/association_proxies_spec.rb +0 -100
  158. data/spec/extensions/auto_literal_strings_spec.rb +0 -205
  159. data/spec/extensions/auto_validations_spec.rb +0 -229
  160. data/spec/extensions/blacklist_security_spec.rb +0 -95
  161. data/spec/extensions/blank_spec.rb +0 -69
  162. data/spec/extensions/boolean_readers_spec.rb +0 -93
  163. data/spec/extensions/boolean_subsets_spec.rb +0 -47
  164. data/spec/extensions/caching_spec.rb +0 -273
  165. data/spec/extensions/caller_logging_spec.rb +0 -52
  166. data/spec/extensions/class_table_inheritance_spec.rb +0 -750
  167. data/spec/extensions/column_conflicts_spec.rb +0 -75
  168. data/spec/extensions/column_select_spec.rb +0 -129
  169. data/spec/extensions/columns_introspection_spec.rb +0 -90
  170. data/spec/extensions/columns_updated_spec.rb +0 -35
  171. data/spec/extensions/composition_spec.rb +0 -248
  172. data/spec/extensions/connection_expiration_spec.rb +0 -151
  173. data/spec/extensions/connection_validator_spec.rb +0 -144
  174. data/spec/extensions/constant_sql_override_spec.rb +0 -24
  175. data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
  176. data/spec/extensions/constraint_validations_spec.rb +0 -439
  177. data/spec/extensions/core_refinements_spec.rb +0 -528
  178. data/spec/extensions/csv_serializer_spec.rb +0 -183
  179. data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
  180. data/spec/extensions/dataset_associations_spec.rb +0 -365
  181. data/spec/extensions/dataset_source_alias_spec.rb +0 -51
  182. data/spec/extensions/date_arithmetic_spec.rb +0 -181
  183. data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
  184. data/spec/extensions/def_dataset_method_spec.rb +0 -100
  185. data/spec/extensions/defaults_setter_spec.rb +0 -150
  186. data/spec/extensions/delay_add_association_spec.rb +0 -73
  187. data/spec/extensions/dirty_spec.rb +0 -222
  188. data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
  189. data/spec/extensions/eager_each_spec.rb +0 -62
  190. data/spec/extensions/eager_graph_eager_spec.rb +0 -100
  191. data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
  192. data/spec/extensions/empty_failure_backtraces_spec.rb +0 -60
  193. data/spec/extensions/error_splitter_spec.rb +0 -18
  194. data/spec/extensions/error_sql_spec.rb +0 -20
  195. data/spec/extensions/escaped_like_spec.rb +0 -40
  196. data/spec/extensions/eval_inspect_spec.rb +0 -81
  197. data/spec/extensions/exclude_or_null_spec.rb +0 -15
  198. data/spec/extensions/finder_spec.rb +0 -260
  199. data/spec/extensions/force_encoding_spec.rb +0 -126
  200. data/spec/extensions/freeze_datasets_spec.rb +0 -31
  201. data/spec/extensions/graph_each_spec.rb +0 -113
  202. data/spec/extensions/hook_class_methods_spec.rb +0 -402
  203. data/spec/extensions/identifier_mangling_spec.rb +0 -201
  204. data/spec/extensions/implicit_subquery_spec.rb +0 -58
  205. data/spec/extensions/index_caching_spec.rb +0 -66
  206. data/spec/extensions/inflector_spec.rb +0 -183
  207. data/spec/extensions/input_transformer_spec.rb +0 -69
  208. data/spec/extensions/insert_conflict_spec.rb +0 -103
  209. data/spec/extensions/insert_returning_select_spec.rb +0 -72
  210. data/spec/extensions/instance_filters_spec.rb +0 -79
  211. data/spec/extensions/instance_hooks_spec.rb +0 -246
  212. data/spec/extensions/integer64_spec.rb +0 -22
  213. data/spec/extensions/inverted_subsets_spec.rb +0 -33
  214. data/spec/extensions/json_serializer_spec.rb +0 -346
  215. data/spec/extensions/lazy_attributes_spec.rb +0 -183
  216. data/spec/extensions/list_spec.rb +0 -291
  217. data/spec/extensions/looser_typecasting_spec.rb +0 -43
  218. data/spec/extensions/many_through_many_spec.rb +0 -2177
  219. data/spec/extensions/migration_spec.rb +0 -864
  220. data/spec/extensions/modification_detection_spec.rb +0 -93
  221. data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
  222. data/spec/extensions/named_timezones_spec.rb +0 -218
  223. data/spec/extensions/nested_attributes_spec.rb +0 -815
  224. data/spec/extensions/null_dataset_spec.rb +0 -85
  225. data/spec/extensions/optimistic_locking_spec.rb +0 -127
  226. data/spec/extensions/pagination_spec.rb +0 -116
  227. data/spec/extensions/pg_array_associations_spec.rb +0 -802
  228. data/spec/extensions/pg_array_ops_spec.rb +0 -144
  229. data/spec/extensions/pg_array_spec.rb +0 -398
  230. data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -209
  231. data/spec/extensions/pg_enum_spec.rb +0 -118
  232. data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
  233. data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
  234. data/spec/extensions/pg_hstore_spec.rb +0 -219
  235. data/spec/extensions/pg_inet_ops_spec.rb +0 -102
  236. data/spec/extensions/pg_inet_spec.rb +0 -72
  237. data/spec/extensions/pg_interval_spec.rb +0 -103
  238. data/spec/extensions/pg_json_ops_spec.rb +0 -356
  239. data/spec/extensions/pg_json_spec.rb +0 -451
  240. data/spec/extensions/pg_loose_count_spec.rb +0 -23
  241. data/spec/extensions/pg_range_ops_spec.rb +0 -60
  242. data/spec/extensions/pg_range_spec.rb +0 -600
  243. data/spec/extensions/pg_row_ops_spec.rb +0 -61
  244. data/spec/extensions/pg_row_plugin_spec.rb +0 -60
  245. data/spec/extensions/pg_row_spec.rb +0 -363
  246. data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
  247. data/spec/extensions/pg_timestamptz_spec.rb +0 -17
  248. data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
  249. data/spec/extensions/prepared_statements_spec.rb +0 -177
  250. data/spec/extensions/pretty_table_spec.rb +0 -123
  251. data/spec/extensions/query_spec.rb +0 -94
  252. data/spec/extensions/rcte_tree_spec.rb +0 -387
  253. data/spec/extensions/round_timestamps_spec.rb +0 -39
  254. data/spec/extensions/s_spec.rb +0 -60
  255. data/spec/extensions/schema_caching_spec.rb +0 -64
  256. data/spec/extensions/schema_dumper_spec.rb +0 -870
  257. data/spec/extensions/select_remove_spec.rb +0 -38
  258. data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
  259. data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
  260. data/spec/extensions/serialization_spec.rb +0 -365
  261. data/spec/extensions/server_block_spec.rb +0 -135
  262. data/spec/extensions/server_logging_spec.rb +0 -45
  263. data/spec/extensions/sharding_spec.rb +0 -197
  264. data/spec/extensions/shared_caching_spec.rb +0 -151
  265. data/spec/extensions/single_table_inheritance_spec.rb +0 -347
  266. data/spec/extensions/singular_table_names_spec.rb +0 -22
  267. data/spec/extensions/skip_create_refresh_spec.rb +0 -18
  268. data/spec/extensions/spec_helper.rb +0 -70
  269. data/spec/extensions/split_array_nil_spec.rb +0 -24
  270. data/spec/extensions/split_values_spec.rb +0 -57
  271. data/spec/extensions/sql_comments_spec.rb +0 -33
  272. data/spec/extensions/sql_expr_spec.rb +0 -59
  273. data/spec/extensions/static_cache_cache_spec.rb +0 -35
  274. data/spec/extensions/static_cache_spec.rb +0 -471
  275. data/spec/extensions/string_agg_spec.rb +0 -90
  276. data/spec/extensions/string_date_time_spec.rb +0 -95
  277. data/spec/extensions/string_stripper_spec.rb +0 -68
  278. data/spec/extensions/subclasses_spec.rb +0 -79
  279. data/spec/extensions/subset_conditions_spec.rb +0 -38
  280. data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
  281. data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
  282. data/spec/extensions/synchronize_sql_spec.rb +0 -124
  283. data/spec/extensions/table_select_spec.rb +0 -83
  284. data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
  285. data/spec/extensions/thread_local_timezones_spec.rb +0 -67
  286. data/spec/extensions/throw_failures_spec.rb +0 -74
  287. data/spec/extensions/timestamps_spec.rb +0 -209
  288. data/spec/extensions/to_dot_spec.rb +0 -153
  289. data/spec/extensions/touch_spec.rb +0 -226
  290. data/spec/extensions/tree_spec.rb +0 -334
  291. data/spec/extensions/typecast_on_load_spec.rb +0 -86
  292. data/spec/extensions/unlimited_update_spec.rb +0 -21
  293. data/spec/extensions/update_or_create_spec.rb +0 -83
  294. data/spec/extensions/update_primary_key_spec.rb +0 -105
  295. data/spec/extensions/update_refresh_spec.rb +0 -59
  296. data/spec/extensions/uuid_spec.rb +0 -101
  297. data/spec/extensions/validate_associated_spec.rb +0 -52
  298. data/spec/extensions/validation_class_methods_spec.rb +0 -1040
  299. data/spec/extensions/validation_contexts_spec.rb +0 -31
  300. data/spec/extensions/validation_helpers_spec.rb +0 -525
  301. data/spec/extensions/whitelist_security_spec.rb +0 -157
  302. data/spec/extensions/xml_serializer_spec.rb +0 -213
  303. data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
  304. data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
  305. data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  306. data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  307. data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
  308. data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
  309. data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
  310. data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
  311. data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
  312. data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
  313. data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
  314. data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
  315. data/spec/files/double_migration/001_create_sessions.rb +0 -9
  316. data/spec/files/double_migration/002_create_nodes.rb +0 -19
  317. data/spec/files/double_migration/003_3_create_users.rb +0 -4
  318. data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
  319. data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
  320. data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  321. data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
  322. data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
  323. data/spec/files/empty_migration/001_create_sessions.rb +0 -9
  324. data/spec/files/empty_migration/002_create_nodes.rb +0 -0
  325. data/spec/files/empty_migration/003_3_create_users.rb +0 -4
  326. data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
  327. data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
  328. data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
  329. data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  330. data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
  331. data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  332. data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
  333. data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  334. data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
  335. data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
  336. data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  337. data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  338. data/spec/files/reversible_migrations/001_reversible.rb +0 -5
  339. data/spec/files/reversible_migrations/002_reversible.rb +0 -5
  340. data/spec/files/reversible_migrations/003_reversible.rb +0 -5
  341. data/spec/files/reversible_migrations/004_reversible.rb +0 -5
  342. data/spec/files/reversible_migrations/005_reversible.rb +0 -10
  343. data/spec/files/reversible_migrations/006_reversible.rb +0 -10
  344. data/spec/files/reversible_migrations/007_reversible.rb +0 -10
  345. data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
  346. data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
  347. data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
  348. data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
  349. data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
  350. data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
  351. data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
  352. data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
  353. data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
  354. data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
  355. data/spec/guards_helper.rb +0 -59
  356. data/spec/integration/associations_test.rb +0 -2597
  357. data/spec/integration/database_test.rb +0 -113
  358. data/spec/integration/dataset_test.rb +0 -2037
  359. data/spec/integration/eager_loader_test.rb +0 -687
  360. data/spec/integration/migrator_test.rb +0 -262
  361. data/spec/integration/model_test.rb +0 -203
  362. data/spec/integration/plugin_test.rb +0 -2423
  363. data/spec/integration/prepared_statement_test.rb +0 -405
  364. data/spec/integration/schema_test.rb +0 -903
  365. data/spec/integration/spec_helper.rb +0 -71
  366. data/spec/integration/timezone_test.rb +0 -86
  367. data/spec/integration/transaction_test.rb +0 -603
  368. data/spec/integration/type_test.rb +0 -127
  369. data/spec/model/association_reflection_spec.rb +0 -803
  370. data/spec/model/associations_spec.rb +0 -4738
  371. data/spec/model/base_spec.rb +0 -875
  372. data/spec/model/class_dataset_methods_spec.rb +0 -146
  373. data/spec/model/dataset_methods_spec.rb +0 -198
  374. data/spec/model/eager_loading_spec.rb +0 -2377
  375. data/spec/model/hooks_spec.rb +0 -370
  376. data/spec/model/inflector_spec.rb +0 -26
  377. data/spec/model/model_spec.rb +0 -956
  378. data/spec/model/plugins_spec.rb +0 -429
  379. data/spec/model/record_spec.rb +0 -2118
  380. data/spec/model/spec_helper.rb +0 -46
  381. data/spec/model/validations_spec.rb +0 -220
  382. data/spec/model_no_assoc_spec.rb +0 -1
  383. data/spec/model_spec.rb +0 -1
  384. data/spec/plugin_spec.rb +0 -1
  385. data/spec/sequel_coverage.rb +0 -15
  386. data/spec/sequel_warning.rb +0 -5
  387. data/spec/spec_config.rb +0 -12
@@ -1,451 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- Sequel.extension :pg_array, :pg_json
4
-
5
- describe "pg_json extension" do
6
- integer_class = RUBY_VERSION >= '2.4' ? Integer : Fixnum
7
-
8
- before(:all) do
9
- m = Sequel::Postgres
10
- @m = m::JSONDatabaseMethods
11
- @hc = m::JSONHash
12
- @ac = m::JSONArray
13
- @bhc = m::JSONBHash
14
- @bac = m::JSONBArray
15
- end
16
- before do
17
- @db = Sequel.connect('mock://postgres')
18
- @db.extend_datasets{def quote_identifiers?; false end}
19
- @db.extension(:pg_array, :pg_json)
20
- end
21
-
22
- it "should set up conversion procs correctly" do
23
- cp = @db.conversion_procs
24
- cp[114].call("{}").must_equal @hc.new({})
25
- cp[3802].call("{}").must_equal @bhc.new({})
26
- end
27
-
28
- it "should set up conversion procs for arrays correctly" do
29
- cp = @db.conversion_procs
30
- cp[199].call("{[]}").must_equal [@ac.new([])]
31
- cp[3807].call("{[]}").must_equal [@bac.new([])]
32
- end
33
-
34
- deprecated "should parse json strings correctly" do
35
- @m.parse_json('[]').class.must_equal(@ac)
36
- @m.parse_json('[]').to_a.must_equal []
37
- @m.parse_json('[1]').to_a.must_equal [1]
38
- @m.parse_json('[1, 2]').to_a.must_equal [1, 2]
39
- @m.parse_json('[1, [2], {"a": "b"}]').to_a.must_equal [1, [2], {'a'=>'b'}]
40
- @m.parse_json('{}').class.must_equal(@hc)
41
- @m.parse_json('{}').to_hash.must_equal({})
42
- @m.parse_json('{"a": "b"}').to_hash.must_equal('a'=>'b')
43
- @m.parse_json('{"a": "b", "c": [1, 2, 3]}').to_hash.must_equal('a'=>'b', 'c'=>[1, 2, 3])
44
- @m.parse_json('{"a": "b", "c": {"d": "e"}}').to_hash.must_equal('a'=>'b', 'c'=>{'d'=>'e'})
45
- proc{@m.parse_json("a")}.must_raise Sequel::InvalidValue
46
-
47
- begin
48
- Sequel.instance_eval do
49
- alias pj parse_json
50
- def parse_json(v)
51
- {'1'=>1, "'a'"=>'a', 'true'=>true, 'false'=>false, 'null'=>nil, 'o'=>Object.new, '[one]'=>[1]}.fetch(v){pj(v)}
52
- end
53
- end
54
- proc{@m.parse_json('o')}.must_raise(Sequel::InvalidValue)
55
- ensure
56
- Sequel.instance_eval do
57
- alias parse_json pj
58
- end
59
- end
60
- end
61
-
62
- deprecated "should parse json and non-json plain strings, integers, and floats correctly in db_parse_json" do
63
- @m.db_parse_json('{"a": "b", "c": {"d": "e"}}').to_hash.must_equal('a'=>'b', 'c'=>{'d'=>'e'})
64
- @m.db_parse_json('[1, [2], {"a": "b"}]').to_a.must_equal [1, [2], {'a'=>'b'}]
65
- @m.db_parse_json('1').must_equal 1
66
- @m.db_parse_json('"b"').must_equal 'b'
67
- @m.db_parse_json('1.1').must_equal 1.1
68
- proc{@m.db_parse_json("a")}.must_raise Sequel::InvalidValue
69
- end
70
-
71
- deprecated "should parse jsonb and non-jsonb plain strings, integers, and floats correctly in db_parse_jsonb" do
72
- @m.db_parse_jsonb('{"a": "b", "c": {"d": "e"}}').to_hash.must_equal('a'=>'b', 'c'=>{'d'=>'e'})
73
- @m.db_parse_jsonb('[1, [2], {"a": "b"}]').to_a.must_equal [1, [2], {'a'=>'b'}]
74
- @m.db_parse_jsonb('1').must_equal 1
75
- @m.db_parse_jsonb('"b"').must_equal 'b'
76
- @m.db_parse_jsonb('1.1').must_equal 1.1
77
- proc{@m.db_parse_jsonb("a")}.must_raise Sequel::InvalidValue
78
- end
79
-
80
- it "should parse json and non-json plain strings, integers, and floats correctly in conversion_proc" do
81
- cp = @db.conversion_procs[114]
82
- cp.call('{"a": "b", "c": {"d": "e"}}').to_hash.must_equal('a'=>'b', 'c'=>{'d'=>'e'})
83
- cp.call('[1, [2], {"a": "b"}]').to_a.must_equal [1, [2], {'a'=>'b'}]
84
- cp.call('1').must_equal 1
85
- cp.call('"b"').must_equal 'b'
86
- cp.call('1.1').must_equal 1.1
87
- end
88
-
89
- it "should parse jsonb and non-jsonb plain strings, integers, and floats correctly in conversion_proc" do
90
- cp = @db.conversion_procs[3802]
91
- cp.call('{"a": "b", "c": {"d": "e"}}').to_hash.must_equal('a'=>'b', 'c'=>{'d'=>'e'})
92
- cp.call('[1, [2], {"a": "b"}]').to_a.must_equal [1, [2], {'a'=>'b'}]
93
- cp.call('1').must_equal 1
94
- cp.call('"b"').must_equal 'b'
95
- cp.call('1.1').must_equal 1.1
96
- end
97
-
98
- it "should raise an error when attempting to parse invalid json" do
99
- [114, 3802].each do |oid|
100
- cp = @db.conversion_procs[oid]
101
- proc{cp.call('a')}.must_raise(Sequel::InvalidValue)
102
-
103
- begin
104
- Sequel.instance_eval do
105
- alias pj parse_json
106
- def parse_json(v)
107
- {'1'=>1, "'a'"=>'a', 'true'=>true, 'false'=>false, 'null'=>nil, 'o'=>Object.new, '[one]'=>[1]}.fetch(v){pj(v)}
108
- end
109
- end
110
- cp.call('1').must_equal 1
111
- cp.call("'a'").must_equal 'a'
112
- cp.call('true').must_equal true
113
- cp.call('false').must_equal false
114
- cp.call('null').must_be_nil
115
- proc{cp.call('o')}.must_raise(Sequel::InvalidValue)
116
- cp.call('one').must_equal 1
117
- ensure
118
- Sequel.instance_eval do
119
- alias parse_json pj
120
- end
121
- end
122
- end
123
- end
124
-
125
- it "should literalize JSONHash and JSONArray to strings correctly" do
126
- @db.literal(Sequel.pg_json([])).must_equal "'[]'::json"
127
- @db.literal(Sequel.pg_json([1, [2], {'a'=>'b'}])).must_equal "'[1,[2],{\"a\":\"b\"}]'::json"
128
- @db.literal(Sequel.pg_json({})).must_equal "'{}'::json"
129
- @db.literal(Sequel.pg_json('a'=>'b')).must_equal "'{\"a\":\"b\"}'::json"
130
- end
131
-
132
- it "should literalize JSONBHash and JSONBArray to strings correctly" do
133
- @db.literal(Sequel.pg_jsonb([])).must_equal "'[]'::jsonb"
134
- @db.literal(Sequel.pg_jsonb([1, [2], {'a'=>'b'}])).must_equal "'[1,[2],{\"a\":\"b\"}]'::jsonb"
135
- @db.literal(Sequel.pg_jsonb({})).must_equal "'{}'::jsonb"
136
- @db.literal(Sequel.pg_jsonb('a'=>'b')).must_equal "'{\"a\":\"b\"}'::jsonb"
137
- end
138
-
139
- it "should have Sequel.pg_json return JSONHash and JSONArray as is" do
140
- a = Sequel.pg_json({})
141
- Sequel.pg_json(a).object_id.must_equal(a.object_id)
142
- a = Sequel.pg_json([])
143
- Sequel.pg_json(a).object_id.must_equal(a.object_id)
144
- end
145
-
146
- it "should have Sequel.pg_json convert jsonb values" do
147
- a = {}
148
- v = Sequel.pg_json(Sequel.pg_jsonb(a))
149
- v.to_hash.must_be_same_as(a)
150
- v.class.must_equal(@hc)
151
-
152
- a = []
153
- v = Sequel.pg_json(Sequel.pg_jsonb(a))
154
- v.to_a.must_be_same_as(a)
155
- v.class.must_equal(@ac)
156
- end
157
-
158
- it "should have Sequel.pg_jsonb return JSONBHash and JSONBArray as is" do
159
- a = Sequel.pg_jsonb({})
160
- Sequel.pg_jsonb(a).object_id.must_equal(a.object_id)
161
- a = Sequel.pg_jsonb([])
162
- Sequel.pg_jsonb(a).object_id.must_equal(a.object_id)
163
- end
164
-
165
- it "should have Sequel.pg_jsonb convert json values" do
166
- a = {}
167
- v = Sequel.pg_jsonb(Sequel.pg_json(a))
168
- v.to_hash.must_be_same_as(a)
169
- v.class.must_equal(@bhc)
170
-
171
- a = []
172
- v = Sequel.pg_jsonb(Sequel.pg_json(a))
173
- v.to_a.must_be_same_as(a)
174
- v.class.must_equal(@bac)
175
- end
176
-
177
- it "should have JSONHashBase#to_hash method for getting underlying hash" do
178
- Sequel.pg_json({}).to_hash.must_be_kind_of(Hash)
179
- Sequel.pg_jsonb({}).to_hash.must_be_kind_of(Hash)
180
- end
181
-
182
- it "should allow aliasing json objects" do
183
- @db.literal(Sequel.pg_json({}).as(:a)).must_equal "'{}'::json AS a"
184
- @db.literal(Sequel.pg_json([]).as(:a)).must_equal "'[]'::json AS a"
185
- @db.literal(Sequel.pg_jsonb({}).as(:a)).must_equal "'{}'::jsonb AS a"
186
- @db.literal(Sequel.pg_jsonb([]).as(:a)).must_equal "'[]'::jsonb AS a"
187
- end
188
-
189
- it "should allow casting json objects" do
190
- @db.literal(Sequel.pg_json({}).cast(String)).must_equal "CAST('{}'::json AS text)"
191
- @db.literal(Sequel.pg_json([]).cast(String)).must_equal "CAST('[]'::json AS text)"
192
- @db.literal(Sequel.pg_jsonb({}).cast(String)).must_equal "CAST('{}'::jsonb AS text)"
193
- @db.literal(Sequel.pg_jsonb([]).cast(String)).must_equal "CAST('[]'::jsonb AS text)"
194
- end
195
-
196
- it "should have JSONArrayBase#to_a method for getting underlying array" do
197
- Sequel.pg_json([]).to_a.must_be_kind_of(Array)
198
- Sequel.pg_jsonb([]).to_a.must_be_kind_of(Array)
199
- end
200
-
201
- it "should support using JSONHashBase and JSONArrayBase as bound variables" do
202
- @db.bound_variable_arg(1, nil).must_equal 1
203
- @db.bound_variable_arg(Sequel.pg_json([1]), nil).must_equal '[1]'
204
- @db.bound_variable_arg(Sequel.pg_json('a'=>'b'), nil).must_equal '{"a":"b"}'
205
- @db.bound_variable_arg(Sequel.pg_jsonb([1]), nil).must_equal '[1]'
206
- @db.bound_variable_arg(Sequel.pg_jsonb('a'=>'b'), nil).must_equal '{"a":"b"}'
207
- end
208
-
209
- it "should support using json[] and jsonb[] types in bound variables" do
210
- @db.bound_variable_arg(Sequel.pg_array([Sequel.pg_json([{"a"=>1}]), Sequel.pg_json("b"=>[1, 2])]), nil).must_equal '{"[{\\"a\\":1}]","{\\"b\\":[1,2]}"}'
211
- @db.bound_variable_arg(Sequel.pg_array([Sequel.pg_jsonb([{"a"=>1}]), Sequel.pg_jsonb("b"=>[1, 2])]), nil).must_equal '{"[{\\"a\\":1}]","{\\"b\\":[1,2]}"}'
212
- end
213
-
214
- it "should support using wrapped JSON and JSONB primitives as bound variables" do
215
- @db.bound_variable_arg(Sequel.pg_json_wrap(1), nil).must_equal '1'
216
- @db.bound_variable_arg(Sequel.pg_json_wrap(2.5), nil).must_equal '2.5'
217
- @db.bound_variable_arg(Sequel.pg_json_wrap('a'), nil).must_equal '"a"'
218
- @db.bound_variable_arg(Sequel.pg_json_wrap(true), nil).must_equal 'true'
219
- @db.bound_variable_arg(Sequel.pg_json_wrap(false), nil).must_equal 'false'
220
- @db.bound_variable_arg(Sequel.pg_json_wrap(nil), nil).must_equal 'null'
221
- end
222
-
223
- it "should support using json[] and jsonb[] types in bound variables with ruby primitives" do
224
- @db.bound_variable_arg(Sequel.pg_array([1, 2.5, 'a', true, false, nil].map{|v| Sequel.pg_json_wrap(v)}), nil).must_equal '{"1","2.5","\"a\"","true","false","null"}'
225
- end
226
-
227
- it "Sequel.pg_json_wrap should wrap Ruby primitives in JSON wrappers" do
228
- Sequel.pg_json_wrap({}).class.must_equal Sequel::Postgres::JSONHash
229
- Sequel.pg_json_wrap({}).must_equal({})
230
- Sequel.pg_json_wrap([]).class.must_equal Sequel::Postgres::JSONArray
231
- Sequel.pg_json_wrap([]).must_equal []
232
- Sequel.pg_json_wrap('a').class.must_equal Sequel::Postgres::JSONString
233
- Sequel.pg_json_wrap('a').must_equal 'a'
234
- Sequel.pg_json_wrap(1).class.must_equal Sequel::Postgres::JSONInteger
235
- Sequel.pg_json_wrap(1).must_equal 1
236
- Sequel.pg_json_wrap(2.5).class.must_equal Sequel::Postgres::JSONFloat
237
- Sequel.pg_json_wrap(2.5).must_equal 2.5
238
- Sequel.pg_json_wrap(true).class.must_equal Sequel::Postgres::JSONTrue
239
- Sequel.pg_json_wrap(true).must_equal true
240
- Sequel.pg_json_wrap(false).class.must_equal Sequel::Postgres::JSONFalse
241
- Sequel.pg_json_wrap(false).must_equal false
242
- Sequel.pg_json_wrap(nil).class.must_equal Sequel::Postgres::JSONNull
243
- Sequel.pg_json_wrap(nil).must_be_nil
244
-
245
- c = Class.new(Hash).new
246
- Sequel.pg_json_wrap(c).class.must_equal Sequel::Postgres::JSONHash
247
- Sequel.pg_json_wrap(c).must_equal(c)
248
-
249
- c = Class.new(Array).new
250
- Sequel.pg_json_wrap(c).class.must_equal Sequel::Postgres::JSONArray
251
- Sequel.pg_json_wrap(c).must_equal c
252
-
253
- c = Class.new(String).new('a')
254
- Sequel.pg_json_wrap(c).class.must_equal Sequel::Postgres::JSONString
255
- Sequel.pg_json_wrap(c).must_equal c
256
- end
257
-
258
- it "Sequel.pg_json_wrap should fail when passed an unsupported object" do
259
- proc{Sequel.pg_json_wrap(Object.new)}.must_raise Sequel::Error
260
- end
261
-
262
- it "Sequel.pg_jsonb_wrap should wrap Ruby primitives in JSONB wrappers" do
263
- Sequel.pg_jsonb_wrap({}).class.must_equal Sequel::Postgres::JSONBHash
264
- Sequel.pg_jsonb_wrap({}).must_equal({})
265
- Sequel.pg_jsonb_wrap([]).class.must_equal Sequel::Postgres::JSONBArray
266
- Sequel.pg_jsonb_wrap([]).must_equal []
267
- Sequel.pg_jsonb_wrap('a').class.must_equal Sequel::Postgres::JSONBString
268
- Sequel.pg_jsonb_wrap('a').must_equal 'a'
269
- Sequel.pg_jsonb_wrap(1).class.must_equal Sequel::Postgres::JSONBInteger
270
- Sequel.pg_jsonb_wrap(1).must_equal 1
271
- Sequel.pg_jsonb_wrap(2.5).class.must_equal Sequel::Postgres::JSONBFloat
272
- Sequel.pg_jsonb_wrap(2.5).must_equal 2.5
273
- Sequel.pg_jsonb_wrap(true).class.must_equal Sequel::Postgres::JSONBTrue
274
- Sequel.pg_jsonb_wrap(true).must_equal true
275
- Sequel.pg_jsonb_wrap(false).class.must_equal Sequel::Postgres::JSONBFalse
276
- Sequel.pg_jsonb_wrap(false).must_equal false
277
- Sequel.pg_jsonb_wrap(nil).class.must_equal Sequel::Postgres::JSONBNull
278
- Sequel.pg_jsonb_wrap(nil).must_be_nil
279
- end
280
-
281
- it "Sequel.pg_jsonb_wrap should fail when passed an unsupported object" do
282
- proc{Sequel.pg_jsonb_wrap(Object.new)}.must_raise Sequel::Error
283
- end
284
-
285
- it "should not wrap JSON primitives in json and jsonb conversion_proc when not setting wrap_json_primitives" do
286
- [114, 3802].each do |oid|
287
- cp = @db.conversion_procs[oid]
288
- cp.call('1').class.must_equal(integer_class)
289
- cp.call('1').must_equal 1
290
- cp.call('2.5').class.must_equal Float
291
- cp.call('2.5').must_equal 2.5
292
- cp.call('"a"').class.must_equal String
293
- cp.call('"a"').must_equal 'a'
294
- cp.call('true').class.must_equal TrueClass
295
- cp.call('true').must_equal true
296
- cp.call('false').class.must_equal FalseClass
297
- cp.call('false').must_equal false
298
- cp.call('null').class.must_equal NilClass
299
- cp.call('null').must_be_nil
300
- end
301
- end
302
-
303
- it "should wrap JSON primitives in json conversion_proc when setting wrap_json_primitives" do
304
- cp = @db.conversion_procs[114]
305
- @db.wrap_json_primitives = true
306
- cp.call('1').class.must_equal Sequel::Postgres::JSONInteger
307
- cp.call('1').must_equal 1
308
- cp.call('2.5').class.must_equal Sequel::Postgres::JSONFloat
309
- cp.call('2.5').must_equal 2.5
310
- cp.call('"a"').class.must_equal Sequel::Postgres::JSONString
311
- cp.call('"a"').must_equal "a"
312
- cp.call('true').class.must_equal Sequel::Postgres::JSONTrue
313
- cp.call('true').must_equal true
314
- cp.call('false').class.must_equal Sequel::Postgres::JSONFalse
315
- cp.call('false').must_equal false
316
- cp.call('null').class.must_equal Sequel::Postgres::JSONNull
317
- cp.call('null').must_be_nil
318
- end
319
-
320
- it "should wrap JSON primitives in jsonb conversion_proc when setting wrap_json_primitives" do
321
- cp = @db.conversion_procs[3802]
322
- @db.wrap_json_primitives = true
323
- cp.call('1').class.must_equal Sequel::Postgres::JSONBInteger
324
- cp.call('1').must_equal 1
325
- cp.call('2.5').class.must_equal Sequel::Postgres::JSONBFloat
326
- cp.call('2.5').must_equal 2.5
327
- cp.call('"a"').class.must_equal Sequel::Postgres::JSONBString
328
- cp.call('"a"').must_equal "a"
329
- cp.call('true').class.must_equal Sequel::Postgres::JSONBTrue
330
- cp.call('true').must_equal true
331
- cp.call('false').class.must_equal Sequel::Postgres::JSONBFalse
332
- cp.call('false').must_equal false
333
- cp.call('null').class.must_equal Sequel::Postgres::JSONBNull
334
- cp.call('null').must_be_nil
335
- end
336
-
337
- it "should parse json type from the schema correctly" do
338
- @db.fetch = [{:name=>'id', :db_type=>'integer'}, {:name=>'i', :db_type=>'json'}]
339
- @db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :json]
340
- end
341
-
342
- it "should parse json type from the schema correctly" do
343
- @db.fetch = [{:name=>'id', :db_type=>'integer'}, {:name=>'i', :db_type=>'jsonb'}]
344
- @db.schema(:items).map{|e| e[1][:type]}.must_equal [:integer, :jsonb]
345
- end
346
-
347
- it "should set :callable_default schema entries if default value is recognized" do
348
- @db.fetch = [{:name=>'id', :db_type=>'integer', :default=>'1'}, {:name=>'jh', :db_type=>'json', :default=>"'{}'::json"}, {:name=>'ja', :db_type=>'json', :default=>"'[]'::json"}, {:name=>'jbh', :db_type=>'jsonb', :default=>"'{}'::jsonb"}, {:name=>'jba', :db_type=>'jsonb', :default=>"'[]'::jsonb"}]
349
- s = @db.schema(:items)
350
- s[0][1][:callable_default].must_be_nil
351
- v = s[1][1][:callable_default].call
352
- Sequel::Postgres::JSONHash.===(v).must_equal true
353
- @db.literal(v).must_equal "'{}'::json"
354
- v['a'] = 'b'
355
- @db.literal(v).must_equal "'{\"a\":\"b\"}'::json"
356
-
357
- v = s[2][1][:callable_default].call
358
- Sequel::Postgres::JSONArray.===(v).must_equal true
359
- @db.literal(v).must_equal "'[]'::json"
360
- v << 1
361
- @db.literal(v).must_equal "'[1]'::json"
362
-
363
- v = s[3][1][:callable_default].call
364
- Sequel::Postgres::JSONBHash.===(v).must_equal true
365
- @db.literal(v).must_equal "'{}'::jsonb"
366
- v['a'] = 'b'
367
- @db.literal(v).must_equal "'{\"a\":\"b\"}'::jsonb"
368
-
369
- v = s[4][1][:callable_default].call
370
- Sequel::Postgres::JSONBArray.===(v).must_equal true
371
- @db.literal(v).must_equal "'[]'::jsonb"
372
- v << 1
373
- @db.literal(v).must_equal "'[1]'::jsonb"
374
- end
375
-
376
- it "should support typecasting for the json type" do
377
- h = Sequel.pg_json(1=>2)
378
- a = Sequel.pg_json([1])
379
- @db.typecast_value(:json, h).object_id.must_equal(h.object_id)
380
- @db.typecast_value(:json, h.to_hash).must_equal h
381
- @db.typecast_value(:json, h.to_hash).class.must_equal(@hc)
382
- @db.typecast_value(:json, Sequel.pg_jsonb(h)).must_equal h
383
- @db.typecast_value(:json, Sequel.pg_jsonb(h)).class.must_equal(@hc)
384
- @db.typecast_value(:json, a).object_id.must_equal(a.object_id)
385
- @db.typecast_value(:json, a.to_a).must_equal a
386
- @db.typecast_value(:json, a.to_a).class.must_equal(@ac)
387
- @db.typecast_value(:json, Sequel.pg_jsonb(a)).must_equal a
388
- @db.typecast_value(:json, Sequel.pg_jsonb(a)).class.must_equal(@ac)
389
- @db.typecast_value(:json, '[]').must_equal Sequel.pg_json([])
390
- @db.typecast_value(:json, '[]').class.must_equal(@ac)
391
- @db.typecast_value(:json, '{"a": "b"}').must_equal Sequel.pg_json("a"=>"b")
392
- @db.typecast_value(:json, '{"a": "b"}').class.must_equal(@hc)
393
- @db.typecast_value(:json, 1).class.must_equal Sequel::Postgres::JSONInteger
394
- @db.typecast_value(:json, 1).must_equal 1
395
- @db.typecast_value(:json, 2.5).class.must_equal Sequel::Postgres::JSONFloat
396
- @db.typecast_value(:json, 2.5).must_equal 2.5
397
- @db.typecast_value(:json, true).class.must_equal Sequel::Postgres::JSONTrue
398
- @db.typecast_value(:json, true).must_equal true
399
- @db.typecast_value(:json, false).class.must_equal Sequel::Postgres::JSONFalse
400
- @db.typecast_value(:json, false).must_equal false
401
- @db.typecast_value(:json, nil).class.must_equal NilClass
402
- @db.typecast_value(:json, nil).must_be_nil
403
- proc{@db.typecast_value(:json, 'a')}.must_raise(Sequel::InvalidValue)
404
- proc{@db.typecast_value(:json, Object.new)}.must_raise(Sequel::InvalidValue)
405
-
406
- @db.typecast_json_strings = true
407
- @db.typecast_value(:json, '[]').class.must_equal(Sequel::Postgres::JSONString)
408
- @db.typecast_value(:json, '[]').must_equal '[]'
409
- end
410
-
411
- it "should support typecasting for the jsonb type" do
412
- h = Sequel.pg_jsonb(1=>2)
413
- a = Sequel.pg_jsonb([1])
414
- @db.typecast_value(:jsonb, h).object_id.must_equal(h.object_id)
415
- @db.typecast_value(:jsonb, h.to_hash).must_equal h
416
- @db.typecast_value(:jsonb, h.to_hash).class.must_equal(@bhc)
417
- @db.typecast_value(:jsonb, Sequel.pg_json(h)).must_equal h
418
- @db.typecast_value(:jsonb, Sequel.pg_json(h)).class.must_equal(@bhc)
419
- @db.typecast_value(:jsonb, a).object_id.must_equal(a.object_id)
420
- @db.typecast_value(:jsonb, a.to_a).must_equal a
421
- @db.typecast_value(:jsonb, a.to_a).class.must_equal(@bac)
422
- @db.typecast_value(:jsonb, Sequel.pg_json(a)).must_equal a
423
- @db.typecast_value(:jsonb, Sequel.pg_json(a)).class.must_equal(@bac)
424
- @db.typecast_value(:jsonb, '[]').must_equal Sequel.pg_jsonb([])
425
- @db.typecast_value(:jsonb, '[]').class.must_equal(@bac)
426
- @db.typecast_value(:jsonb, '{"a": "b"}').must_equal Sequel.pg_jsonb("a"=>"b")
427
- @db.typecast_value(:jsonb, '{"a": "b"}').class.must_equal(@bhc)
428
- @db.typecast_value(:jsonb, 1).class.must_equal Sequel::Postgres::JSONBInteger
429
- @db.typecast_value(:jsonb, 1).must_equal 1
430
- @db.typecast_value(:jsonb, 2.5).class.must_equal Sequel::Postgres::JSONBFloat
431
- @db.typecast_value(:jsonb, 2.5).must_equal 2.5
432
- @db.typecast_value(:jsonb, true).class.must_equal Sequel::Postgres::JSONBTrue
433
- @db.typecast_value(:jsonb, true).must_equal true
434
- @db.typecast_value(:jsonb, false).class.must_equal Sequel::Postgres::JSONBFalse
435
- @db.typecast_value(:jsonb, false).must_equal false
436
- @db.typecast_value(:jsonb, nil).class.must_equal NilClass
437
- @db.typecast_value(:jsonb, nil).must_be_nil
438
- proc{@db.typecast_value(:jsonb, 'a')}.must_raise(Sequel::InvalidValue)
439
- proc{@db.typecast_value(:jsonb, Object.new)}.must_raise(Sequel::InvalidValue)
440
-
441
- @db.typecast_json_strings = true
442
- @db.typecast_value(:jsonb, '[]').class.must_equal(Sequel::Postgres::JSONBString)
443
- @db.typecast_value(:jsonb, '[]').must_equal '[]'
444
- end
445
-
446
- it "should return correct results for Database#schema_type_class" do
447
- @db.schema_type_class(:json).must_equal [Sequel::Postgres::JSONObject]
448
- @db.schema_type_class(:jsonb).must_equal [Sequel::Postgres::JSONBObject]
449
- @db.schema_type_class(:integer).must_equal Integer
450
- end
451
- end
@@ -1,23 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "pg_loose_count extension" do
4
- before do
5
- @db = Sequel.mock(:host=>'postgres', :fetch=>{:v=>1}).extension(:pg_loose_count)
6
- @db.extend_datasets{def quote_identifiers?; false end}
7
- end
8
-
9
- it "should add loose_count method getting fast count for entire table using table statistics" do
10
- @db.loose_count(:a).must_equal 1
11
- @db.sqls.must_equal ["SELECT CAST(reltuples AS integer) AS v FROM pg_class WHERE (oid = CAST(CAST('a' AS regclass) AS oid)) LIMIT 1"]
12
- end
13
-
14
- it "should support schema qualified tables" do
15
- @db.loose_count(Sequel[:a][:b]).must_equal 1
16
- @db.sqls.must_equal ["SELECT CAST(reltuples AS integer) AS v FROM pg_class WHERE (oid = CAST(CAST('a.b' AS regclass) AS oid)) LIMIT 1"]
17
- end
18
-
19
- with_symbol_splitting "should support schema qualified table symbols" do
20
- @db.loose_count(:a__b).must_equal 1
21
- @db.sqls.must_equal ["SELECT CAST(reltuples AS integer) AS v FROM pg_class WHERE (oid = CAST(CAST('a.b' AS regclass) AS oid)) LIMIT 1"]
22
- end
23
- end