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,62 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::EagerEach" do
4
- before do
5
- @c = Class.new(Sequel::Model(:items))
6
- @c.columns :id, :parent_id
7
- @c.plugin :eager_each
8
- @c.one_to_many :children, :class=>@c, :key=>:parent_id
9
- @c.db.sqls
10
- end
11
-
12
- it "should make #each on an eager dataset do eager loading" do
13
- a = []
14
- ds = @c.eager(:children).with_fetch([{:id=>1, :parent_id=>nil}, {:id=>2, :parent_id=>nil}])
15
- @c.dataset = @c.dataset.with_fetch([{:id=>3, :parent_id=>1}, {:id=>4, :parent_id=>1}, {:id=>5, :parent_id=>2}, {:id=>6, :parent_id=>2}])
16
- ds.each{|c| a << c}
17
- a.must_equal [@c.load(:id=>1, :parent_id=>nil), @c.load(:id=>2, :parent_id=>nil)]
18
- a.map{|c| c.associations[:children]}.must_equal [[@c.load(:id=>3, :parent_id=>1), @c.load(:id=>4, :parent_id=>1)], [@c.load(:id=>5, :parent_id=>2), @c.load(:id=>6, :parent_id=>2)]]
19
- sqls = @c.db.sqls
20
- sqls.shift.must_equal 'SELECT * FROM items'
21
- ['SELECT * FROM items WHERE (items.parent_id IN (1, 2))',
22
- 'SELECT * FROM items WHERE (items.parent_id IN (2, 1))'].must_include(sqls.pop)
23
- end
24
-
25
- it "should make #each on an eager_graph dataset do eager loading" do
26
- a = []
27
- ds = @c.eager_graph(:children).with_fetch([{:id=>1, :parent_id=>nil, :children_id=>3, :children_parent_id=>1}, {:id=>1, :parent_id=>nil, :children_id=>4, :children_parent_id=>1}, {:id=>2, :parent_id=>nil, :children_id=>5, :children_parent_id=>2}, {:id=>2, :parent_id=>nil, :children_id=>6, :children_parent_id=>2}])
28
- ds.each{|c| a << c}
29
- a.must_equal [@c.load(:id=>1, :parent_id=>nil), @c.load(:id=>2, :parent_id=>nil)]
30
- a.map{|c| c.associations[:children]}.must_equal [[@c.load(:id=>3, :parent_id=>1), @c.load(:id=>4, :parent_id=>1)], [@c.load(:id=>5, :parent_id=>2), @c.load(:id=>6, :parent_id=>2)]]
31
- @c.db.sqls.must_equal ['SELECT items.id, items.parent_id, children.id AS children_id, children.parent_id AS children_parent_id FROM items LEFT OUTER JOIN items AS children ON (children.parent_id = items.id)']
32
- end
33
-
34
- it "should make #first on an eager dataset do eager loading" do
35
- ds = @c.eager(:children).with_fetch([{:id=>1, :parent_id=>nil}])
36
- @c.dataset = @c.dataset.with_fetch([{:id=>3, :parent_id=>1}, {:id=>4, :parent_id=>1}])
37
- a = ds.first
38
- a.values.must_equal(:id=>1, :parent_id=>nil)
39
- a.associations[:children].must_equal [@c.load(:id=>3, :parent_id=>1), @c.load(:id=>4, :parent_id=>1)]
40
- @c.db.sqls.must_equal ['SELECT * FROM items LIMIT 1','SELECT * FROM items WHERE (items.parent_id IN (1))']
41
- end
42
-
43
- it "should make #first on an eager_graph dataset do eager loading" do
44
- a = @c.eager_graph(:children).with_fetch([[{:id=>1, :parent_id=>nil, :children_id=>3, :children_parent_id=>1}], [{:id=>1, :parent_id=>nil, :children_id=>3, :children_parent_id=>1}, {:id=>1, :parent_id=>nil, :children_id=>4, :children_parent_id=>1}]]).first
45
- a.values.must_equal(:id=>1, :parent_id=>nil)
46
- a.associations[:children].must_equal [@c.load(:id=>3, :parent_id=>1), @c.load(:id=>4, :parent_id=>1)]
47
- @c.db.sqls.must_equal ['SELECT items.id, items.parent_id, children.id AS children_id, children.parent_id AS children_parent_id FROM items LEFT OUTER JOIN items AS children ON (children.parent_id = items.id) LIMIT 1',
48
- 'SELECT items.id, items.parent_id, children.id AS children_id, children.parent_id AS children_parent_id FROM items LEFT OUTER JOIN items AS children ON (children.parent_id = items.id) WHERE (items.id = 1)']
49
- end
50
-
51
- it "should make #first on a non-eager dataset work correctly" do
52
- @c.dataset.with_fetch([{:id=>1, :parent_id=>nil}]).first.must_equal @c.load(:id=>1, :parent_id=>nil)
53
- end
54
-
55
- it "should get columns normally columns" do
56
- @c.dataset.columns!.must_equal [:id, :parent_id]
57
- end
58
-
59
- it "should not attempt to eager load when getting the columns" do
60
- @c.eager(:children).with_extend{def all; raise; end}.columns!.must_equal [:id, :parent_id]
61
- end
62
- end
@@ -1,100 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "eager_graph_eager plugin" do
4
- before do
5
- @c = Class.new(Sequel::Model(:items))
6
- @c.columns :id, :parent_id
7
- @c.plugin :eager_graph_eager
8
- @c.one_to_many :children, :class=>@c, :key=>:parent_id
9
- @c.many_to_one :parent, :class=>@c
10
- @c.db.sqls
11
- end
12
-
13
- it "should support Dataset#eager_graph_eager for eager loading dependencies of eager_graph associations for one_to_many associations" do
14
- a = @c.eager_graph(:children).
15
- with_fetch([{:id=>1, :parent_id=>nil, :children_id=>3, :children_parent_id=>1}, {:id=>2, :parent_id=>nil}]).
16
- eager_graph_eager([:children], :children=>proc{|ds| ds.with_fetch(:id=>4, :parent_id=>3)}).
17
- all
18
- @c.db.sqls.must_equal ["SELECT items.id, items.parent_id, children.id AS children_id, children.parent_id AS children_parent_id FROM items LEFT OUTER JOIN items AS children ON (children.parent_id = items.id)",
19
- "SELECT * FROM items WHERE (items.parent_id IN (3))"]
20
-
21
- a.must_equal [@c.load(:id=>1, :parent_id=>nil), @c.load(:id=>2, :parent_id=>nil)]
22
- a.map(&:children).must_equal [[@c.load(:id=>3, :parent_id=>1)], []]
23
- a.first.children.first.children.must_equal [@c.load(:id=>4, :parent_id=>3)]
24
- @c.db.sqls.must_equal []
25
- end
26
-
27
- it "should support Dataset#eager_graph_eager for eager loading dependencies of eager_graph associations for many_to_one associations" do
28
- a = @c.eager_graph(:parent).
29
- with_fetch([{:id=>4, :parent_id=>3, :parent_id_0=>3, :parent_parent_id=>1}, {:id=>2, :parent_id=>nil}]).
30
- eager_graph_eager([:parent], :parent=>proc{|ds| ds.with_fetch(:id=>1, :parent_id=>nil)}).
31
- all
32
- @c.db.sqls.must_equal ["SELECT items.id, items.parent_id, parent.id AS parent_id_0, parent.parent_id AS parent_parent_id FROM items LEFT OUTER JOIN items AS parent ON (parent.id = items.parent_id)",
33
- "SELECT * FROM items WHERE (items.id IN (1))"]
34
-
35
- a.must_equal [@c.load(:id=>4, :parent_id=>3), @c.load(:id=>2, :parent_id=>nil)]
36
- a.map(&:parent).must_equal [@c.load(:id=>3, :parent_id=>1), nil]
37
- a.first.parent.parent.must_equal @c.load(:id=>1, :parent_id=>nil)
38
- @c.db.sqls.must_equal []
39
- end
40
-
41
- it "should support multiple entries in dependency chain" do
42
- a = @c.eager_graph(:children=>:children).
43
- with_fetch([{:id=>1, :parent_id=>nil, :children_id=>3, :children_parent_id=>1, :children_0_id=>4, :children_0_parent_id=>3}, {:id=>2, :parent_id=>nil}]).
44
- eager_graph_eager([:children, :children], :children=>proc{|ds| ds.with_fetch(:id=>5, :parent_id=>4)}).
45
- all
46
- @c.db.sqls.must_equal ["SELECT items.id, items.parent_id, children.id AS children_id, children.parent_id AS children_parent_id, children_0.id AS children_0_id, children_0.parent_id AS children_0_parent_id FROM items LEFT OUTER JOIN items AS children ON (children.parent_id = items.id) LEFT OUTER JOIN items AS children_0 ON (children_0.parent_id = children.id)",
47
- "SELECT * FROM items WHERE (items.parent_id IN (4))"]
48
-
49
- a.must_equal [@c.load(:id=>1, :parent_id=>nil), @c.load(:id=>2, :parent_id=>nil)]
50
- a.map(&:children).must_equal [[@c.load(:id=>3, :parent_id=>1)], []]
51
- a.first.children.first.children.must_equal [@c.load(:id=>4, :parent_id=>3)]
52
- a.first.children.first.children.first.children.must_equal [@c.load(:id=>5, :parent_id=>4)]
53
- @c.db.sqls.must_equal []
54
- end
55
-
56
- it "should support multiple dependency chains" do
57
- a = @c.eager_graph(:children, :parent).
58
- with_fetch([{:id=>4, :parent_id=>3, :children_id=>5, :children_parent_id=>4, :parent_id_0=>3, :parent_parent_id=>1}, {:id=>2, :parent_id=>nil}]).
59
- eager_graph_eager([:children], :children=>proc{|ds| ds.with_fetch(:id=>6, :parent_id=>5)}).
60
- eager_graph_eager([:parent], :parent=>proc{|ds| ds.with_fetch(:id=>1, :parent_id=>nil)}).
61
- all
62
- @c.db.sqls.must_equal ["SELECT items.id, items.parent_id, children.id AS children_id, children.parent_id AS children_parent_id, parent.id AS parent_id_0, parent.parent_id AS parent_parent_id FROM items LEFT OUTER JOIN items AS children ON (children.parent_id = items.id) LEFT OUTER JOIN items AS parent ON (parent.id = items.parent_id)",
63
- "SELECT * FROM items WHERE (items.parent_id IN (5))",
64
- "SELECT * FROM items WHERE (items.id IN (1))"]
65
-
66
- a.must_equal [@c.load(:id=>4, :parent_id=>3), @c.load(:id=>2, :parent_id=>nil)]
67
- a.map(&:children).must_equal [[@c.load(:id=>5, :parent_id=>4)], []]
68
- a.map(&:parent).must_equal [@c.load(:id=>3, :parent_id=>1), nil]
69
- a.first.children.first.children.must_equal [@c.load(:id=>6, :parent_id=>5)]
70
- a.first.parent.parent.must_equal @c.load(:id=>1, :parent_id=>nil)
71
- @c.db.sqls.must_equal []
72
- end
73
-
74
- it "should raise for invalid dependency chains" do
75
- proc{@c.dataset.eager_graph_eager([], :children)}.must_raise Sequel::Error
76
- proc{@c.dataset.eager_graph_eager(:children, :children)}.must_raise Sequel::Error
77
- proc{@c.dataset.eager_graph_eager(['foo'], :children)}.must_raise Sequel::Error
78
- proc{@c.dataset.eager_graph_eager([:foo], :children)}.must_raise Sequel::Error
79
- end
80
-
81
- it "should handle cases where not all associated objects are unique" do
82
- a = @c.eager_graph(:parent=>:children).
83
- with_fetch([
84
- {:id=>4, :parent_id=>3, :parent_id_0=>3, :parent_parent_id=>1, :children_id=>4, :children_parent_id=>3},
85
- {:id=>5, :parent_id=>3, :parent_id_0=>3, :parent_parent_id=>1, :children_id=>4, :children_parent_id=>3},
86
- {:id=>4, :parent_id=>3, :parent_id_0=>3, :parent_parent_id=>1, :children_id=>5, :children_parent_id=>3},
87
- {:id=>5, :parent_id=>3, :parent_id_0=>3, :parent_parent_id=>1, :children_id=>5, :children_parent_id=>3}
88
- ]).
89
- eager_graph_eager([:parent], :parent=>proc{|ds| ds.with_fetch(:id=>1, :parent_id=>nil)}).
90
- all
91
- @c.db.sqls.must_equal ["SELECT items.id, items.parent_id, parent.id AS parent_id_0, parent.parent_id AS parent_parent_id, children.id AS children_id, children.parent_id AS children_parent_id FROM items LEFT OUTER JOIN items AS parent ON (parent.id = items.parent_id) LEFT OUTER JOIN items AS children ON (children.parent_id = parent.id)",
92
- "SELECT * FROM items WHERE (items.id IN (1))"]
93
-
94
- a.must_equal [@c.load(:id=>4, :parent_id=>3), @c.load(:id=>5, :parent_id=>3)]
95
- a.map(&:parent).must_equal [@c.load(:id=>3, :parent_id=>1), @c.load(:id=>3, :parent_id=>1)]
96
- a.map(&:parent).map(&:children).must_equal [a, a]
97
- a.map(&:parent).map(&:parent).must_equal [@c.load(:id=>1, :parent_id=>nil), @c.load(:id=>1, :parent_id=>nil)]
98
- @c.db.sqls.must_equal []
99
- end
100
- end
@@ -1,24 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "filter_having extension" do
4
- before do
5
- @dataset = Sequel.mock[:test].extension(:empty_array_consider_nulls)
6
- end
7
-
8
- it "should handle all types of IN/NOT IN queries with empty arrays" do
9
- @dataset.filter(:id => []).sql.must_equal "SELECT * FROM test WHERE (id != id)"
10
- @dataset.filter([:id1, :id2] => []).sql.must_equal "SELECT * FROM test WHERE ((id1 != id1) AND (id2 != id2))"
11
- @dataset.exclude(:id => []).sql.must_equal "SELECT * FROM test WHERE (id = id)"
12
- @dataset.exclude([:id1, :id2] => []).sql.must_equal "SELECT * FROM test WHERE ((id1 = id1) AND (id2 = id2))"
13
- end
14
-
15
- it "should handle IN/NOT IN queries with multiple columns and an empty dataset where the database doesn't support it" do
16
- db = Sequel.mock
17
- d1 = db[:test].select(:id1, :id2).filter(:region=>'Asia').columns(:id1, :id2)
18
- @dataset = @dataset.with_extend{def supports_multiple_column_in?; false end}
19
- @dataset.filter([:id1, :id2] => d1).sql.must_equal "SELECT * FROM test WHERE ((id1 != id1) AND (id2 != id2))"
20
- db.sqls.must_equal ["SELECT id1, id2 FROM test WHERE (region = 'Asia')"]
21
- @dataset.exclude([:id1, :id2] => d1).sql.must_equal "SELECT * FROM test WHERE ((id1 = id1) AND (id2 = id2))"
22
- db.sqls.must_equal ["SELECT id1, id2 FROM test WHERE (region = 'Asia')"]
23
- end
24
- end
@@ -1,60 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "empty_failure_backtraces plugin" do
4
- before do
5
- @c = Class.new(Sequel::Model(:items)) do
6
- plugin :empty_failure_backtraces
7
- columns :x
8
- set_primary_key :x
9
- unrestrict_primary_key
10
- def before_create
11
- super
12
- cancel_action 'bc' if x == 2
13
- end
14
- def before_destroy
15
- super
16
- cancel_action 'bd' if x == 2
17
- end
18
- def validate
19
- super
20
- errors.add(:x, "3") if x == 3
21
- end
22
- end
23
- DB.reset
24
- end
25
-
26
- it "should work normally if no exceptions are thrown/raised" do
27
- o = @c.create(:x=>1)
28
- o.must_be_kind_of @c
29
- o.valid?.must_equal true
30
- o.destroy.must_equal o
31
- end
32
-
33
- it "should work normally when not rescuing exceptions internally when calling save" do
34
- @c.new.set(:x => 2).save(:raise_on_failure=>false).must_be_nil
35
- @c.raise_on_save_failure = false
36
- @c.create(:x => 2).must_be_nil
37
- @c.load(:x => 2).destroy(:raise_on_failure=>false).must_be_nil
38
- end
39
-
40
- it "should work normally when not rescuing exceptions internally when calling valid?" do
41
- @c.send(:define_method, :before_validation){cancel_action "bv"}
42
- @c.new(:x => 2).valid?.must_equal false
43
- end
44
-
45
- it "should raise exceptions with empty backtraces" do
46
- begin
47
- @c.create(:x => 2)
48
- rescue Sequel::HookFailed => e
49
- e.backtrace.must_be_empty
50
- 1
51
- end.must_equal 1
52
-
53
- begin
54
- @c.create(:x => 3)
55
- rescue Sequel::ValidationFailed => e
56
- e.backtrace.must_be_empty
57
- 1
58
- end.must_equal 1
59
- end
60
- end
@@ -1,18 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "Sequel::Plugins::ErrorSplitter" do
4
- before do
5
- @c = Class.new(Sequel::Model)
6
- @c.plugin :error_splitter
7
- @m = @c.new
8
- def @m.validate
9
- errors.add([:a, :b], 'is bad')
10
- end
11
- end
12
-
13
- it "should split errors for multiple columns and assign them to each column" do
14
- @m.valid?.must_equal false
15
- @m.errors.must_equal(:a=>['is bad'], :b=>['is bad'])
16
- end
17
- end
18
-
@@ -1,20 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "error_sql extension" do
4
- before do
5
- @db = Sequel.mock(:fetch=>proc{|sql| @db.log_connection_yield(sql, nil){raise StandardError}}).extension(:error_sql)
6
- end
7
-
8
- it "should have Sequel::DatabaseError#sql give the SQL causing the error" do
9
- @db["SELECT"].all rescue (e = $!)
10
- e.sql.must_equal "SELECT"
11
- end
12
-
13
- it "should have Sequel::DatabaseError#sql give the SQL causing the error when using a logger" do
14
- l = Object.new
15
- def l.method_missing(*) end
16
- @db.loggers = [l]
17
- @db["SELECT"].all rescue (e = $!)
18
- e.sql.must_equal "SELECT"
19
- end
20
- end
@@ -1,40 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "escaped_like extension" do
4
- before do
5
- Sequel.extension(:escaped_like)
6
- @ds = Sequel.mock[:t]
7
- @c = Sequel[:c]
8
- end
9
-
10
- it "escaped_like should support creating case sensitive pattern matches" do
11
- @ds.where(@c.escaped_like('?', 'a')).sql.must_equal "SELECT * FROM t WHERE (c LIKE 'a' ESCAPE '\\')"
12
- @ds.where(@c.escaped_like('?%', 'a')).sql.must_equal "SELECT * FROM t WHERE (c LIKE 'a%' ESCAPE '\\')"
13
- @ds.where(@c.escaped_like('?', 'a%')).sql.must_equal "SELECT * FROM t WHERE (c LIKE 'a\\%' ESCAPE '\\')"
14
- @ds.where(@c.escaped_like('?', ['a%'])).sql.must_equal "SELECT * FROM t WHERE (c LIKE 'a\\%' ESCAPE '\\')"
15
- @ds.where(@c.escaped_like('??', ['a', '%'])).sql.must_equal "SELECT * FROM t WHERE (c LIKE 'a\\%' ESCAPE '\\')"
16
- end
17
-
18
- it "escaped_ilike should support creating case insensitive pattern matches" do
19
- @ds.where(@c.escaped_ilike('?', 'a')).sql.must_equal "SELECT * FROM t WHERE (UPPER(c) LIKE UPPER('a') ESCAPE '\\')"
20
- @ds.where(@c.escaped_ilike('?%', 'a')).sql.must_equal "SELECT * FROM t WHERE (UPPER(c) LIKE UPPER('a%') ESCAPE '\\')"
21
- @ds.where(@c.escaped_ilike('?', 'a%')).sql.must_equal "SELECT * FROM t WHERE (UPPER(c) LIKE UPPER('a\\%') ESCAPE '\\')"
22
- @ds.where(@c.escaped_ilike('?', ['a%'])).sql.must_equal "SELECT * FROM t WHERE (UPPER(c) LIKE UPPER('a\\%') ESCAPE '\\')"
23
- @ds.where(@c.escaped_ilike('??', ['a', '%'])).sql.must_equal "SELECT * FROM t WHERE (UPPER(c) LIKE UPPER('a\\%') ESCAPE '\\')"
24
- end
25
-
26
- it "should raise an Error for a mismatched number of placeholders" do
27
- proc{@ds.where(@c.escaped_like('?', [])).sql}.must_raise Sequel::Error
28
- proc{@ds.where(@c.escaped_like('??', ['a'])).sql}.must_raise Sequel::Error
29
- proc{@ds.where(@c.escaped_ilike('', ['a'])).sql}.must_raise Sequel::Error
30
- proc{@ds.where(@c.escaped_ilike('?', ['a', 'a'])).sql}.must_raise Sequel::Error
31
- end
32
-
33
- it "escaped_like and escaped_ilike should return expressions" do
34
- @ds.select(@c.escaped_like('?', 'a').as(:b)).sql.must_equal "SELECT (c LIKE 'a' ESCAPE '\\') AS b FROM t"
35
- @ds.select(@c.escaped_like('?', 'a').cast(String)).sql.must_equal "SELECT CAST((c LIKE 'a' ESCAPE '\\') AS varchar(255)) FROM t"
36
- @ds.order(@c.escaped_like('?', 'a').desc).sql.must_equal "SELECT * FROM t ORDER BY (c LIKE 'a' ESCAPE '\\') DESC"
37
- @ds.where(@c.escaped_like('?', 'a') | @c.escaped_like('?', 'b')).sql.must_equal "SELECT * FROM t WHERE ((c LIKE 'a' ESCAPE '\\') OR (c LIKE 'b' ESCAPE '\\'))"
38
- end
39
- end
40
-
@@ -1,81 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- Sequel.extension :eval_inspect
4
-
5
- describe "eval_inspect extension" do
6
- before do
7
- @ds = Sequel.mock.dataset.with_extend do
8
- def supports_window_functions?; true end
9
- def literal_blob_append(sql, s) sql << "X'#{s}'" end
10
- end
11
- end
12
-
13
- it "should make eval(obj.inspect) == obj for all Sequel::SQL::Expression subclasses" do
14
- [
15
- # Objects with components where eval(inspect) == self
16
- Sequel::SQL::AliasedExpression.new(:b, :a),
17
- Sequel::SQL::AliasedExpression.new(:b, :a, [:c, :d]),
18
- Sequel::SQL::CaseExpression.new({:b=>:a}, :c),
19
- Sequel::SQL::CaseExpression.new({:b=>:a}, :c, :d),
20
- Sequel::SQL::Cast.new(:a, :b),
21
- Sequel::SQL::ColumnAll.new(:a),
22
- Sequel::SQL::ComplexExpression.new(:'=', :b, :a),
23
- Sequel::SQL::Constant.new(:a),
24
- Sequel::CURRENT_DATE,
25
- Sequel::CURRENT_TIMESTAMP,
26
- Sequel::CURRENT_TIME,
27
- Sequel::SQLTRUE,
28
- Sequel::SQLFALSE,
29
- Sequel::NULL,
30
- Sequel::NOTNULL,
31
- Sequel::SQL::Function.new(:a, :b, :c),
32
- Sequel::SQL::Identifier.new(:a),
33
- Sequel::SQL::JoinClause.new(:inner, :b),
34
- Sequel::SQL::JoinOnClause.new({:d=>:a}, :inner, :b),
35
- Sequel::SQL::JoinUsingClause.new([:a], :inner, :b),
36
- Sequel::SQL::JoinClause.new(:inner, Sequel.as(:b, :c, [:d, :e])),
37
- Sequel::SQL::JoinOnClause.new({:d=>:a}, :inner, Sequel.as(:b, :c, [:d, :e])),
38
- Sequel::SQL::JoinUsingClause.new([:a], :inner, Sequel.as(:b, :c, [:d, :e])),
39
- Sequel::SQL::PlaceholderLiteralString.new('? = ?', [:a, :b]),
40
- Sequel::SQL::PlaceholderLiteralString.new(':a = :b', [{:a=>:b, :b=>42}]),
41
- Sequel::SQL::OrderedExpression.new(:a),
42
- Sequel::SQL::OrderedExpression.new(:a, false),
43
- Sequel::SQL::OrderedExpression.new(:a, false, :nulls=>:first),
44
- Sequel::SQL::OrderedExpression.new(:a, false, :nulls=>:last),
45
- Sequel::SQL::QualifiedIdentifier.new(:b, :a),
46
- Sequel::SQL::Subscript.new(:a, [1, 2]),
47
- Sequel::SQL::Window.new(:order=>:a, :partition=>:b),
48
- Sequel::SQL::Function.new(:a, :b, :c).over(:order=>:a, :partition=>:b),
49
- Sequel::SQL::Wrapper.new(:a),
50
-
51
- # Objects with components where eval(inspect) != self
52
- Sequel::SQL::AliasedExpression.new(Sequel::SQL::Blob.new('s'), :a),
53
- Sequel::SQL::AliasedExpression.new(Sequel::LiteralString.new('s'), :a),
54
- Sequel::SQL::PlaceholderLiteralString.new('(a, b) IN ?', [Sequel::SQL::ValueList.new([[1, 2]])]),
55
- Sequel::SQL::CaseExpression.new({{:d=>Sequel::LiteralString.new('e')}=>:a}, :c, :d),
56
- Sequel::SQL::AliasedExpression.new(Date.new(2011, 10, 11), :a),
57
- Sequel::SQL::AliasedExpression.new(Sequel::SQLTime.create(10, 20, 30, 500000.125), :a),
58
- Sequel::SQL::AliasedExpression.new(DateTime.new(2011, 9, 11, 10, 20, 30), :a),
59
- Sequel::SQL::AliasedExpression.new(DateTime.new(2011, 9, 11, 10, 20, 30, 0.25), :a),
60
- Sequel::SQL::AliasedExpression.new(DateTime.new(2011, 9, 11, 10, 20, 30, -0.25), :a),
61
- Sequel::SQL::AliasedExpression.new(Time.local(2011, 9, 11, 10, 20, 30), :a),
62
- Sequel::SQL::AliasedExpression.new(Time.local(2011, 9, 11, 10, 20, 30, 500000.125), :a),
63
- Sequel::SQL::AliasedExpression.new(Time.utc(2011, 9, 11, 10, 20, 30), :a),
64
- Sequel::SQL::AliasedExpression.new(Time.utc(2011, 9, 11, 10, 20, 30, 500000.125), :a),
65
- Sequel::SQL::AliasedExpression.new(BigDecimal('1.000000000000000000000000000000000000000000000001'), :a),
66
- Sequel::SQL::AliasedExpression.new(Sequel::CURRENT_DATE, :a),
67
- Sequel::SQL::AliasedExpression.new(Sequel::CURRENT_TIMESTAMP, :a),
68
- ].each do |o|
69
- v = eval(o.inspect)
70
- v.must_equal o
71
- @ds.literal(v).must_equal @ds.literal(o)
72
-
73
- ds = @ds
74
- @ds.db.create_table(:test) do
75
- v = eval(o.inspect)
76
- v.must_equal o
77
- ds.literal(v).must_equal ds.literal(o)
78
- end
79
- end
80
- end
81
- end
@@ -1,15 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe "exclude_or_null extension" do
4
- before do
5
- @ds = Sequel.mock[:t].extension(:exclude_or_null)
6
- end
7
-
8
- it "should add condition where a is false or NULL" do
9
- @ds.exclude_or_null(:a).sql.must_equal "SELECT * FROM t WHERE NOT coalesce(a, 'f')"
10
- end
11
-
12
- it "should not effect normal exclude" do
13
- @ds.exclude(:a).sql.must_equal "SELECT * FROM t WHERE NOT a"
14
- end
15
- end
@@ -1,260 +0,0 @@
1
- require_relative "spec_helper"
2
-
3
- describe Sequel::Model, ".finder" do
4
- before do
5
- @h = {:id=>1}
6
- @db = Sequel.mock(:fetch=>@h)
7
- @c = Class.new(Sequel::Model(@db[:items]))
8
- @c.instance_eval do
9
- def foo(a, b)
10
- where(:bar=>a).order(b)
11
- end
12
- end
13
- @c.plugin :finder
14
- @o = @c.load(@h)
15
- @db.sqls
16
- end
17
-
18
- it "should create a method that calls the method given and returns the first instance" do
19
- @c.finder :foo
20
- @c.first_foo(1, 2).must_equal @o
21
- @c.first_foo(3, 4).must_equal @o
22
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
23
- end
24
-
25
- it "should work correctly when subclassing" do
26
- @c.finder(:foo)
27
- @sc = Class.new(@c)
28
- @sc.set_dataset :foos
29
- @db.sqls
30
- @sc.first_foo(1, 2).must_equal @sc.load(@h)
31
- @sc.first_foo(3, 4).must_equal @sc.load(@h)
32
- @db.sqls.must_equal ["SELECT * FROM foos WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
33
- end
34
-
35
- it "should work correctly when dataset is modified" do
36
- @c.finder(:foo)
37
- @c.first_foo(1, 2).must_equal @o
38
- @c.set_dataset :foos
39
- @c.first_foo(3, 4).must_equal @o
40
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM foos LIMIT 1", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
41
- end
42
-
43
- it "should create a method based on the given block if no method symbol provided" do
44
- @c.finder(:name=>:first_foo){|pl, ds| ds.where(pl.arg).limit(1)}
45
- @c.first_foo(:id=>1).must_equal @o
46
- @db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1) LIMIT 1"]
47
- end
48
-
49
- it "should raise an error if both a block and method symbol given" do
50
- proc{@c.finder(:foo, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
51
- end
52
-
53
- it "should raise an error if two option hashes are provided" do
54
- proc{@c.finder({:name2=>:foo}, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
55
- end
56
-
57
- it "should support :type option" do
58
- @c.finder :foo, :type=>:all
59
- @c.finder :foo, :type=>:each
60
- @c.finder :foo, :type=>:get
61
-
62
- a = []
63
- @c.all_foo(1, 2){|r| a << r}.must_equal [@o]
64
- a.must_equal [@o]
65
-
66
- a = []
67
- @c.each_foo(3, 4){|r| a << r}
68
- a.must_equal [@o]
69
-
70
- @c.get_foo(5, 6).must_equal 1
71
-
72
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4", "SELECT * FROM items WHERE (bar = 5) ORDER BY 6 LIMIT 1"]
73
- end
74
-
75
- it "should support :name option" do
76
- @c.finder :foo, :name=>:find_foo
77
- @c.find_foo(1, 2).must_equal @o
78
- @c.find_foo(3, 4).must_equal @o
79
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
80
- end
81
-
82
- it "should support :arity option" do
83
- def @c.foobar(*b)
84
- ds = dataset
85
- b.each_with_index do |a, i|
86
- ds = ds.where(i=>a)
87
- end
88
- ds
89
- end
90
- @c.finder :foobar, :arity=>1, :name=>:find_foobar_1
91
- @c.finder :foobar, :arity=>2, :name=>:find_foobar_2
92
- @c.find_foobar_1(:a)
93
- @c.find_foobar_2(:a, :b)
94
- @db.sqls.must_equal ["SELECT * FROM items WHERE (0 = a) LIMIT 1", "SELECT * FROM items WHERE ((0 = a) AND (1 = b)) LIMIT 1"]
95
- end
96
-
97
- it "should support :mod option" do
98
- m = Module.new
99
- @c.finder :foo, :mod=>m
100
- proc{@c.first_foo}.must_raise NoMethodError
101
- @c.extend m
102
- @c.first_foo(1, 2).must_equal @o
103
- @c.first_foo(3, 4).must_equal @o
104
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1"]
105
- end
106
-
107
- it "should raise error when calling with the wrong arity" do
108
- @c.finder :foo
109
- proc{@c.first_foo(1)}.must_raise Sequel::Error
110
- proc{@c.first_foo(1,2,3)}.must_raise Sequel::Error
111
- end
112
- end
113
-
114
- describe Sequel::Model, ".prepared_finder" do
115
- before do
116
- @h = {:id=>1}
117
- @db = Sequel.mock(:fetch=>@h)
118
- @db.extend_datasets do
119
- def select_sql
120
- sql = super
121
- sql << ' -- prepared' if is_a?(Sequel::Dataset::PreparedStatementMethods) && !opts[:sql]
122
- sql
123
- end
124
- end
125
- @c = Class.new(Sequel::Model(@db[:items]))
126
- @c.instance_eval do
127
- def foo(a, b)
128
- where(:bar=>a).order(b)
129
- end
130
- end
131
- @c.plugin :finder
132
- @o = @c.load(@h)
133
- @db.sqls
134
- end
135
-
136
- it "should create a method that calls the method given and returns the first instance" do
137
- @c.prepared_finder :foo
138
- @c.first_foo(1, 2).must_equal @o
139
- @c.first_foo(3, 4).must_equal @o
140
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
141
- end
142
-
143
- it "should work correctly when subclassing" do
144
- @c.prepared_finder(:foo)
145
- @sc = Class.new(@c)
146
- @sc.set_dataset :foos
147
- @db.sqls
148
- @sc.first_foo(1, 2).must_equal @sc.load(@h)
149
- @sc.first_foo(3, 4).must_equal @sc.load(@h)
150
- @db.sqls.must_equal ["SELECT * FROM foos WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
151
- end
152
-
153
- it "should work correctly when dataset is modified" do
154
- @c.prepared_finder(:foo)
155
- @c.first_foo(1, 2).must_equal @o
156
- @c.set_dataset :foos
157
- @c.first_foo(3, 4).must_equal @o
158
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM foos LIMIT 1", "SELECT * FROM foos WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
159
- end
160
-
161
- it "should create a method based on the given block if no method symbol provided" do
162
- @c.prepared_finder(:name=>:first_foo){|a1| where(:id=>a1).limit(1)}
163
- @c.first_foo(1).must_equal @o
164
- @db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1) LIMIT 1 -- prepared"]
165
- end
166
-
167
- it "should raise an error if both a block and method symbol given" do
168
- proc{@c.prepared_finder(:foo, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
169
- end
170
-
171
- it "should raise an error if two option hashes are provided" do
172
- proc{@c.prepared_finder({:name2=>:foo}, :name=>:first_foo){|pl, ds| ds.where(pl.arg)}}.must_raise(Sequel::Error)
173
- end
174
-
175
- it "should support :type option" do
176
- @c.prepared_finder :foo, :type=>:all
177
- @c.prepared_finder :foo, :type=>:each
178
-
179
- a = []
180
- @c.all_foo(1, 2){|r| a << r}.must_equal [@o]
181
- a.must_equal [@o]
182
-
183
- a = []
184
- @c.each_foo(3, 4){|r| a << r}
185
- a.must_equal [@o]
186
-
187
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 -- prepared"]
188
- end
189
-
190
- it "should support :name option" do
191
- @c.prepared_finder :foo, :name=>:find_foo
192
- @c.find_foo(1, 2).must_equal @o
193
- @c.find_foo(3, 4).must_equal @o
194
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
195
- end
196
-
197
- it "should support :arity option" do
198
- def @c.foobar(*b)
199
- ds = dataset
200
- b.each_with_index do |a, i|
201
- ds = ds.where(i=>a)
202
- end
203
- ds
204
- end
205
- @c.prepared_finder :foobar, :arity=>1, :name=>:find_foobar_1
206
- @c.prepared_finder :foobar, :arity=>2, :name=>:find_foobar_2
207
- @c.find_foobar_1(:a)
208
- @c.find_foobar_2(:a, :b)
209
- @db.sqls.must_equal ["SELECT * FROM items WHERE (0 = a) LIMIT 1 -- prepared", "SELECT * FROM items WHERE ((0 = a) AND (1 = b)) LIMIT 1 -- prepared"]
210
- end
211
-
212
- it "should support :mod option" do
213
- m = Module.new
214
- @c.prepared_finder :foo, :mod=>m
215
- proc{@c.first_foo}.must_raise NoMethodError
216
- @c.extend m
217
- @c.first_foo(1, 2).must_equal @o
218
- @c.first_foo(3, 4).must_equal @o
219
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared", "SELECT * FROM items WHERE (bar = 3) ORDER BY 4 LIMIT 1 -- prepared"]
220
- end
221
-
222
- it "should handle models with names" do
223
- def @c.name; 'foobar' end
224
- @c.prepared_finder :foo
225
- @c.first_foo(1, 2).must_equal @o
226
- @db.sqls.must_equal ["SELECT * FROM items WHERE (bar = 1) ORDER BY 2 LIMIT 1 -- prepared"]
227
- end
228
- end
229
-
230
- describe "Sequel::Model.freeze" do
231
- it "should freeze the model class and not allow any changes" do
232
- model = Class.new(Sequel::Model(:items))
233
- model.plugin :finder
234
- model.finder(:name=>:f_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}
235
- model.freeze
236
- model.f_by_name('a').must_equal model.call(:id=>1, :x=>1)
237
- proc{model.finder(:name=>:first_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}}.must_raise RuntimeError, TypeError
238
- end
239
-
240
- it "should freeze a model class without a dataset without breaking" do
241
- model = Class.new(Sequel::Model)
242
- model.plugin :finder
243
- model.freeze
244
- proc{model.finder(:name=>:first_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}}.must_raise RuntimeError, TypeError
245
- end
246
-
247
- it "should allow subclasses of frozen model classes to work correctly" do
248
- model = Class.new(Sequel::Model(:items))
249
- model.plugin :finder
250
- model.freeze
251
- model = Class.new(model)
252
- model.dataset = :items2
253
-
254
- model.dataset_module{}
255
- model.plugin Module.new
256
- model.finder(:name=>:first_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}
257
- model.first_by_name('a').values.must_equal(:id=>1, :x=>1)
258
- end
259
- end
260
-