sequel 5.29.0 → 5.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (387) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +70 -1922
  3. data/README.rdoc +1 -1
  4. data/doc/advanced_associations.rdoc +4 -4
  5. data/doc/association_basics.rdoc +3 -3
  6. data/doc/code_order.rdoc +12 -2
  7. data/doc/model_dataset_method_design.rdoc +1 -1
  8. data/doc/postgresql.rdoc +71 -0
  9. data/doc/release_notes/5.30.0.txt +20 -0
  10. data/doc/release_notes/5.31.0.txt +148 -0
  11. data/doc/release_notes/5.32.0.txt +46 -0
  12. data/doc/release_notes/5.33.0.txt +24 -0
  13. data/doc/release_notes/5.34.0.txt +40 -0
  14. data/doc/testing.rdoc +1 -1
  15. data/lib/sequel/adapters/shared/access.rb +6 -6
  16. data/lib/sequel/adapters/shared/mssql.rb +5 -5
  17. data/lib/sequel/adapters/shared/mysql.rb +9 -9
  18. data/lib/sequel/adapters/shared/oracle.rb +16 -16
  19. data/lib/sequel/adapters/shared/postgres.rb +169 -14
  20. data/lib/sequel/adapters/shared/sqlanywhere.rb +9 -9
  21. data/lib/sequel/adapters/shared/sqlite.rb +32 -5
  22. data/lib/sequel/connection_pool/sharded_single.rb +4 -1
  23. data/lib/sequel/connection_pool/sharded_threaded.rb +12 -12
  24. data/lib/sequel/connection_pool/single.rb +1 -1
  25. data/lib/sequel/connection_pool/threaded.rb +2 -2
  26. data/lib/sequel/core.rb +318 -314
  27. data/lib/sequel/database/connecting.rb +1 -1
  28. data/lib/sequel/database/misc.rb +16 -10
  29. data/lib/sequel/database/query.rb +3 -1
  30. data/lib/sequel/database/schema_generator.rb +0 -1
  31. data/lib/sequel/database/schema_methods.rb +15 -16
  32. data/lib/sequel/database/transactions.rb +12 -13
  33. data/lib/sequel/dataset/placeholder_literalizer.rb +3 -7
  34. data/lib/sequel/dataset/query.rb +4 -3
  35. data/lib/sequel/deprecated.rb +2 -0
  36. data/lib/sequel/exceptions.rb +2 -0
  37. data/lib/sequel/extensions/connection_expiration.rb +2 -2
  38. data/lib/sequel/extensions/connection_validator.rb +2 -2
  39. data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
  40. data/lib/sequel/extensions/index_caching.rb +9 -7
  41. data/lib/sequel/extensions/integer64.rb +2 -0
  42. data/lib/sequel/extensions/migration.rb +1 -1
  43. data/lib/sequel/extensions/pg_enum.rb +5 -2
  44. data/lib/sequel/extensions/pg_hstore.rb +6 -0
  45. data/lib/sequel/extensions/pg_inet.rb +13 -5
  46. data/lib/sequel/extensions/pg_interval.rb +2 -0
  47. data/lib/sequel/extensions/pg_range.rb +2 -0
  48. data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
  49. data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
  50. data/lib/sequel/extensions/schema_dumper.rb +10 -4
  51. data/lib/sequel/extensions/server_block.rb +3 -3
  52. data/lib/sequel/model.rb +2 -0
  53. data/lib/sequel/model/associations.rb +30 -18
  54. data/lib/sequel/model/base.rb +64 -55
  55. data/lib/sequel/model/plugins.rb +3 -3
  56. data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
  57. data/lib/sequel/plugins/association_multi_add_remove.rb +2 -0
  58. data/lib/sequel/plugins/association_pks.rb +57 -16
  59. data/lib/sequel/plugins/association_proxies.rb +2 -0
  60. data/lib/sequel/plugins/boolean_subsets.rb +4 -1
  61. data/lib/sequel/plugins/class_table_inheritance.rb +26 -26
  62. data/lib/sequel/plugins/dirty.rb +13 -13
  63. data/lib/sequel/plugins/forbid_lazy_load.rb +214 -0
  64. data/lib/sequel/plugins/json_serializer.rb +3 -7
  65. data/lib/sequel/plugins/rcte_tree.rb +2 -2
  66. data/lib/sequel/plugins/single_table_inheritance.rb +15 -15
  67. data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
  68. data/lib/sequel/plugins/subclasses.rb +2 -0
  69. data/lib/sequel/timezones.rb +6 -4
  70. data/lib/sequel/version.rb +1 -1
  71. metadata +17 -368
  72. data/Rakefile +0 -151
  73. data/doc/release_notes/4.0.0.txt +0 -262
  74. data/doc/release_notes/4.1.0.txt +0 -85
  75. data/doc/release_notes/4.10.0.txt +0 -226
  76. data/doc/release_notes/4.11.0.txt +0 -147
  77. data/doc/release_notes/4.12.0.txt +0 -105
  78. data/doc/release_notes/4.13.0.txt +0 -169
  79. data/doc/release_notes/4.14.0.txt +0 -68
  80. data/doc/release_notes/4.15.0.txt +0 -56
  81. data/doc/release_notes/4.16.0.txt +0 -36
  82. data/doc/release_notes/4.17.0.txt +0 -38
  83. data/doc/release_notes/4.18.0.txt +0 -36
  84. data/doc/release_notes/4.19.0.txt +0 -45
  85. data/doc/release_notes/4.2.0.txt +0 -129
  86. data/doc/release_notes/4.20.0.txt +0 -79
  87. data/doc/release_notes/4.21.0.txt +0 -94
  88. data/doc/release_notes/4.22.0.txt +0 -72
  89. data/doc/release_notes/4.23.0.txt +0 -65
  90. data/doc/release_notes/4.24.0.txt +0 -99
  91. data/doc/release_notes/4.25.0.txt +0 -181
  92. data/doc/release_notes/4.26.0.txt +0 -44
  93. data/doc/release_notes/4.27.0.txt +0 -78
  94. data/doc/release_notes/4.28.0.txt +0 -57
  95. data/doc/release_notes/4.29.0.txt +0 -41
  96. data/doc/release_notes/4.3.0.txt +0 -40
  97. data/doc/release_notes/4.30.0.txt +0 -37
  98. data/doc/release_notes/4.31.0.txt +0 -57
  99. data/doc/release_notes/4.32.0.txt +0 -132
  100. data/doc/release_notes/4.33.0.txt +0 -88
  101. data/doc/release_notes/4.34.0.txt +0 -86
  102. data/doc/release_notes/4.35.0.txt +0 -130
  103. data/doc/release_notes/4.36.0.txt +0 -116
  104. data/doc/release_notes/4.37.0.txt +0 -50
  105. data/doc/release_notes/4.38.0.txt +0 -67
  106. data/doc/release_notes/4.39.0.txt +0 -127
  107. data/doc/release_notes/4.4.0.txt +0 -92
  108. data/doc/release_notes/4.40.0.txt +0 -179
  109. data/doc/release_notes/4.41.0.txt +0 -77
  110. data/doc/release_notes/4.42.0.txt +0 -221
  111. data/doc/release_notes/4.43.0.txt +0 -87
  112. data/doc/release_notes/4.44.0.txt +0 -125
  113. data/doc/release_notes/4.45.0.txt +0 -370
  114. data/doc/release_notes/4.46.0.txt +0 -404
  115. data/doc/release_notes/4.47.0.txt +0 -56
  116. data/doc/release_notes/4.48.0.txt +0 -293
  117. data/doc/release_notes/4.49.0.txt +0 -222
  118. data/doc/release_notes/4.5.0.txt +0 -34
  119. data/doc/release_notes/4.6.0.txt +0 -30
  120. data/doc/release_notes/4.7.0.txt +0 -103
  121. data/doc/release_notes/4.8.0.txt +0 -175
  122. data/doc/release_notes/4.9.0.txt +0 -190
  123. data/spec/adapter_spec.rb +0 -4
  124. data/spec/adapters/db2_spec.rb +0 -170
  125. data/spec/adapters/mssql_spec.rb +0 -828
  126. data/spec/adapters/mysql_spec.rb +0 -1060
  127. data/spec/adapters/oracle_spec.rb +0 -371
  128. data/spec/adapters/postgres_spec.rb +0 -4476
  129. data/spec/adapters/spec_helper.rb +0 -44
  130. data/spec/adapters/sqlanywhere_spec.rb +0 -97
  131. data/spec/adapters/sqlite_spec.rb +0 -652
  132. data/spec/bin_spec.rb +0 -278
  133. data/spec/core/connection_pool_spec.rb +0 -1250
  134. data/spec/core/database_spec.rb +0 -2915
  135. data/spec/core/dataset_spec.rb +0 -5544
  136. data/spec/core/deprecated_spec.rb +0 -70
  137. data/spec/core/expression_filters_spec.rb +0 -1498
  138. data/spec/core/mock_adapter_spec.rb +0 -722
  139. data/spec/core/object_graph_spec.rb +0 -336
  140. data/spec/core/placeholder_literalizer_spec.rb +0 -166
  141. data/spec/core/schema_generator_spec.rb +0 -214
  142. data/spec/core/schema_spec.rb +0 -1844
  143. data/spec/core/spec_helper.rb +0 -24
  144. data/spec/core/version_spec.rb +0 -14
  145. data/spec/core_extensions_spec.rb +0 -763
  146. data/spec/core_model_spec.rb +0 -2
  147. data/spec/core_spec.rb +0 -1
  148. data/spec/deprecation_helper.rb +0 -30
  149. data/spec/extensions/accessed_columns_spec.rb +0 -51
  150. data/spec/extensions/active_model_spec.rb +0 -99
  151. data/spec/extensions/after_initialize_spec.rb +0 -28
  152. data/spec/extensions/any_not_empty_spec.rb +0 -23
  153. data/spec/extensions/arbitrary_servers_spec.rb +0 -109
  154. data/spec/extensions/association_dependencies_spec.rb +0 -125
  155. data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
  156. data/spec/extensions/association_pks_spec.rb +0 -423
  157. data/spec/extensions/association_proxies_spec.rb +0 -100
  158. data/spec/extensions/auto_literal_strings_spec.rb +0 -205
  159. data/spec/extensions/auto_validations_spec.rb +0 -229
  160. data/spec/extensions/blacklist_security_spec.rb +0 -95
  161. data/spec/extensions/blank_spec.rb +0 -69
  162. data/spec/extensions/boolean_readers_spec.rb +0 -93
  163. data/spec/extensions/boolean_subsets_spec.rb +0 -47
  164. data/spec/extensions/caching_spec.rb +0 -273
  165. data/spec/extensions/caller_logging_spec.rb +0 -52
  166. data/spec/extensions/class_table_inheritance_spec.rb +0 -750
  167. data/spec/extensions/column_conflicts_spec.rb +0 -75
  168. data/spec/extensions/column_select_spec.rb +0 -129
  169. data/spec/extensions/columns_introspection_spec.rb +0 -90
  170. data/spec/extensions/columns_updated_spec.rb +0 -35
  171. data/spec/extensions/composition_spec.rb +0 -248
  172. data/spec/extensions/connection_expiration_spec.rb +0 -151
  173. data/spec/extensions/connection_validator_spec.rb +0 -144
  174. data/spec/extensions/constant_sql_override_spec.rb +0 -24
  175. data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
  176. data/spec/extensions/constraint_validations_spec.rb +0 -439
  177. data/spec/extensions/core_refinements_spec.rb +0 -528
  178. data/spec/extensions/csv_serializer_spec.rb +0 -183
  179. data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
  180. data/spec/extensions/dataset_associations_spec.rb +0 -365
  181. data/spec/extensions/dataset_source_alias_spec.rb +0 -51
  182. data/spec/extensions/date_arithmetic_spec.rb +0 -181
  183. data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
  184. data/spec/extensions/def_dataset_method_spec.rb +0 -100
  185. data/spec/extensions/defaults_setter_spec.rb +0 -150
  186. data/spec/extensions/delay_add_association_spec.rb +0 -73
  187. data/spec/extensions/dirty_spec.rb +0 -222
  188. data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
  189. data/spec/extensions/eager_each_spec.rb +0 -62
  190. data/spec/extensions/eager_graph_eager_spec.rb +0 -100
  191. data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
  192. data/spec/extensions/empty_failure_backtraces_spec.rb +0 -60
  193. data/spec/extensions/error_splitter_spec.rb +0 -18
  194. data/spec/extensions/error_sql_spec.rb +0 -20
  195. data/spec/extensions/escaped_like_spec.rb +0 -40
  196. data/spec/extensions/eval_inspect_spec.rb +0 -81
  197. data/spec/extensions/exclude_or_null_spec.rb +0 -15
  198. data/spec/extensions/finder_spec.rb +0 -260
  199. data/spec/extensions/force_encoding_spec.rb +0 -126
  200. data/spec/extensions/freeze_datasets_spec.rb +0 -31
  201. data/spec/extensions/graph_each_spec.rb +0 -113
  202. data/spec/extensions/hook_class_methods_spec.rb +0 -402
  203. data/spec/extensions/identifier_mangling_spec.rb +0 -201
  204. data/spec/extensions/implicit_subquery_spec.rb +0 -58
  205. data/spec/extensions/index_caching_spec.rb +0 -66
  206. data/spec/extensions/inflector_spec.rb +0 -183
  207. data/spec/extensions/input_transformer_spec.rb +0 -69
  208. data/spec/extensions/insert_conflict_spec.rb +0 -103
  209. data/spec/extensions/insert_returning_select_spec.rb +0 -72
  210. data/spec/extensions/instance_filters_spec.rb +0 -79
  211. data/spec/extensions/instance_hooks_spec.rb +0 -246
  212. data/spec/extensions/integer64_spec.rb +0 -22
  213. data/spec/extensions/inverted_subsets_spec.rb +0 -33
  214. data/spec/extensions/json_serializer_spec.rb +0 -346
  215. data/spec/extensions/lazy_attributes_spec.rb +0 -183
  216. data/spec/extensions/list_spec.rb +0 -291
  217. data/spec/extensions/looser_typecasting_spec.rb +0 -43
  218. data/spec/extensions/many_through_many_spec.rb +0 -2177
  219. data/spec/extensions/migration_spec.rb +0 -864
  220. data/spec/extensions/modification_detection_spec.rb +0 -93
  221. data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
  222. data/spec/extensions/named_timezones_spec.rb +0 -218
  223. data/spec/extensions/nested_attributes_spec.rb +0 -815
  224. data/spec/extensions/null_dataset_spec.rb +0 -85
  225. data/spec/extensions/optimistic_locking_spec.rb +0 -127
  226. data/spec/extensions/pagination_spec.rb +0 -116
  227. data/spec/extensions/pg_array_associations_spec.rb +0 -802
  228. data/spec/extensions/pg_array_ops_spec.rb +0 -144
  229. data/spec/extensions/pg_array_spec.rb +0 -398
  230. data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -209
  231. data/spec/extensions/pg_enum_spec.rb +0 -118
  232. data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
  233. data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
  234. data/spec/extensions/pg_hstore_spec.rb +0 -219
  235. data/spec/extensions/pg_inet_ops_spec.rb +0 -102
  236. data/spec/extensions/pg_inet_spec.rb +0 -72
  237. data/spec/extensions/pg_interval_spec.rb +0 -103
  238. data/spec/extensions/pg_json_ops_spec.rb +0 -356
  239. data/spec/extensions/pg_json_spec.rb +0 -451
  240. data/spec/extensions/pg_loose_count_spec.rb +0 -23
  241. data/spec/extensions/pg_range_ops_spec.rb +0 -60
  242. data/spec/extensions/pg_range_spec.rb +0 -600
  243. data/spec/extensions/pg_row_ops_spec.rb +0 -61
  244. data/spec/extensions/pg_row_plugin_spec.rb +0 -60
  245. data/spec/extensions/pg_row_spec.rb +0 -363
  246. data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
  247. data/spec/extensions/pg_timestamptz_spec.rb +0 -17
  248. data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
  249. data/spec/extensions/prepared_statements_spec.rb +0 -177
  250. data/spec/extensions/pretty_table_spec.rb +0 -123
  251. data/spec/extensions/query_spec.rb +0 -94
  252. data/spec/extensions/rcte_tree_spec.rb +0 -387
  253. data/spec/extensions/round_timestamps_spec.rb +0 -39
  254. data/spec/extensions/s_spec.rb +0 -60
  255. data/spec/extensions/schema_caching_spec.rb +0 -64
  256. data/spec/extensions/schema_dumper_spec.rb +0 -870
  257. data/spec/extensions/select_remove_spec.rb +0 -38
  258. data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
  259. data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
  260. data/spec/extensions/serialization_spec.rb +0 -365
  261. data/spec/extensions/server_block_spec.rb +0 -135
  262. data/spec/extensions/server_logging_spec.rb +0 -45
  263. data/spec/extensions/sharding_spec.rb +0 -197
  264. data/spec/extensions/shared_caching_spec.rb +0 -151
  265. data/spec/extensions/single_table_inheritance_spec.rb +0 -347
  266. data/spec/extensions/singular_table_names_spec.rb +0 -22
  267. data/spec/extensions/skip_create_refresh_spec.rb +0 -18
  268. data/spec/extensions/spec_helper.rb +0 -70
  269. data/spec/extensions/split_array_nil_spec.rb +0 -24
  270. data/spec/extensions/split_values_spec.rb +0 -57
  271. data/spec/extensions/sql_comments_spec.rb +0 -33
  272. data/spec/extensions/sql_expr_spec.rb +0 -59
  273. data/spec/extensions/static_cache_cache_spec.rb +0 -35
  274. data/spec/extensions/static_cache_spec.rb +0 -471
  275. data/spec/extensions/string_agg_spec.rb +0 -90
  276. data/spec/extensions/string_date_time_spec.rb +0 -95
  277. data/spec/extensions/string_stripper_spec.rb +0 -68
  278. data/spec/extensions/subclasses_spec.rb +0 -79
  279. data/spec/extensions/subset_conditions_spec.rb +0 -38
  280. data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
  281. data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
  282. data/spec/extensions/synchronize_sql_spec.rb +0 -124
  283. data/spec/extensions/table_select_spec.rb +0 -83
  284. data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
  285. data/spec/extensions/thread_local_timezones_spec.rb +0 -67
  286. data/spec/extensions/throw_failures_spec.rb +0 -74
  287. data/spec/extensions/timestamps_spec.rb +0 -209
  288. data/spec/extensions/to_dot_spec.rb +0 -153
  289. data/spec/extensions/touch_spec.rb +0 -226
  290. data/spec/extensions/tree_spec.rb +0 -334
  291. data/spec/extensions/typecast_on_load_spec.rb +0 -86
  292. data/spec/extensions/unlimited_update_spec.rb +0 -21
  293. data/spec/extensions/update_or_create_spec.rb +0 -83
  294. data/spec/extensions/update_primary_key_spec.rb +0 -105
  295. data/spec/extensions/update_refresh_spec.rb +0 -59
  296. data/spec/extensions/uuid_spec.rb +0 -101
  297. data/spec/extensions/validate_associated_spec.rb +0 -52
  298. data/spec/extensions/validation_class_methods_spec.rb +0 -1040
  299. data/spec/extensions/validation_contexts_spec.rb +0 -31
  300. data/spec/extensions/validation_helpers_spec.rb +0 -525
  301. data/spec/extensions/whitelist_security_spec.rb +0 -157
  302. data/spec/extensions/xml_serializer_spec.rb +0 -213
  303. data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
  304. data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
  305. data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  306. data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  307. data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
  308. data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
  309. data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
  310. data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
  311. data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
  312. data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
  313. data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
  314. data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
  315. data/spec/files/double_migration/001_create_sessions.rb +0 -9
  316. data/spec/files/double_migration/002_create_nodes.rb +0 -19
  317. data/spec/files/double_migration/003_3_create_users.rb +0 -4
  318. data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
  319. data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
  320. data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  321. data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
  322. data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
  323. data/spec/files/empty_migration/001_create_sessions.rb +0 -9
  324. data/spec/files/empty_migration/002_create_nodes.rb +0 -0
  325. data/spec/files/empty_migration/003_3_create_users.rb +0 -4
  326. data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
  327. data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
  328. data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
  329. data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  330. data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
  331. data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  332. data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
  333. data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  334. data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
  335. data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
  336. data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  337. data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  338. data/spec/files/reversible_migrations/001_reversible.rb +0 -5
  339. data/spec/files/reversible_migrations/002_reversible.rb +0 -5
  340. data/spec/files/reversible_migrations/003_reversible.rb +0 -5
  341. data/spec/files/reversible_migrations/004_reversible.rb +0 -5
  342. data/spec/files/reversible_migrations/005_reversible.rb +0 -10
  343. data/spec/files/reversible_migrations/006_reversible.rb +0 -10
  344. data/spec/files/reversible_migrations/007_reversible.rb +0 -10
  345. data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
  346. data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
  347. data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
  348. data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
  349. data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
  350. data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
  351. data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
  352. data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
  353. data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
  354. data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
  355. data/spec/guards_helper.rb +0 -59
  356. data/spec/integration/associations_test.rb +0 -2597
  357. data/spec/integration/database_test.rb +0 -113
  358. data/spec/integration/dataset_test.rb +0 -2037
  359. data/spec/integration/eager_loader_test.rb +0 -687
  360. data/spec/integration/migrator_test.rb +0 -262
  361. data/spec/integration/model_test.rb +0 -203
  362. data/spec/integration/plugin_test.rb +0 -2423
  363. data/spec/integration/prepared_statement_test.rb +0 -405
  364. data/spec/integration/schema_test.rb +0 -903
  365. data/spec/integration/spec_helper.rb +0 -71
  366. data/spec/integration/timezone_test.rb +0 -86
  367. data/spec/integration/transaction_test.rb +0 -603
  368. data/spec/integration/type_test.rb +0 -127
  369. data/spec/model/association_reflection_spec.rb +0 -803
  370. data/spec/model/associations_spec.rb +0 -4738
  371. data/spec/model/base_spec.rb +0 -875
  372. data/spec/model/class_dataset_methods_spec.rb +0 -146
  373. data/spec/model/dataset_methods_spec.rb +0 -198
  374. data/spec/model/eager_loading_spec.rb +0 -2377
  375. data/spec/model/hooks_spec.rb +0 -370
  376. data/spec/model/inflector_spec.rb +0 -26
  377. data/spec/model/model_spec.rb +0 -956
  378. data/spec/model/plugins_spec.rb +0 -429
  379. data/spec/model/record_spec.rb +0 -2118
  380. data/spec/model/spec_helper.rb +0 -46
  381. data/spec/model/validations_spec.rb +0 -220
  382. data/spec/model_no_assoc_spec.rb +0 -1
  383. data/spec/model_spec.rb +0 -1
  384. data/spec/plugin_spec.rb +0 -1
  385. data/spec/sequel_coverage.rb +0 -15
  386. data/spec/sequel_warning.rb +0 -5
  387. data/spec/spec_config.rb +0 -12
