activerecord-nuodb-adapter 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (456) hide show
  1. data/.DS_Store +0 -0
  2. data/.travis.yml +26 -2
  3. data/{CONTRIBUTION.rdoc → CONTRIBUTION.md} +16 -15
  4. data/Gemfile +1 -1
  5. data/README.md +48 -0
  6. data/active_setup_linux.sh +97 -0
  7. data/activerecord-nuodb-adapter.gemspec +1 -1
  8. data/lib/active_record/connection_adapters/nuodb/version.rb +1 -1
  9. data/lib/active_record/connection_adapters/nuodb_adapter.rb +45 -9
  10. data/test/.DS_Store +0 -0
  11. data/test/.gitignore +1 -0
  12. data/test/active_record/connection_adapters/fake_adapter.rb +45 -0
  13. data/test/ar_schema_test.rb +70 -0
  14. data/test/assets/example.log +1 -0
  15. data/test/assets/flowers.jpg +0 -0
  16. data/test/assets/test.txt +1 -0
  17. data/test/base_test.rb +1481 -0
  18. data/test/cases/.DS_Store +0 -0
  19. data/test/cases/adapter_test.rb +211 -0
  20. data/test/cases/adapters/firebird/connection_test.rb +8 -0
  21. data/test/cases/adapters/firebird/default_test.rb +16 -0
  22. data/test/cases/adapters/firebird/migration_test.rb +124 -0
  23. data/test/cases/adapters/mysql/active_schema_test.rb +143 -0
  24. data/test/cases/adapters/mysql/case_sensitivity_test.rb +35 -0
  25. data/test/cases/adapters/mysql/connection_test.rb +172 -0
  26. data/test/cases/adapters/mysql/enum_test.rb +10 -0
  27. data/test/cases/adapters/mysql/mysql_adapter_test.rb +125 -0
  28. data/test/cases/adapters/mysql/quoting_test.rb +25 -0
  29. data/test/cases/adapters/mysql/reserved_word_test.rb +153 -0
  30. data/test/cases/adapters/mysql/schema_test.rb +62 -0
  31. data/test/cases/adapters/mysql/sp_test.rb +15 -0
  32. data/test/cases/adapters/mysql/sql_types_test.rb +14 -0
  33. data/test/cases/adapters/mysql/statement_pool_test.rb +23 -0
  34. data/test/cases/adapters/mysql2/active_schema_test.rb +143 -0
  35. data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
  36. data/test/cases/adapters/mysql2/case_sensitivity_test.rb +35 -0
  37. data/test/cases/adapters/mysql2/connection_test.rb +97 -0
  38. data/test/cases/adapters/mysql2/enum_test.rb +10 -0
  39. data/test/cases/adapters/mysql2/explain_test.rb +26 -0
  40. data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
  41. data/test/cases/adapters/mysql2/schema_migrations_test.rb +26 -0
  42. data/test/cases/adapters/mysql2/schema_test.rb +70 -0
  43. data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
  44. data/test/cases/adapters/oracle/synonym_test.rb +17 -0
  45. data/test/cases/adapters/postgresql/active_schema_test.rb +58 -0
  46. data/test/cases/adapters/postgresql/array_test.rb +104 -0
  47. data/test/cases/adapters/postgresql/bytea_test.rb +104 -0
  48. data/test/cases/adapters/postgresql/connection_test.rb +163 -0
  49. data/test/cases/adapters/postgresql/datatype_test.rb +604 -0
  50. data/test/cases/adapters/postgresql/explain_test.rb +28 -0
  51. data/test/cases/adapters/postgresql/hstore_test.rb +200 -0
  52. data/test/cases/adapters/postgresql/json_test.rb +99 -0
  53. data/test/cases/adapters/postgresql/ltree_test.rb +41 -0
  54. data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +288 -0
  55. data/test/cases/adapters/postgresql/quoting_test.rb +58 -0
  56. data/test/cases/adapters/postgresql/schema_authorization_test.rb +114 -0
  57. data/test/cases/adapters/postgresql/schema_test.rb +376 -0
  58. data/test/cases/adapters/postgresql/sql_types_test.rb +18 -0
  59. data/test/cases/adapters/postgresql/statement_pool_test.rb +39 -0
  60. data/test/cases/adapters/postgresql/timestamp_test.rb +113 -0
  61. data/test/cases/adapters/postgresql/utils_test.rb +20 -0
  62. data/test/cases/adapters/postgresql/uuid_test.rb +95 -0
  63. data/test/cases/adapters/postgresql/view_test.rb +49 -0
  64. data/test/cases/adapters/sqlite3/copy_table_test.rb +99 -0
  65. data/test/cases/adapters/sqlite3/explain_test.rb +26 -0
  66. data/test/cases/adapters/sqlite3/quoting_test.rb +102 -0
  67. data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +366 -0
  68. data/test/cases/adapters/sqlite3/statement_pool_test.rb +24 -0
  69. data/test/cases/aggregations_test.rb +158 -0
  70. data/test/cases/ar_schema_test.rb +70 -0
  71. data/test/cases/associations/association_scope_test.rb +15 -0
  72. data/test/cases/associations/belongs_to_associations_test.rb +831 -0
  73. data/test/cases/associations/callbacks_test.rb +168 -0
  74. data/test/cases/associations/cascaded_eager_loading_test.rb +179 -0
  75. data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +36 -0
  76. data/test/cases/associations/eager_load_nested_include_test.rb +128 -0
  77. data/test/cases/associations/eager_singularization_test.rb +145 -0
  78. data/test/cases/associations/eager_test.rb +1179 -0
  79. data/test/cases/associations/extension_test.rb +80 -0
  80. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +779 -0
  81. data/test/cases/associations/has_many_associations_test.rb +1699 -0
  82. data/test/cases/associations/has_many_through_associations_test.rb +950 -0
  83. data/test/cases/associations/has_one_associations_test.rb +525 -0
  84. data/test/cases/associations/has_one_through_associations_test.rb +317 -0
  85. data/test/cases/associations/inner_join_association_test.rb +115 -0
  86. data/test/cases/associations/inverse_associations_test.rb +631 -0
  87. data/test/cases/associations/join_dependency_test.rb +8 -0
  88. data/test/cases/associations/join_model_test.rb +750 -0
  89. data/test/cases/associations/nested_through_associations_test.rb +575 -0
  90. data/test/cases/associations_test.rb +344 -0
  91. data/test/cases/attribute_methods/read_test.rb +58 -0
  92. data/test/cases/attribute_methods/serialization_test.rb +29 -0
  93. data/test/cases/attribute_methods_test.rb +819 -0
  94. data/test/cases/autosave_association_test.rb +1447 -0
  95. data/test/cases/base_test.rb +1481 -0
  96. data/test/cases/batches_test.rb +173 -0
  97. data/test/cases/binary_test.rb +49 -0
  98. data/test/cases/bind_parameter_test.rb +89 -0
  99. data/test/cases/calculations_test.rb +589 -0
  100. data/test/cases/callbacks_test.rb +535 -0
  101. data/test/cases/clone_test.rb +40 -0
  102. data/test/cases/coders/yaml_column_test.rb +63 -0
  103. data/test/cases/column_alias_test.rb +17 -0
  104. data/test/cases/column_definition_test.rb +143 -0
  105. data/test/cases/column_test.rb +115 -0
  106. data/test/cases/connection_adapters/abstract_adapter_test.rb +62 -0
  107. data/test/cases/connection_adapters/connection_handler_test.rb +53 -0
  108. data/test/cases/connection_adapters/connection_specification_test.rb +12 -0
  109. data/test/cases/connection_adapters/quoting_test.rb +13 -0
  110. data/test/cases/connection_adapters/schema_cache_test.rb +56 -0
  111. data/test/cases/connection_management_test.rb +112 -0
  112. data/test/cases/connection_pool_test.rb +344 -0
  113. data/test/cases/connection_specification/resolver_test.rb +63 -0
  114. data/test/cases/core_test.rb +33 -0
  115. data/test/cases/counter_cache_test.rb +163 -0
  116. data/test/cases/custom_locking_test.rb +17 -0
  117. data/test/cases/database_statements_test.rb +19 -0
  118. data/test/cases/date_time_test.rb +43 -0
  119. data/test/cases/defaults_test.rb +214 -0
  120. data/test/cases/dirty_test.rb +626 -0
  121. data/test/cases/disconnected_test.rb +27 -0
  122. data/test/cases/dup_test.rb +136 -0
  123. data/test/cases/explain_subscriber_test.rb +59 -0
  124. data/test/cases/explain_test.rb +72 -0
  125. data/test/cases/finder_respond_to_test.rb +50 -0
  126. data/test/cases/finder_test.rb +886 -0
  127. data/test/cases/fixture_set/file_test.rb +83 -0
  128. data/test/cases/fixtures_test.rb +808 -0
  129. data/test/cases/forbidden_attributes_protection_test.rb +64 -0
  130. data/test/cases/habtm_destroy_order_test.rb +61 -0
  131. data/test/cases/helper.rb +151 -0
  132. data/test/cases/hot_compatibility_test.rb +54 -0
  133. data/test/cases/i18n_test.rb +45 -0
  134. data/test/cases/inheritance_test.rb +355 -0
  135. data/test/cases/integration_test.rb +87 -0
  136. data/test/cases/invalid_connection_test.rb +22 -0
  137. data/test/cases/invalid_date_test.rb +32 -0
  138. data/test/cases/invertible_migration_test.rb +259 -0
  139. data/test/cases/json_serialization_test.rb +300 -0
  140. data/test/cases/locking_test.rb +453 -0
  141. data/test/cases/log_subscriber_test.rb +129 -0
  142. data/test/cases/migration/change_schema_test.rb +379 -0
  143. data/test/cases/migration/change_table_test.rb +204 -0
  144. data/test/cases/migration/column_attributes_test.rb +186 -0
  145. data/test/cases/migration/column_positioning_test.rb +60 -0
  146. data/test/cases/migration/columns_test.rb +279 -0
  147. data/test/cases/migration/command_recorder_test.rb +247 -0
  148. data/test/cases/migration/create_join_table_test.rb +125 -0
  149. data/test/cases/migration/helper.rb +43 -0
  150. data/test/cases/migration/index_test.rb +209 -0
  151. data/test/cases/migration/logger_test.rb +37 -0
  152. data/test/cases/migration/references_index_test.rb +102 -0
  153. data/test/cases/migration/references_statements_test.rb +111 -0
  154. data/test/cases/migration/rename_table_test.rb +90 -0
  155. data/test/cases/migration/table_and_index_test.rb +24 -0
  156. data/test/cases/migration_test.rb +861 -0
  157. data/test/cases/migrator_test.rb +378 -0
  158. data/test/cases/mixin_test.rb +96 -0
  159. data/test/cases/modules_test.rb +143 -0
  160. data/test/cases/multiparameter_attributes_test.rb +350 -0
  161. data/test/cases/multiple_db_test.rb +108 -0
  162. data/test/cases/nested_attributes_test.rb +1056 -0
  163. data/test/cases/persistence_test.rb +802 -0
  164. data/test/cases/pooled_connections_test.rb +51 -0
  165. data/test/cases/primary_keys_test.rb +218 -0
  166. data/test/cases/query_cache_test.rb +276 -0
  167. data/test/cases/quoting_test.rb +229 -0
  168. data/test/cases/readonly_test.rb +111 -0
  169. data/test/cases/reaper_test.rb +81 -0
  170. data/test/cases/reflection_test.rb +386 -0
  171. data/test/cases/relation/where_chain_test.rb +80 -0
  172. data/test/cases/relation/where_test.rb +120 -0
  173. data/test/cases/relation_test.rb +315 -0
  174. data/test/cases/relations_test.rb +1559 -0
  175. data/test/cases/reload_models_test.rb +22 -0
  176. data/test/cases/result_test.rb +32 -0
  177. data/test/cases/sanitize_test.rb +34 -0
  178. data/test/cases/schema_dumper_test.rb +391 -0
  179. data/test/cases/scoping/default_scoping_test.rb +374 -0
  180. data/test/cases/scoping/named_scoping_test.rb +451 -0
  181. data/test/cases/scoping/relation_scoping_test.rb +331 -0
  182. data/test/cases/serialization_test.rb +68 -0
  183. data/test/cases/serialized_attribute_test.rb +252 -0
  184. data/test/cases/statement_cache_test.rb +64 -0
  185. data/test/cases/store_test.rb +153 -0
  186. data/test/cases/tasks/database_tasks_test.rb +315 -0
  187. data/test/cases/tasks/mysql_rake_test.rb +301 -0
  188. data/test/cases/tasks/postgresql_rake_test.rb +236 -0
  189. data/test/cases/tasks/sqlite_rake_test.rb +191 -0
  190. data/test/cases/test_case.rb +95 -0
  191. data/test/cases/test_simple.rb +194 -0
  192. data/test/cases/timestamp_test.rb +308 -0
  193. data/test/cases/transaction_callbacks_test.rb +317 -0
  194. data/test/cases/transaction_isolation_test.rb +114 -0
  195. data/test/cases/transactions_test.rb +595 -0
  196. data/test/cases/unconnected_test.rb +33 -0
  197. data/test/cases/validations/association_validation_test.rb +121 -0
  198. data/test/cases/validations/i18n_generate_message_validation_test.rb +76 -0
  199. data/test/cases/validations/i18n_validation_test.rb +89 -0
  200. data/test/cases/validations/presence_validation_test.rb +51 -0
  201. data/test/cases/validations/uniqueness_validation_test.rb +379 -0
  202. data/test/cases/validations_repair_helper.rb +23 -0
  203. data/test/cases/validations_test.rb +124 -0
  204. data/test/cases/xml_serialization_test.rb +455 -0
  205. data/test/cases/yaml_serialization_test.rb +52 -0
  206. data/test/config.example.yml +154 -0
  207. data/test/config.rb +5 -0
  208. data/test/database_statements_test.rb +19 -0
  209. data/test/fixtures/.gitignore +1 -0
  210. data/test/fixtures/accounts.yml +29 -0
  211. data/test/fixtures/admin/accounts.yml +2 -0
  212. data/test/fixtures/admin/randomly_named_a9.yml +7 -0
  213. data/test/fixtures/admin/randomly_named_b0.yml +7 -0
  214. data/test/fixtures/admin/users.yml +10 -0
  215. data/test/fixtures/all/developers.yml +0 -0
  216. data/test/fixtures/all/people.yml +0 -0
  217. data/test/fixtures/all/tasks.yml +0 -0
  218. data/test/fixtures/author_addresses.yml +5 -0
  219. data/test/fixtures/author_favorites.yml +4 -0
  220. data/test/fixtures/authors.yml +15 -0
  221. data/test/fixtures/binaries.yml +133 -0
  222. data/test/fixtures/books.yml +9 -0
  223. data/test/fixtures/cars.yml +9 -0
  224. data/test/fixtures/categories.yml +19 -0
  225. data/test/fixtures/categories/special_categories.yml +9 -0
  226. data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
  227. data/test/fixtures/categories_ordered.yml +7 -0
  228. data/test/fixtures/categories_posts.yml +31 -0
  229. data/test/fixtures/categorizations.yml +23 -0
  230. data/test/fixtures/clubs.yml +8 -0
  231. data/test/fixtures/collections.yml +3 -0
  232. data/test/fixtures/colleges.yml +3 -0
  233. data/test/fixtures/comments.yml +65 -0
  234. data/test/fixtures/companies.yml +59 -0
  235. data/test/fixtures/computers.yml +4 -0
  236. data/test/fixtures/courses.yml +8 -0
  237. data/test/fixtures/customers.yml +26 -0
  238. data/test/fixtures/dashboards.yml +6 -0
  239. data/test/fixtures/developers.yml +21 -0
  240. data/test/fixtures/developers_projects.yml +17 -0
  241. data/test/fixtures/dog_lovers.yml +7 -0
  242. data/test/fixtures/dogs.yml +4 -0
  243. data/test/fixtures/edges.yml +5 -0
  244. data/test/fixtures/entrants.yml +14 -0
  245. data/test/fixtures/essays.yml +6 -0
  246. data/test/fixtures/faces.yml +11 -0
  247. data/test/fixtures/fk_test_has_fk.yml +3 -0
  248. data/test/fixtures/fk_test_has_pk.yml +2 -0
  249. data/test/fixtures/friendships.yml +4 -0
  250. data/test/fixtures/funny_jokes.yml +10 -0
  251. data/test/fixtures/interests.yml +33 -0
  252. data/test/fixtures/items.yml +3 -0
  253. data/test/fixtures/jobs.yml +7 -0
  254. data/test/fixtures/legacy_things.yml +3 -0
  255. data/test/fixtures/mateys.yml +4 -0
  256. data/test/fixtures/member_details.yml +8 -0
  257. data/test/fixtures/member_types.yml +6 -0
  258. data/test/fixtures/members.yml +11 -0
  259. data/test/fixtures/memberships.yml +34 -0
  260. data/test/fixtures/men.yml +5 -0
  261. data/test/fixtures/minimalistics.yml +2 -0
  262. data/test/fixtures/minivans.yml +5 -0
  263. data/test/fixtures/mixed_case_monkeys.yml +6 -0
  264. data/test/fixtures/mixins.yml +29 -0
  265. data/test/fixtures/movies.yml +7 -0
  266. data/test/fixtures/naked/csv/accounts.csv +1 -0
  267. data/test/fixtures/naked/yml/accounts.yml +1 -0
  268. data/test/fixtures/naked/yml/companies.yml +1 -0
  269. data/test/fixtures/naked/yml/courses.yml +1 -0
  270. data/test/fixtures/organizations.yml +5 -0
  271. data/test/fixtures/other_topics.yml +42 -0
  272. data/test/fixtures/owners.yml +8 -0
  273. data/test/fixtures/parrots.yml +27 -0
  274. data/test/fixtures/parrots_pirates.yml +7 -0
  275. data/test/fixtures/people.yml +24 -0
  276. data/test/fixtures/peoples_treasures.yml +3 -0
  277. data/test/fixtures/pets.yml +19 -0
  278. data/test/fixtures/pirates.yml +9 -0
  279. data/test/fixtures/posts.yml +82 -0
  280. data/test/fixtures/price_estimates.yml +7 -0
  281. data/test/fixtures/products.yml +4 -0
  282. data/test/fixtures/projects.yml +7 -0
  283. data/test/fixtures/randomly_named_a9.yml +7 -0
  284. data/test/fixtures/ratings.yml +14 -0
  285. data/test/fixtures/readers.yml +11 -0
  286. data/test/fixtures/references.yml +17 -0
  287. data/test/fixtures/reserved_words/distinct.yml +5 -0
  288. data/test/fixtures/reserved_words/distinct_select.yml +11 -0
  289. data/test/fixtures/reserved_words/group.yml +14 -0
  290. data/test/fixtures/reserved_words/select.yml +8 -0
  291. data/test/fixtures/reserved_words/values.yml +7 -0
  292. data/test/fixtures/ships.yml +6 -0
  293. data/test/fixtures/speedometers.yml +8 -0
  294. data/test/fixtures/sponsors.yml +12 -0
  295. data/test/fixtures/string_key_objects.yml +7 -0
  296. data/test/fixtures/subscribers.yml +11 -0
  297. data/test/fixtures/subscriptions.yml +12 -0
  298. data/test/fixtures/taggings.yml +78 -0
  299. data/test/fixtures/tags.yml +11 -0
  300. data/test/fixtures/tasks.yml +7 -0
  301. data/test/fixtures/teapots.yml +3 -0
  302. data/test/fixtures/topics.yml +42 -0
  303. data/test/fixtures/toys.yml +14 -0
  304. data/test/fixtures/traffic_lights.yml +10 -0
  305. data/test/fixtures/treasures.yml +10 -0
  306. data/test/fixtures/variants.yml +4 -0
  307. data/test/fixtures/vegetables.yml +20 -0
  308. data/test/fixtures/vertices.yml +4 -0
  309. data/test/fixtures/warehouse-things.yml +3 -0
  310. data/test/fixtures/zines.yml +5 -0
  311. data/test/migration_test.rb +861 -0
  312. data/test/migrations/10_urban/9_add_expressions.rb +11 -0
  313. data/test/migrations/decimal/1_give_me_big_numbers.rb +15 -0
  314. data/test/migrations/empty/.gitkeep +0 -0
  315. data/test/migrations/magic/1_currencies_have_symbols.rb +12 -0
  316. data/test/migrations/missing/1000_people_have_middle_names.rb +9 -0
  317. data/test/migrations/missing/1_people_have_last_names.rb +9 -0
  318. data/test/migrations/missing/3_we_need_reminders.rb +12 -0
  319. data/test/migrations/missing/4_innocent_jointable.rb +12 -0
  320. data/test/migrations/rename/1_we_need_things.rb +11 -0
  321. data/test/migrations/rename/2_rename_things.rb +9 -0
  322. data/test/migrations/to_copy/1_people_have_hobbies.rb +9 -0
  323. data/test/migrations/to_copy/2_people_have_descriptions.rb +9 -0
  324. data/test/migrations/to_copy2/1_create_articles.rb +7 -0
  325. data/test/migrations/to_copy2/2_create_comments.rb +7 -0
  326. data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +9 -0
  327. data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +9 -0
  328. data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +9 -0
  329. data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +7 -0
  330. data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +7 -0
  331. data/test/migrations/valid/1_valid_people_have_last_names.rb +9 -0
  332. data/test/migrations/valid/2_we_need_reminders.rb +12 -0
  333. data/test/migrations/valid/3_innocent_jointable.rb +12 -0
  334. data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +9 -0
  335. data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +12 -0
  336. data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +12 -0
  337. data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +9 -0
  338. data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +12 -0
  339. data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +12 -0
  340. data/test/models/admin.rb +5 -0
  341. data/test/models/admin/account.rb +3 -0
  342. data/test/models/admin/randomly_named_c1.rb +3 -0
  343. data/test/models/admin/user.rb +39 -0
  344. data/test/models/aircraft.rb +4 -0
  345. data/test/models/arunit2_model.rb +3 -0
  346. data/test/models/author.rb +196 -0
  347. data/test/models/auto_id.rb +4 -0
  348. data/test/models/autoloadable/extra_firm.rb +2 -0
  349. data/test/models/binary.rb +2 -0
  350. data/test/models/bird.rb +12 -0
  351. data/test/models/book.rb +9 -0
  352. data/test/models/boolean.rb +2 -0
  353. data/test/models/bulb.rb +45 -0
  354. data/test/models/car.rb +28 -0
  355. data/test/models/categorization.rb +19 -0
  356. data/test/models/category.rb +34 -0
  357. data/test/models/citation.rb +6 -0
  358. data/test/models/club.rb +15 -0
  359. data/test/models/college.rb +5 -0
  360. data/test/models/column_name.rb +3 -0
  361. data/test/models/comment.rb +38 -0
  362. data/test/models/company.rb +214 -0
  363. data/test/models/company_in_module.rb +80 -0
  364. data/test/models/computer.rb +3 -0
  365. data/test/models/contact.rb +40 -0
  366. data/test/models/contract.rb +19 -0
  367. data/test/models/country.rb +7 -0
  368. data/test/models/course.rb +6 -0
  369. data/test/models/customer.rb +77 -0
  370. data/test/models/dashboard.rb +3 -0
  371. data/test/models/default.rb +2 -0
  372. data/test/models/developer.rb +250 -0
  373. data/test/models/dog.rb +5 -0
  374. data/test/models/dog_lover.rb +5 -0
  375. data/test/models/edge.rb +5 -0
  376. data/test/models/electron.rb +3 -0
  377. data/test/models/engine.rb +4 -0
  378. data/test/models/entrant.rb +3 -0
  379. data/test/models/essay.rb +5 -0
  380. data/test/models/event.rb +3 -0
  381. data/test/models/eye.rb +37 -0
  382. data/test/models/face.rb +7 -0
  383. data/test/models/friendship.rb +6 -0
  384. data/test/models/guid.rb +2 -0
  385. data/test/models/interest.rb +5 -0
  386. data/test/models/invoice.rb +4 -0
  387. data/test/models/item.rb +7 -0
  388. data/test/models/job.rb +7 -0
  389. data/test/models/joke.rb +7 -0
  390. data/test/models/keyboard.rb +3 -0
  391. data/test/models/legacy_thing.rb +3 -0
  392. data/test/models/lesson.rb +11 -0
  393. data/test/models/line_item.rb +3 -0
  394. data/test/models/liquid.rb +4 -0
  395. data/test/models/man.rb +9 -0
  396. data/test/models/matey.rb +4 -0
  397. data/test/models/member.rb +36 -0
  398. data/test/models/member_detail.rb +7 -0
  399. data/test/models/member_type.rb +3 -0
  400. data/test/models/membership.rb +15 -0
  401. data/test/models/minimalistic.rb +2 -0
  402. data/test/models/minivan.rb +9 -0
  403. data/test/models/mixed_case_monkey.rb +3 -0
  404. data/test/models/molecule.rb +4 -0
  405. data/test/models/movie.rb +5 -0
  406. data/test/models/order.rb +4 -0
  407. data/test/models/organization.rb +12 -0
  408. data/test/models/owner.rb +5 -0
  409. data/test/models/parrot.rb +29 -0
  410. data/test/models/person.rb +128 -0
  411. data/test/models/pet.rb +15 -0
  412. data/test/models/pirate.rb +86 -0
  413. data/test/models/possession.rb +3 -0
  414. data/test/models/post.rb +194 -0
  415. data/test/models/price_estimate.rb +4 -0
  416. data/test/models/project.rb +30 -0
  417. data/test/models/randomly_named_c1.rb +3 -0
  418. data/test/models/rating.rb +4 -0
  419. data/test/models/reader.rb +21 -0
  420. data/test/models/reference.rb +22 -0
  421. data/test/models/reply.rb +61 -0
  422. data/test/models/ship.rb +19 -0
  423. data/test/models/ship_part.rb +7 -0
  424. data/test/models/shop.rb +12 -0
  425. data/test/models/speedometer.rb +6 -0
  426. data/test/models/sponsor.rb +7 -0
  427. data/test/models/string_key_object.rb +3 -0
  428. data/test/models/student.rb +3 -0
  429. data/test/models/subject.rb +16 -0
  430. data/test/models/subscriber.rb +8 -0
  431. data/test/models/subscription.rb +4 -0
  432. data/test/models/tag.rb +7 -0
  433. data/test/models/tagging.rb +13 -0
  434. data/test/models/task.rb +5 -0
  435. data/test/models/topic.rb +121 -0
  436. data/test/models/toy.rb +6 -0
  437. data/test/models/traffic_light.rb +4 -0
  438. data/test/models/treasure.rb +11 -0
  439. data/test/models/treaty.rb +7 -0
  440. data/test/models/tyre.rb +3 -0
  441. data/test/models/vegetables.rb +24 -0
  442. data/test/models/vertex.rb +9 -0
  443. data/test/models/warehouse_thing.rb +5 -0
  444. data/test/models/wheel.rb +3 -0
  445. data/test/models/without_table.rb +3 -0
  446. data/test/models/zine.rb +3 -0
  447. data/test/schema/mysql2_specific_schema.rb +58 -0
  448. data/test/schema/mysql_specific_schema.rb +70 -0
  449. data/test/schema/oracle_specific_schema.rb +46 -0
  450. data/test/schema/postgresql_specific_schema.rb +224 -0
  451. data/test/schema/schema.rb +809 -0
  452. data/test/schema/sqlite_specific_schema.rb +25 -0
  453. data/test/support/config.rb +43 -0
  454. data/test/support/connection.rb +21 -0
  455. metadata +898 -6
  456. data/README.rdoc +0 -42
