ibm_db 3.0.5-x86-mingw32 → 5.0.5-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (358) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +4 -0
  3. data/LICENSE +1 -1
  4. data/ParameterizedQueries README +6 -6
  5. data/README +38 -55
  6. data/ext/Makefile +269 -0
  7. data/ext/extconf.rb +34 -3
  8. data/ext/gil_release_version +3 -0
  9. data/ext/ibm_db-i386-mingw32.def +2 -0
  10. data/ext/ibm_db.c +100 -108
  11. data/ext/ibm_db.o +0 -0
  12. data/ext/ibm_db.so +0 -0
  13. data/ext/mkmf.log +110 -0
  14. data/ext/ruby_ibm_db_cli.o +0 -0
  15. data/ext/unicode_support_version +3 -0
  16. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +923 -527
  17. data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
  18. data/lib/mswin32/ibm_db.rb +7 -39
  19. data/lib/mswin32/rb2x/i386/ibm_db.so +0 -0
  20. data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
  21. data/test/cases/adapter_test.rb +133 -58
  22. data/test/cases/adapters/mysql2/active_schema_test.rb +193 -0
  23. data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
  24. data/test/cases/adapters/mysql2/boolean_test.rb +100 -0
  25. data/test/cases/adapters/mysql2/case_sensitivity_test.rb +63 -0
  26. data/test/cases/adapters/mysql2/charset_collation_test.rb +54 -0
  27. data/test/cases/adapters/mysql2/connection_test.rb +210 -0
  28. data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +45 -0
  29. data/test/cases/adapters/mysql2/enum_test.rb +26 -0
  30. data/test/cases/adapters/mysql2/explain_test.rb +21 -0
  31. data/test/cases/adapters/mysql2/json_test.rb +195 -0
  32. data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +83 -0
  33. data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
  34. data/test/cases/adapters/mysql2/schema_migrations_test.rb +59 -0
  35. data/test/cases/adapters/mysql2/schema_test.rb +126 -0
  36. data/test/cases/adapters/mysql2/sp_test.rb +36 -0
  37. data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
  38. data/test/cases/adapters/mysql2/table_options_test.rb +42 -0
  39. data/test/cases/adapters/mysql2/unsigned_type_test.rb +66 -0
  40. data/test/cases/adapters/postgresql/active_schema_test.rb +98 -0
  41. data/test/cases/adapters/postgresql/array_test.rb +339 -0
  42. data/test/cases/adapters/postgresql/bit_string_test.rb +82 -0
  43. data/test/cases/adapters/postgresql/bytea_test.rb +134 -0
  44. data/test/cases/adapters/postgresql/case_insensitive_test.rb +26 -0
  45. data/test/cases/adapters/postgresql/change_schema_test.rb +38 -0
  46. data/test/cases/adapters/postgresql/cidr_test.rb +25 -0
  47. data/test/cases/adapters/postgresql/citext_test.rb +78 -0
  48. data/test/cases/adapters/postgresql/collation_test.rb +53 -0
  49. data/test/cases/adapters/postgresql/composite_test.rb +132 -0
  50. data/test/cases/adapters/postgresql/connection_test.rb +257 -0
  51. data/test/cases/adapters/postgresql/datatype_test.rb +92 -0
  52. data/test/cases/adapters/postgresql/domain_test.rb +47 -0
  53. data/test/cases/adapters/postgresql/enum_test.rb +91 -0
  54. data/test/cases/adapters/postgresql/explain_test.rb +20 -0
  55. data/test/cases/adapters/postgresql/extension_migration_test.rb +63 -0
  56. data/test/cases/adapters/postgresql/full_text_test.rb +44 -0
  57. data/test/cases/adapters/postgresql/geometric_test.rb +378 -0
  58. data/test/cases/adapters/postgresql/hstore_test.rb +382 -0
  59. data/test/cases/adapters/postgresql/infinity_test.rb +69 -0
  60. data/test/cases/adapters/postgresql/integer_test.rb +25 -0
  61. data/test/cases/adapters/postgresql/json_test.rb +237 -0
  62. data/test/cases/adapters/postgresql/ltree_test.rb +53 -0
  63. data/test/cases/adapters/postgresql/money_test.rb +96 -0
  64. data/test/cases/adapters/postgresql/network_test.rb +94 -0
  65. data/test/cases/adapters/postgresql/numbers_test.rb +49 -0
  66. data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +405 -0
  67. data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
  68. data/test/cases/adapters/postgresql/quoting_test.rb +44 -0
  69. data/test/cases/adapters/postgresql/range_test.rb +343 -0
  70. data/test/cases/adapters/postgresql/referential_integrity_test.rb +111 -0
  71. data/test/cases/adapters/postgresql/rename_table_test.rb +34 -0
  72. data/test/cases/adapters/postgresql/schema_authorization_test.rb +119 -0
  73. data/test/cases/adapters/postgresql/schema_test.rb +597 -0
  74. data/test/cases/adapters/postgresql/serial_test.rb +154 -0
  75. data/test/cases/adapters/postgresql/statement_pool_test.rb +41 -0
  76. data/test/cases/adapters/postgresql/timestamp_test.rb +90 -0
  77. data/test/cases/adapters/postgresql/type_lookup_test.rb +33 -0
  78. data/test/cases/adapters/postgresql/utils_test.rb +62 -0
  79. data/test/cases/adapters/postgresql/uuid_test.rb +294 -0
  80. data/test/cases/adapters/postgresql/xml_test.rb +54 -0
  81. data/test/cases/adapters/sqlite3/collation_test.rb +53 -0
  82. data/test/cases/adapters/sqlite3/copy_table_test.rb +98 -0
  83. data/test/cases/adapters/sqlite3/explain_test.rb +21 -0
  84. data/test/cases/adapters/sqlite3/quoting_test.rb +101 -0
  85. data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +441 -0
  86. data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
  87. data/test/cases/adapters/sqlite3/statement_pool_test.rb +20 -0
  88. data/test/cases/aggregations_test.rb +11 -1
  89. data/test/cases/ar_schema_test.rb +35 -50
  90. data/test/cases/associations/association_scope_test.rb +1 -6
  91. data/test/cases/associations/belongs_to_associations_test.rb +122 -10
  92. data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +41 -0
  93. data/test/cases/associations/callbacks_test.rb +5 -7
  94. data/test/cases/associations/cascaded_eager_loading_test.rb +1 -1
  95. data/test/cases/associations/eager_load_nested_include_test.rb +1 -3
  96. data/test/cases/associations/eager_test.rb +158 -73
  97. data/test/cases/associations/extension_test.rb +7 -2
  98. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +64 -32
  99. data/test/cases/associations/has_many_associations_test.rb +362 -43
  100. data/test/cases/associations/has_many_through_associations_test.rb +108 -41
  101. data/test/cases/associations/has_one_associations_test.rb +105 -8
  102. data/test/cases/associations/has_one_through_associations_test.rb +6 -3
  103. data/test/cases/associations/inner_join_association_test.rb +3 -3
  104. data/test/cases/associations/inverse_associations_test.rb +38 -11
  105. data/test/cases/associations/join_model_test.rb +59 -36
  106. data/test/cases/associations/left_outer_join_association_test.rb +88 -0
  107. data/test/cases/associations/nested_through_associations_test.rb +2 -2
  108. data/test/cases/associations/required_test.rb +25 -5
  109. data/test/cases/associations_test.rb +39 -34
  110. data/test/cases/attribute_decorators_test.rb +9 -8
  111. data/test/cases/attribute_methods/read_test.rb +5 -5
  112. data/test/cases/attribute_methods_test.rb +97 -40
  113. data/test/cases/attribute_set_test.rb +64 -4
  114. data/test/cases/attribute_test.rb +84 -18
  115. data/test/cases/attributes_test.rb +151 -34
  116. data/test/cases/autosave_association_test.rb +149 -36
  117. data/test/cases/base_test.rb +290 -241
  118. data/test/cases/batches_test.rb +299 -22
  119. data/test/cases/binary_test.rb +2 -10
  120. data/test/cases/bind_parameter_test.rb +76 -66
  121. data/test/cases/cache_key_test.rb +26 -0
  122. data/test/cases/calculations_test.rb +167 -15
  123. data/test/cases/callbacks_test.rb +161 -68
  124. data/test/cases/coders/json_test.rb +15 -0
  125. data/test/cases/collection_cache_key_test.rb +115 -0
  126. data/test/cases/column_definition_test.rb +26 -57
  127. data/test/cases/comment_test.rb +145 -0
  128. data/test/cases/connection_adapters/adapter_leasing_test.rb +5 -3
  129. data/test/cases/connection_adapters/connection_handler_test.rb +128 -21
  130. data/test/cases/connection_adapters/connection_specification_test.rb +1 -1
  131. data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +0 -38
  132. data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -1
  133. data/test/cases/connection_adapters/schema_cache_test.rb +8 -3
  134. data/test/cases/connection_adapters/type_lookup_test.rb +15 -7
  135. data/test/cases/connection_management_test.rb +46 -56
  136. data/test/cases/connection_pool_test.rb +195 -20
  137. data/test/cases/connection_specification/resolver_test.rb +15 -0
  138. data/test/cases/counter_cache_test.rb +10 -5
  139. data/test/cases/custom_locking_test.rb +1 -1
  140. data/test/cases/database_statements_test.rb +18 -3
  141. data/test/cases/{invalid_date_test.rb → date_test.rb} +13 -1
  142. data/test/cases/date_time_precision_test.rb +107 -0
  143. data/test/cases/defaults_test.rb +85 -89
  144. data/test/cases/dirty_test.rb +30 -52
  145. data/test/cases/disconnected_test.rb +4 -2
  146. data/test/cases/enum_test.rb +178 -24
  147. data/test/cases/errors_test.rb +16 -0
  148. data/test/cases/explain_test.rb +32 -21
  149. data/test/cases/finder_test.rb +273 -148
  150. data/test/cases/fixture_set/file_test.rb +18 -0
  151. data/test/cases/fixtures_test.rb +112 -32
  152. data/test/cases/forbidden_attributes_protection_test.rb +69 -3
  153. data/test/cases/helper.rb +10 -16
  154. data/test/cases/hot_compatibility_test.rb +89 -1
  155. data/test/cases/inheritance_test.rb +284 -53
  156. data/test/cases/integration_test.rb +23 -7
  157. data/test/cases/invalid_connection_test.rb +4 -2
  158. data/test/cases/invertible_migration_test.rb +124 -32
  159. data/test/cases/json_serialization_test.rb +11 -2
  160. data/test/cases/locking_test.rb +22 -6
  161. data/test/cases/log_subscriber_test.rb +106 -17
  162. data/test/cases/migration/change_schema_test.rb +60 -114
  163. data/test/cases/migration/change_table_test.rb +34 -2
  164. data/test/cases/migration/column_attributes_test.rb +7 -23
  165. data/test/cases/migration/column_positioning_test.rb +8 -8
  166. data/test/cases/migration/columns_test.rb +17 -11
  167. data/test/cases/migration/command_recorder_test.rb +47 -2
  168. data/test/cases/migration/compatibility_test.rb +118 -0
  169. data/test/cases/migration/create_join_table_test.rb +21 -12
  170. data/test/cases/migration/foreign_key_test.rb +52 -18
  171. data/test/cases/migration/index_test.rb +14 -12
  172. data/test/cases/migration/logger_test.rb +1 -1
  173. data/test/cases/migration/pending_migrations_test.rb +0 -1
  174. data/test/cases/migration/references_foreign_key_test.rb +59 -7
  175. data/test/cases/migration/references_index_test.rb +4 -4
  176. data/test/cases/migration/references_statements_test.rb +26 -6
  177. data/test/cases/migration/rename_table_test.rb +25 -25
  178. data/test/cases/migration_test.rb +279 -81
  179. data/test/cases/migrator_test.rb +91 -8
  180. data/test/cases/mixin_test.rb +0 -2
  181. data/test/cases/modules_test.rb +3 -4
  182. data/test/cases/multiparameter_attributes_test.rb +24 -2
  183. data/test/cases/multiple_db_test.rb +11 -4
  184. data/test/cases/nested_attributes_test.rb +61 -33
  185. data/test/cases/persistence_test.rb +102 -10
  186. data/test/cases/pooled_connections_test.rb +3 -3
  187. data/test/cases/primary_keys_test.rb +170 -31
  188. data/test/cases/query_cache_test.rb +216 -96
  189. data/test/cases/quoting_test.rb +65 -19
  190. data/test/cases/readonly_test.rb +2 -1
  191. data/test/cases/reflection_test.rb +68 -22
  192. data/test/cases/relation/delegation_test.rb +3 -8
  193. data/test/cases/relation/merging_test.rb +10 -14
  194. data/test/cases/relation/mutation_test.rb +42 -24
  195. data/test/cases/relation/or_test.rb +92 -0
  196. data/test/cases/relation/predicate_builder_test.rb +4 -2
  197. data/test/cases/relation/record_fetch_warning_test.rb +40 -0
  198. data/test/cases/relation/where_chain_test.rb +23 -99
  199. data/test/cases/relation/where_clause_test.rb +182 -0
  200. data/test/cases/relation/where_test.rb +45 -23
  201. data/test/cases/relation_test.rb +67 -58
  202. data/test/cases/relations_test.rb +249 -38
  203. data/test/cases/result_test.rb +10 -0
  204. data/test/cases/sanitize_test.rb +108 -15
  205. data/test/cases/schema_dumper_test.rb +119 -125
  206. data/test/cases/schema_loading_test.rb +52 -0
  207. data/test/cases/scoping/default_scoping_test.rb +113 -39
  208. data/test/cases/scoping/named_scoping_test.rb +46 -9
  209. data/test/cases/scoping/relation_scoping_test.rb +47 -4
  210. data/test/cases/secure_token_test.rb +32 -0
  211. data/test/cases/serialization_test.rb +1 -1
  212. data/test/cases/serialized_attribute_test.rb +93 -6
  213. data/test/cases/statement_cache_test.rb +38 -0
  214. data/test/cases/store_test.rb +2 -1
  215. data/test/cases/suppressor_test.rb +63 -0
  216. data/test/cases/tasks/database_tasks_test.rb +73 -9
  217. data/test/cases/tasks/mysql_rake_test.rb +139 -118
  218. data/test/cases/tasks/postgresql_rake_test.rb +60 -6
  219. data/test/cases/tasks/sqlite_rake_test.rb +30 -3
  220. data/test/cases/test_case.rb +28 -20
  221. data/test/cases/test_fixtures_test.rb +36 -0
  222. data/test/cases/time_precision_test.rb +103 -0
  223. data/test/cases/timestamp_test.rb +44 -10
  224. data/test/cases/touch_later_test.rb +121 -0
  225. data/test/cases/transaction_callbacks_test.rb +128 -62
  226. data/test/cases/transaction_isolation_test.rb +2 -2
  227. data/test/cases/transactions_test.rb +61 -43
  228. data/test/cases/type/adapter_specific_registry_test.rb +133 -0
  229. data/test/cases/type/date_time_test.rb +14 -0
  230. data/test/cases/type/integer_test.rb +2 -96
  231. data/test/cases/type/string_test.rb +0 -14
  232. data/test/cases/type_test.rb +39 -0
  233. data/test/cases/types_test.rb +1 -118
  234. data/test/cases/unconnected_test.rb +1 -1
  235. data/test/cases/validations/absence_validation_test.rb +73 -0
  236. data/test/cases/validations/association_validation_test.rb +13 -2
  237. data/test/cases/validations/i18n_validation_test.rb +6 -10
  238. data/test/cases/validations/length_validation_test.rb +62 -30
  239. data/test/cases/validations/presence_validation_test.rb +36 -1
  240. data/test/cases/validations/uniqueness_validation_test.rb +128 -37
  241. data/test/cases/validations_repair_helper.rb +2 -6
  242. data/test/cases/validations_test.rb +36 -7
  243. data/test/cases/view_test.rb +102 -5
  244. data/test/cases/yaml_serialization_test.rb +21 -26
  245. data/test/config.example.yml +97 -0
  246. data/test/fixtures/bad_posts.yml +9 -0
  247. data/test/fixtures/books.yml +20 -0
  248. data/test/fixtures/content.yml +3 -0
  249. data/test/fixtures/content_positions.yml +3 -0
  250. data/test/fixtures/dead_parrots.yml +5 -0
  251. data/test/fixtures/live_parrots.yml +4 -0
  252. data/test/fixtures/naked/yml/parrots.yml +2 -0
  253. data/test/fixtures/naked/yml/trees.yml +3 -0
  254. data/test/fixtures/nodes.yml +29 -0
  255. data/test/fixtures/other_comments.yml +6 -0
  256. data/test/fixtures/other_dogs.yml +2 -0
  257. data/test/fixtures/other_posts.yml +7 -0
  258. data/test/fixtures/price_estimates.yml +10 -1
  259. data/test/fixtures/trees.yml +3 -0
  260. data/test/migrations/10_urban/9_add_expressions.rb +1 -1
  261. data/test/migrations/decimal/1_give_me_big_numbers.rb +1 -1
  262. data/test/migrations/magic/1_currencies_have_symbols.rb +1 -1
  263. data/test/migrations/missing/1000_people_have_middle_names.rb +2 -2
  264. data/test/migrations/missing/1_people_have_last_names.rb +2 -2
  265. data/test/migrations/missing/3_we_need_reminders.rb +2 -2
  266. data/test/migrations/missing/4_innocent_jointable.rb +2 -2
  267. data/test/migrations/rename/1_we_need_things.rb +2 -2
  268. data/test/migrations/rename/2_rename_things.rb +2 -2
  269. data/test/migrations/to_copy/1_people_have_hobbies.rb +1 -1
  270. data/test/migrations/to_copy/2_people_have_descriptions.rb +1 -1
  271. data/test/migrations/to_copy2/1_create_articles.rb +1 -1
  272. data/test/migrations/to_copy2/2_create_comments.rb +1 -1
  273. data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +1 -1
  274. data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +1 -1
  275. data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +1 -1
  276. data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +1 -1
  277. data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +1 -1
  278. data/test/migrations/valid/1_valid_people_have_last_names.rb +1 -1
  279. data/test/migrations/valid/2_we_need_reminders.rb +2 -2
  280. data/test/migrations/valid/3_innocent_jointable.rb +2 -2
  281. data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +1 -1
  282. data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -2
  283. data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +2 -2
  284. data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +1 -1
  285. data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +1 -1
  286. data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +1 -1
  287. data/test/migrations/version_check/20131219224947_migration_version_check.rb +1 -1
  288. data/test/models/admin/randomly_named_c1.rb +6 -2
  289. data/test/models/aircraft.rb +1 -0
  290. data/test/models/author.rb +4 -7
  291. data/test/models/bird.rb +1 -1
  292. data/test/models/book.rb +5 -0
  293. data/test/models/bulb.rb +2 -1
  294. data/test/models/car.rb +3 -0
  295. data/test/models/cat.rb +10 -0
  296. data/test/models/chef.rb +1 -0
  297. data/test/models/club.rb +2 -0
  298. data/test/models/comment.rb +17 -5
  299. data/test/models/company.rb +4 -2
  300. data/test/models/company_in_module.rb +1 -1
  301. data/test/models/contact.rb +1 -1
  302. data/test/models/content.rb +40 -0
  303. data/test/models/customer.rb +8 -2
  304. data/test/models/developer.rb +19 -0
  305. data/test/models/face.rb +1 -1
  306. data/test/models/guitar.rb +4 -0
  307. data/test/models/hotel.rb +2 -0
  308. data/test/models/member.rb +1 -0
  309. data/test/models/member_detail.rb +4 -3
  310. data/test/models/mentor.rb +3 -0
  311. data/test/models/mocktail_designer.rb +2 -0
  312. data/test/models/node.rb +5 -0
  313. data/test/models/non_primary_key.rb +2 -0
  314. data/test/models/notification.rb +3 -0
  315. data/test/models/other_dog.rb +5 -0
  316. data/test/models/owner.rb +4 -1
  317. data/test/models/parrot.rb +6 -7
  318. data/test/models/person.rb +0 -1
  319. data/test/models/pet.rb +3 -0
  320. data/test/models/pet_treasure.rb +6 -0
  321. data/test/models/pirate.rb +3 -3
  322. data/test/models/post.rb +18 -9
  323. data/test/models/project.rb +9 -0
  324. data/test/models/randomly_named_c1.rb +1 -1
  325. data/test/models/recipe.rb +3 -0
  326. data/test/models/ship.rb +8 -2
  327. data/test/models/tag.rb +6 -0
  328. data/test/models/topic.rb +2 -8
  329. data/test/models/tree.rb +3 -0
  330. data/test/models/tuning_peg.rb +4 -0
  331. data/test/models/user.rb +14 -0
  332. data/test/models/uuid_item.rb +6 -0
  333. data/test/schema/mysql2_specific_schema.rb +33 -23
  334. data/test/schema/oracle_specific_schema.rb +1 -4
  335. data/test/schema/postgresql_specific_schema.rb +36 -124
  336. data/test/schema/schema.rb +170 -65
  337. data/test/schema/schema.rb.original +1057 -0
  338. data/test/schema/sqlite_specific_schema.rb +1 -5
  339. data/test/support/connection.rb +1 -0
  340. data/test/support/schema_dumping_helper.rb +1 -1
  341. data/test/support/yaml_compatibility_fixtures/rails_4_1.yml +22 -0
  342. data/test/support/yaml_compatibility_fixtures/rails_4_2_0.yml +182 -0
  343. metadata +146 -30
  344. data/lib/mswin32/rb19x/ibm_db.so +0 -0
  345. data/lib/mswin32/rb21x/i386/ibm_db.so +0 -0
  346. data/lib/mswin32/rb22x/i386/ibm_db.so +0 -0
  347. data/lib/mswin32/rb23x/i386/ibm_db.so +0 -0
  348. data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +0 -26
  349. data/test/cases/attribute_methods/serialization_test.rb +0 -29
  350. data/test/cases/migration/change_schema_test - Copy.rb +0 -448
  351. data/test/cases/migration/foreign_key_test - Changed.rb +0 -325
  352. data/test/cases/migration/table_and_index_test.rb +0 -24
  353. data/test/cases/relation/where_test2.rb +0 -36
  354. data/test/cases/type/decimal_test.rb +0 -56
  355. data/test/cases/type/unsigned_integer_test.rb +0 -18
  356. data/test/cases/xml_serialization_test.rb +0 -457
  357. data/test/fixtures/naked/csv/accounts.csv +0 -1
  358. data/test/schema/mysql_specific_schema.rb +0 -70
