sequel 5.29.0 → 5.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (323) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +8 -1922
  3. data/doc/release_notes/5.30.0.txt +20 -0
  4. data/lib/sequel/adapters/shared/sqlite.rb +7 -1
  5. data/lib/sequel/database/transactions.rb +5 -9
  6. data/lib/sequel/version.rb +1 -1
  7. metadata +4 -368
  8. data/Rakefile +0 -151
  9. data/doc/release_notes/4.0.0.txt +0 -262
  10. data/doc/release_notes/4.1.0.txt +0 -85
  11. data/doc/release_notes/4.10.0.txt +0 -226
  12. data/doc/release_notes/4.11.0.txt +0 -147
  13. data/doc/release_notes/4.12.0.txt +0 -105
  14. data/doc/release_notes/4.13.0.txt +0 -169
  15. data/doc/release_notes/4.14.0.txt +0 -68
  16. data/doc/release_notes/4.15.0.txt +0 -56
  17. data/doc/release_notes/4.16.0.txt +0 -36
  18. data/doc/release_notes/4.17.0.txt +0 -38
  19. data/doc/release_notes/4.18.0.txt +0 -36
  20. data/doc/release_notes/4.19.0.txt +0 -45
  21. data/doc/release_notes/4.2.0.txt +0 -129
  22. data/doc/release_notes/4.20.0.txt +0 -79
  23. data/doc/release_notes/4.21.0.txt +0 -94
  24. data/doc/release_notes/4.22.0.txt +0 -72
  25. data/doc/release_notes/4.23.0.txt +0 -65
  26. data/doc/release_notes/4.24.0.txt +0 -99
  27. data/doc/release_notes/4.25.0.txt +0 -181
  28. data/doc/release_notes/4.26.0.txt +0 -44
  29. data/doc/release_notes/4.27.0.txt +0 -78
  30. data/doc/release_notes/4.28.0.txt +0 -57
  31. data/doc/release_notes/4.29.0.txt +0 -41
  32. data/doc/release_notes/4.3.0.txt +0 -40
  33. data/doc/release_notes/4.30.0.txt +0 -37
  34. data/doc/release_notes/4.31.0.txt +0 -57
  35. data/doc/release_notes/4.32.0.txt +0 -132
  36. data/doc/release_notes/4.33.0.txt +0 -88
  37. data/doc/release_notes/4.34.0.txt +0 -86
  38. data/doc/release_notes/4.35.0.txt +0 -130
  39. data/doc/release_notes/4.36.0.txt +0 -116
  40. data/doc/release_notes/4.37.0.txt +0 -50
  41. data/doc/release_notes/4.38.0.txt +0 -67
  42. data/doc/release_notes/4.39.0.txt +0 -127
  43. data/doc/release_notes/4.4.0.txt +0 -92
  44. data/doc/release_notes/4.40.0.txt +0 -179
  45. data/doc/release_notes/4.41.0.txt +0 -77
  46. data/doc/release_notes/4.42.0.txt +0 -221
  47. data/doc/release_notes/4.43.0.txt +0 -87
  48. data/doc/release_notes/4.44.0.txt +0 -125
  49. data/doc/release_notes/4.45.0.txt +0 -370
  50. data/doc/release_notes/4.46.0.txt +0 -404
  51. data/doc/release_notes/4.47.0.txt +0 -56
  52. data/doc/release_notes/4.48.0.txt +0 -293
  53. data/doc/release_notes/4.49.0.txt +0 -222
  54. data/doc/release_notes/4.5.0.txt +0 -34
  55. data/doc/release_notes/4.6.0.txt +0 -30
  56. data/doc/release_notes/4.7.0.txt +0 -103
  57. data/doc/release_notes/4.8.0.txt +0 -175
  58. data/doc/release_notes/4.9.0.txt +0 -190
  59. data/spec/adapter_spec.rb +0 -4
  60. data/spec/adapters/db2_spec.rb +0 -170
  61. data/spec/adapters/mssql_spec.rb +0 -828
  62. data/spec/adapters/mysql_spec.rb +0 -1060
  63. data/spec/adapters/oracle_spec.rb +0 -371
  64. data/spec/adapters/postgres_spec.rb +0 -4476
  65. data/spec/adapters/spec_helper.rb +0 -44
  66. data/spec/adapters/sqlanywhere_spec.rb +0 -97
  67. data/spec/adapters/sqlite_spec.rb +0 -652
  68. data/spec/bin_spec.rb +0 -278
  69. data/spec/core/connection_pool_spec.rb +0 -1250
  70. data/spec/core/database_spec.rb +0 -2915
  71. data/spec/core/dataset_spec.rb +0 -5544
  72. data/spec/core/deprecated_spec.rb +0 -70
  73. data/spec/core/expression_filters_spec.rb +0 -1498
  74. data/spec/core/mock_adapter_spec.rb +0 -722
  75. data/spec/core/object_graph_spec.rb +0 -336
  76. data/spec/core/placeholder_literalizer_spec.rb +0 -166
  77. data/spec/core/schema_generator_spec.rb +0 -214
  78. data/spec/core/schema_spec.rb +0 -1844
  79. data/spec/core/spec_helper.rb +0 -24
  80. data/spec/core/version_spec.rb +0 -14
  81. data/spec/core_extensions_spec.rb +0 -763
  82. data/spec/core_model_spec.rb +0 -2
  83. data/spec/core_spec.rb +0 -1
  84. data/spec/deprecation_helper.rb +0 -30
  85. data/spec/extensions/accessed_columns_spec.rb +0 -51
  86. data/spec/extensions/active_model_spec.rb +0 -99
  87. data/spec/extensions/after_initialize_spec.rb +0 -28
  88. data/spec/extensions/any_not_empty_spec.rb +0 -23
  89. data/spec/extensions/arbitrary_servers_spec.rb +0 -109
  90. data/spec/extensions/association_dependencies_spec.rb +0 -125
  91. data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
  92. data/spec/extensions/association_pks_spec.rb +0 -423
  93. data/spec/extensions/association_proxies_spec.rb +0 -100
  94. data/spec/extensions/auto_literal_strings_spec.rb +0 -205
  95. data/spec/extensions/auto_validations_spec.rb +0 -229
  96. data/spec/extensions/blacklist_security_spec.rb +0 -95
  97. data/spec/extensions/blank_spec.rb +0 -69
  98. data/spec/extensions/boolean_readers_spec.rb +0 -93
  99. data/spec/extensions/boolean_subsets_spec.rb +0 -47
  100. data/spec/extensions/caching_spec.rb +0 -273
  101. data/spec/extensions/caller_logging_spec.rb +0 -52
  102. data/spec/extensions/class_table_inheritance_spec.rb +0 -750
  103. data/spec/extensions/column_conflicts_spec.rb +0 -75
  104. data/spec/extensions/column_select_spec.rb +0 -129
  105. data/spec/extensions/columns_introspection_spec.rb +0 -90
  106. data/spec/extensions/columns_updated_spec.rb +0 -35
  107. data/spec/extensions/composition_spec.rb +0 -248
  108. data/spec/extensions/connection_expiration_spec.rb +0 -151
  109. data/spec/extensions/connection_validator_spec.rb +0 -144
  110. data/spec/extensions/constant_sql_override_spec.rb +0 -24
  111. data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
  112. data/spec/extensions/constraint_validations_spec.rb +0 -439
  113. data/spec/extensions/core_refinements_spec.rb +0 -528
  114. data/spec/extensions/csv_serializer_spec.rb +0 -183
  115. data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
  116. data/spec/extensions/dataset_associations_spec.rb +0 -365
  117. data/spec/extensions/dataset_source_alias_spec.rb +0 -51
  118. data/spec/extensions/date_arithmetic_spec.rb +0 -181
  119. data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
  120. data/spec/extensions/def_dataset_method_spec.rb +0 -100
  121. data/spec/extensions/defaults_setter_spec.rb +0 -150
  122. data/spec/extensions/delay_add_association_spec.rb +0 -73
  123. data/spec/extensions/dirty_spec.rb +0 -222
  124. data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
  125. data/spec/extensions/eager_each_spec.rb +0 -62
  126. data/spec/extensions/eager_graph_eager_spec.rb +0 -100
  127. data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
  128. data/spec/extensions/empty_failure_backtraces_spec.rb +0 -60
  129. data/spec/extensions/error_splitter_spec.rb +0 -18
  130. data/spec/extensions/error_sql_spec.rb +0 -20
  131. data/spec/extensions/escaped_like_spec.rb +0 -40
  132. data/spec/extensions/eval_inspect_spec.rb +0 -81
  133. data/spec/extensions/exclude_or_null_spec.rb +0 -15
  134. data/spec/extensions/finder_spec.rb +0 -260
  135. data/spec/extensions/force_encoding_spec.rb +0 -126
  136. data/spec/extensions/freeze_datasets_spec.rb +0 -31
  137. data/spec/extensions/graph_each_spec.rb +0 -113
  138. data/spec/extensions/hook_class_methods_spec.rb +0 -402
  139. data/spec/extensions/identifier_mangling_spec.rb +0 -201
  140. data/spec/extensions/implicit_subquery_spec.rb +0 -58
  141. data/spec/extensions/index_caching_spec.rb +0 -66
  142. data/spec/extensions/inflector_spec.rb +0 -183
  143. data/spec/extensions/input_transformer_spec.rb +0 -69
  144. data/spec/extensions/insert_conflict_spec.rb +0 -103
  145. data/spec/extensions/insert_returning_select_spec.rb +0 -72
  146. data/spec/extensions/instance_filters_spec.rb +0 -79
  147. data/spec/extensions/instance_hooks_spec.rb +0 -246
  148. data/spec/extensions/integer64_spec.rb +0 -22
  149. data/spec/extensions/inverted_subsets_spec.rb +0 -33
  150. data/spec/extensions/json_serializer_spec.rb +0 -346
  151. data/spec/extensions/lazy_attributes_spec.rb +0 -183
  152. data/spec/extensions/list_spec.rb +0 -291
  153. data/spec/extensions/looser_typecasting_spec.rb +0 -43
  154. data/spec/extensions/many_through_many_spec.rb +0 -2177
  155. data/spec/extensions/migration_spec.rb +0 -864
  156. data/spec/extensions/modification_detection_spec.rb +0 -93
  157. data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
  158. data/spec/extensions/named_timezones_spec.rb +0 -218
  159. data/spec/extensions/nested_attributes_spec.rb +0 -815
  160. data/spec/extensions/null_dataset_spec.rb +0 -85
  161. data/spec/extensions/optimistic_locking_spec.rb +0 -127
  162. data/spec/extensions/pagination_spec.rb +0 -116
  163. data/spec/extensions/pg_array_associations_spec.rb +0 -802
  164. data/spec/extensions/pg_array_ops_spec.rb +0 -144
  165. data/spec/extensions/pg_array_spec.rb +0 -398
  166. data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -209
  167. data/spec/extensions/pg_enum_spec.rb +0 -118
  168. data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
  169. data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
  170. data/spec/extensions/pg_hstore_spec.rb +0 -219
  171. data/spec/extensions/pg_inet_ops_spec.rb +0 -102
  172. data/spec/extensions/pg_inet_spec.rb +0 -72
  173. data/spec/extensions/pg_interval_spec.rb +0 -103
  174. data/spec/extensions/pg_json_ops_spec.rb +0 -356
  175. data/spec/extensions/pg_json_spec.rb +0 -451
  176. data/spec/extensions/pg_loose_count_spec.rb +0 -23
  177. data/spec/extensions/pg_range_ops_spec.rb +0 -60
  178. data/spec/extensions/pg_range_spec.rb +0 -600
  179. data/spec/extensions/pg_row_ops_spec.rb +0 -61
  180. data/spec/extensions/pg_row_plugin_spec.rb +0 -60
  181. data/spec/extensions/pg_row_spec.rb +0 -363
  182. data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
  183. data/spec/extensions/pg_timestamptz_spec.rb +0 -17
  184. data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
  185. data/spec/extensions/prepared_statements_spec.rb +0 -177
  186. data/spec/extensions/pretty_table_spec.rb +0 -123
  187. data/spec/extensions/query_spec.rb +0 -94
  188. data/spec/extensions/rcte_tree_spec.rb +0 -387
  189. data/spec/extensions/round_timestamps_spec.rb +0 -39
  190. data/spec/extensions/s_spec.rb +0 -60
  191. data/spec/extensions/schema_caching_spec.rb +0 -64
  192. data/spec/extensions/schema_dumper_spec.rb +0 -870
  193. data/spec/extensions/select_remove_spec.rb +0 -38
  194. data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
  195. data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
  196. data/spec/extensions/serialization_spec.rb +0 -365
  197. data/spec/extensions/server_block_spec.rb +0 -135
  198. data/spec/extensions/server_logging_spec.rb +0 -45
  199. data/spec/extensions/sharding_spec.rb +0 -197
  200. data/spec/extensions/shared_caching_spec.rb +0 -151
  201. data/spec/extensions/single_table_inheritance_spec.rb +0 -347
  202. data/spec/extensions/singular_table_names_spec.rb +0 -22
  203. data/spec/extensions/skip_create_refresh_spec.rb +0 -18
  204. data/spec/extensions/spec_helper.rb +0 -70
  205. data/spec/extensions/split_array_nil_spec.rb +0 -24
  206. data/spec/extensions/split_values_spec.rb +0 -57
  207. data/spec/extensions/sql_comments_spec.rb +0 -33
  208. data/spec/extensions/sql_expr_spec.rb +0 -59
  209. data/spec/extensions/static_cache_cache_spec.rb +0 -35
  210. data/spec/extensions/static_cache_spec.rb +0 -471
  211. data/spec/extensions/string_agg_spec.rb +0 -90
  212. data/spec/extensions/string_date_time_spec.rb +0 -95
  213. data/spec/extensions/string_stripper_spec.rb +0 -68
  214. data/spec/extensions/subclasses_spec.rb +0 -79
  215. data/spec/extensions/subset_conditions_spec.rb +0 -38
  216. data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
  217. data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
  218. data/spec/extensions/synchronize_sql_spec.rb +0 -124
  219. data/spec/extensions/table_select_spec.rb +0 -83
  220. data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
  221. data/spec/extensions/thread_local_timezones_spec.rb +0 -67
  222. data/spec/extensions/throw_failures_spec.rb +0 -74
  223. data/spec/extensions/timestamps_spec.rb +0 -209
  224. data/spec/extensions/to_dot_spec.rb +0 -153
  225. data/spec/extensions/touch_spec.rb +0 -226
  226. data/spec/extensions/tree_spec.rb +0 -334
  227. data/spec/extensions/typecast_on_load_spec.rb +0 -86
  228. data/spec/extensions/unlimited_update_spec.rb +0 -21
  229. data/spec/extensions/update_or_create_spec.rb +0 -83
  230. data/spec/extensions/update_primary_key_spec.rb +0 -105
  231. data/spec/extensions/update_refresh_spec.rb +0 -59
  232. data/spec/extensions/uuid_spec.rb +0 -101
  233. data/spec/extensions/validate_associated_spec.rb +0 -52
  234. data/spec/extensions/validation_class_methods_spec.rb +0 -1040
  235. data/spec/extensions/validation_contexts_spec.rb +0 -31
  236. data/spec/extensions/validation_helpers_spec.rb +0 -525
  237. data/spec/extensions/whitelist_security_spec.rb +0 -157
  238. data/spec/extensions/xml_serializer_spec.rb +0 -213
  239. data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
  240. data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
  241. data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  242. data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  243. data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
  244. data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
  245. data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
  246. data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
  247. data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
  248. data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
  249. data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
  250. data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
  251. data/spec/files/double_migration/001_create_sessions.rb +0 -9
  252. data/spec/files/double_migration/002_create_nodes.rb +0 -19
  253. data/spec/files/double_migration/003_3_create_users.rb +0 -4
  254. data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
  255. data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
  256. data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  257. data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
  258. data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
  259. data/spec/files/empty_migration/001_create_sessions.rb +0 -9
  260. data/spec/files/empty_migration/002_create_nodes.rb +0 -0
  261. data/spec/files/empty_migration/003_3_create_users.rb +0 -4
  262. data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
  263. data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
  264. data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
  265. data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  266. data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
  267. data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  268. data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
  269. data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  270. data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
  271. data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
  272. data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  273. data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  274. data/spec/files/reversible_migrations/001_reversible.rb +0 -5
  275. data/spec/files/reversible_migrations/002_reversible.rb +0 -5
  276. data/spec/files/reversible_migrations/003_reversible.rb +0 -5
  277. data/spec/files/reversible_migrations/004_reversible.rb +0 -5
  278. data/spec/files/reversible_migrations/005_reversible.rb +0 -10
  279. data/spec/files/reversible_migrations/006_reversible.rb +0 -10
  280. data/spec/files/reversible_migrations/007_reversible.rb +0 -10
  281. data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
  282. data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
  283. data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
  284. data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
  285. data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
  286. data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
  287. data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
  288. data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
  289. data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
  290. data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
  291. data/spec/guards_helper.rb +0 -59
  292. data/spec/integration/associations_test.rb +0 -2597
  293. data/spec/integration/database_test.rb +0 -113
  294. data/spec/integration/dataset_test.rb +0 -2037
  295. data/spec/integration/eager_loader_test.rb +0 -687
  296. data/spec/integration/migrator_test.rb +0 -262
  297. data/spec/integration/model_test.rb +0 -203
  298. data/spec/integration/plugin_test.rb +0 -2423
  299. data/spec/integration/prepared_statement_test.rb +0 -405
  300. data/spec/integration/schema_test.rb +0 -903
  301. data/spec/integration/spec_helper.rb +0 -71
  302. data/spec/integration/timezone_test.rb +0 -86
  303. data/spec/integration/transaction_test.rb +0 -603
  304. data/spec/integration/type_test.rb +0 -127
  305. data/spec/model/association_reflection_spec.rb +0 -803
  306. data/spec/model/associations_spec.rb +0 -4738
  307. data/spec/model/base_spec.rb +0 -875
  308. data/spec/model/class_dataset_methods_spec.rb +0 -146
  309. data/spec/model/dataset_methods_spec.rb +0 -198
  310. data/spec/model/eager_loading_spec.rb +0 -2377
  311. data/spec/model/hooks_spec.rb +0 -370
  312. data/spec/model/inflector_spec.rb +0 -26
  313. data/spec/model/model_spec.rb +0 -956
  314. data/spec/model/plugins_spec.rb +0 -429
  315. data/spec/model/record_spec.rb +0 -2118
  316. data/spec/model/spec_helper.rb +0 -46
  317. data/spec/model/validations_spec.rb +0 -220
  318. data/spec/model_no_assoc_spec.rb +0 -1
  319. data/spec/model_spec.rb +0 -1
  320. data/spec/plugin_spec.rb +0 -1
  321. data/spec/sequel_coverage.rb +0 -15
  322. data/spec/sequel_warning.rb +0 -5
  323. data/spec/spec_config.rb +0 -12
