ibm_db 3.0.4 → 5.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (351) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +8 -1
  3. data/LICENSE +1 -1
  4. data/ParameterizedQueries README +6 -6
  5. data/README +38 -55
  6. data/ext/Makefile +266 -0
  7. data/ext/extconf.rb +34 -3
  8. data/ext/gil_release_version +3 -0
  9. data/ext/ibm_db.c +106 -111
  10. data/ext/ibm_db.o +0 -0
  11. data/ext/ibm_db.so +0 -0
  12. data/ext/mkmf.log +103 -0
  13. data/ext/ruby_ibm_db_cli.o +0 -0
  14. data/ext/unicode_support_version +3 -0
  15. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +911 -527
  16. data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
  17. data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
  18. data/test/cases/adapter_test.rb +148 -58
  19. data/test/cases/adapters/mysql2/active_schema_test.rb +193 -0
  20. data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
  21. data/test/cases/adapters/mysql2/boolean_test.rb +100 -0
  22. data/test/cases/adapters/mysql2/case_sensitivity_test.rb +63 -0
  23. data/test/cases/adapters/mysql2/charset_collation_test.rb +54 -0
  24. data/test/cases/adapters/mysql2/connection_test.rb +210 -0
  25. data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +45 -0
  26. data/test/cases/adapters/mysql2/enum_test.rb +26 -0
  27. data/test/cases/adapters/mysql2/explain_test.rb +21 -0
  28. data/test/cases/adapters/mysql2/json_test.rb +195 -0
  29. data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +83 -0
  30. data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
  31. data/test/cases/adapters/mysql2/schema_migrations_test.rb +59 -0
  32. data/test/cases/adapters/mysql2/schema_test.rb +126 -0
  33. data/test/cases/adapters/mysql2/sp_test.rb +36 -0
  34. data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
  35. data/test/cases/adapters/mysql2/table_options_test.rb +42 -0
  36. data/test/cases/adapters/mysql2/unsigned_type_test.rb +66 -0
  37. data/test/cases/adapters/postgresql/active_schema_test.rb +98 -0
  38. data/test/cases/adapters/postgresql/array_test.rb +339 -0
  39. data/test/cases/adapters/postgresql/bit_string_test.rb +82 -0
  40. data/test/cases/adapters/postgresql/bytea_test.rb +134 -0
  41. data/test/cases/adapters/postgresql/case_insensitive_test.rb +26 -0
  42. data/test/cases/adapters/postgresql/change_schema_test.rb +38 -0
  43. data/test/cases/adapters/postgresql/cidr_test.rb +25 -0
  44. data/test/cases/adapters/postgresql/citext_test.rb +78 -0
  45. data/test/cases/adapters/postgresql/collation_test.rb +53 -0
  46. data/test/cases/adapters/postgresql/composite_test.rb +132 -0
  47. data/test/cases/adapters/postgresql/connection_test.rb +257 -0
  48. data/test/cases/adapters/postgresql/datatype_test.rb +92 -0
  49. data/test/cases/adapters/postgresql/domain_test.rb +47 -0
  50. data/test/cases/adapters/postgresql/enum_test.rb +91 -0
  51. data/test/cases/adapters/postgresql/explain_test.rb +20 -0
  52. data/test/cases/adapters/postgresql/extension_migration_test.rb +63 -0
  53. data/test/cases/adapters/postgresql/full_text_test.rb +44 -0
  54. data/test/cases/adapters/postgresql/geometric_test.rb +378 -0
  55. data/test/cases/adapters/postgresql/hstore_test.rb +382 -0
  56. data/test/cases/adapters/postgresql/infinity_test.rb +69 -0
  57. data/test/cases/adapters/postgresql/integer_test.rb +25 -0
  58. data/test/cases/adapters/postgresql/json_test.rb +237 -0
  59. data/test/cases/adapters/postgresql/ltree_test.rb +53 -0
  60. data/test/cases/adapters/postgresql/money_test.rb +96 -0
  61. data/test/cases/adapters/postgresql/network_test.rb +94 -0
  62. data/test/cases/adapters/postgresql/numbers_test.rb +49 -0
  63. data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +405 -0
  64. data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
  65. data/test/cases/adapters/postgresql/quoting_test.rb +44 -0
  66. data/test/cases/adapters/postgresql/range_test.rb +343 -0
  67. data/test/cases/adapters/postgresql/referential_integrity_test.rb +111 -0
  68. data/test/cases/adapters/postgresql/rename_table_test.rb +34 -0
  69. data/test/cases/adapters/postgresql/schema_authorization_test.rb +119 -0
  70. data/test/cases/adapters/postgresql/schema_test.rb +597 -0
  71. data/test/cases/adapters/postgresql/serial_test.rb +154 -0
  72. data/test/cases/adapters/postgresql/statement_pool_test.rb +41 -0
  73. data/test/cases/adapters/postgresql/timestamp_test.rb +90 -0
  74. data/test/cases/adapters/postgresql/type_lookup_test.rb +33 -0
  75. data/test/cases/adapters/postgresql/utils_test.rb +62 -0
  76. data/test/cases/adapters/postgresql/uuid_test.rb +294 -0
  77. data/test/cases/adapters/postgresql/xml_test.rb +54 -0
  78. data/test/cases/adapters/sqlite3/collation_test.rb +53 -0
  79. data/test/cases/adapters/sqlite3/copy_table_test.rb +98 -0
  80. data/test/cases/adapters/sqlite3/explain_test.rb +21 -0
  81. data/test/cases/adapters/sqlite3/quoting_test.rb +101 -0
  82. data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +441 -0
  83. data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
  84. data/test/cases/adapters/sqlite3/statement_pool_test.rb +20 -0
  85. data/test/cases/aggregations_test.rb +11 -1
  86. data/test/cases/ar_schema_test.rb +35 -50
  87. data/test/cases/associations/association_scope_test.rb +1 -6
  88. data/test/cases/associations/belongs_to_associations_test.rb +122 -10
  89. data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +41 -0
  90. data/test/cases/associations/callbacks_test.rb +5 -7
  91. data/test/cases/associations/cascaded_eager_loading_test.rb +1 -1
  92. data/test/cases/associations/eager_load_nested_include_test.rb +1 -3
  93. data/test/cases/associations/eager_test.rb +176 -73
  94. data/test/cases/associations/extension_test.rb +7 -2
  95. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +104 -32
  96. data/test/cases/associations/has_many_associations_test.rb +382 -43
  97. data/test/cases/associations/has_many_through_associations_test.rb +108 -41
  98. data/test/cases/associations/has_one_associations_test.rb +105 -8
  99. data/test/cases/associations/has_one_through_associations_test.rb +6 -3
  100. data/test/cases/associations/inner_join_association_test.rb +3 -3
  101. data/test/cases/associations/inverse_associations_test.rb +51 -11
  102. data/test/cases/associations/join_model_test.rb +59 -36
  103. data/test/cases/associations/left_outer_join_association_test.rb +88 -0
  104. data/test/cases/associations/nested_through_associations_test.rb +2 -2
  105. data/test/cases/associations/required_test.rb +25 -5
  106. data/test/cases/associations_test.rb +39 -34
  107. data/test/cases/attribute_decorators_test.rb +9 -8
  108. data/test/cases/attribute_methods/read_test.rb +5 -5
  109. data/test/cases/attribute_methods_test.rb +97 -40
  110. data/test/cases/attribute_set_test.rb +74 -4
  111. data/test/cases/attribute_test.rb +84 -18
  112. data/test/cases/attributes_test.rb +151 -34
  113. data/test/cases/autosave_association_test.rb +149 -36
  114. data/test/cases/base_test.rb +311 -236
  115. data/test/cases/batches_test.rb +299 -22
  116. data/test/cases/binary_test.rb +2 -10
  117. data/test/cases/bind_parameter_test.rb +76 -66
  118. data/test/cases/cache_key_test.rb +26 -0
  119. data/test/cases/calculations_test.rb +167 -15
  120. data/test/cases/callbacks_test.rb +161 -68
  121. data/test/cases/coders/json_test.rb +15 -0
  122. data/test/cases/collection_cache_key_test.rb +115 -0
  123. data/test/cases/column_definition_test.rb +26 -57
  124. data/test/cases/comment_test.rb +145 -0
  125. data/test/cases/connection_adapters/adapter_leasing_test.rb +5 -3
  126. data/test/cases/connection_adapters/connection_handler_test.rb +128 -21
  127. data/test/cases/connection_adapters/connection_specification_test.rb +1 -1
  128. data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +0 -38
  129. data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -1
  130. data/test/cases/connection_adapters/schema_cache_test.rb +8 -3
  131. data/test/cases/connection_adapters/type_lookup_test.rb +15 -7
  132. data/test/cases/connection_management_test.rb +46 -56
  133. data/test/cases/connection_pool_test.rb +195 -20
  134. data/test/cases/connection_specification/resolver_test.rb +15 -0
  135. data/test/cases/counter_cache_test.rb +10 -5
  136. data/test/cases/custom_locking_test.rb +1 -1
  137. data/test/cases/database_statements_test.rb +18 -3
  138. data/test/cases/{invalid_date_test.rb → date_test.rb} +13 -1
  139. data/test/cases/date_time_precision_test.rb +107 -0
  140. data/test/cases/defaults_test.rb +85 -89
  141. data/test/cases/dirty_test.rb +32 -44
  142. data/test/cases/disconnected_test.rb +4 -2
  143. data/test/cases/enum_test.rb +178 -24
  144. data/test/cases/errors_test.rb +16 -0
  145. data/test/cases/explain_test.rb +32 -21
  146. data/test/cases/finder_test.rb +279 -151
  147. data/test/cases/fixture_set/file_test.rb +18 -0
  148. data/test/cases/fixtures_test.rb +123 -32
  149. data/test/cases/forbidden_attributes_protection_test.rb +69 -3
  150. data/test/cases/helper.rb +10 -16
  151. data/test/cases/hot_compatibility_test.rb +89 -1
  152. data/test/cases/inheritance_test.rb +284 -53
  153. data/test/cases/integration_test.rb +23 -7
  154. data/test/cases/invalid_connection_test.rb +4 -2
  155. data/test/cases/invertible_migration_test.rb +124 -32
  156. data/test/cases/json_serialization_test.rb +11 -2
  157. data/test/cases/locking_test.rb +22 -6
  158. data/test/cases/log_subscriber_test.rb +106 -17
  159. data/test/cases/migration/change_schema_test.rb +118 -132
  160. data/test/cases/migration/change_table_test.rb +34 -2
  161. data/test/cases/migration/column_attributes_test.rb +7 -23
  162. data/test/cases/migration/column_positioning_test.rb +8 -8
  163. data/test/cases/migration/columns_test.rb +17 -11
  164. data/test/cases/migration/command_recorder_test.rb +47 -2
  165. data/test/cases/migration/compatibility_test.rb +118 -0
  166. data/test/cases/migration/create_join_table_test.rb +21 -12
  167. data/test/cases/migration/foreign_key_test.rb +68 -66
  168. data/test/cases/migration/index_test.rb +14 -12
  169. data/test/cases/migration/logger_test.rb +1 -1
  170. data/test/cases/migration/pending_migrations_test.rb +0 -1
  171. data/test/cases/migration/references_foreign_key_test.rb +114 -107
  172. data/test/cases/migration/references_index_test.rb +4 -4
  173. data/test/cases/migration/references_statements_test.rb +26 -6
  174. data/test/cases/migration/rename_table_test.rb +25 -25
  175. data/test/cases/migration_test.rb +279 -81
  176. data/test/cases/migrator_test.rb +91 -8
  177. data/test/cases/mixin_test.rb +0 -2
  178. data/test/cases/modules_test.rb +3 -4
  179. data/test/cases/multiparameter_attributes_test.rb +24 -2
  180. data/test/cases/multiple_db_test.rb +18 -11
  181. data/test/cases/nested_attributes_test.rb +74 -33
  182. data/test/cases/persistence_test.rb +102 -10
  183. data/test/cases/pooled_connections_test.rb +3 -3
  184. data/test/cases/primary_keys_test.rb +170 -31
  185. data/test/cases/query_cache_test.rb +216 -96
  186. data/test/cases/quoting_test.rb +65 -19
  187. data/test/cases/readonly_test.rb +2 -1
  188. data/test/cases/reflection_test.rb +77 -22
  189. data/test/cases/relation/delegation_test.rb +3 -8
  190. data/test/cases/relation/merging_test.rb +10 -14
  191. data/test/cases/relation/mutation_test.rb +42 -24
  192. data/test/cases/relation/or_test.rb +92 -0
  193. data/test/cases/relation/predicate_builder_test.rb +4 -2
  194. data/test/cases/relation/record_fetch_warning_test.rb +40 -0
  195. data/test/cases/relation/where_chain_test.rb +23 -99
  196. data/test/cases/relation/where_clause_test.rb +182 -0
  197. data/test/cases/relation/where_test.rb +45 -23
  198. data/test/cases/relation_test.rb +89 -58
  199. data/test/cases/relations_test.rb +249 -38
  200. data/test/cases/result_test.rb +10 -0
  201. data/test/cases/sanitize_test.rb +108 -15
  202. data/test/cases/schema_dumper_test.rb +119 -125
  203. data/test/cases/schema_loading_test.rb +52 -0
  204. data/test/cases/scoping/default_scoping_test.rb +113 -39
  205. data/test/cases/scoping/named_scoping_test.rb +46 -9
  206. data/test/cases/scoping/relation_scoping_test.rb +47 -4
  207. data/test/cases/secure_token_test.rb +32 -0
  208. data/test/cases/serialization_test.rb +1 -1
  209. data/test/cases/serialized_attribute_test.rb +93 -6
  210. data/test/cases/statement_cache_test.rb +38 -0
  211. data/test/cases/store_test.rb +2 -1
  212. data/test/cases/suppressor_test.rb +63 -0
  213. data/test/cases/tasks/database_tasks_test.rb +74 -8
  214. data/test/cases/tasks/mysql_rake_test.rb +143 -109
  215. data/test/cases/tasks/postgresql_rake_test.rb +71 -12
  216. data/test/cases/tasks/sqlite_rake_test.rb +30 -3
  217. data/test/cases/test_case.rb +28 -20
  218. data/test/cases/test_fixtures_test.rb +36 -0
  219. data/test/cases/time_precision_test.rb +103 -0
  220. data/test/cases/timestamp_test.rb +47 -14
  221. data/test/cases/touch_later_test.rb +121 -0
  222. data/test/cases/transaction_callbacks_test.rb +128 -62
  223. data/test/cases/transaction_isolation_test.rb +2 -2
  224. data/test/cases/transactions_test.rb +61 -43
  225. data/test/cases/type/adapter_specific_registry_test.rb +133 -0
  226. data/test/cases/type/date_time_test.rb +14 -0
  227. data/test/cases/type/integer_test.rb +2 -96
  228. data/test/cases/type/string_test.rb +0 -14
  229. data/test/cases/type_test.rb +39 -0
  230. data/test/cases/types_test.rb +1 -118
  231. data/test/cases/unconnected_test.rb +1 -1
  232. data/test/cases/validations/absence_validation_test.rb +73 -0
  233. data/test/cases/validations/association_validation_test.rb +13 -2
  234. data/test/cases/validations/i18n_validation_test.rb +6 -10
  235. data/test/cases/validations/length_validation_test.rb +62 -30
  236. data/test/cases/validations/presence_validation_test.rb +36 -1
  237. data/test/cases/validations/uniqueness_validation_test.rb +150 -36
  238. data/test/cases/validations_repair_helper.rb +2 -6
  239. data/test/cases/validations_test.rb +36 -7
  240. data/test/cases/view_test.rb +108 -5
  241. data/test/cases/yaml_serialization_test.rb +36 -1
  242. data/test/config.example.yml +97 -0
  243. data/test/fixtures/bad_posts.yml +9 -0
  244. data/test/fixtures/books.yml +20 -0
  245. data/test/fixtures/content.yml +3 -0
  246. data/test/fixtures/content_positions.yml +3 -0
  247. data/test/fixtures/dead_parrots.yml +5 -0
  248. data/test/fixtures/live_parrots.yml +4 -0
  249. data/test/fixtures/naked/yml/parrots.yml +2 -0
  250. data/test/fixtures/naked/yml/trees.yml +3 -0
  251. data/test/fixtures/nodes.yml +29 -0
  252. data/test/fixtures/other_comments.yml +6 -0
  253. data/test/fixtures/other_dogs.yml +2 -0
  254. data/test/fixtures/other_posts.yml +7 -0
  255. data/test/fixtures/price_estimates.yml +10 -1
  256. data/test/fixtures/trees.yml +3 -0
  257. data/test/migrations/10_urban/9_add_expressions.rb +1 -1
  258. data/test/migrations/decimal/1_give_me_big_numbers.rb +1 -1
  259. data/test/migrations/magic/1_currencies_have_symbols.rb +1 -1
  260. data/test/migrations/missing/1000_people_have_middle_names.rb +2 -2
  261. data/test/migrations/missing/1_people_have_last_names.rb +2 -2
  262. data/test/migrations/missing/3_we_need_reminders.rb +2 -2
  263. data/test/migrations/missing/4_innocent_jointable.rb +2 -2
  264. data/test/migrations/rename/1_we_need_things.rb +2 -2
  265. data/test/migrations/rename/2_rename_things.rb +2 -2
  266. data/test/migrations/to_copy/1_people_have_hobbies.rb +1 -1
  267. data/test/migrations/to_copy/2_people_have_descriptions.rb +1 -1
  268. data/test/migrations/to_copy2/1_create_articles.rb +1 -1
  269. data/test/migrations/to_copy2/2_create_comments.rb +1 -1
  270. data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +1 -1
  271. data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +1 -1
  272. data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +1 -1
  273. data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +1 -1
  274. data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +1 -1
  275. data/test/migrations/valid/1_valid_people_have_last_names.rb +1 -1
  276. data/test/migrations/valid/2_we_need_reminders.rb +2 -2
  277. data/test/migrations/valid/3_innocent_jointable.rb +2 -2
  278. data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +1 -1
  279. data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -2
  280. data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +2 -2
  281. data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +1 -1
  282. data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +1 -1
  283. data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +1 -1
  284. data/test/migrations/version_check/20131219224947_migration_version_check.rb +1 -1
  285. data/test/models/admin/randomly_named_c1.rb +6 -2
  286. data/test/models/aircraft.rb +1 -0
  287. data/test/models/author.rb +4 -7
  288. data/test/models/bird.rb +1 -1
  289. data/test/models/book.rb +5 -0
  290. data/test/models/bulb.rb +2 -1
  291. data/test/models/car.rb +3 -0
  292. data/test/models/cat.rb +10 -0
  293. data/test/models/chef.rb +5 -0
  294. data/test/models/club.rb +2 -0
  295. data/test/models/comment.rb +17 -5
  296. data/test/models/company.rb +7 -2
  297. data/test/models/company_in_module.rb +1 -1
  298. data/test/models/contact.rb +1 -1
  299. data/test/models/content.rb +40 -0
  300. data/test/models/customer.rb +8 -2
  301. data/test/models/developer.rb +22 -0
  302. data/test/models/face.rb +1 -1
  303. data/test/models/guitar.rb +4 -0
  304. data/test/models/hotel.rb +5 -0
  305. data/test/models/member.rb +1 -0
  306. data/test/models/member_detail.rb +4 -3
  307. data/test/models/mentor.rb +3 -0
  308. data/test/models/mocktail_designer.rb +2 -0
  309. data/test/models/node.rb +5 -0
  310. data/test/models/non_primary_key.rb +2 -0
  311. data/test/models/notification.rb +3 -0
  312. data/test/models/other_dog.rb +5 -0
  313. data/test/models/owner.rb +4 -1
  314. data/test/models/parrot.rb +6 -7
  315. data/test/models/person.rb +0 -1
  316. data/test/models/pet.rb +3 -0
  317. data/test/models/pet_treasure.rb +6 -0
  318. data/test/models/pirate.rb +3 -3
  319. data/test/models/post.rb +18 -9
  320. data/test/models/project.rb +11 -0
  321. data/test/models/randomly_named_c1.rb +1 -1
  322. data/test/models/recipe.rb +3 -0
  323. data/test/models/ship.rb +8 -2
  324. data/test/models/tag.rb +6 -0
  325. data/test/models/topic.rb +2 -8
  326. data/test/models/tree.rb +3 -0
  327. data/test/models/tuning_peg.rb +4 -0
  328. data/test/models/user.rb +14 -0
  329. data/test/models/uuid_item.rb +6 -0
  330. data/test/schema/mysql2_specific_schema.rb +33 -23
  331. data/test/schema/oracle_specific_schema.rb +1 -4
  332. data/test/schema/postgresql_specific_schema.rb +36 -124
  333. data/test/schema/schema.rb +183 -64
  334. data/test/schema/schema.rb.original +1057 -0
  335. data/test/schema/sqlite_specific_schema.rb +1 -5
  336. data/test/support/connection.rb +1 -0
  337. data/test/support/schema_dumping_helper.rb +1 -1
  338. data/test/support/yaml_compatibility_fixtures/rails_4_1.yml +22 -0
  339. data/test/support/yaml_compatibility_fixtures/rails_4_2_0.yml +182 -0
  340. metadata +145 -26
  341. data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +0 -26
  342. data/test/cases/attribute_methods/serialization_test.rb +0 -29
  343. data/test/cases/migration/change_schema_test - Copy.rb +0 -448
  344. data/test/cases/migration/foreign_key_test - Changed.rb +0 -325
  345. data/test/cases/migration/table_and_index_test.rb +0 -24
  346. data/test/cases/relation/where_test2.rb +0 -36
  347. data/test/cases/type/decimal_test.rb +0 -51
  348. data/test/cases/type/unsigned_integer_test.rb +0 -18
  349. data/test/cases/xml_serialization_test.rb +0 -457
  350. data/test/fixtures/naked/csv/accounts.csv +0 -1
  351. data/test/schema/mysql_specific_schema.rb +0 -70