@@ -7,9 +7,10 @@ require 'models/computer'
7
7
  require 'models/project'
8
8
  require 'models/reader'
9
9
  require 'models/person'
10
+ require 'models/ship'
10
11
 
11
12
  class ReadOnlyTest < ActiveRecord::TestCase
12
- fixtures :authors, :posts, :comments, :developers, :projects, :developers_projects, :people, :readers, :author_addresses
13
+ fixtures :authors, :posts, :comments, :developers, :projects, :developers_projects, :people, :readers
13
14
 
14
15
  def test_cant_save_readonly_record
15
16
  dev = Developer.find(1)
@@ -24,6 +24,7 @@ require 'models/department'
24
24
  require 'models/cake_designer'
25
25
  require 'models/drink_designer'
26
26
  require 'models/mocktail_designer'
27
+ require 'models/recipe'
27
28
 
28
29
  class ReflectionTest < ActiveRecord::TestCase
29
30
  include ActiveRecord::Reflection
@@ -51,13 +52,13 @@ class ReflectionTest < ActiveRecord::TestCase
51
52
  end
52
53
 
53
54
  def test_columns_are_returned_in_the_order_they_were_declared
54
- column_names = Topic.columns.map { |column| column.name }
55
+ column_names = Topic.columns.map(&:name)
55
56
  assert_equal %w(id title author_name author_email_address written_on bonus_time last_read content important approved replies_count unique_replies_count parent_id parent_title type group created_at updated_at), column_names
