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,31 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::ValidationHelpers" do
4
- before do
5
- @c = Class.new(Sequel::Model(:foo))
6
- @c.class_eval do
7
- columns :a, :b, :c
8
- plugin :validation_contexts
9
- def validate
10
- errors.add(:a, 'bad') if a == 1 && validation_context == :create
11
- errors.add(:b, 'bad') if b == 2 && validation_context == :update
12
- errors.add(:c, 'bad') if c == 3 && validation_context == :foo
13
- end
14
- end
15
- end
16
-
17
- it "should support :validation_context option to valid?" do
18
- @c.new(:c=>3).valid?.must_equal true
19
- @c.new(:c=>3).valid?(:validation_context=>:foo).must_equal false
20
- end
21
-
22
- it "should support :validation_context option to save?" do
23
- @c.new(:c=>3).save
24
- proc{@c.new(:c=>3).save(:validation_context=>:foo)}.must_raise Sequel::ValidationFailed
25
- end
26
-
27
- it "should raise error if using a validation context on a frozen model instance" do
28
- @c.new(:c=>3).freeze.valid?.must_equal true
29
- proc{@c.new(:c=>3).freeze.valid?(:validation_context=>:foo)}.must_raise RuntimeError, TypeError
30
- end
31
- end
@@ -1,525 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::ValidationHelpers" do
4
- before do
5
- @c = Class.new(Sequel::Model) do
6
- def self.set_validations(&block)
7
- define_method(:validate, &block)
8
- end
9
- columns :value
10
- end
11
- @c.plugin :validation_helpers
12
- @m = @c.new
13
- end
14
-
15
- it "should take an :allow_blank option" do
16
- @c.set_validations{validates_format(/.+_.+/, :value, :allow_blank=>true)}
17
- @m.value = 'abc_'
18
- @m.wont_be :valid?
19
- @m.value = '1_1'
20
- @m.must_be :valid?
21
- o = String.new
22
- o.singleton_class.send(:undef_method, :blank?)
23
- @m.value = o
24
- @m.must_be :valid?
25
- o = Object.new
26
- @m.value = o
27
- @m.wont_be :valid?
28
- def o.blank?
29
- true
30
- end
31
- @m.must_be :valid?
32
- end
33
-
34
- it "should take an :allow_missing option" do
35
- @c.set_validations{validates_format(/.+_.+/, :value, :allow_missing=>true)}
36
- @m.values.clear
37
- @m.must_be :valid?
38
- @m.value = nil
39
- @m.wont_be :valid?
40
- @m.value = '1_1'
41
- @m.must_be :valid?
42
- end
43
-
44
- it "should take an :allow_nil option" do
45
- @c.set_validations{validates_format(/.+_.+/, :value, :allow_nil=>true)}
46
- @m.value = 'abc_'
47
- @m.wont_be :valid?
48
- @m.value = '1_1'
49
- @m.must_be :valid?
50
- @m.value = nil
51
- @m.must_be :valid?
52
- end
53
-
54
- it "should take a :message option" do
55
- @c.set_validations{validates_format(/.+_.+/, :value, :message=>"is so blah")}
56
- @m.value = 'abc_'
57
- @m.wont_be :valid?
58
- @m.errors.full_messages.must_equal ['value is so blah']
59
- @m.value = '1_1'
60
- @m.must_be :valid?
61
- end
62
-
63
- it "should take a :from=>:values option to lookup in values hash" do
64
- @c.set_validations{validates_max_length(50, :value, :from=>:values)}
65
- @c.send(:define_method, :value){super() * 2}
66
- @m.value = ' ' * 26
67
- @m.must_be :valid?
68
- end
69
-
70
- it "should allow a proc for the :message option" do
71
- @c.set_validations{validates_format(/.+_.+/, :value, :message=>proc{|f| "doesn't match #{f.inspect}"})}
72
- @m.value = 'abc_'
73
- @m.wont_be :valid?
74
- @m.errors.must_equal(:value=>["doesn't match /.+_.+/"])
75
- end
76
-
77
- it "should take multiple attributes in the same call" do
78
- @c.columns :value, :value2
79
- @c.set_validations{validates_presence([:value, :value2])}
80
- @m.wont_be :valid?
81
- @m.value = 1
82
- @m.wont_be :valid?
83
- @m.value2 = 1
84
- @m.must_be :valid?
85
- end
86
-
87
- it "should support modifying default validation options for a particular model" do
88
- @c.set_validations{validates_presence(:value)}
89
- @m.wont_be :valid?
90
- @m.errors.must_equal(:value=>['is not present'])
91
- @c.class_eval do
92
- def default_validation_helpers_options(type)
93
- {:allow_missing=>true, :message=>proc{'was not entered'}}
94
- end
95
- end
96
- @m.value = nil
97
- @m.wont_be :valid?
98
- @m.errors.must_equal(:value=>["was not entered"])
99
- @m.value = 1
100
- @m.must_be :valid?
101
-
102
- @m.values.clear
103
- @m.must_be :valid?
104
-
105
- c = Class.new(Sequel::Model)
106
- c.class_eval do
107
- plugin :validation_helpers
108
- attr_accessor :value
109
- def validate
110
- validates_presence(:value)
111
- end
112
- end
113
- m = c.new
114
- m.wont_be :valid?
115
- m.errors.must_equal(:value=>['is not present'])
116
- end
117
-
118
- it "should support validates_exact_length" do
119
- @c.set_validations{validates_exact_length(3, :value)}
120
- @m.wont_be :valid?
121
- @m.value = '123'
122
- @m.must_be :valid?
123
- @m.value = '12'
124
- @m.wont_be :valid?
125
- @m.value = '1234'
126
- @m.wont_be :valid?
127
- end
128
-
129
- it "should support validate_format" do
130
- @c.set_validations{validates_format(/.+_.+/, :value)}
131
- @m.value = 'abc_'
132
- @m.wont_be :valid?
133
- @m.value = 'abc_def'
134
- @m.must_be :valid?
135
- end
136
-
137
- it "should support validates_includes with an array" do
138
- @c.set_validations{validates_includes([1,2], :value)}
139
- @m.wont_be :valid?
140
- @m.value = 1
141
- @m.must_be :valid?
142
- @m.value = 1.5
143
- @m.wont_be :valid?
144
- @m.value = 2
145
- @m.must_be :valid?
146
- @m.value = 3
147
- @m.wont_be :valid?
148
- end
149
-
150
- it "should support validates_includes with a range" do
151
- @c.set_validations{validates_includes(1..4, :value)}
152
- @m.wont_be :valid?
153
- @m.value = 1
154
- @m.must_be :valid?
155
- @m.value = 1.5
156
- @m.must_be :valid?
157
- @m.value = 0
158
- @m.wont_be :valid?
159
- @m.value = 5
160
- @m.wont_be :valid?
161
- end
162
-
163
- it "should supports validates_integer" do
164
- @c.set_validations{validates_integer(:value)}
165
- @m.value = 'blah'
166
- @m.wont_be :valid?
167
- @m.value = '123'
168
- @m.must_be :valid?
169
- @m.value = '123.1231'
170
- @m.wont_be :valid?
171
- end
172
-
173
- it "should support validates_length_range" do
174
- @c.set_validations{validates_length_range(2..5, :value)}
175
- @m.wont_be :valid?
176
- @m.value = '12345'
177
- @m.must_be :valid?
178
- @m.value = '1'
179
- @m.wont_be :valid?
180
- @m.value = '123456'
181
- @m.wont_be :valid?
182
- end
183
-
184
- it "should support validates_max_length" do
185
- @c.set_validations{validates_max_length(5, :value)}
186
- @m.wont_be :valid?
187
- @m.value = '12345'
188
- @m.must_be :valid?
189
- @m.value = '123456'
190
- @m.wont_be :valid?
191
- @m.errors[:value].must_equal ['is longer than 5 characters']
192
- @m.value = nil
193
- @m.wont_be :valid?
194
- @m.errors[:value].must_equal ['is not present']
195
- end
196
-
197
- it "should support validates_max_length with nil value" do
198
- @c.set_validations{validates_max_length(5, :value, :message=>'tl', :nil_message=>'np')}
199
- @m.value = '123456'
200
- @m.wont_be :valid?
201
- @m.errors[:value].must_equal ['tl']
202
- @m.value = nil
203
- @m.wont_be :valid?
204
- @m.errors[:value].must_equal ['np']
205
- end
206
-
207
- it "should support validates_min_length" do
208
- @c.set_validations{validates_min_length(5, :value)}
209
- @m.wont_be :valid?
210
- @m.value = '12345'
211
- @m.must_be :valid?
212
- @m.value = '1234'
213
- @m.wont_be :valid?
214
- end
215
-
216
- it "should support validates_schema_types" do
217
- @c.set_validations{validates_schema_types}
218
- @m.value = 123
219
- @m.must_be :valid?
220
- @m.value = '123'
221
- @m.must_be :valid?
222
- def @m.db_schema; {:value=>{:type=>:integer}} end
223
- @m.wont_be :valid?
224
- @m.errors.full_messages.must_equal ['value is not a valid integer']
225
-
226
- @c.set_validations{validates_schema_types(:value)}
227
- def @m.db_schema; {:value=>{:type=>:integer}} end
228
- @m.wont_be :valid?
229
- @m.errors.full_messages.must_equal ['value is not a valid integer']
230
-
231
- @c.set_validations{validates_schema_types(:value, :message=>'is bad')}
232
- def @m.db_schema; {:value=>{:type=>:integer}} end
233
- @m.wont_be :valid?
234
- @m.errors.full_messages.must_equal ['value is bad']
235
- end
236
-
237
- it "should support validates_numeric" do
238
- @c.set_validations{validates_numeric(:value)}
239
- @m.value = 'blah'
240
- @m.wont_be :valid?
241
- @m.value = '123'
242
- @m.must_be :valid?
243
- @m.value = '123.1231'
244
- @m.must_be :valid?
245
- @m.value = '+1'
246
- @m.must_be :valid?
247
- @m.value = '-1'
248
- @m.must_be :valid?
249
- @m.value = '+1.123'
250
- @m.must_be :valid?
251
- @m.value = '-0.123'
252
- @m.must_be :valid?
253
- @m.value = '-0.123E10'
254
- @m.must_be :valid?
255
- @m.value = '32.123e10'
256
- @m.must_be :valid?
257
- @m.value = '+32.123E10'
258
- @m.must_be :valid?
259
- @m.must_be :valid?
260
- @m.value = '.0123'
261
- end
262
-
263
- it "should support validates_type" do
264
- @c.set_validations{validates_type(Integer, :value)}
265
- @m.value = 123
266
- @m.must_be :valid?
267
- @m.value = '123'
268
- @m.wont_be :valid?
269
- @m.errors.full_messages.must_equal ['value is not a valid integer']
270
-
271
- @c.set_validations{validates_type(:String, :value)}
272
- @m.value = '123'
273
- @m.must_be :valid?
274
- @m.value = 123
275
- @m.wont_be :valid?
276
- @m.errors.full_messages.must_equal ['value is not a valid string']
277
-
278
- @c.set_validations{validates_type('Integer', :value)}
279
- @m.value = 123
280
- @m.must_be :valid?
281
- @m.value = 123.05
282
- @m.wont_be :valid?
283
- @m.errors.full_messages.must_equal ['value is not a valid integer']
284
-
285
- @c.set_validations{validates_type(Integer, :value)}
286
- @m.value = 1
287
- @m.must_be :valid?
288
- @m.value = false
289
- @m.wont_be :valid?
290
-
291
- @c.set_validations{validates_type([Integer, Float], :value)}
292
- @m.value = 1
293
- @m.must_be :valid?
294
- @m.value = 1.0
295
- @m.must_be :valid?
296
- @m.value = BigDecimal('1.0')
297
- @m.wont_be :valid?
298
- @m.errors.full_messages.must_equal ['value is not a valid integer or float']
299
- end
300
-
301
- it "should support validates_not_null" do
302
- @c.set_validations{validates_not_null(:value)}
303
- @m.wont_be :valid?
304
- @m.value = ''
305
- @m.must_be :valid?
306
- @m.value = 1234
307
- @m.must_be :valid?
308
- @m.value = nil
309
- @m.wont_be :valid?
310
- @m.value = true
311
- @m.must_be :valid?
312
- @m.value = false
313
- @m.must_be :valid?
314
- @m.value = Time.now
315
- @m.must_be :valid?
316
- end
317
-
318
- it "should support validates_presence" do
319
- @c.set_validations{validates_presence(:value)}
320
- @m.wont_be :valid?
321
- @m.value = ''
322
- @m.wont_be :valid?
323
- @m.value = 1234
324
- @m.must_be :valid?
325
- @m.value = nil
326
- @m.wont_be :valid?
327
- @m.value = true
328
- @m.must_be :valid?
329
- @m.value = false
330
- @m.must_be :valid?
331
- @m.value = Time.now
332
- @m.must_be :valid?
333
- end
334
-
335
- it "should support validates_unique with a single attribute" do
336
- @c.columns(:id, :username, :password)
337
- @c.set_dataset DB[:items]
338
- @c.set_validations{validates_unique(:username, :only_if_modified=>false)}
339
- @c.dataset = @c.dataset.with_fetch(proc do |sql|
340
- case sql
341
- when /count.*username = '0records'/
342
- {:v => 0}
343
- when /count.*username = '1record'/
344
- {:v => 1}
345
- end
346
- end)
347
-
348
- @user = @c.new(:username => "0records", :password => "anothertest")
349
- @user.must_be :valid?
350
- @user = @c.load(:id=>3, :username => "0records", :password => "anothertest")
351
- @user.must_be :valid?
352
-
353
- DB.sqls
354
- @user = @c.new(:password => "anothertest")
355
- @user.must_be :valid?
356
- DB.sqls.must_equal []
357
-
358
- @user = @c.new(:username => "1record", :password => "anothertest")
359
- @user.wont_be :valid?
360
- @user.errors.full_messages.must_equal ['username is already taken']
361
- @user = @c.load(:id=>4, :username => "1record", :password => "anothertest")
362
- @user.wont_be :valid?
363
- @user.errors.full_messages.must_equal ['username is already taken']
364
-
365
- @user = @c.load(:id=>1, :username => "0records", :password => "anothertest")
366
- @user.must_be :valid?
367
- DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (id != 1)) LIMIT 1"
368
- @user = @c.new(:username => "0records", :password => "anothertest")
369
- @user.must_be :valid?
370
- DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE (username = '0records') LIMIT 1"
371
- end
372
-
373
- it "should support validates_unique with multiple attributes" do
374
- @c.columns(:id, :username, :password)
375
- @c.set_dataset DB[:items]
376
- @c.set_validations{validates_unique([:username, :password], :only_if_modified=>false)}
377
- @c.dataset = @c.dataset.with_fetch(proc do |sql|
378
- case sql
379
- when /count.*username = '0records'/
380
- {:v => 0}
381
- when /count.*username = '1record'/
382
- {:v => 1}
383
- end
384
- end)
385
-
386
- @user = @c.new(:username => "0records", :password => "anothertest")
387
- @user.must_be :valid?
388
- @user = @c.load(:id=>3, :username => "0records", :password => "anothertest")
389
- @user.must_be :valid?
390
-
391
- DB.sqls
392
- @user = @c.new(:password => "anothertest")
393
- @user.must_be :valid?
394
- @user.errors.full_messages.must_equal []
395
- @user = @c.new(:username => "0records")
396
- @user.must_be :valid?
397
- @user.errors.full_messages.must_equal []
398
- @user = @c.new
399
- @user.must_be :valid?
400
- @user.errors.full_messages.must_equal []
401
- DB.sqls.must_equal []
402
-
403
- @user = @c.new(:username => "1record", :password => "anothertest")
404
- @user.wont_be :valid?
405
- @user.errors.full_messages.must_equal ['username and password is already taken']
406
- @user = @c.load(:id=>4, :username => "1record", :password => "anothertest")
407
- @user.wont_be :valid?
408
- @user.errors.full_messages.must_equal ['username and password is already taken']
409
-
410
- @user = @c.load(:id=>1, :username => "0records", :password => "anothertest")
411
- @user.must_be :valid?
412
- DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest') AND (id != 1)) LIMIT 1"
413
- @user = @c.new(:username => "0records", :password => "anothertest")
414
- @user.must_be :valid?
415
- DB.sqls.last.must_equal "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest')) LIMIT 1"
416
- end
417
-
418
- it "should support validates_unique with a block" do
419
- @c.columns(:id, :username, :password)
420
- @c.set_dataset DB[:items]
421
- @c.set_validations{validates_unique(:username, :only_if_modified=>false){|ds| ds.filter(:active)}}
422
- @c.dataset = @c.dataset.with_fetch(:v=>0)
423
-
424
- DB.reset
425
- @c.new(:username => "0records", :password => "anothertest").must_be :valid?
426
- @c.load(:id=>3, :username => "0records", :password => "anothertest").must_be :valid?
427
- DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND active) LIMIT 1",
428
- "SELECT count(*) AS count FROM items WHERE ((username = '0records') AND active AND (id != 3)) LIMIT 1"]
429
- end
430
-
431
- it "should support validates_unique with :where option" do
432
- @c.columns(:id, :username, :password)
433
- @c.set_dataset DB[:items]
434
- @c.set_validations{validates_unique(:username, :only_if_modified=>false, :where=>proc{|ds, obj, cols| ds.where(cols.map{|c| [Sequel.function(:lower, c), obj.send(c).downcase]})})}
435
- @c.dataset = @c.dataset.with_fetch(:v=>0)
436
-
437
- DB.reset
438
- @c.new(:username => "0RECORDS", :password => "anothertest").must_be :valid?
439
- @c.load(:id=>3, :username => "0RECORDS", :password => "anothertest").must_be :valid?
440
- DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE (lower(username) = '0records') LIMIT 1",
441
- "SELECT count(*) AS count FROM items WHERE ((lower(username) = '0records') AND (id != 3)) LIMIT 1"]
442
- end
443
-
444
- it "should support validates_unique with :dataset option" do
445
- @c.columns(:id, :username, :password)
446
- @c.set_dataset DB[:items]
447
- c = @c
448
- @c.set_validations{validates_unique(:username, :only_if_modified=>false, :dataset=>c.where(:a=>[1,2,3]))}
449
- @c.dataset = @c.dataset.with_fetch(:v=>0)
450
-
451
- DB.reset
452
- @c.new(:username => "0records", :password => "anothertest").must_be :valid?
453
- @c.load(:id=>3, :username => "0records", :password => "anothertest").must_be :valid?
454
- DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((a IN (1, 2, 3)) AND (username = '0records')) LIMIT 1",
455
- "SELECT count(*) AS count FROM items WHERE ((a IN (1, 2, 3)) AND (username = '0records') AND (id != 3)) LIMIT 1"]
456
- end
457
-
458
- it "should use qualified primary keys for validates_unique when the dataset is joined" do
459
- @c.columns(:id, :username, :password)
460
- @c.set_dataset DB[:items]
461
- c = @c
462
- @c.set_validations{validates_unique(:username, :only_if_modified=>false, :dataset=>c.cross_join(:a))}
463
- @c.dataset = @c.dataset.with_fetch(:v=>0)
464
-
465
- DB.reset
466
- @c.new(:username => "0records", :password => "anothertest").must_be :valid?
467
- @c.load(:id=>3, :username => "0records", :password => "anothertest").must_be :valid?
468
- DB.sqls.must_equal ["SELECT count(*) AS count FROM items CROSS JOIN a WHERE (username = '0records') LIMIT 1",
469
- "SELECT count(*) AS count FROM items CROSS JOIN a WHERE ((username = '0records') AND (items.id != 3)) LIMIT 1"]
470
- end
471
-
472
- it "should not have validates_unique check uniqueness for existing records if values haven't changed" do
473
- @c.columns(:id, :username, :password)
474
- @c.set_dataset DB[:items]
475
- @c.set_validations{validates_unique([:username, :password])}
476
- @c.dataset = @c.dataset.with_fetch(:v=>0)
477
-
478
- DB.reset
479
- @c.new(:username => "0records", :password => "anothertest").must_be :valid?
480
- DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = 'anothertest')) LIMIT 1"]
481
- DB.reset
482
- m = @c.load(:id=>3, :username => "0records", :password => "anothertest")
483
- m.must_be :valid?
484
- DB.sqls.must_equal []
485
-
486
- m.username = '1'
487
- m.must_be :valid?
488
- DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '1') AND (password = 'anothertest') AND (id != 3)) LIMIT 1"]
489
-
490
- m = @c.load(:id=>3, :username => "0records", :password => "anothertest")
491
- DB.reset
492
- m.password = '1'
493
- m.must_be :valid?
494
- DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '0records') AND (password = '1') AND (id != 3)) LIMIT 1"]
495
- DB.reset
496
- m.username = '2'
497
- m.must_be :valid?
498
- DB.sqls.must_equal ["SELECT count(*) AS count FROM items WHERE ((username = '2') AND (password = '1') AND (id != 3)) LIMIT 1"]
499
- end
500
-
501
- it "should not attempt a database query if the underlying columns have validation errors" do
502
- @c.columns(:id, :username, :password)
503
- @c.set_dataset DB[:items]
504
- @c.set_validations{errors.add(:username, 'foo'); validates_unique([:username, :password])}
505
- @c.dataset = @c.dataset.with_fetch(:v=>0)
506
-
507
- DB.reset
508
- m = @c.new(:username => "1", :password => "anothertest")
509
- m.wont_be :valid?
510
- DB.sqls.must_equal []
511
- end
512
-
513
- it "should support validates_operator" do
514
- @c.set_validations{validates_operator(:>, 3, :value)}
515
- @m.value = 1
516
- @m.wont_be :valid?
517
- @m.errors.full_messages.must_equal ['value is not > 3']
518
- @m.value = 3
519
- @m.wont_be :valid?
520
- @m.value = nil
521
- @m.wont_be :valid?
522
- @m.value = 4
523
- @m.must_be :valid?
524
- end
525
- end