@@ -123,6 +123,24 @@ END
123
123
  end
124
124
  end
125
125
 
126
+ def test_removes_fixture_config_row
127
+ File.open(::File.join(FIXTURES_ROOT, 'other_posts.yml')) do |fh|
128
+ assert_equal(['second_welcome'], fh.each.map { |name, _| name })
129
+ end
130
+ end
131
+
132
+ def test_extracts_model_class_from_config_row
133
+ File.open(::File.join(FIXTURES_ROOT, 'other_posts.yml')) do |fh|
134
+ assert_equal 'Post', fh.model_class
135
+ end
136
+ end
137
+
138
+ def test_erb_filename
139
+ filename = 'filename.yaml'
140
+ erb = File.new(filename).send(:prepare_erb, "<% Rails.env %>\n")
141
+ assert_equal erb.filename, filename
142
+ end
143
+
126
144
  private
127
145
  def tmp_yaml(name, contents)
128
146
  t = Tempfile.new name
@@ -7,16 +7,18 @@ require 'models/binary'
7
7
  require 'models/book'
8
8
  require 'models/bulb'
9
9
  require 'models/category'
10
+ require 'models/comment'
10
11
  require 'models/company'
11
12
  require 'models/computer'
12
13
  require 'models/course'
13
14
  require 'models/developer'