56
57
  end
57
58
 
58
59
  def test_content_columns
59
60
  content_columns = Topic.content_columns
60
- content_column_names = content_columns.map {|column| column.name}
61
+ content_column_names = content_columns.map(&:name)
61
62
  assert_equal 13, content_columns.length
62
63
  assert_equal %w(title author_name author_email_address written_on bonus_time last_read content important group approved parent_title created_at updated_at).sort, content_column_names.sort
63
64
  end
@@ -81,10 +82,21 @@ class ReflectionTest < ActiveRecord::TestCase
81
82
  assert_equal :integer, @first.column_for_attribute("id").type
82
83
  end
83
84
 
84
- def test_non_existent_columns_return_nil
85
- assert_deprecated do
86
- assert_nil @first.column_for_attribute("attribute_that_doesnt_exist")
87
- end
85
+ def test_non_existent_columns_return_null_object
86
+ column = @first.column_for_attribute("attribute_that_doesnt_exist")
87
+ assert_instance_of ActiveRecord::ConnectionAdapters::NullColumn, column
88
+ assert_equal "attribute_that_doesnt_exist", column.name
89
+ assert_equal nil, column.sql_type
90
+ assert_equal nil, column.type
91
+ end
92
+
93
+ def test_non_existent_types_are_identity_types
94
+ type = @first.type_for_attribute("attribute_that_doesnt_exist")
95
+ object = Object.new
96
+
97
+ assert_equal object, type.deserialize(object)
98
+ assert_equal object, type.cast(object)
99
+ assert_equal object, type.serialize(object)
88
100
  end