@@ -1,151 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- connection_expiration_specs = shared_description do
4
- describe "connection expiration" do
5
- before do
6
- @m = Module.new do
7
- def disconnect_connection(conn)
8
- @sqls << 'disconnect'
9
- end
10
- end
11
- @db.extend @m
12
- @db.extension(:connection_expiration)
13
- @db.pool.connection_expiration_timeout = 2
14
- end
15
-
16
- it "should still allow new connections" do
17
- @db.synchronize{|c| c}.must_be_kind_of(Sequel::Mock::Connection)
18
- end
19
-
20
- it "should not override connection_expiration_timeout when loading extension" do
21
- @db.extension(:connection_expiration)
22
- @db.pool.connection_expiration_timeout.must_equal 2
23
- end
24
-
25
- it "should handle Database#disconnect calls while the connection is checked out" do
26
- @db.synchronize{|c| @db.disconnect}
27
- end
28
-
29
- it "should handle disconnected connections" do
30
- proc{@db.synchronize{|c| raise Sequel::DatabaseDisconnectError}}.must_raise Sequel::DatabaseDisconnectError
31
- @db.sqls.must_equal ['disconnect']
32
- end
33
-
34
- it "should handle :connection_handling => :disconnect setting" do
35
- @db = Sequel.mock(@db.opts.merge(:connection_handling => :disconnect))
36
- @db.extend @m
37
- @db.extension(:connection_expiration)
38
- @db.synchronize{}
39
- @db.sqls.must_equal ['disconnect']
40
- end
41
-
42
- it "should only expire if older than timeout" do
43
- c1 = @db.synchronize{|c| c}
44
- @db.sqls.must_equal []
45
- @db.synchronize{|c| c}.must_be_same_as(c1)
46
- @db.sqls.must_equal []
47
- end
48
-
49
- it "should disconnect connection if expired" do
50
- c1 = @db.synchronize{|c| c}
51
- @db.sqls.must_equal []
52
- simulate_sleep(c1)
53
- c2 = @db.synchronize{|c| c}
54
- @db.sqls.must_equal ['disconnect']
55
- c2.wont_be_same_as(c1)
56
- end
57
-
58
- it "should disconnect only expired connections among multiple" do
59
- c1, c2 = multiple_connections
60
-
61
- # Expire c1 only.
62
- simulate_sleep(c1)
63
- simulate_sleep(c2, 1)
64
- c1, c2 = multiple_connections
65
-
66
- c3 = @db.synchronize{|c| c}
67
- @db.sqls.must_equal ['disconnect']
68
- c3.wont_be_same_as(c1)
69
- c3.must_be_same_as(c2)
70
- end
71
-
72
- it "should disconnect connections repeatedly if they are expired" do
73
- c1, c2 = multiple_connections
74
-
75
- simulate_sleep(c1)
76
- simulate_sleep(c2)
77
-
78
- c3 = @db.synchronize{|c| c}
79
- @db.sqls.must_equal ['disconnect', 'disconnect']
80
- c3.wont_be_same_as(c1)
81
- c3.wont_be_same_as(c2)
82
- end
83
-
84
- it "should not leak connection references to expiring connections" do
85
- c1 = @db.synchronize{|c| c}
86
- simulate_sleep(c1)
87
- c2 = @db.synchronize{|c| c}
88
- c2.wont_be_same_as(c1)
89
- @db.pool.instance_variable_get(:@connection_expiration_timestamps).must_include(c2)
90
- @db.pool.instance_variable_get(:@connection_expiration_timestamps).wont_include(c1)
91
- end
92
-
93
- it "should not leak connection references during disconnect" do
94
- multiple_connections
95
- @db.pool.instance_variable_get(:@connection_expiration_timestamps).size.must_equal 2
96
- @db.disconnect
97
- @db.pool.instance_variable_get(:@connection_expiration_timestamps).size.must_equal 0
98
- end
99
-
100
- it "should not vary expiration timestamps by default" do
101
- c1 = @db.synchronize{|c| c}
102
- @db.pool.instance_variable_get(:@connection_expiration_timestamps)[c1].last.must_equal 2
103
- end
104
-
105
- it "should support #connection_expiration_random_delay to vary expiration timestamps" do
106
- @db.pool.connection_expiration_random_delay = 1
107
- c1 = @db.synchronize{|c| c}
108
- @db.pool.instance_variable_get(:@connection_expiration_timestamps)[c1].last.wont_equal 2
109
- end
110
-
111
- def multiple_connections
112
- q, q1 = Queue.new, Queue.new
113
- c1 = nil
114
- c2 = nil
115
- @db.synchronize do |c|
116
- Thread.new do
117
- @db.synchronize do |cc|
118
- c2 = cc
119
- end
120
- q1.pop
121
- q.push nil
122
- end
123
- q1.push nil
124
- q.pop
125
- c1 = c
126
- end
127
- [c1, c2]
128
- end
129
-
130
- # Set the timestamp back in time to simulate sleep / passage of time.
131
- def simulate_sleep(conn, sleep_time = 3)
132
- timestamps = @db.pool.instance_variable_get(:@connection_expiration_timestamps)
133
- timer, max = timestamps[conn]
134
- timestamps[conn] = [timer - sleep_time, max]
135
- @db.pool.instance_variable_set(:@connection_expiration_timestamps, timestamps)
136
- end
137
- end
138
- end
139
-
140
- describe "Sequel::ConnectionExpiration with threaded pool" do
141
- before do
142
- @db = Sequel.mock(:test=>false)
143
- end
144
- include connection_expiration_specs
145
- end
146
- describe "Sequel::ConnectionExpiration with sharded threaded pool" do
147
- before do
148
- @db = Sequel.mock(:test=>false, :servers=>{})
149
- end
150
- include connection_expiration_specs
151
- end
@@ -1,144 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- connection_validator_specs = shared_description do
4
- describe "connection validator" do
5
- before do
6
- @m = Module.new do
7
- def disconnect_connection(conn)
8
- @sqls << 'disconnect'
9
- end
10
- def valid_connection?(conn)
11
- super
12
- conn.valid
13
- end
14
- def connect(server)
15
- conn = super
16
- conn.extend(Module.new do
17
- attr_accessor :valid
18
- end)
19
- conn.valid = true
20
- conn
21
- end
22
- end
23
- @db.extend @m
24
- @db.extension(:connection_validator)
25
- end
26
-
27
- it "should still allow new connections" do
28
- @db.synchronize{|c| c}.must_be_kind_of(Sequel::Mock::Connection)
29
- end
30
-
31
- it "should only validate if connection idle longer than timeout" do
32
- c1 = @db.synchronize{|c| c}
33
- @db.sqls.must_equal []
34
- @db.synchronize{|c| c}.must_be_same_as(c1)
35
- @db.sqls.must_equal []
36
- @db.pool.connection_validation_timeout = -1
37
- @db.synchronize{|c| c}.must_be_same_as(c1)
38
- @db.sqls.must_equal ['SELECT NULL']
39
- @db.pool.connection_validation_timeout = 1
40
- @db.synchronize{|c| c}.must_be_same_as(c1)
41
- @db.sqls.must_equal []
42
- @db.synchronize{|c| c}.must_be_same_as(c1)
43
- @db.sqls.must_equal []
44
- end
45
-
46
- it "should disconnect connection if not valid" do
47
- c1 = @db.synchronize{|c| c}
48
- @db.sqls.must_equal []
49
- c1.valid = false
50
- @db.pool.connection_validation_timeout = -1
51
- c2 = @db.synchronize{|c| c}
52
- @db.sqls.must_equal ['SELECT NULL', 'disconnect']
53
- c2.wont_be_same_as(c1)
54
- end
55
-
56
- it "should handle Database#disconnect calls while the connection is checked out" do
57
- @db.synchronize{|c| @db.disconnect}
58
- end
59
-
60
- it "should handle disconnected connections" do
61
- proc{@db.synchronize{|c| raise Sequel::DatabaseDisconnectError}}.must_raise Sequel::DatabaseDisconnectError
62
- @db.sqls.must_equal ['disconnect']
63
- end
64
-
65
- it "should handle :connection_handling => :disconnect setting" do
66
- @db = Sequel.mock(@db.opts.merge(:connection_handling => :disconnect))
67
- @db.extend @m
68
- @db.extension(:connection_validator)
69
- @db.synchronize{}
70
- @db.sqls.must_equal ['disconnect']
71
- end
72
-
73
- it "should disconnect multiple connections repeatedly if they are not valid" do
74
- q, q1 = Queue.new, Queue.new
75
- c1 = nil
76
- c2 = nil
77
- @db.pool.connection_validation_timeout = -1
78
- @db.synchronize do |c|
79
- Thread.new do
80
- @db.synchronize do |cc|
81
- c2 = cc
82
- end
83
- q1.pop
84
- q.push nil
85
- end
86
- q1.push nil
87
- q.pop
88
- c1 = c
89
- end
90
- c1.valid = false
91
- c2.valid = false
92
-
93
- c3 = @db.synchronize{|c| c}
94
- @db.sqls.must_equal ['SELECT NULL', 'disconnect', 'SELECT NULL', 'disconnect']
95
- c3.wont_be_same_as(c1)
96
- c3.wont_be_same_as(c2)
97
- end
98
-
99
- it "should not leak connection references during disconnect" do
100
- @db.synchronize{}
101
- @db.pool.instance_variable_get(:@connection_timestamps).size.must_equal 1
102
- @db.disconnect
103
- @db.pool.instance_variable_get(:@connection_timestamps).size.must_equal 0
104
- end
105
-
106
- it "should not leak connection references" do
107
- c1 = @db.synchronize do |c|
108
- @db.pool.instance_variable_get(:@connection_timestamps).must_equal({})
109
- c
110
- end
111
- @db.pool.instance_variable_get(:@connection_timestamps).must_include(c1)
112
-
113
- c1.valid = false
114
- @db.pool.connection_validation_timeout = -1
115
- c2 = @db.synchronize do |c|
116
- @db.pool.instance_variable_get(:@connection_timestamps).must_equal({})
117
- c
118
- end
119
- c2.wont_be_same_as(c1)
120
- @db.pool.instance_variable_get(:@connection_timestamps).wont_include(c1)
121
- @db.pool.instance_variable_get(:@connection_timestamps).must_include(c2)
122
- end
123
-
124
- it "should handle case where determining validity requires a connection" do
125
- def @db.valid_connection?(c) synchronize{}; true end
126
- @db.pool.connection_validation_timeout = -1
127
- c1 = @db.synchronize{|c| c}
128
- @db.synchronize{|c| c}.must_be_same_as(c1)
129
- end
130
- end
131
- end
132
-
133
- describe "Sequel::ConnectionValidator with threaded pool" do
134
- before do
135
- @db = Sequel.mock(:test=>false)
136
- end
137
- include connection_validator_specs
138
- end
139
- describe "Sequel::ConnectionValidator with sharded threaded pool" do
140
- before do
141
- @db = Sequel.mock(:test=>false, :servers=>{})
142
- end
143
- include connection_validator_specs
144
- end
@@ -1,24 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "constant_sql_override extension" do
4
- before do
5
- @db = Sequel.mock.extension(:constant_sql_override)
6
- end
7
-
8
- it 'overrides configured constants' do
9
- @db.set_constant_sql(Sequel::CURRENT_TIMESTAMP, "CURRENT TIMESTAMP AT TIME ZONE 'UTC'")
10
- @db[:tbl].where(foo: Sequel::CURRENT_TIMESTAMP).first
11
- @db.sqls.must_equal ["SELECT * FROM tbl WHERE (foo = CURRENT TIMESTAMP AT TIME ZONE 'UTC') LIMIT 1"]
12
- end
13
-
14
- it 'does not change behavior for unconfigured constants' do
15
- @db[:tbl].where(foo: Sequel::CURRENT_TIMESTAMP).first
16
- @db.sqls.must_equal ["SELECT * FROM tbl WHERE (foo = CURRENT_TIMESTAMP) LIMIT 1"]
17
- end
18
-
19
- it 'freezes the constant_sqls hash when frozen' do
20
- @db.freeze
21
- @db.constant_sqls.frozen?.must_equal true
22
- proc{@db.set_constant_sql(Sequel::CURRENT_TIMESTAMP, "CURRENT TIMESTAMP AT TIME ZONE 'UTC'")}.must_raise RuntimeError
23
- end
24
- end
@@ -1,300 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::ConstraintValidations" do
4
- def model_class(opts={})
5
- return @c if @c
6
- @c = Class.new(Sequel::Model(@db[:items]))
7
- @c.columns :name
8
- @db.sqls
9
- set_fetch(opts)
10
- @c.plugin :constraint_validations
11
- @c
12
- end
13
-
14
- def set_fetch(opts)
15
- @db.fetch = {:table=>'items', :message=>nil, :allow_nil=>nil, :constraint_name=>nil, :validation_type=>'presence', :argument=>nil, :column=>'name'}.merge(opts)
16
- end
17
-
18
- before do
19
- @db = Sequel.mock
20
- set_fetch({})
21
- @ds = @db[:items]
22
- @ds.send(:columns=, [:name])
23
- @ds2 = Sequel.mock[:items2]
24
- @ds2.send(:columns=, [:name])
25
- end
26
-
27
- it "should load the validation_helpers plugin into the class" do
28
- model_class.new.must_respond_to(:validates_presence)
29
- end
30
-
31
- it "should parse constraint validations when loading plugin" do
32
- @c = model_class
33
- @db.sqls.must_equal ["SELECT * FROM sequel_constraint_validations"]
34
- @db.constraint_validations.must_equal("items"=>[{:allow_nil=>nil, :constraint_name=>nil, :message=>nil, :validation_type=>"presence", :column=>"name", :argument=>nil, :table=>"items"}])
35
- @c.constraint_validations.must_equal [[:validates_presence, :name]]
36
- @c.constraint_validation_reflections.must_equal(:name=>[[:presence, {}]])
37
- end
38
-
39
- it "should parse constraint validations with a custom constraint validations table" do
40
- c = Class.new(Sequel::Model(@db[:items]))
41
- @db.sqls
42
- c.plugin :constraint_validations, :constraint_validations_table=>:foo
43
- @db.sqls.must_equal ["SELECT * FROM foo"]
44
- @db.constraint_validations.must_equal("items"=>[{:allow_nil=>nil, :constraint_name=>nil, :message=>nil, :validation_type=>"presence", :column=>"name", :argument=>nil, :table=>"items"}])
45
- c.constraint_validations.must_equal [[:validates_presence, :name]]
46
- c.constraint_validation_reflections.must_equal(:name=>[[:presence, {}]])
47
- end
48
-
49
- it "should populate constraint_validations when subclassing" do
50
- c = Class.new(Sequel::Model(@db))
51
- c.plugin :constraint_validations
52
- @db.sqls.must_equal ["SELECT * FROM sequel_constraint_validations"]
53
- sc = Class.new(c)
54
- sc.set_dataset @ds
55
- @db.sqls.must_equal []
56
- sc.constraint_validations.must_equal [[:validates_presence, :name]]
57
- sc.constraint_validation_reflections.must_equal(:name=>[[:presence, {}]])
58
- end
59
-
60
- it "should handle plugin being loaded in subclass when superclass uses a custom constraint validations table" do
61
- c = Class.new(Sequel::Model(@db))
62
- c.plugin :constraint_validations, :constraint_validations_table=>:foo
63
- @db.sqls.must_equal ["SELECT * FROM foo"]
64
- sc = Class.new(c)
65
- sc.plugin :constraint_validations
66
- sc.constraint_validations_table.must_equal :foo
67
- sc.set_dataset @ds
68
- @db.sqls.must_equal []
69
- sc.constraint_validations.must_equal [[:validates_presence, :name]]
70
- sc.constraint_validation_reflections.must_equal(:name=>[[:presence, {}]])
71
- end
72
-
73
- it "should populate constraint_validations when changing the model's dataset" do
74
- c = Class.new(Sequel::Model(@db[:foo]))
75
- c.columns :name
76
- @db.sqls
77
- c.plugin :constraint_validations
78
- @db.sqls.must_equal ["SELECT * FROM sequel_constraint_validations"]
79
- sc = Class.new(c)
80
- sc.set_dataset @ds
81
- @db.sqls.must_equal []
82
- sc.constraint_validations.must_equal [[:validates_presence, :name]]
83
- sc.constraint_validation_reflections.must_equal(:name=>[[:presence, {}]])
84
- end
85
-
86
- it "should reparse constraint validations when changing the model's database" do
87
- c = Class.new(Sequel::Model(@ds2))
88
- c.plugin :constraint_validations
89
- @ds2.db.sqls.must_equal ["SELECT * FROM sequel_constraint_validations"]
90
- sc = Class.new(c)
91
- sc.set_dataset @ds
92
- @db.sqls.must_equal ["SELECT * FROM sequel_constraint_validations"]
93
- sc.constraint_validations.must_equal [[:validates_presence, :name]]
94
- sc.constraint_validation_reflections.must_equal(:name=>[[:presence, {}]])
95
- end
96
-
97
- it "should reparse constraint validations when changing the model's database with a custom constraint validations table" do
98
- c = Class.new(Sequel::Model(@ds2))
99
- c.plugin :constraint_validations, :constraint_validations_table=>:foo
100
- @ds2.db.sqls.must_equal ["SELECT * FROM foo"]
101
- sc = Class.new(c)
102
- sc.set_dataset @ds
103
- @db.sqls.must_equal ["SELECT * FROM foo"]
104
- sc.constraint_validations.must_equal [[:validates_presence, :name]]
105
- sc.constraint_validation_reflections.must_equal(:name=>[[:presence, {}]])
106
- end
107
-
108
- it "should correctly retrieve :message option from constraint validations table" do
109
- model_class(:message=>'foo').constraint_validations.must_equal [[:validates_presence, :name, {:message=>'foo'}]]
110
- @c.constraint_validation_reflections.must_equal(:name=>[[:presence, {:message=>'foo'}]])
111
- end
112
-
113
- it "should correctly retrieve :allow_nil option from constraint validations table" do
114
- model_class(:allow_nil=>true).constraint_validations.must_equal [[:validates_presence, :name, {:allow_nil=>true}]]
115
- @c.constraint_validation_reflections.must_equal(:name=>[[:presence, {:allow_nil=>true}]])
116
- end
117
-
118
- it "should handle presence validation" do
119
- model_class(:validation_type=>'presence').constraint_validations.must_equal [[:validates_presence, :name]]
120
- @c.constraint_validation_reflections.must_equal(:name=>[[:presence, {}]])
121
- end
122
-
123
- it "should handle exact_length validation" do
124
- model_class(:validation_type=>'exact_length', :argument=>'5').constraint_validations.must_equal [[:validates_exact_length, 5, :name]]
125
- @c.constraint_validation_reflections.must_equal(:name=>[[:exact_length, {:argument=>5}]])
126
- end
127
-
128
- it "should handle min_length validation" do
129
- model_class(:validation_type=>'min_length', :argument=>'5').constraint_validations.must_equal [[:validates_min_length, 5, :name]]
130
- @c.constraint_validation_reflections.must_equal(:name=>[[:min_length, {:argument=>5}]])
131
- end
132
-
133
- it "should handle max_length validation" do
134
- model_class(:validation_type=>'max_length', :argument=>'5').constraint_validations.must_equal [[:validates_max_length, 5, :name]]
135
- @c.constraint_validation_reflections.must_equal(:name=>[[:max_length, {:argument=>5}]])
136
- end
137
-
138
- it "should handle length_range validation" do
139
- model_class(:validation_type=>'length_range', :argument=>'3..5').constraint_validations.must_equal [[:validates_length_range, 3..5, :name]]
140
- @c.constraint_validation_reflections.must_equal(:name=>[[:length_range, {:argument=>3..5}]])
141
- end
142
-
143
- it "should handle length_range validation with an exclusive end" do
144
- model_class(:validation_type=>'length_range', :argument=>'3...5').constraint_validations.must_equal [[:validates_length_range, 3...5, :name]]
145
- @c.constraint_validation_reflections.must_equal(:name=>[[:length_range, {:argument=>3...5}]])
146
- end
147
-
148
- it "should handle format validation" do
149
- model_class(:validation_type=>'format', :argument=>'^foo.*').constraint_validations.must_equal [[:validates_format, /^foo.*/, :name]]
150
- @c.constraint_validation_reflections.must_equal(:name=>[[:format, {:argument=>/^foo.*/}]])
151
- end
152
-
153
- it "should handle format validation with case insensitive format" do
154
- model_class(:validation_type=>'iformat', :argument=>'^foo.*').constraint_validations.must_equal [[:validates_format, /^foo.*/i, :name]]
155
- @c.constraint_validation_reflections.must_equal(:name=>[[:format, {:argument=>/^foo.*/i}]])
156
- end
157
-
158
- it "should handle includes validation with array of strings" do
159
- model_class(:validation_type=>'includes_str_array', :argument=>'a,b,c').constraint_validations.must_equal [[:validates_includes, %w'a b c', :name]]
160
- @c.constraint_validation_reflections.must_equal(:name=>[[:includes, {:argument=>%w'a b c'}]])
161
- end
162
-
163
- it "should handle includes validation with array of integers" do
164
- model_class(:validation_type=>'includes_int_array', :argument=>'1,2,3').constraint_validations.must_equal [[:validates_includes, [1, 2, 3], :name]]
165
- @c.constraint_validation_reflections.must_equal(:name=>[[:includes, {:argument=>[1, 2, 3]}]])
166
- end
167
-
168
- it "should handle includes validation with inclusive range of integers" do
169
- model_class(:validation_type=>'includes_int_range', :argument=>'3..5').constraint_validations.must_equal [[:validates_includes, 3..5, :name]]
170
- @c.constraint_validation_reflections.must_equal(:name=>[[:includes, {:argument=>3..5}]])
171
- end
172
-
173
- it "should handle includes validation with exclusive range of integers" do
174
- model_class(:validation_type=>'includes_int_range', :argument=>'3...5').constraint_validations.must_equal [[:validates_includes, 3...5, :name]]
175
- @c.constraint_validation_reflections.must_equal(:name=>[[:includes, {:argument=>3...5}]])
176
- end
177
-
178
- it "should handle like validation" do
179
- model_class(:validation_type=>'like', :argument=>'foo').constraint_validations.must_equal [[:validates_format, /\Afoo\z/, :name]]
180
- @c.constraint_validation_reflections.must_equal(:name=>[[:format, {:argument=>/\Afoo\z/}]])
181
- end
182
-
183
- it "should handle ilike validation" do
184
- model_class(:validation_type=>'ilike', :argument=>'foo').constraint_validations.must_equal [[:validates_format, /\Afoo\z/i, :name]]
185
- @c.constraint_validation_reflections.must_equal(:name=>[[:format, {:argument=>/\Afoo\z/i}]])
186
- end
187
-
188
- it "should handle operator validation" do
189
- [[:str_lt, :<], [:str_lte, :<=], [:str_gt, :>], [:str_gte, :>=]].each do |vt, op|
190
- model_class(:validation_type=>vt.to_s, :argument=>'a').constraint_validations.must_equal [[:validates_operator, op, 'a', :name]]
191
- @c.constraint_validation_reflections.must_equal(:name=>[[:operator, {:operator=>op, :argument=>'a'}]])
192
- @c = @c.db.constraint_validations = nil
193
- end
194
-
195
- [[:int_lt, :<], [:int_lte, :<=], [:int_gt, :>], [:int_gte, :>=]].each do |vt, op|
196
- model_class(:validation_type=>vt.to_s, :argument=>'1').constraint_validations.must_equal [[:validates_operator, op, 1, :name]]
197
- @c.constraint_validation_reflections.must_equal(:name=>[[:operator, {:operator=>op, :argument=>1}]])
198
- @c = @c.db.constraint_validations = nil
199
- end
200
- end
201
-
202
- it "should handle like validation with % metacharacter" do
203
- model_class(:validation_type=>'like', :argument=>'%foo%').constraint_validations.must_equal [[:validates_format, /\A.*foo.*\z/, :name]]
204
- @c.constraint_validation_reflections.must_equal(:name=>[[:format, {:argument=>/\A.*foo.*\z/}]])
205
- end
206
-
207
- it "should handle like validation with %% metacharacter" do
208
- model_class(:validation_type=>'like', :argument=>'%%foo%%').constraint_validations.must_equal [[:validates_format, /\A%foo%\z/, :name]]
209
- @c.constraint_validation_reflections.must_equal(:name=>[[:format, {:argument=>/\A%foo%\z/}]])
210
- end
211
-
212
- it "should handle like validation with _ metacharacter" do
213
- model_class(:validation_type=>'like', :argument=>'f_o').constraint_validations.must_equal [[:validates_format, /\Af.o\z/, :name]]
214
- @c.constraint_validation_reflections.must_equal(:name=>[[:format, {:argument=>/\Af.o\z/}]])
215
- end
216
-
217
- it "should handle like validation with Regexp metacharacter" do
218
- model_class(:validation_type=>'like', :argument=>'\wfoo\d').constraint_validations.must_equal [[:validates_format, /\A\\wfoo\\d\z/, :name]]
219
- @c.constraint_validation_reflections.must_equal(:name=>[[:format, {:argument=>/\A\\wfoo\\d\z/}]])
220
- end
221
-
222
- it "should handle unique validation" do
223
- model_class(:validation_type=>'unique').constraint_validations.must_equal [[:validates_unique, [:name]]]
224
- @c.constraint_validation_reflections.must_equal(:name=>[[:unique, {}]])
225
- end
226
-
227
- it "should handle unique validation with multiple columns" do
228
- model_class(:validation_type=>'unique', :column=>'name,id').constraint_validations.must_equal [[:validates_unique, [:name, :id]]]
229
- @c.constraint_validation_reflections.must_equal([:name, :id]=>[[:unique, {}]])
230
- end
231
-
232
- it "should handle :validation_options" do
233
- c = model_class(:validation_type=>'unique', :column=>'name')
234
- c.plugin :constraint_validations, :validation_options=>{:unique=>{:message=>'is bad'}}
235
- c.constraint_validations.must_equal [[:validates_unique, [:name], {:message=>'is bad'}]]
236
- c.constraint_validation_reflections.must_equal(:name=>[[:unique, {:message=>'is bad'}]])
237
- c.dataset = c.dataset.with_fetch(:count=>1)
238
- o = c.new(:name=>'a')
239
- o.valid?.must_equal false
240
- o.errors.full_messages.must_equal ['name is bad']
241
- end
242
-
243
- it "should handle :validation_options merging with constraint validation options" do
244
- c = model_class(:validation_type=>'unique', :column=>'name', :allow_nil=>true)
245
- c.plugin :constraint_validations, :validation_options=>{:unique=>{:message=>'is bad'}}
246
- c.constraint_validations.must_equal [[:validates_unique, [:name], {:message=>'is bad', :allow_nil=>true}]]
247
- c.constraint_validation_reflections.must_equal(:name=>[[:unique, {:message=>'is bad', :allow_nil=>true}]])
248
- c.dataset = c.dataset.with_fetch(:count=>1)
249
- o = c.new(:name=>'a')
250
- o.valid?.must_equal false
251
- o.errors.full_messages.must_equal ['name is bad']
252
- end
253
-
254
- it "should handle :validation_options merging with subclasses" do
255
- c = model_class(:validation_type=>'unique', :column=>'name')
256
- c.plugin :constraint_validations, :validation_options=>{:unique=>{:message=>'is bad', :allow_nil=>true}}
257
- sc = Class.new(c)
258
- sc.plugin :constraint_validations, :validation_options=>{:unique=>{:allow_missing=>true, :allow_nil=>false}}
259
- sc.constraint_validations.must_equal [[:validates_unique, [:name], {:message=>'is bad', :allow_missing=>true, :allow_nil=>false}]]
260
- sc.constraint_validation_reflections.must_equal(:name=>[[:unique, {:message=>'is bad', :allow_missing=>true, :allow_nil=>false}]])
261
- sc.dataset = sc.dataset.with_fetch(:count=>1)
262
- o = sc.new(:name=>'a')
263
- o.valid?.must_equal false
264
- o.errors.full_messages.must_equal ['name is bad']
265
- end
266
-
267
- it "should used parsed constraint validations when validating" do
268
- o = model_class.new
269
- o.valid?.must_equal false
270
- o.errors.full_messages.must_equal ['name is not present']
271
- end
272
-
273
- it "should handle a table name specified as SQL::Identifier" do
274
- set_fetch(:table=>'sch__items')
275
- c = Class.new(Sequel::Model(@db[Sequel.identifier(:sch__items)]))
276
- c.plugin :constraint_validations
277
- c.constraint_validations.must_equal [[:validates_presence, :name]]
278
- c.constraint_validation_reflections.must_equal(:name=>[[:presence, {}]])
279
- end
280
-
281
- it "should handle a table name specified as SQL::QualifiedIdentifier" do
282
- set_fetch(:table=>'sch.items')
283
- c = Class.new(Sequel::Model(@db[Sequel.qualify(:sch, :items)]))
284
- c.plugin :constraint_validations
285
- c.constraint_validations.must_equal [[:validates_presence, :name]]
286
- c.constraint_validation_reflections.must_equal(:name=>[[:presence, {}]])
287
- end
288
-
289
- it "should freeze constraint validations data when freezing model class" do
290
- @c = model_class
291
- @c.freeze
292
- @c.constraint_validations.frozen?.must_equal true
293
- @c.constraint_validations.all?(&:frozen?).must_equal true
294
- @c.constraint_validation_reflections.frozen?.must_equal true
295
- @c.constraint_validation_reflections.values.all?(&:frozen?).must_equal true
296
- @c.constraint_validation_reflections.values.all?{|r| r.all?(&:frozen?)}.must_equal true
297
- @c.instance_variable_get(:@constraint_validation_options).frozen?.must_equal true
298
- @c.instance_variable_get(:@constraint_validation_options).values.all?(&:frozen?).must_equal true
299
- end
300
- end