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,86 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe Sequel::Model, "TypecastOnLoad plugin" do
4
- before do
5
- @db = Sequel.mock(:fetch=>{:id=>1, :b=>"1", :y=>"0"}, :columns=>[:id, :b, :y], :numrows=>1)
6
- def @db.supports_schema_parsing?() true end
7
- def @db.schema(*args)
8
- [[:id, {}], [:y, {:type=>:boolean, :db_type=>'tinyint(1)'}], [:b, {:type=>:integer, :db_type=>'integer'}]]
9
- end
10
- @c = Class.new(Sequel::Model(@db[:items])) do
11
- attr_accessor :bset
12
- def b=(x)
13
- self.bset = true
14
- super
15
- end
16
- end
17
- end
18
-
19
- it "should call setter method with value when loading the object, for all given columns" do
20
- @c.plugin :typecast_on_load, :b
21
- o = @c.load(:id=>1, :b=>"1", :y=>"0")
22
- o.values.must_equal(:id=>1, :b=>1, :y=>"0")
23
- o.bset.must_equal true
24
- end
25
-
26
- it "should call setter method with value when reloading the object, for all given columns" do
27
- @c.plugin :typecast_on_load, :b
28
- o = @c.load(:id=>1, :b=>"1", :y=>"0")
29
- o.refresh
30
- o.values.must_equal(:id=>1, :b=>1, :y=>"0")
31
- o.bset.must_equal true
32
- end
33
-
34
- it "should call setter method with value when automatically reloading the object on creation" do
35
- @c.plugin :typecast_on_load, :b
36
- o = @c.new(:b=>"1", :y=>"0")
37
- o.save.values.must_equal(:id=>1, :b=>1, :y=>"0")
38
- o.bset.must_equal true
39
- end
40
-
41
- it "should call setter method with value when automatically reloading the object on creation via insert_select" do
42
- @c.plugin :typecast_on_load, :b
43
- @c.dataset = @c.dataset.with_extend{def insert_select(h) insert(h); first end}
44
- o = @c.new(:b=>"1", :y=>"0")
45
- o.save.values.must_equal(:id=>1, :b=>1, :y=>"0")
46
- o.bset.must_equal true
47
- end
48
-
49
- it "should allowing setting columns separately via add_typecast_on_load_columns" do
50
- @c.plugin :typecast_on_load
51
- @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>"1", :y=>"0")
52
- @c.add_typecast_on_load_columns :b
53
- @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>1, :y=>"0")
54
- @c.add_typecast_on_load_columns :y
55
- @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>1, :y=>false)
56
- end
57
-
58
- it "should work with subclasses" do
59
- @c.plugin :typecast_on_load
60
- @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>"1", :y=>"0")
61
-
62
- c1 = Class.new(@c)
63
- @c.add_typecast_on_load_columns :b
64
- @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>1, :y=>"0")
65
- c1.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>"1", :y=>"0")
66
-
67
- c2 = Class.new(@c)
68
- @c.add_typecast_on_load_columns :y
69
- @c.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>1, :y=>false)
70
- c2.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>1, :y=>"0")
71
-
72
- c1.add_typecast_on_load_columns :y
73
- c1.load(:id=>1, :b=>"1", :y=>"0").values.must_equal(:id=>1, :b=>"1", :y=>false)
74
- end
75
-
76
- it "should not mark the object as modified" do
77
- @c.plugin :typecast_on_load, :b
78
- @c.load(:id=>1, :b=>"1", :y=>"0").modified?.must_equal false
79
- end
80
-
81
- it "should freeze typecast_on_load columns when freezing model class" do
82
- @c.plugin :typecast_on_load, :b
83
- @c.freeze
84
- @c.typecast_on_load_columns.frozen?.must_equal true
85
- end
86
- end
@@ -1,21 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::UnlimitedUpdate" do
4
- before do
5
- @db = Sequel.mock(:host=>'mysql', :numrows=>1)
6
- @db.extend_datasets{def quote_identifiers?; false end}
7
- @c = Class.new(Sequel::Model(@db[:test]))
8
- @c.columns :id, :name
9
- @o = @c.load(:id=>1, :name=>'a')
10
- @db.sqls
11
- end
12
-
13
- it "should remove limit from update dataset" do
14
- @o.save
15
- @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1) LIMIT 1"]
16
-
17
- @c.plugin :unlimited_update
18
- @o.save
19
- @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1)"]
20
- end
21
- end
@@ -1,83 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::UpdateOrCreate" do
4
- before do
5
- @db = Sequel.mock(:autoid=>proc{1}, :numrows=>1)
6
- @c = Class.new(Sequel::Model(@db[:test]))
7
- @c.plugin :update_or_create
8
- @c.columns :id, :a, :b
9
- @db.sqls
10
- end
11
-
12
- it ".update_or_create should update an existing record if one exists" do
13
- @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
14
- @c.update_or_create(:a=>2){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>2, :b=>4)
15
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1", "UPDATE test SET b = 4 WHERE (id = 1)"]
16
-
17
- @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
18
- @c.update_or_create({:a=>2}, :b=>4).must_equal @c.load(:id=>1, :a=>2, :b=>4)
19
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1", "UPDATE test SET b = 4 WHERE (id = 1)"]
20
-
21
- @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
22
- @c.update_or_create({:a=>2}, :a=>3){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>3, :b=>4)
23
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1",
24
- 'UPDATE test SET a = 3, b = 4 WHERE (id = 1)']
25
- end
26
-
27
- it ".update_or_create should create a record if an existing record does not exist" do
28
- @db.fetch = [[], [{:id=>1, :a=>1, :b=>4}]]
29
- @c.update_or_create(:a=>1){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>1, :b=>4)
30
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 1) LIMIT 1",
31
- "INSERT INTO test (a, b) VALUES (1, 4)",
32
- "SELECT * FROM test WHERE (id = 1) LIMIT 1"]
33
-
34
- @db.fetch = [[], [{:id=>1, :a=>1, :b=>4}]]
35
- @c.update_or_create({:a=>1}, :b=>4).must_equal @c.load(:id=>1, :a=>1, :b=>4)
36
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 1) LIMIT 1",
37
- "INSERT INTO test (a, b) VALUES (1, 4)",
38
- "SELECT * FROM test WHERE (id = 1) LIMIT 1"]
39
-
40
- @db.fetch = [[], [{:id=>1, :a=>3, :b=>4}]]
41
- @c.update_or_create({:a=>1}, :a=>3){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>3, :b=>4)
42
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 1) LIMIT 1",
43
- "INSERT INTO test (a, b) VALUES (3, 4)",
44
- "SELECT * FROM test WHERE (id = 1) LIMIT 1"]
45
- end
46
-
47
- it ".update_or_create should return an existing record even if no changes necessary" do
48
- @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
49
- @c.update_or_create(:a=>2){|t| t.b = 3}.must_equal @c.load(:id=>1, :a=>2, :b=>3)
50
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
51
- end
52
-
53
- it ".find_or_new should return an existing record" do
54
- @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
55
- @c.find_or_new(:a=>2){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>2, :b=>4)
56
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
57
-
58
- @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
59
- @c.find_or_new({:a=>2}, :b=>4).must_equal @c.load(:id=>1, :a=>2, :b=>4)
60
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
61
-
62
- @db.fetch = [[{:id=>1, :a=>2, :b=>3}]]
63
- @c.find_or_new({:a=>2}, :a=>3){|t| t.b = 4}.must_equal @c.load(:id=>1, :a=>3, :b=>4)
64
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 2) LIMIT 1"]
65
- end
66
-
67
- it ".find_or_new should return a new record if no record exists" do
68
- o = @c.find_or_new(:a=>1){|t| t.b = 4}
69
- o.must_equal @c.load(:a=>1, :b=>4)
70
- o.new?.must_equal true
71
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 1) LIMIT 1"]
72
-
73
- o = @c.find_or_new({:a=>1}, :b=>4)
74
- o.must_equal @c.load(:a=>1, :b=>4)
75
- o.new?.must_equal true
76
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 1) LIMIT 1"]
77
-
78
- o = @c.find_or_new({:a=>1}, :a=>3){|t| t.b = 4}
79
- o.must_equal @c.load(:a=>3, :b=>4)
80
- o.new?.must_equal true
81
- @db.sqls.must_equal ["SELECT * FROM test WHERE (a = 1) LIMIT 1"]
82
- end
83
- end
@@ -1,105 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::UpdatePrimaryKey" do
4
- before do
5
- @c = Class.new(Sequel::Model(:a))
6
- @c.plugin :update_primary_key
7
- @c.columns :a, :b
8
- def @c.set_dataset(*)
9
- super
10
- set_primary_key :a
11
- end
12
- @c.set_primary_key :a
13
- @c.unrestrict_primary_key
14
- @ds = @c.dataset
15
- DB.reset
16
- end
17
-
18
- it "should handle regular updates" do
19
- @c.dataset = @c.dataset.with_fetch([[{:a=>1, :b=>3}], [{:a=>1, :b=>4}], [{:a=>1, :b=>4}], [{:a=>1, :b=>5}], [{:a=>1, :b=>5}], [{:a=>1, :b=>6}], [{:a=>1, :b=>6}]])
20
- @c.first.update(:b=>4)
21
- @c.all.must_equal [@c.load(:a=>1, :b=>4)]
22
- DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 4 WHERE (a = 1)", "SELECT * FROM a"]
23
- @c.first.set(:b=>5).save
24
- @c.all.must_equal [@c.load(:a=>1, :b=>5)]
25
- DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 5 WHERE (a = 1)", "SELECT * FROM a"]
26
- @c.first.set(:b=>6).save(:columns=>:b)
27
- @c.all.must_equal [@c.load(:a=>1, :b=>6)]
28
- DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET b = 6 WHERE (a = 1)", "SELECT * FROM a"]
29
- end
30
-
31
- it "should handle updating the primary key field with another field" do
32
- @c.dataset = @c.dataset.with_fetch([[{:a=>1, :b=>3}], [{:a=>2, :b=>4}]])
33
- @c.first.update(:a=>2, :b=>4)
34
- @c.all.must_equal [@c.load(:a=>2, :b=>4)]
35
- sqls = DB.sqls
36
- ["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].must_include(sqls.slice!(1))
37
- sqls.must_equal ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
38
- end
39
-
40
- it "should handle updating just the primary key field when saving changes" do
41
- @c.dataset = @c.dataset.with_fetch([[{:a=>1, :b=>3}], [{:a=>2, :b=>3}], [{:a=>2, :b=>3}], [{:a=>3, :b=>3}]])
42
- @c.first.update(:a=>2)
43
- @c.all.must_equal [@c.load(:a=>2, :b=>3)]
44
- DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 2 WHERE (a = 1)", "SELECT * FROM a"]
45
- @c.first.set(:a=>3).save(:columns=>:a)
46
- @c.all.must_equal [@c.load(:a=>3, :b=>3)]
47
- DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 3 WHERE (a = 2)", "SELECT * FROM a"]
48
- end
49
-
50
- it "should handle saving after modifying the primary key field with another field" do
51
- @c.dataset = @c.dataset.with_fetch([[{:a=>1, :b=>3}], [{:a=>2, :b=>4}]])
52
- @c.first.set(:a=>2, :b=>4).save
53
- @c.all.must_equal [@c.load(:a=>2, :b=>4)]
54
- sqls = DB.sqls
55
- ["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].must_include(sqls.slice!(1))
56
- sqls.must_equal ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
57
- end
58
-
59
- it "should handle saving after modifying just the primary key field" do
60
- @c.dataset = @c.dataset.with_fetch([[{:a=>1, :b=>3}], [{:a=>2, :b=>3}]])
61
- @c.first.set(:a=>2).save
62
- @c.all.must_equal [@c.load(:a=>2, :b=>3)]
63
- sqls = DB.sqls
64
- ["UPDATE a SET a = 2, b = 3 WHERE (a = 1)", "UPDATE a SET b = 3, a = 2 WHERE (a = 1)"].must_include(sqls.slice!(1))
65
- sqls.must_equal ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
66
- end
67
-
68
- it "should handle saving after updating the primary key" do
69
- @c.dataset = @c.dataset.with_fetch([[{:a=>1, :b=>3}], [{:a=>2, :b=>5}]])
70
- @c.first.update(:a=>2).update(:b=>4).set(:b=>5).save
71
- @c.all.must_equal [@c.load(:a=>2, :b=>5)]
72
- DB.sqls.must_equal ["SELECT * FROM a LIMIT 1", "UPDATE a SET a = 2 WHERE (a = 1)", "UPDATE a SET b = 4 WHERE (a = 2)", "UPDATE a SET b = 5 WHERE (a = 2)", "SELECT * FROM a"]
73
- end
74
-
75
- it "should work correctly when using the prepared_statements plugin" do
76
- @c.plugin :prepared_statements
77
- @c.dataset = @c.dataset.with_fetch([[{:a=>1, :b=>3}], [{:a=>2, :b=>4}], [{:a=>3}]])
78
- o = @c.first
79
- o.update(:a=>2, :b=>4)
80
- @c.all.must_equal [@c.load(:a=>2, :b=>4)]
81
- sqls = DB.sqls
82
- ["UPDATE a SET a = 2, b = 4 WHERE (a = 1)", "UPDATE a SET b = 4, a = 2 WHERE (a = 1)"].must_include(sqls.slice!(1))
83
- sqls.must_equal ["SELECT * FROM a LIMIT 1", "SELECT * FROM a"]
84
-
85
- @c.create(:a=>3)
86
- DB.sqls.must_equal ["INSERT INTO a (a) VALUES (3)", "SELECT * FROM a WHERE a = 3"]
87
- end
88
-
89
- it "should clear the associations cache of non-many_to_one associations when changing the primary key" do
90
- @c.one_to_many :cs, :class=>@c
91
- @c.many_to_one :c, :class=>@c
92
- o = @c.new(:a=>1)
93
- o.associations[:cs] = @c.new
94
- o.associations[:c] = o2 = @c.new
95
- o.a = 2
96
- o.associations.must_equal(:c=>o2)
97
- end
98
-
99
- it "should handle frozen instances" do
100
- o = @c.new
101
- o.a = 1
102
- o.freeze
103
- o.pk_hash.must_equal(:a=>1)
104
- end
105
- end
@@ -1,59 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::UpdateRefresh" do
4
- before do
5
- @db = Sequel.mock(:numrows=>1, :fetch=>{:id=>1, :name=>'b'})
6
- @c = Class.new(Sequel::Model(@db[:test]))
7
- @ds = @c.dataset
8
- @c.columns :id, :name
9
- @c.plugin :update_refresh
10
- @db.sqls
11
- end
12
-
13
- it "should refresh the instance after updating" do
14
- o = @c.load(:id=>1, :name=>'a')
15
- o.save
16
- @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1)", "SELECT * FROM test WHERE (id = 1) LIMIT 1"]
17
- o.name.must_equal 'b'
18
- end
19
-
20
- it "should refresh the instance after updating" do
21
- @db.extend_datasets{def supports_returning?(x) true end; def update_sql(*); sql = super; update_returning_sql(sql); sql end}
22
- @c.dataset = @db[:test]
23
- @db.sqls
24
- o = @c.load(:id=>1, :name=>'a')
25
- o.save
26
- @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1) RETURNING *"]
27
- o.name.must_equal 'b'
28
- end
29
-
30
- it "should support specifying columns to return" do
31
- @db.extend_datasets{def supports_returning?(x) true end; def update_sql(*); sql = super; update_returning_sql(sql); sql end}
32
- @c.plugin :update_refresh, :columns => [ :a ]
33
- @c.dataset = @db[:test]
34
- @db.sqls
35
- o = @c.load(:id=>1, :name=>'a')
36
- o.save
37
- @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1) RETURNING a"]
38
- o.name.must_equal 'b'
39
- end
40
-
41
- it "should refresh the instance after updating when returning specific columns" do
42
- @db.extend_datasets{def supports_returning?(x) true end; def update_sql(*); sql = super; update_returning_sql(sql); sql end}
43
- @c.plugin :insert_returning_select
44
- @c.dataset = @db[:test].select(:id, :name)
45
- @db.sqls
46
- o = @c.load(:id=>1, :name=>'a')
47
- o.instance_variable_set(:@this, o.this.returning(:id, :name))
48
- o.save
49
- @db.sqls.must_equal ["UPDATE test SET name = 'a' WHERE (id = 1) RETURNING id, name"]
50
- o.name.must_equal 'b'
51
- end
52
-
53
- it "should freeze update refresh columns when freezing model class" do
54
- @db.extend_datasets{def supports_returning?(x) true end; def update_sql(*); sql = super; update_returning_sql(sql); sql end}
55
- @c.plugin :update_refresh, :columns => [ :a ]
56
- @c.freeze
57
- @c.update_refresh_columns.frozen?.must_equal true
58
- end
59
- end
@@ -1,101 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::Uuid" do
4
- before do
5
- uuid = @uuid = '57308544-4e83-47b8-b87f-6f68b987f4f9'
6
- @alt_uuid = 'd5d1ec46-5e8e-4a7b-adc9-50e76b819e19'
7
- @c = Class.new(Sequel::Model(:t))
8
- @c.class_eval do
9
- columns :id, :uuid
10
- plugin :uuid
11
- def _save_refresh(*) end
12
- define_method(:create_uuid) do
13
- uuid
14
- end
15
- db.reset
16
- end
17
- end
18
-
19
- it "should handle validations on the uuid field for new objects" do
20
- @c.plugin :uuid, :force=>true
21
- o = @c.new
22
- def o.validate
23
- errors.add(model.uuid_field, 'not present') unless send(model.uuid_field)
24
- end
25
- o.valid?.must_equal true
26
- end
27
-
28
- it "should set uuid field when skipping validations" do
29
- @c.plugin :uuid
30
- @c.new.save(:validate=>false)
31
- @c.db.sqls.must_equal ["INSERT INTO t (uuid) VALUES ('#{@uuid}')"]
32
- end
33
-
34
- it "should set the uuid field on creation" do
35
- o = @c.create
36
- @c.db.sqls.must_equal ["INSERT INTO t (uuid) VALUES ('#{@uuid}')"]
37
- o.uuid.must_equal @uuid
38
- end
39
-
40
- it "should allow specifying the uuid field via the :field option" do
41
- c = Class.new(Sequel::Model(:t))
42
- c.class_eval do
43
- columns :id, :u
44
- plugin :uuid, :field=>:u
45
- def _save_refresh(*) end
46
- end
47
- o = c.create
48
- c.db.sqls.must_equal ["INSERT INTO t (u) VALUES ('#{o.u}')"]
49
- end
50
-
51
- it "should not raise an error if the model doesn't have the uuid column" do
52
- @c.columns :id, :x
53
- @c.send(:undef_method, :uuid)
54
- @c.create(:x=>2)
55
- @c.load(:id=>1, :x=>2).save
56
- @c.db.sqls.must_equal ["INSERT INTO t (x) VALUES (2)", "UPDATE t SET x = 2 WHERE (id = 1)"]
57
- end
58
-
59
- it "should not overwrite an existing uuid value" do
60
- o = @c.create(:uuid=>@alt_uuid)
61
- @c.db.sqls.must_equal ["INSERT INTO t (uuid) VALUES ('#{@alt_uuid}')"]
62
- o.uuid.must_equal @alt_uuid
63
- end
64
-
65
- it "should overwrite an existing uuid if the :force option is used" do
66
- @c.plugin :uuid, :force=>true
67
- o = @c.create(:uuid=>@alt_uuid)
68
- @c.db.sqls.must_equal ["INSERT INTO t (uuid) VALUES ('#{@uuid}')"]
69
- o.uuid.must_equal @uuid
70
- end
71
-
72
- it "should have uuid_field give the uuid field" do
73
- @c.uuid_field.must_equal :uuid
74
- @c.plugin :uuid, :field=>:u
75
- @c.uuid_field.must_equal :u
76
- end
77
-
78
- it "should have uuid_overwrite? give the whether to overwrite an existing uuid" do
79
- @c.uuid_overwrite?.must_equal false
80
- @c.plugin :uuid, :force=>true
81
- @c.uuid_overwrite?.must_equal true
82
- end
83
-
84
- it "should work with subclasses" do
85
- c = Class.new(@c)
86
- o = c.create
87
- o.uuid.must_equal @uuid
88
- c.db.sqls.must_equal ["INSERT INTO t (uuid) VALUES ('#{@uuid}')"]
89
- c.create(:uuid=>@alt_uuid).uuid.must_equal @alt_uuid
90
-
91
- c.class_eval do
92
- columns :id, :u
93
- plugin :uuid, :field=>:u, :force=>true
94
- end
95
- c2 = Class.new(c)
96
- c2.db.reset
97
- o = c2.create
98
- o.u.must_equal @uuid
99
- c2.db.sqls.must_equal ["INSERT INTO t (u) VALUES ('#{@uuid}')"]
100
- end
101
- end