89
101
 
90
102
  def test_reflection_klass_for_nested_class_name
@@ -272,9 +284,26 @@ class ReflectionTest < ActiveRecord::TestCase
272
284
  @hotel.mocktail_designers << MocktailDesigner.create!
273
285
 
274
286
  assert_equal 1, @hotel.mocktail_designers.size
287
+ assert_equal 1, @hotel.mocktail_designers.count
275
288
  assert_equal 1, @hotel.chef_lists.size
276
289
  end
277
290
 
291
+ def test_scope_chain_of_polymorphic_association_does_not_leak_into_other_hmt_associations
292
+ hotel = Hotel.create!
293
+ department = hotel.departments.create!
294
+ drink = department.chefs.create!(employable: DrinkDesigner.create!)
295
+ Recipe.create!(chef_id: drink.id, hotel_id: hotel.id)
296
+
297
+ expected_sql = capture_sql { hotel.recipes.to_a }
298
+
299
+ Hotel.reflect_on_association(:recipes).clear_association_scope_cache
300
+ hotel.reload
301
+ hotel.drink_designers.to_a
302
+ loaded_sql = capture_sql { hotel.recipes.to_a }
303
+
304
+ assert_equal expected_sql, loaded_sql
305
+ end
306
+
278
307
  def test_nested?