@@ -0,0 +1,4 @@
1
+ product_1:
2
+ id: 1
3
+ collection_id: 1
4
+ name: Product
@@ -0,0 +1,7 @@
1
+ action_controller:
2
+ id: 2
3
+ name: Active Controller
4
+
5
+ active_record:
6
+ id: 1
7
+ name: Active Record
@@ -0,0 +1,7 @@
1
+ first_instance:
2
+ some_attribute: AAA
3
+ another_attribute: 000
4
+
5
+ second_instance:
6
+ some_attribute: BBB
7
+ another_attribute: 999
@@ -0,0 +1,14 @@
1
+ normal_comment_rating:
2
+ id: 1
3
+ comment_id: 8
4
+ value: 1
5
+
6
+ special_comment_rating:
7
+ id: 2
8
+ comment_id: 6
9
+ value: 1
10
+
11
+ sub_special_comment_rating:
12
+ id: 3
13
+ comment_id: 12
14
+ value: 1
@@ -0,0 +1,11 @@
1
+ michael_welcome:
2
+ id: 1
3
+ post_id: 1
4
+ person_id: 1
5
+ first_post_id: 2
6
+
7
+ michael_authorless:
8
+ id: 2
9
+ post_id: 3
10
+ person_id: 1
11
+ first_post_id: 3
@@ -0,0 +1,17 @@
1
+ michael_magician:
2
+ id: 1
3
+ person_id: 1
4
+ job_id: 3
5
+ favourite: false
6
+
7
+ michael_unicyclist:
8
+ id: 2
9
+ person_id: 1
10
+ job_id: 1
11
+ favourite: true
12
+
13
+ david_unicyclist:
14
+ id: 3
15
+ person_id: 2
16
+ job_id: 1
17
+ favourite: false
@@ -0,0 +1,5 @@
1
+ distinct1:
2
+ id: 1
3
+
4
+ distinct2:
5
+ id: 2
@@ -0,0 +1,11 @@
1
+ distinct_select1:
2
+ distinct_id: 1
3
+ select_id: 1
4
+
5
+ distinct_select2:
6
+ distinct_id: 1
7
+ select_id: 2
8
+
9
+ distinct_select3:
10
+ distinct_id: 2
11
+ select_id: 3
@@ -0,0 +1,14 @@
1
+ group1:
2
+ id: 1
3
+ select_id: 1
4
+ order: x
5
+
6
+ group2:
7
+ id: 2
8
+ select_id: 2
9
+ order: y
10
+
11
+ group3:
12
+ id: 3
13
+ select_id: 2
14
+ order: z
@@ -0,0 +1,8 @@
1
+ select1:
2
+ id: 1
3
+
4
+ select2:
5
+ id: 2
6
+
7
+ select3:
8
+ id: 3
@@ -0,0 +1,7 @@
1
+ values1:
2
+ id: 1
3
+ group_id: 2
4
+
5
+ values2:
6
+ id: 2
7
+ group_id: 1
@@ -0,0 +1,6 @@
1
+ black_pearl:
2
+ name: "Black Pearl"
3
+ pirate: blackbeard
4
+ interceptor:
5
+ id: 2
6
+ name: "Interceptor"
@@ -0,0 +1,8 @@
1
+ cool_first:
2
+ speedometer_id: s1
3
+ name: my_speedometer
4
+ dashboard_id: d1
5
+ second:
6
+ speedometer_id: s2
7
+ name: second
8
+ dashboard_id: d2
@@ -0,0 +1,12 @@
1
+ moustache_club_sponsor_for_groucho:
2
+ sponsor_club: moustache_club
3
+ sponsorable_id: 1
4
+ sponsorable_type: Member
5
+ boring_club_sponsor_for_groucho:
6
+ sponsor_club: boring_club
7
+ sponsorable_id: 2
8
+ sponsorable_type: Member
9
+ crazy_club_sponsor_for_groucho:
10
+ sponsor_club: crazy_club
11
+ sponsorable_id: 2
12
+ sponsorable_type: Member
@@ -0,0 +1,7 @@
1
+ first:
2
+ id: record1
3
+ name: first record
4
+
5
+ second:
6
+ id: record2
7
+ name: second record
@@ -0,0 +1,11 @@
1
+ first:
2
+ nick: alterself
3
+ name: Luke Holden
4
+
5
+ second:
6
+ nick: webster132
7
+ name: David Heinemeier Hansson
8
+
9
+ thrid:
10
+ nick: swistak
11
+ name: Marcin Raczkowski
@@ -0,0 +1,12 @@
1
+ webster_awdr:
2
+ id: 1
3
+ subscriber_id: webster132
4
+ book_id: 1
5
+ webster_rfr:
6
+ id: 2
7
+ subscriber_id: webster132
8
+ book_id: 2
9
+ alterself_awdr:
10
+ id: 3
11
+ subscriber_id: alterself
12
+ book_id: 1
@@ -0,0 +1,78 @@
1
+ welcome_general:
2
+ id: 1
3
+ tag_id: 1
4
+ super_tag_id: 2
5
+ taggable_id: 1
6
+ taggable_type: Post
7
+
8
+ thinking_general:
9
+ id: 2
10
+ tag_id: 1
11
+ taggable_id: 2
12
+ taggable_type: Post
13
+
14
+ fake:
15
+ id: 3
16
+ tag_id: 1
17
+ taggable_id: 1
18
+ taggable_type: FakeModel
19
+
20
+ godfather:
21
+ id: 4
22
+ tag_id: 1
23
+ taggable_id: 1
24
+ taggable_type: Item
25
+
26
+ orphaned:
27
+ id: 5
28
+ tag_id: 1
29
+
30
+ misc_post_by_bob:
31
+ id: 6
32
+ tag_id: 2
33
+ taggable_id: 8
34
+ taggable_type: Post
35
+
36
+ misc_post_by_mary:
37
+ id: 7
38
+ tag_id: 2
39
+ taggable_id: 9
40
+ taggable_type: Post
41
+
42
+ misc_by_bob_blue_first:
43
+ id: 8
44
+ tag_id: 3
45
+ taggable_id: 8
46
+ taggable_type: Post
47
+ comment: first
48
+
49
+ misc_by_bob_blue_second:
50
+ id: 9
51
+ tag_id: 3
52
+ taggable_id: 8
53
+ taggable_type: Post
54
+ comment: second
55
+
56
+ other_by_bob_blue:
57
+ id: 10
58
+ tag_id: 3
59
+ taggable_id: 10
60
+ taggable_type: Post
61
+ comment: first
62
+
63
+ other_by_mary_blue:
64
+ id: 11
65
+ tag_id: 3
66
+ taggable_id: 11
67
+ taggable_type: Post
68
+ comment: first
69
+
70
+ special_comment_rating:
71
+ id: 12
72
+ taggable_id: 2
73
+ taggable_type: Rating
74
+
75
+ normal_comment_rating:
76
+ id: 13
77
+ taggable_id: 1
78
+ taggable_type: Rating
@@ -0,0 +1,11 @@
1
+ general:
2
+ id: 1
3
+ name: General
4
+
5
+ misc:
6
+ id: 2
7
+ name: Misc
8
+
9
+ blue:
10
+ id: 3
11
+ name: Blue
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+ first_task:
3
+ id: 1
4
+ starting: 2005-03-30t06:30:00.00+01:00
5
+ ending: 2005-03-30t08:30:00.00+01:00
6
+ another_task:
7
+ id: 2
@@ -0,0 +1,3 @@
1
+ bob:
2
+ id: 1
3
+ name: Bob
@@ -0,0 +1,42 @@
1
+ first:
2
+ id: 1
3
+ title: The First Topic
4
+ author_name: David
5
+ author_email_address: david@loudthinking.com
6
+ written_on: 2003-07-16t15:28:11.2233+01:00
7
+ last_read: 2004-04-15
8
+ bonus_time: 2005-01-30t15:28:00.00+01:00
9
+ content: Have a nice day
10
+ approved: false
11
+ replies_count: 1
12
+
13
+ second:
14
+ id: 2
15
+ title: The Second Topic of the day
16
+ author_name: Mary
17
+ written_on: 2004-07-15t15:28:00.0099+01:00
18
+ content: Have a nice day
19
+ approved: true
20
+ replies_count: 0
21
+ parent_id: 1
22
+ type: Reply
23
+
24
+ third:
25
+ id: 3
26
+ title: The Third Topic of the day
27
+ author_name: Carl
28
+ written_on: 2012-08-12t20:24:22.129346+00:00
29
+ content: I'm a troll
30
+ approved: true
31
+ replies_count: 1
32
+
33
+ fourth:
34
+ id: 4
35
+ title: The Fourth Topic of the day
36
+ author_name: Carl
37
+ written_on: 2006-07-15t15:28:00.0099+01:00
38
+ content: Why not?
39
+ approved: true
40
+ type: Reply
41
+ parent_id: 3
42
+
@@ -0,0 +1,14 @@
1
+ bone:
2
+ toy_id: 1
3
+ name: Bone
4
+ pet_id: 1
5
+
6
+ doll:
7
+ toy_id: 2
8
+ name: Doll
9
+ pet_id: 2
10
+
11
+ bulbuli:
12
+ toy_id: 3
13
+ name: Bulbuli
14
+ pet_id: 4
@@ -0,0 +1,10 @@
1
+ uk:
2
+ location: UK
3
+ state:
4
+ - Green
5
+ - Red
6
+ - Orange
7
+ long_state:
8
+ - "Green, go ahead"
9
+ - "Red, wait"
10
+ - "Orange, caution light is about to switch"
@@ -0,0 +1,10 @@
1
+ diamond:
2
+ name: $LABEL
3
+
4
+ sapphire:
5
+ name: $LABEL
6
+ looter: redbeard (Pirate)
7
+
8
+ ruby:
9
+ name: $LABEL
10
+ looter: louis (Parrot)
@@ -0,0 +1,4 @@
1
+ variant_1:
2
+ id: 1
3
+ product_id: 1
4
+ name: Variant
@@ -0,0 +1,20 @@
1
+ first_cucumber:
2
+ id: 1
3
+ custom_type: Cucumber
4
+ name: 'my cucumber'
5
+
6
+ first_cabbage:
7
+ id: 2
8
+ custom_type: Cabbage
9
+ name: 'my cabbage'
10
+
11
+ second_cabbage:
12
+ id: 3
13
+ custom_type: Cabbage
14
+ name: 'his cabbage'
15
+
16
+ red_cabbage:
17
+ id: 4
18
+ custom_type: RedCabbage
19
+ name: 'red cabbage'
20
+ seller_id: 3
@@ -0,0 +1,4 @@
1
+ <% (1..5).each do |id| %>
2
+ vertex_<%= id %>:
3
+ id: <%= id %>
4
+ <% end %>
@@ -0,0 +1,3 @@
1
+ one:
2
+ id: 1
3
+ value: 1000
@@ -0,0 +1,5 @@
1
+ staying_in:
2
+ title: Staying in '08
3
+
4
+ going_out:
5
+ title: Outdoor Pursuits 2k+8
@@ -0,0 +1,861 @@
1
+ require "cases/helper"
2
+ require "cases/migration/helper"
3
+ require 'bigdecimal/util'
4
+
5
+ require 'models/person'
6
+ require 'models/topic'
7
+ require 'models/developer'
8
+
9
+ require MIGRATIONS_ROOT + "/valid/2_we_need_reminders"
10
+ require MIGRATIONS_ROOT + "/rename/1_we_need_things"
11
+ require MIGRATIONS_ROOT + "/rename/2_rename_things"
12
+ require MIGRATIONS_ROOT + "/decimal/1_give_me_big_numbers"
13
+
14
+ class BigNumber < ActiveRecord::Base; end
15
+
16
+ class Reminder < ActiveRecord::Base; end
17
+
18
+ class Thing < ActiveRecord::Base; end
19
+
20
+ class MigrationTest < ActiveRecord::TestCase
21
+ self.use_transactional_fixtures = false
22
+
23
+ fixtures :people
24
+
25
+ def setup
26
+ super
27
+ %w(reminders people_reminders prefix_reminders_suffix p_things_s).each do |table|
28
+ Reminder.connection.drop_table(table) rescue nil
29
+ end
30
+ Reminder.reset_column_information
31
+ ActiveRecord::Migration.verbose = true
32
+ ActiveRecord::Migration.message_count = 0
33
+ ActiveRecord::Base.connection.schema_cache.clear!
34
+ end
35
+
36
+ def teardown
37
+ ActiveRecord::Base.table_name_prefix = ""
38
+ ActiveRecord::Base.table_name_suffix = ""
39
+
40
+ ActiveRecord::Base.connection.initialize_schema_migrations_table
41
+ ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
42
+
43
+ %w(things awesome_things prefix_things_suffix p_awesome_things_s ).each do |table|
44
+ Thing.connection.drop_table(table) rescue nil
45
+ end
46
+ Thing.reset_column_information
47
+
48
+ %w(reminders people_reminders prefix_reminders_suffix).each do |table|
49
+ Reminder.connection.drop_table(table) rescue nil
50
+ end
51
+ Reminder.reset_table_name
52
+ Reminder.reset_column_information
53
+
54
+ %w(last_name key bio age height wealth birthday favorite_day
55
+ moment_of_truth male administrator funny).each do |column|
56
+ Person.connection.remove_column('people', column) rescue nil
57
+ end
58
+ Person.connection.remove_column("people", "first_name") rescue nil
59
+ Person.connection.remove_column("people", "middle_name") rescue nil
60
+ Person.connection.add_column("people", "first_name", :string, :limit => 40)
61
+ Person.reset_column_information
62
+ end
63
+
64
+ def test_migrator_versions
65
+ migrations_path = MIGRATIONS_ROOT + "/valid"
66
+ ActiveRecord::Migrator.migrations_paths = migrations_path
67
+
68
+ ActiveRecord::Migrator.up(migrations_path)
69
+ assert_equal 3, ActiveRecord::Migrator.current_version
70
+ assert_equal 3, ActiveRecord::Migrator.last_version
71
+ assert_equal false, ActiveRecord::Migrator.needs_migration?
72
+
73
+ ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid")
74
+ assert_equal 0, ActiveRecord::Migrator.current_version
75
+ assert_equal 3, ActiveRecord::Migrator.last_version
76
+ assert_equal true, ActiveRecord::Migrator.needs_migration?
77
+ end
78
+
79
+ def test_create_table_with_force_true_does_not_drop_nonexisting_table
80
+ if Person.connection.table_exists?(:testings2)
81
+ Person.connection.drop_table :testings2
82
+ end
83
+
84
+ # using a copy as we need the drop_table method to
85
+ # continue to work for the ensure block of the test
86
+ temp_conn = Person.connection.dup
87
+
88
+ assert_not_equal temp_conn, Person.connection
89
+
90
+ temp_conn.create_table :testings2, :force => true do |t|
91
+ t.column :foo, :string
92
+ end
93
+ ensure
94
+ Person.connection.drop_table :testings2 rescue nil
95
+ end
96
+
97
+ def connection
98
+ ActiveRecord::Base.connection
99
+ end
100
+
101
+ def test_migration_instance_has_connection
102
+ migration = Class.new(ActiveRecord::Migration).new
103
+ assert_equal connection, migration.connection
104
+ end
105
+
106
+ def test_method_missing_delegates_to_connection
107
+ migration = Class.new(ActiveRecord::Migration) {
108
+ def connection
109
+ Class.new {
110
+ def create_table; "hi mom!"; end
111
+ }.new
112
+ end
113
+ }.new
114
+
115
+ assert_equal "hi mom!", migration.method_missing(:create_table)
116
+ end
117
+
118
+ def test_add_table_with_decimals
119
+ Person.connection.drop_table :big_numbers rescue nil
120
+
121
+ assert !BigNumber.table_exists?
122
+ GiveMeBigNumbers.up
123
+
124
+ assert BigNumber.create(
125
+ :bank_balance => 1586.43,
126
+ :big_bank_balance => BigDecimal("1000234000567.95"),
127
+ :world_population => 6000000000,
128
+ :my_house_population => 3,
129
+ :value_of_e => BigDecimal("2.7182818284590452353602875")
130
+ )
131
+
132
+ b = BigNumber.first
133
+ assert_not_nil b
134
+
135
+ assert_not_nil b.bank_balance
136
+ assert_not_nil b.big_bank_balance
137
+ assert_not_nil b.world_population
138
+ assert_not_nil b.my_house_population
139
+ assert_not_nil b.value_of_e
140
+
141
+ # TODO: set world_population >= 2**62 to cover 64-bit platforms and test
142
+ # is_a?(Bignum)
143
+ assert_kind_of Integer, b.world_population
144
+ assert_equal 6000000000, b.world_population
145
+ assert_kind_of Fixnum, b.my_house_population
146
+ assert_equal 3, b.my_house_population
147
+ assert_kind_of BigDecimal, b.bank_balance
148
+ assert_equal BigDecimal("1586.43"), b.bank_balance
149
+ assert_kind_of BigDecimal, b.big_bank_balance
150
+ assert_equal BigDecimal("1000234000567.95"), b.big_bank_balance
151
+
152
+ # This one is fun. The 'value_of_e' field is defined as 'DECIMAL' with
153
+ # precision/scale explicitly left out. By the SQL standard, numbers
154
+ # assigned to this field should be truncated but that's seldom respected.
155
+ if current_adapter?(:PostgreSQLAdapter)
156
+ # - PostgreSQL changes the SQL spec on columns declared simply as
157
+ # "decimal" to something more useful: instead of being given a scale
158
+ # of 0, they take on the compile-time limit for precision and scale,
159
+ # so the following should succeed unless you have used really wacky
160
+ # compilation options
161
+ # - SQLite2 has the default behavior of preserving all data sent in,
162
+ # so this happens there too
163
+ assert_kind_of BigDecimal, b.value_of_e
164
+ assert_equal BigDecimal("2.7182818284590452353602875"), b.value_of_e
165
+ elsif current_adapter?(:SQLite3Adapter)
166
+ # - SQLite3 stores a float, in violation of SQL
167
+ assert_kind_of BigDecimal, b.value_of_e
168
+ assert_in_delta BigDecimal("2.71828182845905"), b.value_of_e, 0.00000000000001
169
+ else
170
+ # - SQL standard is an integer
171
+ assert_kind_of Fixnum, b.value_of_e
172
+ assert_equal 2, b.value_of_e
173
+ end
174
+
175
+ GiveMeBigNumbers.down
176
+ assert_raise(ActiveRecord::StatementInvalid) { BigNumber.first }
177
+ end
178
+
179
+ def test_filtering_migrations
180
+ assert !Person.column_methods_hash.include?(:last_name)
181
+ assert !Reminder.table_exists?
182
+
183
+ name_filter = lambda { |migration| migration.name == "ValidPeopleHaveLastNames" }
184
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", &name_filter)
185
+
186
+ Person.reset_column_information
187
+ assert Person.column_methods_hash.include?(:last_name)
188
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
189
+
190
+ ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", &name_filter)
191
+
192
+ Person.reset_column_information
193
+ assert !Person.column_methods_hash.include?(:last_name)
194
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
195
+ end
196
+
197
+ class MockMigration < ActiveRecord::Migration
198
+ attr_reader :went_up, :went_down
199
+ def initialize
200
+ @went_up = false
201
+ @went_down = false
202
+ end
203
+
204
+ def up
205
+ @went_up = true
206
+ super
207
+ end
208
+
209
+ def down
210
+ @went_down = true
211
+ super
212
+ end
213
+ end
214
+
215
+ def test_instance_based_migration_up
216
+ migration = MockMigration.new
217
+ assert !migration.went_up, 'have not gone up'
218
+ assert !migration.went_down, 'have not gone down'
219
+
220
+ migration.migrate :up
221
+ assert migration.went_up, 'have gone up'
222
+ assert !migration.went_down, 'have not gone down'
223
+ end
224
+
225
+ def test_instance_based_migration_down
226
+ migration = MockMigration.new
227
+ assert !migration.went_up, 'have not gone up'
228
+ assert !migration.went_down, 'have not gone down'
229
+
230
+ migration.migrate :down
231
+ assert !migration.went_up, 'have gone up'
232
+ assert migration.went_down, 'have not gone down'
233
+ end
234
+
235
+ def test_migrator_one_up_with_exception_and_rollback
236
+ unless ActiveRecord::Base.connection.supports_ddl_transactions?
237
+ skip "not supported on #{ActiveRecord::Base.connection.class}"
238
+ end
239
+
240
+ assert_not Person.column_methods_hash.include?(:last_name)
241
+
242
+ migration = Class.new(ActiveRecord::Migration) {
243
+ def version; 100 end
244
+ def migrate(x)
245
+ add_column "people", "last_name", :string
246
+ raise 'Something broke'
247
+ end
248
+ }.new
249
+
250
+ migrator = ActiveRecord::Migrator.new(:up, [migration], 100)
251
+
252
+ e = assert_raise(StandardError) { migrator.migrate }
253
+
254
+ assert_equal "An error has occurred, this and all later migrations canceled:\n\nSomething broke", e.message
255
+
256
+ Person.reset_column_information
257
+ assert_not Person.column_methods_hash.include?(:last_name),
258
+ "On error, the Migrator should revert schema changes but it did not."
259
+ end
260
+
261
+ def test_migrator_one_up_with_exception_and_rollback_using_run
262
+ unless ActiveRecord::Base.connection.supports_ddl_transactions?
263
+ skip "not supported on #{ActiveRecord::Base.connection.class}"
264
+ end
265
+
266
+ assert_not Person.column_methods_hash.include?(:last_name)
267
+
268
+ migration = Class.new(ActiveRecord::Migration) {
269
+ def version; 100 end
270
+ def migrate(x)
271
+ add_column "people", "last_name", :string
272
+ raise 'Something broke'
273
+ end
274
+ }.new
275
+
276
+ migrator = ActiveRecord::Migrator.new(:up, [migration], 100)
277
+
278
+ e = assert_raise(StandardError) { migrator.run }
279
+
280
+ assert_equal "An error has occurred, this migration was canceled:\n\nSomething broke", e.message
281
+
282
+ Person.reset_column_information
283
+ assert_not Person.column_methods_hash.include?(:last_name),
284
+ "On error, the Migrator should revert schema changes but it did not."
285
+ end
286
+
287
+ def test_migration_without_transaction
288
+ unless ActiveRecord::Base.connection.supports_ddl_transactions?
289
+ skip "not supported on #{ActiveRecord::Base.connection.class}"
290
+ end
291
+
292
+ assert_not Person.column_methods_hash.include?(:last_name)
293
+
294
+ migration = Class.new(ActiveRecord::Migration) {
295
+ self.disable_ddl_transaction!
296
+
297
+ def version; 101 end
298
+ def migrate(x)
299
+ add_column "people", "last_name", :string
300
+ raise 'Something broke'
301
+ end
302
+ }.new
303
+
304
+ migrator = ActiveRecord::Migrator.new(:up, [migration], 101)
305
+ e = assert_raise(StandardError) { migrator.migrate }
306
+ assert_equal "An error has occurred, all later migrations canceled:\n\nSomething broke", e.message
307
+
308
+ Person.reset_column_information
309
+ assert Person.column_methods_hash.include?(:last_name),
310
+ "without ddl transactions, the Migrator should not rollback on error but it did."
311
+ ensure
312
+ Person.reset_column_information
313
+ if Person.column_methods_hash.include?(:last_name)
314
+ Person.connection.remove_column('people', 'last_name')
315
+ end
316
+ end
317
+
318
+ def test_schema_migrations_table_name
319
+ ActiveRecord::Base.table_name_prefix = "prefix_"
320
+ ActiveRecord::Base.table_name_suffix = "_suffix"
321
+ Reminder.reset_table_name
322
+ assert_equal "prefix_schema_migrations_suffix", ActiveRecord::Migrator.schema_migrations_table_name
323
+ ActiveRecord::Base.table_name_prefix = ""
324
+ ActiveRecord::Base.table_name_suffix = ""
325
+ Reminder.reset_table_name
326
+ assert_equal "schema_migrations", ActiveRecord::Migrator.schema_migrations_table_name
327
+ end
328
+
329
+ def test_proper_table_name
330
+ assert_equal "table", ActiveRecord::Migrator.proper_table_name('table')
331
+ assert_equal "table", ActiveRecord::Migrator.proper_table_name(:table)
332
+ assert_equal "reminders", ActiveRecord::Migrator.proper_table_name(Reminder)
333
+ Reminder.reset_table_name
334
+ assert_equal Reminder.table_name, ActiveRecord::Migrator.proper_table_name(Reminder)
335
+
336
+ # Use the model's own prefix/suffix if a model is given
337
+ ActiveRecord::Base.table_name_prefix = "ARprefix_"
338
+ ActiveRecord::Base.table_name_suffix = "_ARsuffix"
339
+ Reminder.table_name_prefix = 'prefix_'
340
+ Reminder.table_name_suffix = '_suffix'
341
+ Reminder.reset_table_name
342
+ assert_equal "prefix_reminders_suffix", ActiveRecord::Migrator.proper_table_name(Reminder)
343
+ Reminder.table_name_prefix = ''
344
+ Reminder.table_name_suffix = ''
345
+ Reminder.reset_table_name
346
+
347
+ # Use AR::Base's prefix/suffix if string or symbol is given
348
+ ActiveRecord::Base.table_name_prefix = "prefix_"
349
+ ActiveRecord::Base.table_name_suffix = "_suffix"
350
+ Reminder.reset_table_name
351
+ assert_equal "prefix_table_suffix", ActiveRecord::Migrator.proper_table_name('table')
352
+ assert_equal "prefix_table_suffix", ActiveRecord::Migrator.proper_table_name(:table)
353
+ end
354
+
355
+ def test_rename_table_with_prefix_and_suffix
356
+ assert !Thing.table_exists?
357
+ ActiveRecord::Base.table_name_prefix = 'p_'
358
+ ActiveRecord::Base.table_name_suffix = '_s'
359
+ Thing.reset_table_name
360
+ Thing.reset_sequence_name
361
+ WeNeedThings.up
362
+
363
+ assert Thing.create("content" => "hello world")
364
+ assert_equal "hello world", Thing.first.content
365
+
366
+ RenameThings.up
367
+ Thing.table_name = "p_awesome_things_s"
368
+
369
+ assert_equal "hello world", Thing.first.content
370
+ ensure
371
+ Thing.reset_table_name
372
+ Thing.reset_sequence_name
373
+ end
374
+
375
+ def test_add_drop_table_with_prefix_and_suffix
376
+ assert !Reminder.table_exists?
377
+ ActiveRecord::Base.table_name_prefix = 'prefix_'
378
+ ActiveRecord::Base.table_name_suffix = '_suffix'
379
+ Reminder.reset_table_name
380
+ Reminder.reset_sequence_name
381
+ WeNeedReminders.up
382
+ assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
383
+ assert_equal "hello world", Reminder.first.content
384
+
385
+ WeNeedReminders.down
386
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
387
+ ensure
388
+ Reminder.reset_sequence_name
389
+ end
390
+
391
+ def test_create_table_with_binary_column
392
+ Person.connection.drop_table :binary_testings rescue nil
393
+
394
+ assert_nothing_raised {
395
+ Person.connection.create_table :binary_testings do |t|
396
+ t.column "data", :binary, :null => false
397
+ end
398
+ }
399
+
400
+ columns = Person.connection.columns(:binary_testings)
401
+ data_column = columns.detect { |c| c.name == "data" }
402
+
403
+ assert_nil data_column.default
404
+
405
+ Person.connection.drop_table :binary_testings rescue nil
406
+ end
407
+
408
+ def test_create_table_with_custom_sequence_name
409
+ skip "not supported" unless current_adapter? :OracleAdapter
410
+
411
+ # table name is 29 chars, the standard sequence name will
412
+ # be 33 chars and should be shortened
413
+ assert_nothing_raised do
414
+ begin
415
+ Person.connection.create_table :table_with_name_thats_just_ok do |t|
416
+ t.column :foo, :string, :null => false
417
+ end
418
+ ensure
419
+ Person.connection.drop_table :table_with_name_thats_just_ok rescue nil
420
+ end
421
+ end
422
+
423
+ # should be all good w/ a custom sequence name
424
+ assert_nothing_raised do
425
+ begin
426
+ Person.connection.create_table :table_with_name_thats_just_ok,
427
+ :sequence_name => 'suitably_short_seq' do |t|
428
+ t.column :foo, :string, :null => false
429
+ end
430
+
431
+ Person.connection.execute("select suitably_short_seq.nextval from dual")
432
+
433
+ ensure
434
+ Person.connection.drop_table :table_with_name_thats_just_ok,
435
+ :sequence_name => 'suitably_short_seq' rescue nil
436
+ end
437
+ end
438
+
439
+ # confirm the custom sequence got dropped
440
+ assert_raise(ActiveRecord::StatementInvalid) do
441
+ Person.connection.execute("select suitably_short_seq.nextval from dual")
442
+ end
443
+ end
444
+
445
+ def test_out_of_range_limit_should_raise
446
+ skip("MySQL and PostgreSQL only") unless current_adapter?(:MysqlAdapter, :Mysql2Adapter, :PostgreSQLAdapter)
447
+
448
+ Person.connection.drop_table :test_limits rescue nil
449
+ assert_raise(ActiveRecord::ActiveRecordError, "integer limit didn't raise") do
450
+ Person.connection.create_table :test_integer_limits, :force => true do |t|
451
+ t.column :bigone, :integer, :limit => 10
452
+ end
453
+ end
454
+
455
+ unless current_adapter?(:PostgreSQLAdapter)
456
+ assert_raise(ActiveRecord::ActiveRecordError, "text limit didn't raise") do
457
+ Person.connection.create_table :test_text_limits, :force => true do |t|
458
+ t.column :bigtext, :text, :limit => 0xfffffffff
459
+ end
460
+ end
461
+ end
462
+
463
+ Person.connection.drop_table :test_limits rescue nil
464
+ end
465
+
466
+ protected
467
+ def with_env_tz(new_tz = 'US/Eastern')
468
+ old_tz, ENV['TZ'] = ENV['TZ'], new_tz
469
+ yield
470
+ ensure
471
+ old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
472
+ end
473
+ end
474
+
475
+ class ReservedWordsMigrationTest < ActiveRecord::TestCase
476
+ def test_drop_index_from_table_named_values
477
+ connection = Person.connection
478
+ connection.create_table :values, :force => true do |t|
479
+ t.integer :value
480
+ end
481
+
482
+ assert_nothing_raised do
483
+ connection.add_index :values, :value
484
+ connection.remove_index :values, :column => :value
485
+ end
486
+
487
+ connection.drop_table :values rescue nil
488
+ end
489
+ end
490
+
491
+ class ExplicitlyNamedIndexMigrationTest < ActiveRecord::TestCase
492
+ def test_drop_index_by_name
493
+ connection = Person.connection
494
+ connection.create_table :values, force: true do |t|
495
+ t.integer :value
496
+ end
497
+
498
+ assert_nothing_raised ArgumentError do
499
+ connection.add_index :values, :value, name: 'a_different_name'
500
+ connection.remove_index :values, column: :value, name: 'a_different_name'
501
+ end
502
+
503
+ connection.drop_table :values rescue nil
504
+ end
505
+ end
506
+
507
+ if ActiveRecord::Base.connection.supports_bulk_alter?
508
+ class BulkAlterTableMigrationsTest < ActiveRecord::TestCase
509
+ def setup
510
+ @connection = Person.connection
511
+ @connection.create_table(:delete_me, :force => true) {|t| }
512
+ Person.reset_column_information
513
+ Person.reset_sequence_name
514
+ end
515
+
516
+ def teardown
517
+ Person.connection.drop_table(:delete_me) rescue nil
518
+ end
519
+
520
+ def test_adding_multiple_columns
521
+ assert_queries(1) do
522
+ with_bulk_change_table do |t|
523
+ t.column :name, :string
524
+ t.string :qualification, :experience
525
+ t.integer :age, :default => 0
526
+ t.date :birthdate
527
+ t.timestamps
528
+ end
529
+ end
530
+
531
+ assert_equal 8, columns.size
532
+ [:name, :qualification, :experience].each {|s| assert_equal :string, column(s).type }
533
+ assert_equal 0, column(:age).default
534
+ end
535
+
536
+ def test_removing_columns
537
+ with_bulk_change_table do |t|
538
+ t.string :qualification, :experience
539
+ end
540
+
541
+ [:qualification, :experience].each {|c| assert column(c) }
542
+
543
+ assert_queries(1) do
544
+ with_bulk_change_table do |t|
545
+ t.remove :qualification, :experience
546
+ t.string :qualification_experience
547
+ end
548
+ end
549
+
550
+ [:qualification, :experience].each {|c| assert ! column(c) }
551
+ assert column(:qualification_experience)
552
+ end
553
+
554
+ def test_adding_indexes
555
+ with_bulk_change_table do |t|
556
+ t.string :username
557
+ t.string :name
558
+ t.integer :age
559
+ end
560
+
561
+ # Adding an index fires a query every time to check if an index already exists or not
562
+ assert_queries(3) do
563
+ with_bulk_change_table do |t|
564
+ t.index :username, :unique => true, :name => :awesome_username_index
565
+ t.index [:name, :age]
566
+ end
567
+ end
568
+
569
+ assert_equal 2, indexes.size
570
+
571
+ name_age_index = index(:index_delete_me_on_name_and_age)
572
+ assert_equal ['name', 'age'].sort, name_age_index.columns.sort
573
+ assert ! name_age_index.unique
574
+
575
+ assert index(:awesome_username_index).unique
576
+ end
577
+
578
+ def test_removing_index
579
+ with_bulk_change_table do |t|
580
+ t.string :name
581
+ t.index :name
582
+ end
583
+
584
+ assert index(:index_delete_me_on_name)
585
+
586
+ assert_queries(3) do
587
+ with_bulk_change_table do |t|
588
+ t.remove_index :name
589
+ t.index :name, :name => :new_name_index, :unique => true
590
+ end
591
+ end
592
+
593
+ assert ! index(:index_delete_me_on_name)
594
+
595
+ new_name_index = index(:new_name_index)
596
+ assert new_name_index.unique
597
+ end
598
+
599
+ def test_changing_columns
600
+ with_bulk_change_table do |t|
601
+ t.string :name
602
+ t.date :birthdate
603
+ end
604
+
605
+ assert ! column(:name).default
606
+ assert_equal :date, column(:birthdate).type
607
+
608
+ # One query for columns (delete_me table)
609
+ # One query for primary key (delete_me table)
610
+ # One query to do the bulk change
611
+ assert_queries(3, :ignore_none => true) do
612
+ with_bulk_change_table do |t|
613
+ t.change :name, :string, :default => 'NONAME'
614
+ t.change :birthdate, :datetime
615
+ end
616
+ end
617
+
618
+ assert_equal 'NONAME', column(:name).default
619
+ assert_equal :datetime, column(:birthdate).type
620
+ end
621
+
622
+ protected
623
+
624
+ def with_bulk_change_table
625
+ # Reset columns/indexes cache as we're changing the table
626
+ @columns = @indexes = nil
627
+
628
+ Person.connection.change_table(:delete_me, :bulk => true) do |t|
629
+ yield t
630
+ end
631
+ end
632
+
633
+ def column(name)
634
+ columns.detect {|c| c.name == name.to_s }
635
+ end
636
+
637
+ def columns
638
+ @columns ||= Person.connection.columns('delete_me')
639
+ end
640
+
641
+ def index(name)
642
+ indexes.detect {|i| i.name == name.to_s }
643
+ end
644
+
645
+ def indexes
646
+ @indexes ||= Person.connection.indexes('delete_me')
647
+ end
648
+ end # AlterTableMigrationsTest
649
+
650
+ end
651
+
652
+ class CopyMigrationsTest < ActiveRecord::TestCase
653
+ def setup
654
+ end
655
+
656
+ def clear
657
+ ActiveRecord::Base.timestamped_migrations = true
658
+ to_delete = Dir[@migrations_path + "/*.rb"] - @existing_migrations
659
+ File.delete(*to_delete)
660
+ end
661
+
662
+ def test_copying_migrations_without_timestamps
663
+ ActiveRecord::Base.timestamped_migrations = false
664
+ @migrations_path = MIGRATIONS_ROOT + "/valid"
665
+ @existing_migrations = Dir[@migrations_path + "/*.rb"]
666
+
667
+ copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"})
668
+ assert File.exists?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
669
+ assert File.exists?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
670
+ assert_equal [@migrations_path + "/4_people_have_hobbies.bukkits.rb", @migrations_path + "/5_people_have_descriptions.bukkits.rb"], copied.map(&:filename)
671
+
672
+ expected = "# This migration comes from bukkits (originally 1)"
673
+ assert_equal expected, IO.readlines(@migrations_path + "/4_people_have_hobbies.bukkits.rb")[0].chomp
674
+
675
+ files_count = Dir[@migrations_path + "/*.rb"].length
676
+ copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"})
677
+ assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
678
+ assert copied.empty?
679
+ ensure
680
+ clear
681
+ end
682
+
683
+ def test_copying_migrations_without_timestamps_from_2_sources
684
+ ActiveRecord::Base.timestamped_migrations = false
685
+ @migrations_path = MIGRATIONS_ROOT + "/valid"
686
+ @existing_migrations = Dir[@migrations_path + "/*.rb"]
687
+
688
+ sources = {}
689
+ sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy"
690
+ sources[:omg] = MIGRATIONS_ROOT + "/to_copy2"
691
+ ActiveRecord::Migration.copy(@migrations_path, sources)
692
+ assert File.exists?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
693
+ assert File.exists?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
694
+ assert File.exists?(@migrations_path + "/6_create_articles.omg.rb")
695
+ assert File.exists?(@migrations_path + "/7_create_comments.omg.rb")
696
+
697
+ files_count = Dir[@migrations_path + "/*.rb"].length
698
+ ActiveRecord::Migration.copy(@migrations_path, sources)
699
+ assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
700
+ ensure
701
+ clear
702
+ end
703
+
704
+ def test_copying_migrations_with_timestamps
705
+ @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
706
+ @existing_migrations = Dir[@migrations_path + "/*.rb"]
707
+
708
+ Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
709
+ copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
710
+ assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
711
+ assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
712
+ expected = [@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb",
713
+ @migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb"]
714
+ assert_equal expected, copied.map(&:filename)
715
+
716
+ files_count = Dir[@migrations_path + "/*.rb"].length
717
+ copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
718
+ assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
719
+ assert copied.empty?
720
+ end
721
+ ensure
722
+ clear
723
+ end
724
+
725
+ def test_copying_migrations_with_timestamps_from_2_sources
726
+ @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
727
+ @existing_migrations = Dir[@migrations_path + "/*.rb"]
728
+
729
+ sources = {}
730
+ sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
731
+ sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_timestamps2"
732
+
733
+ Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
734
+ copied = ActiveRecord::Migration.copy(@migrations_path, sources)
735
+ assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
736
+ assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
737
+ assert File.exists?(@migrations_path + "/20100726101012_create_articles.omg.rb")
738
+ assert File.exists?(@migrations_path + "/20100726101013_create_comments.omg.rb")
739
+ assert_equal 4, copied.length
740
+
741
+ files_count = Dir[@migrations_path + "/*.rb"].length
742
+ ActiveRecord::Migration.copy(@migrations_path, sources)
743
+ assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
744
+ end
745
+ ensure
746
+ clear
747
+ end
748
+
749
+ def test_copying_migrations_with_timestamps_to_destination_with_timestamps_in_future
750
+ @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
751
+ @existing_migrations = Dir[@migrations_path + "/*.rb"]
752
+
753
+ Time.travel_to(Time.utc(2010, 2, 20, 10, 10, 10)) do
754
+ ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
755
+ assert File.exists?(@migrations_path + "/20100301010102_people_have_hobbies.bukkits.rb")
756
+ assert File.exists?(@migrations_path + "/20100301010103_people_have_descriptions.bukkits.rb")
757
+
758
+ files_count = Dir[@migrations_path + "/*.rb"].length
759
+ copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
760
+ assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
761
+ assert copied.empty?
762
+ end
763
+ ensure
764
+ clear
765
+ end
766
+
767
+ def test_copying_migrations_preserving_magic_comments
768
+ ActiveRecord::Base.timestamped_migrations = false
769
+ @migrations_path = MIGRATIONS_ROOT + "/valid"
770
+ @existing_migrations = Dir[@migrations_path + "/*.rb"]
771
+
772
+ copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/magic"})
773
+ assert File.exists?(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")
774
+ assert_equal [@migrations_path + "/4_currencies_have_symbols.bukkits.rb"], copied.map(&:filename)
775
+
776
+ expected = "# coding: ISO-8859-15\n# This migration comes from bukkits (originally 1)"
777
+ assert_equal expected, IO.readlines(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")[0..1].join.chomp
778
+
779
+ files_count = Dir[@migrations_path + "/*.rb"].length
780
+ copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/magic"})
781
+ assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
782
+ assert copied.empty?
783
+ ensure
784
+ clear
785
+ end
786
+
787
+ def test_skipping_migrations
788
+ @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
789
+ @existing_migrations = Dir[@migrations_path + "/*.rb"]
790
+
791
+ sources = {}
792
+ sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
793
+ sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_name_collision"
794
+
795
+ skipped = []
796
+ on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
797
+ copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
798
+ assert_equal 2, copied.length
799
+
800
+ assert_equal 1, skipped.length
801
+ assert_equal ["omg PeopleHaveHobbies"], skipped
802
+ ensure
803
+ clear
804
+ end
805
+
806
+ def test_skip_is_not_called_if_migrations_are_from_the_same_plugin
807
+ @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
808
+ @existing_migrations = Dir[@migrations_path + "/*.rb"]
809
+
810
+ sources = {}
811
+ sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
812
+
813
+ skipped = []
814
+ on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
815
+ copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
816
+ ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
817
+
818
+ assert_equal 2, copied.length
819
+ assert_equal 0, skipped.length
820
+ ensure
821
+ clear
822
+ end
823
+
824
+ def test_copying_migrations_to_non_existing_directory
825
+ @migrations_path = MIGRATIONS_ROOT + "/non_existing"
826
+ @existing_migrations = []
827
+
828
+ Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
829
+ copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
830
+ assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
831
+ assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
832
+ assert_equal 2, copied.length
833
+ end
834
+ ensure
835
+ clear
836
+ Dir.delete(@migrations_path)
837
+ end
838
+
839
+ def test_copying_migrations_to_empty_directory
840
+ @migrations_path = MIGRATIONS_ROOT + "/empty"
841
+ @existing_migrations = []
842
+
843
+ Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
844
+ copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
845
+ assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
846
+ assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
847
+ assert_equal 2, copied.length
848
+ end
849
+ ensure
850
+ clear
851
+ end
852
+
853
+ def test_check_pending_with_stdlib_logger
854
+ old, ActiveRecord::Base.logger = ActiveRecord::Base.logger, ::Logger.new($stdout)
855
+ quietly do
856
+ assert_nothing_raised { ActiveRecord::Migration::CheckPending.new(Proc.new {}).call({}) }
857
+ end
858
+ ensure
859
+ ActiveRecord::Base.logger = old
860
+ end
861
+ end