@@ -1,75 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "column_conflicts plugin" do
4
- before do
5
- @db = Sequel.mock
6
- @c = Class.new(Sequel::Model(@db[:test]))
7
- @c.columns :model, :use_transactions, :foo
8
- @c.plugin :column_conflicts
9
- @o = @c.load(:model=>1, :use_transactions=>2, :foo=>4)
10
- end
11
-
12
- it "should have mass assignment work correctly" do
13
- @o.set_fields({:use_transactions=>3}, [:use_transactions])
14
- @o.get_column_value(:use_transactions).must_equal 3
15
- end
16
-
17
- it "should handle both symbols and strings" do
18
- @o.get_column_value(:model).must_equal 1
19
- @o.get_column_value("model").must_equal 1
20
- @o.set_column_value(:use_transactions=, 3)
21
- @o.get_column_value(:use_transactions).must_equal 3
22
- @o.set_column_value(:use_transactions=, 4)
23
- @o.get_column_value(:use_transactions).must_equal 4
24
- end
25
-
26
- it "should work correctly if there are no conflicts" do
27
- @o.get_column_value(:foo).must_equal 4
28
- @o.set_column_value(:model=, 2).must_equal 2
29
- end
30
-
31
- it "should allow manual setting of conflicted columns" do
32
- @c.send(:define_method, :foo){raise}
33
- @c.get_column_conflict!(:foo)
34
- @o.get_column_value(:foo).must_equal 4
35
-
36
- @c.send(:define_method, :model=){raise}
37
- @c.set_column_conflict!(:model)
38
- @o.set_column_value(:model=, 2).must_equal 2
39
- @o.get_column_value(:model).must_equal 2
40
- end
41
-
42
- it "should not erase existing column conflicts when loading the plugin" do
43
- @c.send(:define_method, :foo){raise}
44
- @c.send(:define_method, :model=){raise}
45
- @c.get_column_conflict!(:foo)
46
- @c.set_column_conflict!(:model)
47
- @c.plugin :column_conflicts
48
- @o.get_column_value(:foo).must_equal 4
49
- @o.set_column_value(:model=, 2).must_equal 2
50
- @o.get_column_value(:model).must_equal 2
51
- end
52
-
53
- it "should work correctly in subclasses" do
54
- @o = Class.new(@c).load(:model=>1, :use_transactions=>2)
55
- @o.get_column_value(:model).must_equal 1
56
- @o.get_column_value("model").must_equal 1
57
- @o.set_column_value(:use_transactions=, 3)
58
- @o.get_column_value(:use_transactions).must_equal 3
59
- @o.set_column_value(:use_transactions=, 4)
60
- @o.get_column_value(:use_transactions).must_equal 4
61
- end
62
-
63
- it "should work correctly for dataset changes" do
64
- @c.dataset = @db[:test].with_extend{def columns; [:object_id] end}
65
- o = @c.load(:object_id=>3)
66
- o.get_column_value(:object_id).must_equal 3
67
- o.object_id.wont_equal 3
68
- end
69
-
70
- it "should freeze column conflict information when freezing model class" do
71
- @c.freeze
72
- @c.get_column_conflicts.frozen?.must_equal true
73
- @c.set_column_conflicts.frozen?.must_equal true
74
- end
75
- end
@@ -1,129 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::ColumnSelect" do
4
- def set_cols(*cols)
5
- @cols.replace(cols)
6
- end
7
-
8
- before do
9
- cols = @cols = []
10
- @db = Sequel.mock
11
- @db.extend_datasets(Module.new{define_method(:columns){cols}})
12
- set_cols :id, :a, :b, :c
13
- @Album = Class.new(Sequel::Model(@db[:albums]))
14
- end
15
-
16
- it "should add a explicit column selections to existing dataset without explicit selection" do
17
- @Album.plugin :column_select
18
- @Album.dataset.sql.must_equal 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums'
19
-
20
- @Album.dataset = :albs
21
- @Album.dataset.sql.must_equal 'SELECT albs.id, albs.a, albs.b, albs.c FROM albs'
22
-
23
- @Album.dataset = Sequel.identifier(:albs)
24
- @Album.dataset.sql.must_equal 'SELECT albs.id, albs.a, albs.b, albs.c FROM albs'
25
- end
26
-
27
- with_symbol_splitting "should handle splittable symbols" do
28
- @Album.dataset = :s__albums
29
- @Album.plugin :column_select
30
- @Album.dataset.sql.must_equal 'SELECT s.albums.id, s.albums.a, s.albums.b, s.albums.c FROM s.albums'
31
-
32
- @Album.dataset = :albums___a
33
- @Album.dataset.sql.must_equal 'SELECT a.id, a.a, a.b, a.c FROM albums AS a'
34
-
35
- @Album.dataset = :s__albums___a
36
- @Album.dataset.sql.must_equal 'SELECT a.id, a.a, a.b, a.c FROM s.albums AS a'
37
- end
38
-
39
- it "should handle qualified tables" do
40
- @Album.dataset = Sequel.qualify(:s2, :albums)
41
- @Album.plugin :column_select
42
- @Album.dataset.sql.must_equal 'SELECT s2.albums.id, s2.albums.a, s2.albums.b, s2.albums.c FROM s2.albums'
43
- end
44
-
45
- it "should handle aliases" do
46
- @Album.plugin :column_select
47
- @Album.dataset = Sequel.as(:albums, :b)
48
- @Album.dataset.sql.must_equal 'SELECT b.id, b.a, b.b, b.c FROM albums AS b'
49
-
50
- @Album.dataset = @Album.db[:albums].from_self
51
- @Album.dataset.sql.must_equal 'SELECT t1.id, t1.a, t1.b, t1.c FROM (SELECT * FROM albums) AS t1'
52
-
53
- @Album.dataset = Sequel.as(@Album.db[:albums], :b)
54
- @Album.dataset.sql.must_equal 'SELECT b.id, b.a, b.b, b.c FROM (SELECT * FROM albums) AS b'
55
- end
56
-
57
- it "should not add a explicit column selection selection on existing dataset with explicit selection" do
58
- @Album.dataset = @Album.dataset.select(:name)
59
- @Album.plugin :column_select
60
- @Album.dataset.sql.must_equal 'SELECT name FROM albums'
61
-
62
- @Album.dataset = @Album.dataset.select(:name, :artist)
63
- @Album.dataset.sql.must_equal 'SELECT name, artist FROM albums'
64
- end
65
-
66
- it "should work with implicit subqueries used for joined datasets" do
67
- @Album.dataset = @Album.db.from(:a1, :a2)
68
- @Album.plugin :column_select
69
- @Album.dataset.sql.must_equal "SELECT a1.id, a1.a, a1.b, a1.c FROM (SELECT * FROM a1, a2) AS a1"
70
-
71
- @Album.dataset = @Album.db.from(:a1).cross_join(:a2)
72
- @Album.dataset.sql.must_equal "SELECT a1.id, a1.a, a1.b, a1.c FROM (SELECT * FROM a1 CROSS JOIN a2) AS a1"
73
- end
74
-
75
- it "should add a explicit column selection on existing dataset with a subquery" do
76
- @Album.dataset = @Album.db.from(:a1, :a2).from_self(:alias=>:foo)
77
- @Album.plugin :column_select
78
- @Album.dataset.sql.must_equal 'SELECT foo.id, foo.a, foo.b, foo.c FROM (SELECT * FROM a1, a2) AS foo'
79
-
80
- @Album.dataset = @Album.db.from(:a1).cross_join(:a2).from_self(:alias=>:foo)
81
- @Album.dataset.sql.must_equal 'SELECT foo.id, foo.a, foo.b, foo.c FROM (SELECT * FROM a1 CROSS JOIN a2) AS foo'
82
- end
83
-
84
- it "should use explicit column selection for many_to_many associations" do
85
- @Album.plugin :column_select
86
- @Album.many_to_many :albums, :class=>@Album, :left_key=>:l, :right_key=>:r, :join_table=>:j
87
- @Album.load(:id=>1).albums_dataset.sql.must_equal 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums INNER JOIN j ON (j.r = albums.id) WHERE (j.l = 1)'
88
- end
89
-
90
- it "should set not explicit column selection for many_to_many associations when overriding select" do
91
- @Album.plugin :column_select
92
- @Album.dataset = @Album.dataset.select(:a)
93
- @Album.many_to_many :albums, :class=>@Album, :left_key=>:l, :right_key=>:r, :join_table=>:j
94
- @Album.load(:id=>1).albums_dataset.sql.must_equal 'SELECT albums.* FROM albums INNER JOIN j ON (j.r = albums.id) WHERE (j.l = 1)'
95
- end
96
-
97
- it "should use the schema to get columns if available" do
98
- def @db.supports_schema_parsing?() true end
99
- def @db.schema(t, *)
100
- [[:t, {}], [:d, {}]]
101
- end
102
- @Album.plugin :column_select
103
- @Album.dataset.sql.must_equal 'SELECT albums.t, albums.d FROM albums'
104
- end
105
-
106
- it "should handle case where schema parsing does not produce results" do
107
- def @db.supports_schema_parsing?() true end
108
- def @db.schema_parse_table(t, *) [] end
109
- @Album.plugin :column_select
110
- @Album.dataset.sql.must_equal 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums'
111
- end
112
-
113
- it "should handle case where schema parsing and columns does not produce results" do
114
- def @db.supports_schema_parsing?() true end
115
- def @db.schema_parse_table(t, *) [] end
116
- @db.extend_datasets{def columns; raise Sequel::DatabaseError; end}
117
- @Album.require_valid_table = false
118
- @Album.plugin :column_select
119
- @Album.dataset.sql.must_equal 'SELECT * FROM albums'
120
- end
121
-
122
- it "works correctly when loaded on model without a dataset" do
123
- c = Class.new(Sequel::Model)
124
- c.plugin :column_select
125
- sc = Class.new(c)
126
- sc.dataset = @db[:a]
127
- sc.dataset.sql.must_equal "SELECT a.id, a.a, a.b, a.c FROM a"
128
- end
129
- end
@@ -1,90 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- Sequel.extension :columns_introspection
4
-
5
- describe "columns_introspection extension" do
6
- before do
7
- @db = Sequel.mock.extension(:columns_introspection)
8
- @ds = @db[:a]
9
- @db.sqls
10
- end
11
-
12
- it "should not issue a database query if the columns are already loaded" do
13
- @ds.send(:columns=, [:x])
14
- @ds.columns.must_equal [:x]
15
- @db.sqls.length.must_equal 0
16
- end
17
-
18
- it "should handle plain symbols without a database query" do
19
- @ds.select(:x).columns.must_equal [:x]
20
- @db.sqls.length.must_equal 0
21
- end
22
-
23
- with_symbol_splitting "should handle qualified symbols without a database query" do
24
- @ds.select(:t__x).columns.must_equal [:x]
25
- @db.sqls.length.must_equal 0
26
- end
27
-
28
- with_symbol_splitting "should handle aliased symbols without a database query" do
29
- @ds.select(:x___a).columns.must_equal [:a]
30
- @db.sqls.length.must_equal 0
31
- end
32
-
33
- with_symbol_splitting "should handle qualified and aliased symbols without a database query" do
34
- @ds.select(:t__x___a).columns.must_equal [:a]
35
- @db.sqls.length.must_equal 0
36
- end
37
-
38
- it "should handle SQL::Identifiers " do
39
- @ds.select(Sequel.identifier(:x)).columns.must_equal [:x]
40
- @db.sqls.length.must_equal 0
41
- end
42
-
43
- it "should handle SQL::QualifiedIdentifiers" do
44
- @ds.select(Sequel.qualify(:t, :x)).columns.must_equal [:x]
45
- @ds.select(Sequel.identifier(:x).qualify(:t)).columns.must_equal [:x]
46
- @db.sqls.length.must_equal 0
47
- end
48
-
49
- it "should handle SQL::AliasedExpressions" do
50
- @ds.select(Sequel.as(:x, :a)).columns.must_equal [:a]
51
- @ds.select(Sequel.as(:x, Sequel.identifier(:a))).columns.must_equal [:a]
52
- @db.sqls.length.must_equal 0
53
- end
54
-
55
- it "should handle selecting * from a single subselect with no joins without a database query if the subselect's columns can be handled" do
56
- @ds.select(:x).from_self.columns.must_equal [:x]
57
- @db.sqls.length.must_equal 0
58
- @ds.select(:x).from_self.from_self.columns.must_equal [:x]
59
- @db.sqls.length.must_equal 0
60
- end
61
-
62
- it "should handle selecting * from a single table with no joins without a database query if the database has cached schema columns for the table" do
63
- @db.instance_variable_set(:@schemas, "a"=>[[:x, {}]])
64
- @ds.columns.must_equal [:x]
65
- @db.sqls.length.must_equal 0
66
- end
67
-
68
- it "should issue a database query for multiple subselects or joins" do
69
- @ds.from(@ds.select(:x), @ds.select(:y)).columns
70
- @db.sqls.length.must_equal 1
71
- @ds.select(:x).from_self.natural_join(:a).columns
72
- @db.sqls.length.must_equal 1
73
- end
74
-
75
- it "should issue a database query when common table expressions are used" do
76
- @db.instance_variable_set(:@schemas, "a"=>[[:x, {}]])
77
- @ds.with_extend{def supports_cte?(*) true end}.with(:a, @ds).columns
78
- @db.sqls.length.must_equal 1
79
- end
80
-
81
- it "should issue a database query if the wildcard is selected" do
82
- @ds.columns
83
- @db.sqls.length.must_equal 1
84
- end
85
-
86
- it "should issue a database query if an unsupported type is used" do
87
- @ds.select(1).columns
88
- @db.sqls.length.must_equal 1
89
- end
90
- end
@@ -1,35 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::ColumnsUpdated" do
4
- before do
5
- @c = Class.new(Sequel::Model(DB[:items].with_autoid(13)))
6
- @c.columns :id, :x, :y
7
- @c.plugin :columns_updated
8
- end
9
-
10
- it "should make hash used for updating available in columns_updated until after hooks finish running" do
11
- res = nil
12
- @c.send(:define_method, :after_save){res = columns_updated}
13
- o = @c.new(:x => 1, :y => nil)
14
- o[:x] = 2
15
- o.save
16
- res.must_be_nil
17
- o.after_save
18
- res.must_be_nil
19
-
20
- o = @c.load(:id => 23,:x => 1, :y => nil)
21
- o[:x] = 2
22
- o.save
23
- res.must_equal(:x=>2, :y=>nil)
24
- o.after_save
25
- res.must_be_nil
26
-
27
- o = @c.load(:id => 23,:x => 2, :y => nil)
28
- o[:x] = 2
29
- o[:y] = 22
30
- o.save(:columns=>:x)
31
- res.must_equal(:x=>2)
32
- o.after_save
33
- res.must_be_nil
34
- end
35
- end
@@ -1,248 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Composition plugin" do
4
- before do
5
- @c = Class.new(Sequel::Model(:items))
6
- @c.plugin :composition
7
- @c.columns :id, :year, :month, :day
8
- @o = @c.load(:id=>1, :year=>1, :month=>2, :day=>3)
9
- DB.reset
10
- end
11
-
12
- it ".composition should add compositions" do
13
- @o.wont_respond_to(:date)
14
- @c.composition :date, :mapping=>[:year, :month, :day]
15
- @o.date.must_equal Date.new(1, 2, 3)
16
- end
17
-
18
- it "loading the plugin twice should not remove existing compositions" do
19
- @c.composition :date, :mapping=>[:year, :month, :day]
20
- @c.plugin :composition
21
- @c.compositions.keys.must_equal [:date]
22
- end
23
-
24
- it ".composition should raise an error if :composer and :decomposer options are not present and :mapping option is not provided" do
25
- proc{@c.composition :date}.must_raise(Sequel::Error)
26
- @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
27
- @c.composition :date, :mapping=>[]
28
- end
29
-
30
- it "should handle validations of underlying columns" do
31
- @c.composition :date, :mapping=>[:year, :month, :day]
32
- o = @c.new
33
- def o.validate
34
- [:year, :month, :day].each{|c| errors.add(c, "not present") unless send(c)}
35
- end
36
- o.valid?.must_equal false
37
- o.date = Date.new(1, 2, 3)
38
- o.valid?.must_equal true
39
- end
40
-
41
- it "should have decomposer work with column_conflicts plugin" do
42
- @c.plugin :column_conflicts
43
- @c.set_column_conflict! :year
44
- @c.composition :date, :mapping=>[:year, :month, :day]
45
- o = @c.new
46
- def o.validate
47
- [:year, :month, :day].each{|c| errors.add(c, "not present") unless send(c)}
48
- end
49
- o.valid?.must_equal false
50
- o.date = Date.new(1, 2, 3)
51
- o.valid?.must_equal true
52
- end
53
-
54
- it "should set column values even when not validating" do
55
- @c.composition :date, :mapping=>[:year, :month, :day]
56
- @c.load(id: 1).set(:date=>Date.new(4, 8, 12)).save(:validate=>false)
57
- DB.sqls.must_equal ['UPDATE items SET year = 4, month = 8, day = 12 WHERE (id = 1)']
58
- end
59
-
60
- it ".compositions should return the reflection hash of compositions" do
61
- @c.compositions.must_equal({})
62
- @c.composition :date, :mapping=>[:year, :month, :day]
63
- @c.compositions.keys.must_equal [:date]
64
- r = @c.compositions.values.first
65
- r[:mapping].must_equal [:year, :month, :day]
66
- r[:composer].must_be_kind_of Proc
67
- r[:decomposer].must_be_kind_of Proc
68
- end
69
-
70
- it "#compositions should be a hash of cached values of compositions" do
71
- @o.compositions.must_equal({})
72
- @c.composition :date, :mapping=>[:year, :month, :day]
73
- @o.date
74
- @o.compositions.must_equal(:date=>Date.new(1, 2, 3))
75
- end
76
-
77
- it "should work with custom :composer and :decomposer options" do
78
- @c.composition :date, :composer=>proc{Date.new(year+1, month+2, day+3)}, :decomposer=>proc{[:year, :month, :day].each{|s| self.send("#{s}=", date.send(s) * 2)}}
79
- @o.date.must_equal Date.new(2, 4, 6)
80
- @o.save
81
- DB.sqls.must_equal ['UPDATE items SET year = 4, month = 8, day = 12 WHERE (id = 1)']
82
- end
83
-
84
- it "should allow call super in composition getter and setter method definition in class" do
85
- @c.composition :date, :mapping=>[:year, :month, :day]
86
- @c.class_eval do
87
- def date
88
- super + 1
89
- end
90
- def date=(v)
91
- super(v - 3)
92
- end
93
- end
94
- @o.date.must_equal Date.new(1, 2, 4)
95
- @o.compositions[:date].must_equal Date.new(1, 2, 3)
96
- @o.date = Date.new(1, 3, 5)
97
- @o.compositions[:date].must_equal Date.new(1, 3, 2)
98
- @o.date.must_equal Date.new(1, 3, 3)
99
- end
100
-
101
- it "should mark the object as modified whenever the composition is set" do
102
- @c.composition :date, :mapping=>[:year, :month, :day]
103
- @o.modified?.must_equal false
104
- @o.date = Date.new(3, 4, 5)
105
- @o.modified?.must_equal true
106
- end
107
-
108
- it "should only decompose existing compositions" do
109
- called = false
110
- @c.composition :date, :composer=>proc{}, :decomposer=>proc{called = true}
111
- called.must_equal false
112
- @o.save
113
- called.must_equal false
114
- @o.date = Date.new(1,2,3)
115
- called.must_equal false
116
- @o.save_changes
117
- called.must_equal true
118
- end
119
-
120
- it "should clear compositions cache when refreshing" do
121
- @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
122
- @o.date = Date.new(3, 4, 5)
123
- @o.refresh
124
- @o.compositions.must_equal({})
125
- end
126
-
127
- it "should not clear compositions cache when refreshing after save" do
128
- @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
129
- @c.create(:date=>Date.new(3, 4, 5)).compositions.must_equal(:date=>Date.new(3, 4, 5))
130
- end
131
-
132
- it "should not clear compositions cache when saving with insert_select" do
133
- @c.dataset = @c.dataset.with_extend do
134
- def supports_insert_select?; true end
135
- def insert_select(*) {:id=>1} end
136
- end
137
- @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
138
- @c.create(:date=>Date.new(3, 4, 5)).compositions.must_equal(:date=>Date.new(3, 4, 5))
139
- end
140
-
141
- it "should instantiate compositions lazily" do
142
- @c.composition :date, :mapping=>[:year, :month, :day]
143
- @o.compositions.must_equal({})
144
- @o.date
145
- @o.compositions.must_equal(:date=>Date.new(1,2,3))
146
- end
147
-
148
- it "should cache value of composition" do
149
- times = 0
150
- @c.composition :date, :composer=>proc{times+=1}, :decomposer=>proc{}
151
- times.must_equal 0
152
- @o.date
153
- times.must_equal 1
154
- @o.date
155
- times.must_equal 1
156
- end
157
-
158
- it ":class option should take an string, symbol, or class" do
159
- @c.composition :date1, :class=>'Date', :mapping=>[:year, :month, :day]
160
- @c.composition :date2, :class=>:Date, :mapping=>[:year, :month, :day]
161
- @c.composition :date3, :class=>Date, :mapping=>[:year, :month, :day]
162
- @o.date1.must_equal Date.new(1, 2, 3)
163
- @o.date2.must_equal Date.new(1, 2, 3)
164
- @o.date3.must_equal Date.new(1, 2, 3)
165
- end
166
-
167
- it ":mapping option should work with a single array of symbols" do
168
- c = Class.new do
169
- def initialize(y, m)
170
- @y, @m = y, m
171
- end
172
- def year
173
- @y * 2
174
- end
175
- def month
176
- @m * 3
177
- end
178
- end
179
- @c.composition :date, :class=>c, :mapping=>[:year, :month]
180
- @o.date.year.must_equal 2
181
- @o.date.month.must_equal 6
182
- @o.date = c.new(3, 4)
183
- @o.save
184
- DB.sqls.must_equal ['UPDATE items SET year = 6, month = 12, day = 3 WHERE (id = 1)']
185
- end
186
-
187
- it ":mapping option should work with an array of two pairs of symbols" do
188
- c = Class.new do
189
- def initialize(y, m)
190
- @y, @m = y, m
191
- end
192
- def y
193
- @y * 2
194
- end
195
- def m
196
- @m * 3
197
- end
198
- end
199
- @c.composition :date, :class=>c, :mapping=>[[:year, :y], [:month, :m]]
200
- @o.date.y.must_equal 2
201
- @o.date.m.must_equal 6
202
- @o.date = c.new(3, 4)
203
- @o.save
204
- DB.sqls.must_equal ['UPDATE items SET year = 6, month = 12, day = 3 WHERE (id = 1)']
205
- end
206
-
207
- it ":mapping option :composer should return nil if all values are nil" do
208
- @c.composition :date, :mapping=>[:year, :month, :day]
209
- @c.new.date.must_be_nil
210
- end
211
-
212
- it ":mapping option :decomposer should set all related fields to nil if nil" do
213
- @c.composition :date, :mapping=>[:year, :month, :day]
214
- @o.date = nil
215
- @o.save
216
- DB.sqls.must_equal ['UPDATE items SET year = NULL, month = NULL, day = NULL WHERE (id = 1)']
217
- end
218
-
219
- it "should work with frozen instances" do
220
- @c.composition :date, :mapping=>[:year, :month, :day]
221
- @o.freeze
222
- @o.date.must_equal Date.new(1, 2, 3)
223
- proc{@o.date = Date.today}.must_raise
224
- end
225
-
226
- it "should have #dup duplicate compositions" do
227
- @c.composition :date, :mapping=>[:year, :month, :day]
228
- @o.date.must_equal Date.new(1, 2, 3)
229
- @o.dup.compositions.must_equal @o.compositions
230
- @o.dup.compositions.wont_be_same_as(@o.compositions)
231
- end
232
-
233
- it "should work correctly with subclasses" do
234
- @c.composition :date, :mapping=>[:year, :month, :day]
235
- c = Class.new(@c)
236
- o = c.load(:id=>1, :year=>1, :month=>2, :day=>3)
237
- o.date.must_equal Date.new(1, 2, 3)
238
- o.save
239
- DB.sqls.must_equal ['UPDATE items SET year = 1, month = 2, day = 3 WHERE (id = 1)']
240
- end
241
-
242
- it "should freeze composition metadata when freezing model class" do
243
- @c.composition :date, :mapping=>[:year, :month, :day]
244
- @c.freeze
245
- @c.compositions.frozen?.must_equal true
246
- @c.compositions[:date].frozen?.must_equal true
247
- end
248
- end