279
308
  assert !Author.reflect_on_association(:comments).nested?
280
309
  assert Author.reflect_on_association(:tags).nested?
@@ -296,6 +325,15 @@ class ReflectionTest < ActiveRecord::TestCase
296
325
  assert_equal "custom_primary_key", Author.reflect_on_association(:tags_with_primary_key).association_primary_key.to_s # nested
297
326
  end
298
327
 
328
+ def test_association_primary_key_type
329
+ # Normal Association
330
+ assert_equal :integer, Author.reflect_on_association(:posts).association_primary_key_type.type
331
+ assert_equal :string, Author.reflect_on_association(:essay).association_primary_key_type.type
332
+
333
+ # Through Association
334
+ assert_equal :string, Author.reflect_on_association(:essay_category).association_primary_key_type.type
335
+ end
336
+
299
337
  def test_association_primary_key_raises_when_missing_primary_key
300
338
  reflection = ActiveRecord::Reflection.create(:has_many, :edge, nil, {}, Author)
301
339
  assert_raises(ActiveRecord::UnknownPrimaryKey) { reflection.association_primary_key }
@@ -374,12 +412,14 @@ class ReflectionTest < ActiveRecord::TestCase
374
412
  product = Struct.new(:table_name, :pluralize_table_names).new('products', true)
375
413
 
376
414
  reflection = ActiveRecord::Reflection.create(:has_many, :categories, nil, {}, product)
377
- reflection.stubs(:klass).returns(category)
378
- assert_equal 'categories_products', reflection.join_table
415
+ reflection.stub(:klass, category) do
416
+ assert_equal 'categories_products', reflection.join_table
417
+ end
379
418
 