14
- require 'models/computer'
15
+ require "models/dog"
16
+ require 'models/doubloon'
15
17
  require 'models/joke'
16
18
  require 'models/matey'
19
+ require "models/other_dog"
17
20
  require 'models/parrot'
18
21
  require 'models/pirate'
19
- require 'models/doubloon'
20
22
  require 'models/post'
21
23
  require 'models/randomly_named_c1'
22
24
  require 'models/reply'
@@ -29,10 +31,10 @@ require 'tempfile'
29
31
 
30
32
  class FixturesTest < ActiveRecord::TestCase
31
33
  self.use_instantiated_fixtures = true
32
- self.use_transactional_fixtures = false
34
+ self.use_transactional_tests = false
33
35
 
34
36
  # other_topics fixture should not be included here
35
- fixtures :topics, :developers, :accounts, :tasks, :categories, :funny_jokes, :binaries, :traffic_lights, :author_addresses
37
+ fixtures :topics, :developers, :accounts, :tasks, :categories, :funny_jokes, :binaries, :traffic_lights
36
38
 
37
39
  FIXTURES = %w( accounts binaries companies customers
38
40
  developers developers_projects entrants
@@ -184,7 +186,6 @@ class FixturesTest < ActiveRecord::TestCase
184
186
  end
185
187
 
186
188
  def test_fixtures_from_root_yml_with_instantiation
187
- # assert_equal 2, @accounts.size
188
189
  assert_equal 50, @unknown.credit_limit
189
190
  end
190
191
 
@@ -217,6 +218,17 @@ class FixturesTest < ActiveRecord::TestCase
217
218
  end
218
219
  end
219
220
 
221
+ def test_yaml_file_with_invalid_column
222
+ e = assert_raise(ActiveRecord::Fixture::FixtureError) do
223
+ ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/naked/yml", "parrots")
224
+ end
225
+ assert_equal(%(table "parrots" has no column named "arrr".), e.message)
226
+ end
227
+
228
+ def test_yaml_file_with_symbol_columns
229
+ ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/naked/yml", "trees")
230
+ end
231
+
220
232
  def test_omap_fixtures
221
233
  assert_nothing_raised do
222
234
  fixtures = ActiveRecord::FixtureSet.new(Account.connection, 'categories', Category, FIXTURES_ROOT + "/categories_ordered")
@@ -252,18 +264,19 @@ class FixturesTest < ActiveRecord::TestCase
252
264
  def test_fixtures_are_set_up_with_database_env_variable
253
265
  db_url_tmp = ENV['DATABASE_URL']
254
266
  ENV['DATABASE_URL'] = "sqlite3::memory:"
255
- ActiveRecord::Base.stubs(:configurations).returns({})
256
- test_case = Class.new(ActiveRecord::TestCase) do
257
- fixtures :accounts
267
+ ActiveRecord::Base.stub(:configurations, {}) do
268
+ test_case = Class.new(ActiveRecord::TestCase) do
269
+ fixtures :accounts
258
270
 
259
- def test_fixtures
260
- assert accounts(:signals37)
271
+ def test_fixtures
272
+ assert accounts(:signals37)
273
+ end
261
274
  end
262
- end
263
275
 
264
- result = test_case.new(:test_fixtures).run
276
+ result = test_case.new(:test_fixtures).run
265
277
 
266
- assert result.passed?, "Expected #{result.name} to pass:\n#{result}"
278
+ assert result.passed?, "Expected #{result.name} to pass:\n#{result}"
279
+ end
267
280
  ensure
268
281
  ENV['DATABASE_URL'] = db_url_tmp
269
282
  end
@@ -401,9 +414,11 @@ class FixturesWithoutInstantiationTest < ActiveRecord::TestCase
401
414
  end
402
415
 
403
416
  def test_reloading_fixtures_through_accessor_methods
417
+ topic = Struct.new(:title)
404
418
  assert_equal "The First Topic", topics(:first).title
405
- @loaded_fixtures['topics']['first'].expects(:find).returns(stub(:title => "Fresh Topic!"))
406
- assert_equal "Fresh Topic!", topics(:first, true).title
419
+ assert_called(@loaded_fixtures['topics']['first'], :find, returns: topic.new("Fresh Topic!")) do
420
+ assert_equal "Fresh Topic!", topics(:first, true).title
421
+ end
407
422
  end
408
423
  end
409
424
 
@@ -420,7 +435,7 @@ end
420
435
 
421
436
  class TransactionalFixturesTest < ActiveRecord::TestCase
422
437
  self.use_instantiated_fixtures = true
423
- self.use_transactional_fixtures = true
438
+ self.use_transactional_tests = true
424
439
 
425
440
  fixtures :topics
426
441
 
@@ -466,7 +481,6 @@ class SetupSubclassTest < SetupTest
466
481
  end
467
482
  end
468
483
 
469
-
470
484
  class OverlappingFixturesTest < ActiveRecord::TestCase
471
485
  fixtures :topics, :developers
472
486
  fixtures :developers, :accounts
@@ -507,12 +521,44 @@ class OverRideFixtureMethodTest < ActiveRecord::TestCase
507
521
  end
508
522
  end
509
523
 
524
+ class FixtureWithSetModelClassTest < ActiveRecord::TestCase
525
+ fixtures :other_posts, :other_comments
526
+
527
+ # Set to false to blow away fixtures cache and ensure our fixtures are loaded
528
+ # and thus takes into account the +set_model_class+.
529
+ self.use_transactional_tests = false
530
+
531
+ def test_uses_fixture_class_defined_in_yaml
532
+ assert_kind_of Post, other_posts(:second_welcome)
533
+ end
534
+
535
+ def test_loads_the_associations_to_fixtures_with_set_model_class
536
+ post = other_posts(:second_welcome)
537
+ comment = other_comments(:second_greetings)
538
+ assert_equal [comment], post.comments
539
+ assert_equal post, comment.post
540
+ end
541
+ end
542
+
543
+ class SetFixtureClassPrevailsTest < ActiveRecord::TestCase
544
+ set_fixture_class bad_posts: Post
545
+ fixtures :bad_posts
546
+
547
+ # Set to false to blow away fixtures cache and ensure our fixtures are loaded
548
+ # and thus takes into account the +set_model_class+.
549
+ self.use_transactional_tests = false
550
+
551
+ def test_uses_set_fixture_class
552
+ assert_kind_of Post, bad_posts(:bad_welcome)
553
+ end
554
+ end
555
+
510
556
  class CheckSetTableNameFixturesTest < ActiveRecord::TestCase
511
557
  set_fixture_class :funny_jokes => Joke
512
558
  fixtures :funny_jokes
513
559
  # Set to false to blow away fixtures cache and ensure our fixtures are loaded
514
560
  # and thus takes into account our set_fixture_class
515
- self.use_transactional_fixtures = false
561
+ self.use_transactional_tests = false
516
562
 
517
563
  def test_table_method
518
564
  assert_kind_of Joke, funny_jokes(:a_joke)
@@ -524,7 +570,7 @@ class FixtureNameIsNotTableNameFixturesTest < ActiveRecord::TestCase
524
570
  fixtures :items
525
571
  # Set to false to blow away fixtures cache and ensure our fixtures are loaded
526
572
  # and thus takes into account our set_fixture_class
527
- self.use_transactional_fixtures = false
573
+ self.use_transactional_tests = false
528
574
 
529
575
  def test_named_accessor
530
576
  assert_kind_of Book, items(:dvd)
@@ -536,7 +582,7 @@ class FixtureNameIsNotTableNameMultipleFixturesTest < ActiveRecord::TestCase
536
582
  fixtures :items, :funny_jokes
537
583
  # Set to false to blow away fixtures cache and ensure our fixtures are loaded
538
584
  # and thus takes into account our set_fixture_class
539
- self.use_transactional_fixtures = false
585
+ self.use_transactional_tests = false
540
586
 
541
587
  def test_named_accessor_of_differently_named_fixture
542
588
  assert_kind_of Book, items(:dvd)
@@ -550,7 +596,7 @@ end
550
596
  class CustomConnectionFixturesTest < ActiveRecord::TestCase
551
597
  set_fixture_class :courses => Course
552
598
  fixtures :courses
553
- self.use_transactional_fixtures = false
599
+ self.use_transactional_tests = false
554
600
 
555
601
  def test_leaky_destroy
556
602
  assert_nothing_raised { courses(:ruby) }
@@ -565,7 +611,7 @@ end
565
611
  class TransactionalFixturesOnCustomConnectionTest < ActiveRecord::TestCase
566
612
  set_fixture_class :courses => Course
567
613
  fixtures :courses
568
- self.use_transactional_fixtures = true
614
+ self.use_transactional_tests = true
569
615
 
570
616
  def test_leaky_destroy
571
617
  assert_nothing_raised { courses(:ruby) }
@@ -581,7 +627,7 @@ class InvalidTableNameFixturesTest < ActiveRecord::TestCase
581
627
  fixtures :funny_jokes
582
628
  # Set to false to blow away fixtures cache and ensure our fixtures are loaded
583
629
  # and thus takes into account our lack of set_fixture_class
584
- self.use_transactional_fixtures = false
630
+ self.use_transactional_tests = false
585
631
 
586
632
  def test_raises_error
587
633
  assert_raise ActiveRecord::FixtureClassNotFound do
@@ -595,7 +641,7 @@ class CheckEscapedYamlFixturesTest < ActiveRecord::TestCase
595
641
  fixtures :funny_jokes
596
642
  # Set to false to blow away fixtures cache and ensure our fixtures are loaded
597
643
  # and thus takes into account our set_fixture_class
598
- self.use_transactional_fixtures = false
644
+ self.use_transactional_tests = false
599
645
 
600
646
  def test_proper_escaped_fixture
601
647
  assert_equal "The \\n Aristocrats\nAte the candy\n", funny_jokes(:another_joke).name
@@ -665,7 +711,7 @@ class LoadAllFixturesWithPathnameTest < ActiveRecord::TestCase
665
711
  end
666
712
 
667
713
  class FasterFixturesTest < ActiveRecord::TestCase
668
- self.use_transactional_fixtures = false
714
+ self.use_transactional_tests = false
669
715
  fixtures :categories, :authors
670
716
 
671
717
  def load_extra_fixture(name)
@@ -691,7 +737,8 @@ class FasterFixturesTest < ActiveRecord::TestCase
691
737
  end
692
738
 
693
739
  class FoxyFixturesTest < ActiveRecord::TestCase
694
- fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers, :developers, :"admin/accounts", :"admin/users"
740
+ fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers,
741
+ :developers, :"admin/accounts", :"admin/users", :live_parrots, :dead_parrots, :books
695
742
 
696
743
  if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
697
744
  require 'models/uuid_parent'
@@ -811,6 +858,10 @@ class FoxyFixturesTest < ActiveRecord::TestCase
811
858
  assert_equal("X marks the spot!", pirates(:mark).catchphrase)
812
859
  end
813
860
 
861
+ def test_supports_label_interpolation_for_integer_label
862
+ assert_equal("#1 pirate!", pirates(1).catchphrase)
863
+ end
864
+
814
865
  def test_supports_polymorphic_belongs_to
815
866
  assert_equal(pirates(:redbeard), treasures(:sapphire).looter)
816
867
  assert_equal(parrots(:louis), treasures(:ruby).looter)
@@ -827,10 +878,23 @@ class FoxyFixturesTest < ActiveRecord::TestCase
827
878
  assert_equal pirates(:blackbeard), parrots(:polly).killer
828
879
  end
829
880
 
881
+ def test_supports_sti_with_respective_files
882
+ assert_kind_of LiveParrot, live_parrots(:dusty)
883
+ assert_kind_of DeadParrot, dead_parrots(:deadbird)
884
+ assert_equal pirates(:blackbeard), dead_parrots(:deadbird).killer
885
+ end
886
+
830
887
  def test_namespaced_models
831
888
  assert admin_accounts(:signals37).users.include?(admin_users(:david))
832
889
  assert_equal 2, admin_accounts(:signals37).users.size
833
890
  end
891
+
892
+ def test_resolves_enums
893
+ assert books(:awdr).published?
894
+ assert books(:awdr).read?
895
+ assert books(:rfr).proposed?
896
+ assert books(:ddd).published?
897
+ end
834
898
  end
835
899
 
836
900
  class ActiveSupportSubclassWithFixturesTest < ActiveRecord::TestCase
@@ -849,9 +913,9 @@ class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase
849
913
  set_fixture_class :randomly_named_a9 =>
850
914
  ClassNameThatDoesNotFollowCONVENTIONS,
851
915
  :'admin/randomly_named_a9' =>
852
- Admin::ClassNameThatDoesNotFollowCONVENTIONS,
916
+ Admin::ClassNameThatDoesNotFollowCONVENTIONS1,
853
917
  'admin/randomly_named_b0' =>
854
- Admin::ClassNameThatDoesNotFollowCONVENTIONS
918
+ Admin::ClassNameThatDoesNotFollowCONVENTIONS2
855
919
 
856
920
  fixtures :randomly_named_a9, 'admin/randomly_named_a9',
857
921
  :'admin/randomly_named_b0'
@@ -862,15 +926,15 @@ class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase
862
926
  end
863
927
 
864
928
  def test_named_accessor_for_randomly_named_namespaced_fixture_and_class
865
- assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS,
929
+ assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS1,
866
930
  admin_randomly_named_a9(:first_instance)
867
- assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS,
931
+ assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS2,
868
932
  admin_randomly_named_b0(:second_instance)
869
933
  end
870
934
 
871
935
  def test_table_name_is_defined_in_the_model
872
- assert_equal 'randomly_named_table', ActiveRecord::FixtureSet::all_loaded_fixtures["admin/randomly_named_a9"].table_name
873
- assert_equal 'randomly_named_table', Admin::ClassNameThatDoesNotFollowCONVENTIONS.table_name
936
+ assert_equal 'randomly_named_table2', ActiveRecord::FixtureSet::all_loaded_fixtures["admin/randomly_named_a9"].table_name
937
+ assert_equal 'randomly_named_table2', Admin::ClassNameThatDoesNotFollowCONVENTIONS1.table_name
874
938
  end
875
939
  end
876
940
 
@@ -895,3 +959,30 @@ class FixturesWithAbstractBelongsTo < ActiveRecord::TestCase
895
959
  assert_equal pirates(:blackbeard), doubloons(:blackbeards_doubloon).pirate
896
960
  end
897
961
  end
962
+
963
+ class FixtureClassNamesTest < ActiveRecord::TestCase
964
+ def setup
965
+ @saved_cache = self.fixture_class_names.dup
966
+ end
967
+
968
+ def teardown
969
+ self.fixture_class_names.replace(@saved_cache)
970
+ end
971
+
972
+ test "fixture_class_names returns nil for unregistered identifier" do
973
+ assert_nil self.fixture_class_names['unregistered_identifier']
974
+ end
975
+ end
976
+
977
+ class SameNameDifferentDatabaseFixturesTest < ActiveRecord::TestCase
978
+ fixtures :dogs, :other_dogs
979
+
980
+ test "fixtures are properly loaded" do
981
+ # Force loading the fixtures again to reproduce issue
982
+ ActiveRecord::FixtureSet.reset_cache
983
+ create_fixtures("dogs", "other_dogs")
984
+
985
+ assert_kind_of Dog, dogs(:sophie)
986
+ assert_kind_of OtherDog, other_dogs(:lassie)
987
+ end
988
+ end
@@ -1,14 +1,20 @@
1
1
  require 'cases/helper'
2
2
  require 'active_support/core_ext/hash/indifferent_access'
3
- require 'models/person'
3
+
4
4
  require 'models/company'
5
+ require 'models/person'
6
+ require 'models/ship'
7
+ require 'models/ship_part'
8
+ require 'models/treasure'
5
9
 
6
- class ProtectedParams < ActiveSupport::HashWithIndifferentAccess
10
+ class ProtectedParams
7
11
  attr_accessor :permitted
8
12
  alias :permitted? :permitted
9
13
 
14
+ delegate :keys, :key?, :has_key?, :empty?, to: :@parameters
15
+
10
16
  def initialize(attributes)
11
- super(attributes)
17
+ @parameters = attributes.with_indifferent_access
12
18
  @permitted = false
13
19
  end
14
20
 
@@ -17,6 +23,18 @@ class ProtectedParams < ActiveSupport::HashWithIndifferentAccess
17
23
  self
18
24
  end
19
25
 
26
+ def [](key)
27
+ @parameters[key]
28
+ end
29
+
30
+ def to_h
31
+ @parameters
32
+ end
33
+
34
+ def stringify_keys
35
+ dup
36
+ end
37
+
20
38
  def dup
21
39
  super.tap do |duplicate|
22
40
  duplicate.instance_variable_set :@permitted, @permitted
@@ -75,6 +93,13 @@ class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase
75
93
  end
76
94
  end
77
95
 
96
+ def test_create_with_works_with_permitted_params
97
+ params = ProtectedParams.new(first_name: 'Guille').permit!
98
+
99
+ person = Person.create_with(params).create!
100
+ assert_equal 'Guille', person.first_name
101
+ end
102
+
78
103
  def test_create_with_works_with_params_values
79
104
  params = ProtectedParams.new(first_name: 'Guille')
80
105
 
@@ -90,10 +115,51 @@ class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase
90
115
  end
91
116
  end
92
117
 
118
+ def test_where_works_with_permitted_params
119
+ params = ProtectedParams.new(first_name: 'Guille').permit!
120
+
121
+ person = Person.where(params).create!
122
+ assert_equal 'Guille', person.first_name
123
+ end
124
+
93
125
  def test_where_works_with_params_values
94
126
  params = ProtectedParams.new(first_name: 'Guille')
95
127
 
96
128
  person = Person.where(first_name: params[:first_name]).create!
97
129
  assert_equal 'Guille', person.first_name
98
130
  end
131
+
132
+ def test_where_not_checks_permitted
133
+ params = ProtectedParams.new(first_name: 'Guille', gender: 'm')
134
+
135
+ assert_raises(ActiveModel::ForbiddenAttributesError) do
136
+ Person.where().not(params)
137
+ end
138
+ end
139
+
140
+ def test_where_not_works_with_permitted_params
141
+ params = ProtectedParams.new(first_name: 'Guille').permit!
142
+ Person.create!(params)
143
+ assert_empty Person.where.not(params).select {|p| p.first_name == 'Guille' }
144
+ end
145
+
146
+ def test_strong_params_style_objects_work_with_singular_associations
147
+ params = ProtectedParams.new( name: "Stern", ship_attributes: ProtectedParams.new(name: "The Black Rock").permit!).permit!
148
+ part = ShipPart.new(params)
149
+
150
+ assert_equal "Stern", part.name
151
+ assert_equal "The Black Rock", part.ship.name
152
+ end
153
+
154
+ def test_strong_params_style_objects_work_with_collection_associations
155
+ params = ProtectedParams.new(
156
+ trinkets_attributes: ProtectedParams.new(
157
+ "0" => ProtectedParams.new(name: "Necklace").permit!,
158
+ "1" => ProtectedParams.new(name: "Spoon").permit! ) ).permit!
159
+ part = ShipPart.new(params)
160
+
161
+ assert_equal "Necklace", part.trinkets[0].name
162
+ assert_equal "Spoon", part.trinkets[1].name
163
+ end
164
+
99
165
  end