380
419
  reflection = ActiveRecord::Reflection.create(:has_many, :products, nil, {}, category)
381
- reflection.stubs(:klass).returns(product)
382
- assert_equal 'categories_products', reflection.join_table
420
+ reflection.stub(:klass, product) do
421
+ assert_equal 'categories_products', reflection.join_table
422
+ end
383
423
  end
384
424
 
385
425
  def test_join_table_with_common_prefix
@@ -387,12 +427,14 @@ class ReflectionTest < ActiveRecord::TestCase
387
427
  product = Struct.new(:table_name, :pluralize_table_names).new('catalog_products', true)
388
428
 
389
429
  reflection = ActiveRecord::Reflection.create(:has_many, :categories, nil, {}, product)
390
- reflection.stubs(:klass).returns(category)
391
- assert_equal 'catalog_categories_products', reflection.join_table
430
+ reflection.stub(:klass, category) do
431
+ assert_equal 'catalog_categories_products', reflection.join_table
432
+ end
392
433
 
393
434
  reflection = ActiveRecord::Reflection.create(:has_many, :products, nil, {}, category)
394
- reflection.stubs(:klass).returns(product)
395
- assert_equal 'catalog_categories_products', reflection.join_table
435
+ reflection.stub(:klass, product) do
436
+ assert_equal 'catalog_categories_products', reflection.join_table
437
+ end
396
438
  end
397
439
 
398
440
  def test_join_table_with_different_prefix
@@ -400,12 +442,14 @@ class ReflectionTest < ActiveRecord::TestCase
400
442
  page = Struct.new(:table_name, :pluralize_table_names).new('content_pages', true)
401
443
 
402
444
  reflection = ActiveRecord::Reflection.create(:has_many, :categories, nil, {}, page)
403
- reflection.stubs(:klass).returns(category)
404
- assert_equal 'catalog_categories_content_pages', reflection.join_table
445
+ reflection.stub(:klass, category) do
446
+ assert_equal 'catalog_categories_content_pages', reflection.join_table
447
+ end
405
448
 
406
449
  reflection = ActiveRecord::Reflection.create(:has_many, :pages, nil, {}, category)
407
- reflection.stubs(:klass).returns(page)
408
- assert_equal 'catalog_categories_content_pages', reflection.join_table
450
+ reflection.stub(:klass, page) do
451
+ assert_equal 'catalog_categories_content_pages', reflection.join_table
452
+ end
409
453
  end
410
454
 
411
455
  def test_join_table_can_be_overridden
@@ -413,12 +457,14 @@ class ReflectionTest < ActiveRecord::TestCase
413
457
  product = Struct.new(:table_name, :pluralize_table_names).new('products', true)
414
458
 
415
459
  reflection = ActiveRecord::Reflection.create(:has_many, :categories, nil, { :join_table => 'product_categories' }, product)
416
- reflection.stubs(:klass).returns(category)
417
- assert_equal 'product_categories', reflection.join_table
460
+ reflection.stub(:klass, category) do
461
+ assert_equal 'product_categories', reflection.join_table
462
+ end
418
463
 
419
464
  reflection = ActiveRecord::Reflection.create(:has_many, :products, nil, { :join_table => 'product_categories' }, category)
420
- reflection.stubs(:klass).returns(product)
421
- assert_equal 'product_categories', reflection.join_table
465
+ reflection.stub(:klass, product) do
466
+ assert_equal 'product_categories', reflection.join_table
467
+ end
422
468
  end
423
469
 
424
470
  def test_includes_accepts_symbols
@@ -27,12 +27,13 @@ module ActiveRecord
27
27
 
28
28
  module DelegationWhitelistBlacklistTests
29
29
  ARRAY_DELEGATES = [
30
- :+, :-, :|, :&, :[],
30
+ :+, :-, :|, :&, :[], :shuffle,
31
31
  :all?, :collect, :compact, :detect, :each, :each_cons, :each_with_index,
32
32
  :exclude?, :find_all, :flat_map, :group_by, :include?, :length,
33
33
  :map, :none?, :one?, :partition, :reject, :reverse,
34
34
  :sample, :second, :sort, :sort_by, :third,
35
- :to_ary, :to_set, :to_xml, :to_yaml, :join
35
+ :to_ary, :to_set, :to_xml, :to_yaml, :join,
36
+ :in_groups, :in_groups_of, :to_sentence, :to_formatted_s
36
37
  ]
37
38
 
38
39
  ARRAY_DELEGATES.each do |method|
@@ -40,12 +41,6 @@ module ActiveRecord
40
41
  assert_respond_to target, method
41
42
  end
42
43
  end
43
-
44
- ActiveRecord::Delegation::BLACKLISTED_ARRAY_METHODS.each do |method|
45
- define_method "test_#{method}_is_not_delegated_to_Array" do
46
- assert_raises(NoMethodError) { call_method(target, method) }
47
- end
48
- end
49
44
  end
50
45
 
51
46
  class DelegationAssociationTest < DelegationTest
@@ -8,7 +8,7 @@ require 'models/project'
8
8
  require 'models/rating'
9
9
 
10
10
  class RelationMergingTest < ActiveRecord::TestCase
11
- fixtures :developers, :comments, :authors, :posts, :author_addresses
11
+ fixtures :developers, :comments, :authors, :posts
12
12
 
13
13
  def test_relation_merging
14
14
  devs = Developer.where("salary >= 80000").merge(Developer.limit(2)).merge(Developer.order('id ASC').where("id < 3"))
@@ -82,26 +82,15 @@ class RelationMergingTest < ActiveRecord::TestCase
82
82
  left = Post.where(title: "omg").where(comments_count: 1)
83
83
  right = Post.where(title: "wtf").where(title: "bbq")
84
84
 
85
- expected = [left.bind_values[1]] + right.bind_values
85
+ expected = [left.bound_attributes[1]] + right.bound_attributes
86
86
  merged = left.merge(right)
87
87
 
88
- assert_equal expected, merged.bind_values
88
+ assert_equal expected, merged.bound_attributes
89
89
  assert !merged.to_sql.include?("omg")
90
90
  assert merged.to_sql.include?("wtf")
91
91
  assert merged.to_sql.include?("bbq")
92
92
  end
93
93
 
94
- def test_merging_keeps_lhs_bind_parameters
95
- column = Post.columns_hash['id']
96
- binds = [[column, 20]]
97
-
98
- right = Post.where(id: 20)
99
- left = Post.where(id: 10)
100
-
101
- merged = left.merge(right)
102
- assert_equal binds, merged.bind_values
103
- end
104
-
105
94
  def test_merging_reorders_bind_params
106
95
  post = Post.first
107
96
  right = Post.where(id: 1)
@@ -115,6 +104,13 @@ class RelationMergingTest < ActiveRecord::TestCase
115
104
  post = PostThatLoadsCommentsInAnAfterSaveHook.create!(title: "First Post", body: "Blah blah blah.")
116
105
  assert_equal "First comment!", post.comments.where(body: "First comment!").first_or_create.body
117
106
  end
107
+
108
+ def test_merging_with_from_clause
109
+ relation = Post.all
110
+ assert relation.from_clause.empty?
111
+ relation = relation.merge(Post.from("posts"))
112
+ refute relation.from_clause.empty?
113
+ end
118
114
  end
119
115
 
120
116
  class MergingDifferentRelationsTest < ActiveRecord::TestCase
@@ -22,13 +22,21 @@ module ActiveRecord
22
22
  def sanitize_sql(sql)
23
23
  sql
24
24
  end
25
+
26
+ def sanitize_sql_for_order(sql)
27
+ sql
28
+ end
29
+
30
+ def arel_attribute(name, table)
31
+ table[name]
32
+ end
25
33
  end
26
34
 
27
35
  def relation
28
- @relation ||= Relation.new FakeKlass.new('posts'), Post.arel_table
36
+ @relation ||= Relation.new FakeKlass.new('posts'), Post.arel_table, Post.predicate_builder
29
37
  end
30
38
 
31
- (Relation::MULTI_VALUE_METHODS - [:references, :extending, :order, :unscope, :select]).each do |method|
39
+ (Relation::MULTI_VALUE_METHODS - [:references, :extending, :order, :unscope, :select, :left_joins]).each do |method|
32
40
  test "##{method}!" do
33
41
  assert relation.public_send("#{method}!", :foo).equal?(relation)
34
42
  assert_equal [:foo], relation.public_send("#{method}_values")
@@ -55,9 +63,10 @@ module ActiveRecord
55
63
 
56
64
  test '#order! on non-string does not attempt regexp match for references' do
57
65
  obj = Object.new
58
- obj.expects(:=~).never
59
- assert relation.order!(obj)
60
- assert_equal [obj], relation.order_values
66
+ assert_not_called(obj, :=~) do
67
+ assert relation.order!(obj)
68
+ assert_equal [obj], relation.order_values
69
+ end
61
70
  end
62
71
 
63
72
  test '#references!' do
@@ -81,7 +90,7 @@ module ActiveRecord
81
90
  assert_equal [], relation.extending_values
82
91
  end
83
92
 
84
- (Relation::SINGLE_VALUE_METHODS - [:from, :lock, :reordering, :reverse_order, :create_with]).each do |method|
93
+ (Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order, :create_with, :uniq]).each do |method|
85
94
  test "##{method}!" do
86
95
  assert relation.public_send("#{method}!", :foo).equal?(relation)
87
96
  assert_equal :foo, relation.public_send("#{method}_value")
@@ -90,7 +99,7 @@ module ActiveRecord
90
99
 
91
100
  test '#from!' do
92
101
  assert relation.from!('foo').equal?(relation)
93
- assert_equal ['foo', nil], relation.from_value
102
+ assert_equal 'foo', relation.from_clause.value
94
103
  end
95
104
 
96
105
  test '#lock!' do
@@ -99,11 +108,11 @@ module ActiveRecord
99
108
  end
100
109
 
101
110
  test '#reorder!' do
102
- order_relation = self.relation.order('foo')
111
+ @relation = self.relation.order('foo')
103
112
 
104
- assert order_relation.reorder!('bar').equal?(order_relation)
105
- assert_equal ['bar'], order_relation.order_values
106
- assert order_relation.reordering_value
113
+ assert relation.reorder!('bar').equal?(relation)
114
+ assert_equal ['bar'], relation.order_values
115
+ assert relation.reordering_value
107
116
  end
108
117
 
109
118
  test '#reorder! with symbol prepends the table name' do
@@ -116,18 +125,18 @@ module ActiveRecord
116
125
  end
117
126
 
118
127
  test 'reverse_order!' do
119
- order_relation = Post.order('title ASC, comments_count DESC')
128
+ @relation = Post.order('title ASC, comments_count DESC')
120
129
 
121
- order_relation.reverse_order!
130
+ relation.reverse_order!
122
131
 
123
- assert_equal 'title DESC', order_relation.order_values.first
124
- assert_equal 'comments_count ASC', order_relation.order_values.last
132
+ assert_equal 'title DESC', relation.order_values.first
133
+ assert_equal 'comments_count ASC', relation.order_values.last
125
134
 
126
135
 
127
- order_relation.reverse_order!
136
+ relation.reverse_order!
128
137
 
129
- assert_equal 'title ASC', order_relation.order_values.first
130
- assert_equal 'comments_count DESC', order_relation.order_values.last
138
+ assert_equal 'title ASC', relation.order_values.first
139
+ assert_equal 'comments_count DESC', relation.order_values.last
131
140
  end
132
141
 
133
142
  test 'create_with!' do
@@ -136,12 +145,12 @@ module ActiveRecord
136
145
  end
137
146
 
138
147
  test 'test_merge!' do
139
- assert relation.merge!(where: :foo).equal?(relation)
140
- assert_equal [:foo], relation.where_values
148
+ assert relation.merge!(select: :foo).equal?(relation)
149
+ assert_equal [:foo], relation.select_values
141
150
  end
142
151
 
143
152
  test 'merge with a proc' do
144
- assert_equal [:foo], relation.merge(-> { where(:foo) }).where_values
153
+ assert_equal [:foo], relation.merge(-> { select(:foo) }).select_values
145
154
  end
146
155
 
147
156
  test 'none!' do
@@ -153,13 +162,22 @@ module ActiveRecord
153
162
  test 'distinct!' do
154
163
  relation.distinct! :foo
155
164
  assert_equal :foo, relation.distinct_value
156
- assert_equal :foo, relation.uniq_value # deprecated access
165
+
166
+ assert_deprecated do
167
+ assert_equal :foo, relation.uniq_value # deprecated access
168
+ end
157
169
  end
158
170
 
159
171
  test 'uniq! was replaced by distinct!' do
160
- relation.uniq! :foo
172
+ assert_deprecated(/use distinct! instead/) do
173
+ relation.uniq! :foo
174
+ end
175
+
176
+ assert_deprecated(/use distinct_value instead/) do
177
+ assert_equal :foo, relation.uniq_value # deprecated access
178
+ end
179
+
161
180
  assert_equal :foo, relation.distinct_value
162
- assert_equal :foo, relation.uniq_value # deprecated access
163
181
  end
164
182
  end
165
183
  end
@@ -0,0 +1,92 @@
1
+ require "cases/helper"
2
+ require 'models/post'
3
+
4
+ module ActiveRecord
5
+ class OrTest < ActiveRecord::TestCase
6
+ fixtures :posts
7
+
8
+ def test_or_with_relation
9
+ expected = Post.where('id = 1 or id = 2').to_a
10
+ assert_equal expected, Post.where('id = 1').or(Post.where('id = 2')).to_a
11
+ end
12
+
13
+ def test_or_identity
14
+ expected = Post.where('id = 1').to_a
15
+ assert_equal expected, Post.where('id = 1').or(Post.where('id = 1')).to_a
16
+ end
17
+
18
+ def test_or_with_null_left
19
+ expected = Post.where('id = 1').to_a
20
+ assert_equal expected, Post.none.or(Post.where('id = 1')).to_a
21
+ end
22
+
23
+ def test_or_with_null_right
24
+ expected = Post.where('id = 1').to_a
25
+ assert_equal expected, Post.where('id = 1').or(Post.none).to_a
26
+ end
27
+
28
+ def test_or_with_bind_params
29
+ assert_equal Post.find([1, 2]), Post.where(id: 1).or(Post.where(id: 2)).to_a
30
+ end
31
+
32
+ def test_or_with_null_both
33
+ expected = Post.none.to_a
34
+ assert_equal expected, Post.none.or(Post.none).to_a
35
+ end
36
+
37
+ def test_or_without_left_where
38
+ expected = Post.all
39
+ assert_equal expected, Post.or(Post.where('id = 1')).to_a
40
+ end
41
+
42
+ def test_or_without_right_where
43
+ expected = Post.all
44
+ assert_equal expected, Post.where('id = 1').or(Post.all).to_a
45
+ end
46
+
47
+ def test_or_preserves_other_querying_methods
48
+ expected = Post.where('id = 1 or id = 2 or id = 3').order('body asc').to_a
49
+ partial = Post.order('body asc')
50
+ assert_equal expected, partial.where('id = 1').or(partial.where(:id => [2, 3])).to_a
51
+ assert_equal expected, Post.order('body asc').where('id = 1').or(Post.order('body asc').where(:id => [2, 3])).to_a
52
+ end
53
+
54
+ def test_or_with_incompatible_relations
55
+ error = assert_raises ArgumentError do
56
+ Post.order('body asc').where('id = 1').or(Post.order('id desc').where(:id => [2, 3])).to_a
57
+ end
58
+
59
+ assert_equal "Relation passed to #or must be structurally compatible. Incompatible values: [:order]", error.message
60
+ end
61
+
62
+ def test_or_when_grouping
63
+ groups = Post.where('id < 10').group('body').select('body, COUNT(*) AS c')
64
+ expected = groups.having("COUNT(*) > 1 OR body like 'Such%'").to_a.map {|o| [o.body, o.c] }
65
+ assert_equal expected, groups.having('COUNT(*) > 1').or(groups.having("body like 'Such%'")).to_a.map {|o| [o.body, o.c] }
66
+ end
67
+
68
+ def test_or_with_named_scope
69
+ expected = Post.where("id = 1 or body LIKE '\%a\%'").to_a
70
+ assert_equal expected, Post.where('id = 1').or(Post.containing_the_letter_a)
71
+ end
72
+
73
+ def test_or_inside_named_scope
74
+ expected = Post.where("body LIKE '\%a\%' OR title LIKE ?", "%'%").order('id DESC').to_a
75
+ assert_equal expected, Post.order(id: :desc).typographically_interesting
76
+ end
77
+
78
+ def test_or_on_loaded_relation
79
+ expected = Post.where('id = 1 or id = 2').to_a
80
+ p = Post.where('id = 1')
81
+ p.load
82
+ assert_equal p.loaded?, true
83
+ assert_equal expected, p.or(Post.where('id = 2')).to_a
84
+ end
85
+
86
+ def test_or_with_non_relation_object_raises_error
87
+ assert_raises ArgumentError do
88
+ Post.where(id: [1, 2, 3]).or(title: 'Rails')
89
+ end
90
+ end
91
+ end
92
+ end