ibm_db 3.0.0-x86-mingw32 → 3.0.1-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES +4 -0
- data/MANIFEST +14 -14
- data/README +225 -225
- data/ext/Makefile.nt32 +181 -181
- data/ext/Makefile.nt32.191 +212 -212
- data/ext/OLD/extconf.rb +264 -0
- data/ext/{extconf_MacOS.rb → OLD/extconf_MacOS.rb} +269 -269
- data/ext/extconf.rb +291 -264
- data/ext/ibm_db.c +2 -2
- data/ext/ruby_ibm_db.h +241 -241
- data/ext/ruby_ibm_db_cli.h +500 -500
- data/init.rb +41 -41
- data/lib/IBM_DB.rb +27 -27
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +4 -4
- data/lib/active_record/connection_adapters/ibmdb_adapter.rb +1 -1
- data/lib/active_record/vendor/db2-i5-zOS.yaml +328 -328
- data/lib/mswin32/ibm_db.rb +115 -115
- data/test/active_record/connection_adapters/fake_adapter.rb +46 -0
- data/test/assets/example.log +1 -0
- data/test/assets/flowers.jpg +0 -0
- data/test/assets/test.txt +1 -0
- data/test/cases/adapter_test.rb +261 -207
- data/test/cases/aggregations_test.rb +158 -0
- data/test/cases/ar_schema_test.rb +161 -0
- data/test/cases/associations/association_scope_test.rb +21 -0
- data/test/cases/associations/belongs_to_associations_test.rb +1029 -711
- data/test/cases/associations/callbacks_test.rb +192 -0
- data/test/cases/associations/cascaded_eager_loading_test.rb +188 -181
- data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +26 -0
- data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +36 -0
- data/test/cases/associations/eager_load_nested_include_test.rb +128 -0
- data/test/cases/associations/eager_singularization_test.rb +148 -0
- data/test/cases/associations/eager_test.rb +1411 -0
- data/test/cases/associations/extension_test.rb +82 -0
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +932 -851
- data/test/cases/associations/has_many_associations_test.rb +2162 -0
- data/test/cases/associations/has_many_through_associations_test.rb +1204 -0
- data/test/cases/associations/has_one_associations_test.rb +610 -0
- data/test/cases/associations/has_one_through_associations_test.rb +380 -0
- data/test/cases/associations/inner_join_association_test.rb +139 -0
- data/test/cases/associations/inverse_associations_test.rb +693 -0
- data/test/cases/associations/join_model_test.rb +754 -743
- data/test/cases/associations/nested_through_associations_test.rb +579 -0
- data/test/cases/associations/required_test.rb +82 -0
- data/test/cases/associations_test.rb +380 -0
- data/test/cases/attribute_decorators_test.rb +125 -0
- data/test/cases/attribute_methods/read_test.rb +60 -0
- data/test/cases/attribute_methods/serialization_test.rb +29 -0
- data/test/cases/attribute_methods_test.rb +952 -822
- data/test/cases/attribute_set_test.rb +200 -0
- data/test/cases/attribute_test.rb +180 -0
- data/test/cases/attributes_test.rb +136 -0
- data/test/cases/autosave_association_test.rb +1595 -0
- data/test/cases/base_test.rb +1638 -2133
- data/test/cases/batches_test.rb +212 -0
- data/test/cases/binary_test.rb +52 -0
- data/test/cases/bind_parameter_test.rb +100 -0
- data/test/cases/calculations_test.rb +646 -482
- data/test/cases/callbacks_test.rb +543 -0
- data/test/cases/clone_test.rb +40 -0
- data/test/cases/coders/yaml_column_test.rb +63 -0
- data/test/cases/column_alias_test.rb +17 -0
- data/test/cases/column_definition_test.rb +123 -0
- data/test/cases/connection_adapters/adapter_leasing_test.rb +54 -0
- data/test/cases/connection_adapters/connection_handler_test.rb +53 -0
- data/test/cases/connection_adapters/connection_specification_test.rb +12 -0
- data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +293 -0
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +65 -0
- data/test/cases/connection_adapters/quoting_test.rb +13 -0
- data/test/cases/connection_adapters/schema_cache_test.rb +56 -0
- data/test/cases/connection_adapters/type_lookup_test.rb +110 -0
- data/test/cases/connection_management_test.rb +122 -0
- data/test/cases/connection_pool_test.rb +346 -0
- data/test/cases/connection_specification/resolver_test.rb +116 -0
- data/test/cases/core_test.rb +112 -0
- data/test/cases/counter_cache_test.rb +209 -0
- data/test/cases/custom_locking_test.rb +17 -0
- data/test/cases/database_statements_test.rb +19 -0
- data/test/cases/date_time_test.rb +61 -0
- data/test/cases/defaults_test.rb +223 -0
- data/test/cases/dirty_test.rb +775 -0
- data/test/cases/disconnected_test.rb +28 -0
- data/test/cases/dup_test.rb +157 -0
- data/test/cases/enum_test.rb +290 -0
- data/test/cases/explain_subscriber_test.rb +64 -0
- data/test/cases/explain_test.rb +76 -0
- data/test/cases/finder_respond_to_test.rb +60 -0
- data/test/cases/finder_test.rb +1166 -0
- data/test/cases/fixture_set/file_test.rb +138 -0
- data/test/cases/fixtures_test.rb +897 -0
- data/test/cases/forbidden_attributes_protection_test.rb +99 -0
- data/test/cases/habtm_destroy_order_test.rb +61 -0
- data/test/cases/helper.rb +210 -0
- data/test/cases/hot_compatibility_test.rb +54 -0
- data/test/cases/i18n_test.rb +45 -0
- data/test/cases/inheritance_test.rb +375 -0
- data/test/cases/integration_test.rb +139 -0
- data/test/cases/invalid_connection_test.rb +22 -0
- data/test/cases/invalid_date_test.rb +32 -0
- data/test/cases/invertible_migration_test.rb +295 -0
- data/test/cases/json_serialization_test.rb +302 -0
- data/test/cases/locking_test.rb +477 -0
- data/test/cases/log_subscriber_test.rb +136 -0
- data/test/cases/migration/change_schema_test - Copy.rb +448 -0
- data/test/cases/migration/change_schema_test.rb +472 -0
- data/test/cases/migration/change_table_test.rb +224 -0
- data/test/cases/migration/column_attributes_test.rb +192 -0
- data/test/cases/migration/column_positioning_test.rb +56 -0
- data/test/cases/migration/columns_test.rb +304 -0
- data/test/cases/migration/command_recorder_test.rb +305 -0
- data/test/cases/migration/create_join_table_test.rb +148 -0
- data/test/cases/migration/foreign_key_test - Changed.rb +325 -0
- data/test/cases/migration/foreign_key_test.rb +360 -0
- data/test/cases/migration/helper.rb +39 -0
- data/test/cases/migration/index_test.rb +216 -0
- data/test/cases/migration/logger_test.rb +36 -0
- data/test/cases/migration/pending_migrations_test.rb +53 -0
- data/test/cases/migration/references_foreign_key_test.rb +214 -0
- data/test/cases/migration/references_index_test.rb +101 -0
- data/test/cases/migration/references_statements_test.rb +116 -0
- data/test/cases/migration/rename_table_test.rb +93 -0
- data/test/cases/migration/table_and_index_test.rb +24 -0
- data/test/cases/migration_test.rb +959 -2408
- data/test/cases/migrator_test.rb +388 -0
- data/test/cases/mixin_test.rb +70 -0
- data/test/cases/modules_test.rb +173 -0
- data/test/cases/multiparameter_attributes_test.rb +350 -0
- data/test/cases/multiple_db_test.rb +115 -0
- data/test/cases/nested_attributes_test.rb +1057 -0
- data/test/cases/nested_attributes_with_callbacks_test.rb +144 -0
- data/test/cases/persistence_test.rb +909 -642
- data/test/cases/pooled_connections_test.rb +81 -0
- data/test/cases/primary_keys_test.rb +237 -0
- data/test/cases/query_cache_test.rb +326 -257
- data/test/cases/quoting_test.rb +156 -0
- data/test/cases/readonly_test.rb +118 -0
- data/test/cases/reaper_test.rb +85 -0
- data/test/cases/reflection_test.rb +454 -0
- data/test/cases/relation/delegation_test.rb +68 -0
- data/test/cases/relation/merging_test.rb +161 -0
- data/test/cases/relation/mutation_test.rb +165 -0
- data/test/cases/relation/predicate_builder_test.rb +14 -0
- data/test/cases/relation/where_chain_test.rb +181 -0
- data/test/cases/relation/where_test.rb +300 -0
- data/test/cases/relation/where_test2.rb +36 -0
- data/test/cases/relation_test.rb +297 -0
- data/test/cases/relations_test.rb +1815 -1182
- data/test/cases/reload_models_test.rb +22 -0
- data/test/cases/result_test.rb +80 -0
- data/test/cases/sanitize_test.rb +83 -0
- data/test/cases/schema_dumper_test.rb +463 -256
- data/test/cases/scoping/default_scoping_test.rb +454 -0
- data/test/cases/scoping/named_scoping_test.rb +524 -0
- data/test/cases/scoping/relation_scoping_test.rb +357 -0
- data/test/cases/serialization_test.rb +104 -0
- data/test/cases/serialized_attribute_test.rb +277 -0
- data/test/cases/statement_cache_test.rb +98 -0
- data/test/cases/store_test.rb +194 -0
- data/test/cases/tasks/database_tasks_test.rb +396 -0
- data/test/cases/tasks/mysql_rake_test.rb +311 -0
- data/test/cases/tasks/postgresql_rake_test.rb +245 -0
- data/test/cases/tasks/sqlite_rake_test.rb +193 -0
- data/test/cases/test_case.rb +123 -0
- data/test/cases/timestamp_test.rb +468 -0
- data/test/cases/transaction_callbacks_test.rb +452 -300
- data/test/cases/transaction_isolation_test.rb +106 -0
- data/test/cases/transactions_test.rb +817 -0
- data/test/cases/type/decimal_test.rb +51 -0
- data/test/cases/type/integer_test.rb +121 -0
- data/test/cases/type/string_test.rb +36 -0
- data/test/cases/type/type_map_test.rb +177 -0
- data/test/cases/type/unsigned_integer_test.rb +18 -0
- data/test/cases/types_test.rb +141 -0
- data/test/cases/unconnected_test.rb +33 -0
- data/test/cases/validations/association_validation_test.rb +86 -0
- data/test/cases/validations/i18n_generate_message_validation_test.rb +84 -0
- data/test/cases/validations/i18n_validation_test.rb +90 -0
- data/test/cases/validations/length_validation_test.rb +47 -0
- data/test/cases/validations/presence_validation_test.rb +68 -0
- data/test/cases/validations/uniqueness_validation_test.rb +434 -299
- data/test/cases/validations_repair_helper.rb +23 -0
- data/test/cases/validations_test.rb +165 -0
- data/test/cases/view_test.rb +113 -0
- data/test/cases/xml_serialization_test.rb +457 -408
- data/test/cases/yaml_serialization_test.rb +86 -0
- data/test/config.rb +5 -0
- data/test/config.yml +154 -154
- data/test/connections/native_ibm_db/connection.rb +43 -43
- data/test/fixtures/accounts.yml +29 -0
- data/test/fixtures/admin/accounts.yml +2 -0
- data/test/fixtures/admin/randomly_named_a9.yml +7 -0
- data/test/fixtures/admin/randomly_named_b0.yml +7 -0
- data/test/fixtures/admin/users.yml +10 -0
- data/test/fixtures/all/admin +1 -0
- data/test/fixtures/all/developers.yml +0 -0
- data/test/fixtures/all/people.yml +0 -0
- data/test/fixtures/all/tasks.yml +0 -0
- data/test/fixtures/author_addresses.yml +18 -0
- data/test/fixtures/author_favorites.yml +4 -0
- data/test/fixtures/authors.yml +23 -0
- data/test/fixtures/binaries.yml +133 -0
- data/test/fixtures/books.yml +11 -0
- data/test/fixtures/bulbs.yml +5 -0
- data/test/fixtures/cars.yml +9 -0
- data/test/fixtures/categories.yml +19 -0
- data/test/fixtures/categories/special_categories.yml +9 -0
- data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
- data/test/fixtures/categories_ordered.yml +7 -0
- data/test/fixtures/categories_posts.yml +31 -0
- data/test/fixtures/categorizations.yml +23 -0
- data/test/fixtures/clubs.yml +8 -0
- data/test/fixtures/collections.yml +3 -0
- data/test/fixtures/colleges.yml +3 -0
- data/test/fixtures/comments.yml +65 -0
- data/test/fixtures/companies.yml +67 -0
- data/test/fixtures/computers.yml +10 -0
- data/test/fixtures/courses.yml +8 -0
- data/test/fixtures/customers.yml +26 -0
- data/test/fixtures/dashboards.yml +6 -0
- data/test/fixtures/developers.yml +22 -0
- data/test/fixtures/developers_projects.yml +17 -0
- data/test/fixtures/dog_lovers.yml +7 -0
- data/test/fixtures/dogs.yml +4 -0
- data/test/fixtures/doubloons.yml +3 -0
- data/test/fixtures/edges.yml +5 -0
- data/test/fixtures/entrants.yml +14 -0
- data/test/fixtures/essays.yml +6 -0
- data/test/fixtures/faces.yml +11 -0
- data/test/fixtures/fk_test_has_fk.yml +3 -0
- data/test/fixtures/fk_test_has_pk.yml +2 -0
- data/test/fixtures/friendships.yml +4 -0
- data/test/fixtures/funny_jokes.yml +10 -0
- data/test/fixtures/interests.yml +33 -0
- data/test/fixtures/items.yml +3 -0
- data/test/fixtures/jobs.yml +7 -0
- data/test/fixtures/legacy_things.yml +3 -0
- data/test/fixtures/mateys.yml +4 -0
- data/test/fixtures/member_details.yml +8 -0
- data/test/fixtures/member_types.yml +6 -0
- data/test/fixtures/members.yml +11 -0
- data/test/fixtures/memberships.yml +34 -0
- data/test/fixtures/men.yml +5 -0
- data/test/fixtures/minimalistics.yml +2 -0
- data/test/fixtures/minivans.yml +5 -0
- data/test/fixtures/mixed_case_monkeys.yml +6 -0
- data/test/fixtures/mixins.yml +29 -0
- data/test/fixtures/movies.yml +7 -0
- data/test/fixtures/naked/csv/accounts.csv +1 -0
- data/test/fixtures/naked/yml/accounts.yml +1 -0
- data/test/fixtures/naked/yml/companies.yml +1 -0
- data/test/fixtures/naked/yml/courses.yml +1 -0
- data/test/fixtures/organizations.yml +5 -0
- data/test/fixtures/other_topics.yml +42 -0
- data/test/fixtures/owners.yml +9 -0
- data/test/fixtures/parrots.yml +27 -0
- data/test/fixtures/parrots_pirates.yml +7 -0
- data/test/fixtures/people.yml +24 -0
- data/test/fixtures/peoples_treasures.yml +3 -0
- data/test/fixtures/pets.yml +19 -0
- data/test/fixtures/pirates.yml +12 -0
- data/test/fixtures/posts.yml +80 -0
- data/test/fixtures/price_estimates.yml +7 -0
- data/test/fixtures/products.yml +4 -0
- data/test/fixtures/projects.yml +7 -0
- data/test/fixtures/randomly_named_a9.yml +7 -0
- data/test/fixtures/ratings.yml +14 -0
- data/test/fixtures/readers.yml +11 -0
- data/test/fixtures/references.yml +17 -0
- data/test/fixtures/reserved_words/distinct.yml +5 -0
- data/test/fixtures/reserved_words/distinct_select.yml +11 -0
- data/test/fixtures/reserved_words/group.yml +14 -0
- data/test/fixtures/reserved_words/select.yml +8 -0
- data/test/fixtures/reserved_words/values.yml +7 -0
- data/test/fixtures/ships.yml +6 -0
- data/test/fixtures/speedometers.yml +8 -0
- data/test/fixtures/sponsors.yml +12 -0
- data/test/fixtures/string_key_objects.yml +7 -0
- data/test/fixtures/subscribers.yml +11 -0
- data/test/fixtures/subscriptions.yml +12 -0
- data/test/fixtures/taggings.yml +78 -0
- data/test/fixtures/tags.yml +11 -0
- data/test/fixtures/tasks.yml +7 -0
- data/test/fixtures/teapots.yml +3 -0
- data/test/fixtures/to_be_linked/accounts.yml +2 -0
- data/test/fixtures/to_be_linked/users.yml +10 -0
- data/test/fixtures/topics.yml +49 -0
- data/test/fixtures/toys.yml +14 -0
- data/test/fixtures/traffic_lights.yml +10 -0
- data/test/fixtures/treasures.yml +10 -0
- data/test/fixtures/uuid_children.yml +3 -0
- data/test/fixtures/uuid_parents.yml +2 -0
- data/test/fixtures/variants.yml +4 -0
- data/test/fixtures/vegetables.yml +20 -0
- data/test/fixtures/vertices.yml +4 -0
- data/test/fixtures/warehouse_things.yml +3 -0
- data/test/fixtures/zines.yml +5 -0
- data/test/ibm_db_test.rb +24 -24
- data/test/migrations/10_urban/9_add_expressions.rb +11 -0
- data/test/migrations/decimal/1_give_me_big_numbers.rb +15 -0
- data/test/migrations/magic/1_currencies_have_symbols.rb +12 -0
- data/test/migrations/missing/1000_people_have_middle_names.rb +9 -0
- data/test/migrations/missing/1_people_have_last_names.rb +9 -0
- data/test/migrations/missing/3_we_need_reminders.rb +12 -0
- data/test/migrations/missing/4_innocent_jointable.rb +12 -0
- data/test/migrations/rename/1_we_need_things.rb +11 -0
- data/test/migrations/rename/2_rename_things.rb +9 -0
- data/test/migrations/to_copy/1_people_have_hobbies.rb +9 -0
- data/test/migrations/to_copy/2_people_have_descriptions.rb +9 -0
- data/test/migrations/to_copy2/1_create_articles.rb +7 -0
- data/test/migrations/to_copy2/2_create_comments.rb +7 -0
- data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +9 -0
- data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +9 -0
- data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +9 -0
- data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +7 -0
- data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +7 -0
- data/test/migrations/valid/1_valid_people_have_last_names.rb +9 -0
- data/test/migrations/valid/2_we_need_reminders.rb +12 -0
- data/test/migrations/valid/3_innocent_jointable.rb +12 -0
- data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +9 -0
- data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +12 -0
- data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +12 -0
- data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +9 -0
- data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +12 -0
- data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +12 -0
- data/test/migrations/version_check/20131219224947_migration_version_check.rb +8 -0
- data/test/models/admin.rb +5 -0
- data/test/models/admin/account.rb +3 -0
- data/test/models/admin/randomly_named_c1.rb +3 -0
- data/test/models/admin/user.rb +40 -0
- data/test/models/aircraft.rb +4 -0
- data/test/models/arunit2_model.rb +3 -0
- data/test/models/author.rb +212 -0
- data/test/models/auto_id.rb +4 -0
- data/test/models/autoloadable/extra_firm.rb +2 -0
- data/test/models/binary.rb +2 -0
- data/test/models/bird.rb +12 -0
- data/test/models/book.rb +18 -0
- data/test/models/boolean.rb +2 -0
- data/test/models/bulb.rb +51 -0
- data/test/models/cake_designer.rb +3 -0
- data/test/models/car.rb +26 -0
- data/test/models/carrier.rb +2 -0
- data/test/models/categorization.rb +19 -0
- data/test/models/category.rb +35 -0
- data/test/models/chef.rb +3 -0
- data/test/models/citation.rb +3 -0
- data/test/models/club.rb +23 -0
- data/test/models/college.rb +10 -0
- data/test/models/column.rb +3 -0
- data/test/models/column_name.rb +3 -0
- data/test/models/comment.rb +64 -0
- data/test/models/company.rb +225 -0
- data/test/models/company_in_module.rb +98 -0
- data/test/models/computer.rb +3 -0
- data/test/models/contact.rb +41 -0
- data/test/models/contract.rb +20 -0
- data/test/models/country.rb +7 -0
- data/test/models/course.rb +6 -0
- data/test/models/customer.rb +77 -0
- data/test/models/customer_carrier.rb +14 -0
- data/test/models/dashboard.rb +3 -0
- data/test/models/default.rb +2 -0
- data/test/models/department.rb +4 -0
- data/test/models/developer.rb +252 -0
- data/test/models/dog.rb +5 -0
- data/test/models/dog_lover.rb +5 -0
- data/test/models/doubloon.rb +12 -0
- data/test/models/drink_designer.rb +3 -0
- data/test/models/edge.rb +5 -0
- data/test/models/electron.rb +5 -0
- data/test/models/engine.rb +4 -0
- data/test/models/entrant.rb +3 -0
- data/test/models/essay.rb +5 -0
- data/test/models/event.rb +3 -0
- data/test/models/eye.rb +37 -0
- data/test/models/face.rb +9 -0
- data/test/models/friendship.rb +6 -0
- data/test/models/guid.rb +2 -0
- data/test/models/hotel.rb +6 -0
- data/test/models/image.rb +3 -0
- data/test/models/interest.rb +5 -0
- data/test/models/invoice.rb +4 -0
- data/test/models/item.rb +7 -0
- data/test/models/job.rb +7 -0
- data/test/models/joke.rb +7 -0
- data/test/models/keyboard.rb +3 -0
- data/test/models/legacy_thing.rb +3 -0
- data/test/models/lesson.rb +11 -0
- data/test/models/line_item.rb +3 -0
- data/test/models/liquid.rb +4 -0
- data/test/models/man.rb +11 -0
- data/test/models/matey.rb +4 -0
- data/test/models/member.rb +41 -0
- data/test/models/member_detail.rb +7 -0
- data/test/models/member_type.rb +3 -0
- data/test/models/membership.rb +35 -0
- data/test/models/minimalistic.rb +2 -0
- data/test/models/minivan.rb +9 -0
- data/test/models/mixed_case_monkey.rb +3 -0
- data/test/models/molecule.rb +6 -0
- data/test/models/movie.rb +5 -0
- data/test/models/order.rb +4 -0
- data/test/models/organization.rb +14 -0
- data/test/models/owner.rb +34 -0
- data/test/models/parrot.rb +29 -0
- data/test/models/person.rb +143 -0
- data/test/models/personal_legacy_thing.rb +4 -0
- data/test/models/pet.rb +15 -0
- data/test/models/pirate.rb +92 -0
- data/test/models/possession.rb +3 -0
- data/test/models/post.rb +264 -0
- data/test/models/price_estimate.rb +4 -0
- data/test/models/professor.rb +5 -0
- data/test/models/project.rb +29 -0
- data/test/models/publisher.rb +2 -0
- data/test/models/publisher/article.rb +4 -0
- data/test/models/publisher/magazine.rb +3 -0
- data/test/models/randomly_named_c1.rb +3 -0
- data/test/models/rating.rb +4 -0
- data/test/models/reader.rb +23 -0
- data/test/models/record.rb +2 -0
- data/test/models/reference.rb +22 -0
- data/test/models/reply.rb +61 -0
- data/test/models/ship.rb +33 -0
- data/test/models/ship_part.rb +8 -0
- data/test/models/shop.rb +17 -0
- data/test/models/shop_account.rb +6 -0
- data/test/models/speedometer.rb +6 -0
- data/test/models/sponsor.rb +7 -0
- data/test/models/string_key_object.rb +3 -0
- data/test/models/student.rb +4 -0
- data/test/models/subject.rb +16 -0
- data/test/models/subscriber.rb +8 -0
- data/test/models/subscription.rb +4 -0
- data/test/models/tag.rb +7 -0
- data/test/models/tagging.rb +13 -0
- data/test/models/task.rb +5 -0
- data/test/models/topic.rb +124 -0
- data/test/models/toy.rb +6 -0
- data/test/models/traffic_light.rb +4 -0
- data/test/models/treasure.rb +14 -0
- data/test/models/treaty.rb +7 -0
- data/test/models/tyre.rb +11 -0
- data/test/models/uuid_child.rb +3 -0
- data/test/models/uuid_parent.rb +3 -0
- data/test/models/vegetables.rb +24 -0
- data/test/models/vehicle.rb +7 -0
- data/test/models/vertex.rb +9 -0
- data/test/models/warehouse_thing.rb +5 -5
- data/test/models/wheel.rb +3 -0
- data/test/models/without_table.rb +3 -0
- data/test/models/zine.rb +3 -0
- data/test/schema/mysql2_specific_schema.rb +58 -0
- data/test/schema/mysql_specific_schema.rb +70 -0
- data/test/schema/oracle_specific_schema.rb +43 -0
- data/test/schema/postgresql_specific_schema.rb +202 -0
- data/test/schema/schema.rb +938 -751
- data/test/schema/sqlite_specific_schema.rb +22 -0
- data/test/support/config.rb +43 -0
- data/test/support/connection.rb +22 -0
- data/test/support/connection_helper.rb +14 -0
- data/test/support/ddl_helper.rb +8 -0
- data/test/support/schema_dumping_helper.rb +20 -0
- metadata +444 -18
@@ -0,0 +1,93 @@
|
|
1
|
+
require "cases/migration/helper"
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class Migration
|
5
|
+
class RenameTableTest < ActiveRecord::TestCase
|
6
|
+
include ActiveRecord::Migration::TestHelper
|
7
|
+
|
8
|
+
self.use_transactional_fixtures = false
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
add_column 'test_models', :url, :string
|
13
|
+
remove_column 'test_models', :created_at
|
14
|
+
remove_column 'test_models', :updated_at
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
rename_table :octopi, :test_models if connection.table_exists? :octopi
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
if current_adapter?(:SQLite3Adapter)
|
23
|
+
def test_rename_table_for_sqlite_should_work_with_reserved_words
|
24
|
+
renamed = false
|
25
|
+
|
26
|
+
add_column :test_models, :url, :string
|
27
|
+
connection.rename_table :references, :old_references
|
28
|
+
connection.rename_table :test_models, :references
|
29
|
+
|
30
|
+
renamed = true
|
31
|
+
|
32
|
+
# Using explicit id in insert for compatibility across all databases
|
33
|
+
connection.execute "INSERT INTO 'references' (url, created_at, updated_at) VALUES ('http://rubyonrails.com', 0, 0)"
|
34
|
+
assert_equal 'http://rubyonrails.com', connection.select_value("SELECT url FROM 'references' WHERE id=1")
|
35
|
+
ensure
|
36
|
+
return unless renamed
|
37
|
+
connection.rename_table :references, :test_models
|
38
|
+
connection.rename_table :old_references, :references
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_rename_table
|
43
|
+
rename_table :test_models, :octopi
|
44
|
+
|
45
|
+
connection.execute "INSERT INTO octopi (#{connection.quote_column_name('id')}, #{connection.quote_column_name('url')}) VALUES (1, 'http://www.foreverflying.com/octopus-black7.jpg')"
|
46
|
+
|
47
|
+
assert_equal 'http://www.foreverflying.com/octopus-black7.jpg', connection.select_value("SELECT url FROM octopi WHERE id=1")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_rename_table_with_an_index
|
51
|
+
add_index :test_models, :url
|
52
|
+
|
53
|
+
rename_table :test_models, :octopi
|
54
|
+
|
55
|
+
connection.execute "INSERT INTO octopi (#{connection.quote_column_name('id')}, #{connection.quote_column_name('url')}) VALUES (1, 'http://www.foreverflying.com/octopus-black7.jpg')"
|
56
|
+
|
57
|
+
assert_equal 'http://www.foreverflying.com/octopus-black7.jpg', connection.select_value("SELECT url FROM octopi WHERE id=1")
|
58
|
+
index = connection.indexes(:octopi).first
|
59
|
+
assert index.columns.include?("url")
|
60
|
+
assert_equal 'index_octopi_on_url', index.name
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_rename_table_does_not_rename_custom_named_index
|
64
|
+
add_index :test_models, :url, name: 'special_url_idx'
|
65
|
+
|
66
|
+
rename_table :test_models, :octopi
|
67
|
+
|
68
|
+
assert_equal ['special_url_idx'], connection.indexes(:octopi).map(&:name)
|
69
|
+
end
|
70
|
+
|
71
|
+
if current_adapter?(:PostgreSQLAdapter)
|
72
|
+
def test_rename_table_for_postgresql_should_also_rename_default_sequence
|
73
|
+
rename_table :test_models, :octopi
|
74
|
+
|
75
|
+
pk, seq = connection.pk_and_sequence_for('octopi')
|
76
|
+
|
77
|
+
assert_equal ConnectionAdapters::PostgreSQL::Name.new("public", "octopi_#{pk}_seq"), seq
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_renaming_table_doesnt_attempt_to_rename_non_existent_sequences
|
81
|
+
enable_extension!('uuid-ossp', connection)
|
82
|
+
connection.create_table :cats, id: :uuid
|
83
|
+
assert_nothing_raised { rename_table :cats, :felines }
|
84
|
+
assert connection.table_exists? :felines
|
85
|
+
ensure
|
86
|
+
disable_extension!('uuid-ossp', connection)
|
87
|
+
connection.drop_table :cats if connection.table_exists? :cats
|
88
|
+
connection.drop_table :felines if connection.table_exists? :felines
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class Migration
|
5
|
+
class TableAndIndexTest < ActiveRecord::TestCase
|
6
|
+
def test_add_schema_info_respects_prefix_and_suffix
|
7
|
+
conn = ActiveRecord::Base.connection
|
8
|
+
|
9
|
+
conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
|
10
|
+
# Use shorter prefix and suffix as in Oracle database identifier cannot be larger than 30 characters
|
11
|
+
ActiveRecord::Base.table_name_prefix = 'p_'
|
12
|
+
ActiveRecord::Base.table_name_suffix = '_s'
|
13
|
+
conn.drop_table(ActiveRecord::Migrator.schema_migrations_table_name) if conn.table_exists?(ActiveRecord::Migrator.schema_migrations_table_name)
|
14
|
+
|
15
|
+
conn.initialize_schema_migrations_table
|
16
|
+
|
17
|
+
assert_equal "p_unique_schema_migrations_s", conn.indexes(ActiveRecord::Migrator.schema_migrations_table_name)[0][:name]
|
18
|
+
ensure
|
19
|
+
ActiveRecord::Base.table_name_prefix = ""
|
20
|
+
ActiveRecord::Base.table_name_suffix = ""
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,2408 +1,959 @@
|
|
1
|
-
require "cases/helper"
|
2
|
-
require
|
3
|
-
|
4
|
-
|
5
|
-
require 'models/
|
6
|
-
require 'models/
|
7
|
-
|
8
|
-
require
|
9
|
-
|
10
|
-
require MIGRATIONS_ROOT + "/
|
11
|
-
require MIGRATIONS_ROOT + "/
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
Person
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
assert_equal "
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
end
|
337
|
-
|
338
|
-
def
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
Person.connection.
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
end
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
end
|
961
|
-
ActiveRecord::Base.connection.rename_table :octopuses, :octopi
|
962
|
-
|
963
|
-
# Using explicit id in insert for compatibility across all databases
|
964
|
-
con = ActiveRecord::Base.connection
|
965
|
-
con.enable_identity_insert("octopi", true) if current_adapter?(:SybaseAdapter)
|
966
|
-
assert_nothing_raised { con.execute "INSERT INTO octopi (#{con.quote_column_name('id')}, #{con.quote_column_name('url')}) VALUES (1, 'http://www.foreverflying.com/octopus-black7.jpg')" }
|
967
|
-
con.enable_identity_insert("octopi", false) if current_adapter?(:SybaseAdapter)
|
968
|
-
|
969
|
-
assert_equal 'http://www.foreverflying.com/octopus-black7.jpg', ActiveRecord::Base.connection.select_value("SELECT url FROM octopi WHERE id=1")
|
970
|
-
|
971
|
-
ensure
|
972
|
-
ActiveRecord::Base.connection.drop_table :octopuses rescue nil
|
973
|
-
ActiveRecord::Base.connection.drop_table :octopi rescue nil
|
974
|
-
end
|
975
|
-
end
|
976
|
-
|
977
|
-
def test_change_column_nullability
|
978
|
-
Person.delete_all
|
979
|
-
Person.connection.add_column "people", "funny", :boolean
|
980
|
-
Person.reset_column_information
|
981
|
-
assert Person.columns_hash["funny"].null, "Column 'funny' must initially allow nulls"
|
982
|
-
unless current_adapter?(:IBM_DBAdapter)
|
983
|
-
Person.connection.change_column "people", "funny", :boolean, :null => false, :default => true
|
984
|
-
else
|
985
|
-
Person.connection.change_column_null "people", "funny",false
|
986
|
-
end
|
987
|
-
Person.reset_column_information
|
988
|
-
assert !Person.columns_hash["funny"].null, "Column 'funny' must *not* allow nulls at this point"
|
989
|
-
unless current_adapter?(:IBM_DBAdapter)
|
990
|
-
Person.connection.change_column "people", "funny", :boolean, :null => true
|
991
|
-
else
|
992
|
-
Person.connection.change_column_null "people", "funny",true
|
993
|
-
end
|
994
|
-
Person.reset_column_information
|
995
|
-
assert Person.columns_hash["funny"].null, "Column 'funny' must allow nulls again at this point"
|
996
|
-
end
|
997
|
-
|
998
|
-
def test_rename_table_with_an_index
|
999
|
-
begin
|
1000
|
-
ActiveRecord::Base.connection.create_table :octopuses do |t|
|
1001
|
-
t.column :url, :string
|
1002
|
-
end
|
1003
|
-
ActiveRecord::Base.connection.add_index :octopuses, :url
|
1004
|
-
|
1005
|
-
ActiveRecord::Base.connection.rename_table :octopuses, :octopi
|
1006
|
-
|
1007
|
-
# Using explicit id in insert for compatibility across all databases
|
1008
|
-
con = ActiveRecord::Base.connection
|
1009
|
-
con.enable_identity_insert("octopi", true) if current_adapter?(:SybaseAdapter)
|
1010
|
-
assert_nothing_raised { con.execute "INSERT INTO octopi (#{con.quote_column_name('id')}, #{con.quote_column_name('url')}) VALUES (1, 'http://www.foreverflying.com/octopus-black7.jpg')" }
|
1011
|
-
con.enable_identity_insert("octopi", false) if current_adapter?(:SybaseAdapter)
|
1012
|
-
|
1013
|
-
assert_equal 'http://www.foreverflying.com/octopus-black7.jpg', ActiveRecord::Base.connection.select_value("SELECT url FROM octopi WHERE id=1")
|
1014
|
-
assert ActiveRecord::Base.connection.indexes(:octopi).first.columns.include?("url")
|
1015
|
-
ensure
|
1016
|
-
ActiveRecord::Base.connection.drop_table :octopuses rescue nil
|
1017
|
-
ActiveRecord::Base.connection.drop_table :octopi rescue nil
|
1018
|
-
end
|
1019
|
-
end
|
1020
|
-
|
1021
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1022
|
-
# Cannot convert from type integer to varchar.
|
1023
|
-
# Safe to not run this test as add_column will be covered in other test cases
|
1024
|
-
def test_change_column
|
1025
|
-
Person.connection.add_column 'people', 'age', :integer
|
1026
|
-
label = "test_change_column Columns"
|
1027
|
-
old_columns = Person.connection.columns(Person.table_name, label)
|
1028
|
-
assert old_columns.find { |c| c.name == 'age' and c.type == :integer }
|
1029
|
-
|
1030
|
-
assert_nothing_raised { Person.connection.change_column "people", "age", :string }
|
1031
|
-
|
1032
|
-
new_columns = Person.connection.columns(Person.table_name, label)
|
1033
|
-
assert_nil new_columns.find { |c| c.name == 'age' and c.type == :integer }
|
1034
|
-
assert new_columns.find { |c| c.name == 'age' and c.type == :string }
|
1035
|
-
|
1036
|
-
old_columns = Topic.connection.columns(Topic.table_name, label)
|
1037
|
-
assert old_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true }
|
1038
|
-
assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => false }
|
1039
|
-
new_columns = Topic.connection.columns(Topic.table_name, label)
|
1040
|
-
assert_nil new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true }
|
1041
|
-
assert new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == false }
|
1042
|
-
assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => true }
|
1043
|
-
end
|
1044
|
-
end
|
1045
|
-
|
1046
|
-
def test_change_column_with_nil_default
|
1047
|
-
Person.connection.add_column "people", "contributor", :boolean, :default => true
|
1048
|
-
Person.reset_column_information
|
1049
|
-
assert Person.new.contributor?
|
1050
|
-
|
1051
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1052
|
-
assert_nothing_raised { Person.connection.change_column "people", "contributor", :boolean, :default => nil }
|
1053
|
-
else
|
1054
|
-
assert_nothing_raised { Person.connection.change_column_default "people", "contributor", nil }
|
1055
|
-
end
|
1056
|
-
Person.reset_column_information
|
1057
|
-
assert !Person.new.contributor?
|
1058
|
-
assert_nil Person.new.contributor
|
1059
|
-
ensure
|
1060
|
-
Person.connection.remove_column("people", "contributor") rescue nil
|
1061
|
-
end
|
1062
|
-
|
1063
|
-
def test_change_column_with_new_default
|
1064
|
-
Person.connection.add_column "people", "administrator", :boolean, :default => true
|
1065
|
-
Person.reset_column_information
|
1066
|
-
assert Person.new.administrator?
|
1067
|
-
|
1068
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1069
|
-
assert_nothing_raised { Person.connection.change_column "people", "administrator", :boolean, :default => false }
|
1070
|
-
else
|
1071
|
-
assert_nothing_raised { Person.connection.change_column_default "people", "administrator", false }
|
1072
|
-
end
|
1073
|
-
Person.reset_column_information
|
1074
|
-
assert !Person.new.administrator?
|
1075
|
-
ensure
|
1076
|
-
Person.connection.remove_column("people", "administrator") rescue nil
|
1077
|
-
end
|
1078
|
-
|
1079
|
-
def test_change_column_default
|
1080
|
-
Person.connection.change_column_default "people", "first_name", "Tester"
|
1081
|
-
Person.reset_column_information
|
1082
|
-
assert_equal "Tester", Person.new.first_name
|
1083
|
-
end
|
1084
|
-
|
1085
|
-
def test_change_column_quotes_column_names
|
1086
|
-
Person.connection.create_table :testings do |t|
|
1087
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1088
|
-
t.column :select, :string
|
1089
|
-
else
|
1090
|
-
# If no limit specified by default column of length 255 is created, which later cannot be scaled down to 10
|
1091
|
-
t.column :select, :string, :limit => 5
|
1092
|
-
end
|
1093
|
-
end
|
1094
|
-
|
1095
|
-
assert_nothing_raised { Person.connection.change_column :testings, :select, :string, :limit => 10 }
|
1096
|
-
|
1097
|
-
# Oracle needs primary key value from sequence
|
1098
|
-
if current_adapter?(:OracleAdapter)
|
1099
|
-
assert_nothing_raised { Person.connection.execute "insert into testings (id, #{Person.connection.quote_column_name('select')}) values (testings_seq.nextval, '7 chars')" }
|
1100
|
-
else
|
1101
|
-
assert_nothing_raised { Person.connection.execute "insert into testings (#{Person.connection.quote_column_name('select')}) values ('7 chars')" }
|
1102
|
-
end
|
1103
|
-
ensure
|
1104
|
-
Person.connection.drop_table :testings rescue nil
|
1105
|
-
end
|
1106
|
-
|
1107
|
-
def test_keeping_default_and_notnull_constaint_on_change
|
1108
|
-
Person.connection.create_table :testings do |t|
|
1109
|
-
t.column :title, :string
|
1110
|
-
end
|
1111
|
-
person_klass = Class.new(Person)
|
1112
|
-
person_klass.table_name = 'testings'
|
1113
|
-
|
1114
|
-
person_klass.connection.add_column "testings", "wealth", :integer, :null => false, :default => 99
|
1115
|
-
person_klass.reset_column_information
|
1116
|
-
assert_equal 99, person_klass.columns_hash["wealth"].default
|
1117
|
-
assert_equal false, person_klass.columns_hash["wealth"].null
|
1118
|
-
# Oracle needs primary key value from sequence
|
1119
|
-
if current_adapter?(:OracleAdapter)
|
1120
|
-
assert_nothing_raised {person_klass.connection.execute("insert into testings (id, title) values (testings_seq.nextval, 'tester')")}
|
1121
|
-
else
|
1122
|
-
assert_nothing_raised {person_klass.connection.execute("insert into testings (title) values ('tester')")}
|
1123
|
-
end
|
1124
|
-
|
1125
|
-
# change column default to see that column doesn't lose its not null definition
|
1126
|
-
person_klass.connection.change_column_default "testings", "wealth", 100
|
1127
|
-
person_klass.reset_column_information
|
1128
|
-
assert_equal 100, person_klass.columns_hash["wealth"].default
|
1129
|
-
assert_equal false, person_klass.columns_hash["wealth"].null
|
1130
|
-
|
1131
|
-
# rename column to see that column doesn't lose its not null and/or default definition
|
1132
|
-
if (!current_adapter?(:IBM_DBAdapter) || @ibm_db_rename_supported)
|
1133
|
-
person_klass.connection.rename_column "testings", "wealth", "money"
|
1134
|
-
person_klass.reset_column_information
|
1135
|
-
assert_nil person_klass.columns_hash["wealth"]
|
1136
|
-
assert_equal 100, person_klass.columns_hash["money"].default
|
1137
|
-
assert_equal false, person_klass.columns_hash["money"].null
|
1138
|
-
end
|
1139
|
-
|
1140
|
-
# change column
|
1141
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1142
|
-
person_klass.connection.change_column "testings", "money", :integer, :null => false, :default => 1000
|
1143
|
-
person_klass.reset_column_information
|
1144
|
-
assert_equal 1000, person_klass.columns_hash["money"].default
|
1145
|
-
assert_equal false, person_klass.columns_hash["money"].null
|
1146
|
-
else
|
1147
|
-
person_klass.connection.change_column "testings", "wealth", :decimal, :precision => 15, :scale => 1,:null => false, :default => 1000
|
1148
|
-
person_klass.reset_column_information
|
1149
|
-
assert_equal 1000, person_klass.columns_hash["wealth"].default
|
1150
|
-
assert_equal false, person_klass.columns_hash["wealth"].null
|
1151
|
-
end
|
1152
|
-
|
1153
|
-
# change column, make it nullable and clear default
|
1154
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1155
|
-
person_klass.connection.change_column "testings", "money", :integer, :null => true, :default => nil
|
1156
|
-
person_klass.reset_column_information
|
1157
|
-
assert_nil person_klass.columns_hash["money"].default
|
1158
|
-
assert_equal true, person_klass.columns_hash["money"].null
|
1159
|
-
else
|
1160
|
-
person_klass.connection.change_column "testings", "wealth", :decimal, :precision => 20, :scale => 2, :null => true, :default => nil
|
1161
|
-
person_klass.reset_column_information
|
1162
|
-
assert_nil person_klass.columns_hash["wealth"].default
|
1163
|
-
assert_equal true, person_klass.columns_hash["wealth"].null
|
1164
|
-
end
|
1165
|
-
|
1166
|
-
# change_column_null, make it not nullable and set null values to a default value
|
1167
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1168
|
-
person_klass.connection.execute('UPDATE testings SET money = NULL')
|
1169
|
-
person_klass.connection.change_column_null "testings", "money", false, 2000
|
1170
|
-
person_klass.reset_column_information
|
1171
|
-
assert_nil person_klass.columns_hash["money"].default
|
1172
|
-
assert_equal false, person_klass.columns_hash["money"].null
|
1173
|
-
assert_equal [2000], Person.connection.select_values("SELECT money FROM testings").map { |s| s.to_i }.sort
|
1174
|
-
else
|
1175
|
-
# Trying to set the value of the column wealth to NULL and
|
1176
|
-
# in the next statement a not null constraint is being applied which is wrong
|
1177
|
-
#person_klass.connection.execute('UPDATE testings SET money = NULL')
|
1178
|
-
person_klass.connection.change_column_null "testings", "wealth", false, 2000
|
1179
|
-
person_klass.reset_column_information
|
1180
|
-
#assert_nil person_klass.columns_hash["wealth"].default #Setting default to 2000 and expecting nil is nor correct
|
1181
|
-
assert_not_nil person_klass.columns_hash["wealth"].default
|
1182
|
-
assert_equal false, person_klass.columns_hash["wealth"].null
|
1183
|
-
#Changing default does not change the already inserted value. Hence expecting 2000 is wrong.
|
1184
|
-
assert_equal [99], Person.connection.select_values("SELECT wealth FROM testings").map { |s| s.to_i }.sort
|
1185
|
-
end
|
1186
|
-
ensure
|
1187
|
-
Person.connection.drop_table :testings rescue nil
|
1188
|
-
end
|
1189
|
-
|
1190
|
-
def test_change_column_default_to_null
|
1191
|
-
Person.connection.change_column_default "people", "first_name", nil
|
1192
|
-
Person.reset_column_information
|
1193
|
-
assert_nil Person.new.first_name
|
1194
|
-
end
|
1195
|
-
|
1196
|
-
def test_column_exists
|
1197
|
-
Person.connection.create_table :testings do |t|
|
1198
|
-
t.column :foo, :string
|
1199
|
-
end
|
1200
|
-
|
1201
|
-
assert Person.connection.column_exists?(:testings, :foo)
|
1202
|
-
assert !Person.connection.column_exists?(:testings, :bar)
|
1203
|
-
ensure
|
1204
|
-
Person.connection.drop_table :testings rescue nil
|
1205
|
-
end
|
1206
|
-
|
1207
|
-
def test_column_exists_with_type
|
1208
|
-
Person.connection.create_table :testings do |t|
|
1209
|
-
t.column :foo, :string
|
1210
|
-
t.column :bar, :decimal, :precision => 8, :scale => 2
|
1211
|
-
end
|
1212
|
-
|
1213
|
-
assert Person.connection.column_exists?(:testings, :foo, :string)
|
1214
|
-
assert !Person.connection.column_exists?(:testings, :foo, :integer)
|
1215
|
-
assert Person.connection.column_exists?(:testings, :bar, :decimal)
|
1216
|
-
assert !Person.connection.column_exists?(:testings, :bar, :integer)
|
1217
|
-
ensure
|
1218
|
-
Person.connection.drop_table :testings rescue nil
|
1219
|
-
end
|
1220
|
-
|
1221
|
-
def test_column_exists_with_definition
|
1222
|
-
Person.connection.create_table :testings do |t|
|
1223
|
-
t.column :foo, :string, :limit => 100
|
1224
|
-
t.column :bar, :decimal, :precision => 8, :scale => 2
|
1225
|
-
end
|
1226
|
-
|
1227
|
-
assert Person.connection.column_exists?(:testings, :foo, :string, :limit => 100)
|
1228
|
-
assert !Person.connection.column_exists?(:testings, :foo, :string, :limit => 50)
|
1229
|
-
assert Person.connection.column_exists?(:testings, :bar, :decimal, :precision => 8, :scale => 2)
|
1230
|
-
assert !Person.connection.column_exists?(:testings, :bar, :decimal, :precision => 10, :scale => 2)
|
1231
|
-
ensure
|
1232
|
-
Person.connection.drop_table :testings rescue nil
|
1233
|
-
end
|
1234
|
-
|
1235
|
-
def test_column_exists_on_table_with_no_options_parameter_supplied
|
1236
|
-
Person.connection.create_table :testings do |t|
|
1237
|
-
t.string :foo
|
1238
|
-
end
|
1239
|
-
Person.connection.change_table :testings do |t|
|
1240
|
-
assert t.column_exists?(:foo)
|
1241
|
-
assert !(t.column_exists?(:bar))
|
1242
|
-
end
|
1243
|
-
ensure
|
1244
|
-
Person.connection.drop_table :testings rescue nil
|
1245
|
-
end
|
1246
|
-
|
1247
|
-
def test_add_table
|
1248
|
-
assert !Reminder.table_exists?
|
1249
|
-
|
1250
|
-
WeNeedReminders.up
|
1251
|
-
|
1252
|
-
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
|
1253
|
-
assert_equal "hello world", Reminder.find(:first).content
|
1254
|
-
|
1255
|
-
WeNeedReminders.down
|
1256
|
-
assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
|
1257
|
-
end
|
1258
|
-
|
1259
|
-
def test_add_table_with_decimals
|
1260
|
-
Person.connection.drop_table :big_numbers rescue nil
|
1261
|
-
|
1262
|
-
assert !BigNumber.table_exists?
|
1263
|
-
GiveMeBigNumbers.up
|
1264
|
-
|
1265
|
-
assert BigNumber.create(
|
1266
|
-
:bank_balance => 1586.43,
|
1267
|
-
:big_bank_balance => BigDecimal("1000234000567.95"),
|
1268
|
-
:world_population => 6000000000,
|
1269
|
-
:my_house_population => 3,
|
1270
|
-
:value_of_e => BigDecimal("2.7182818284590452353602875")
|
1271
|
-
)
|
1272
|
-
|
1273
|
-
b = BigNumber.find(:first)
|
1274
|
-
assert_not_nil b
|
1275
|
-
|
1276
|
-
assert_not_nil b.bank_balance
|
1277
|
-
assert_not_nil b.big_bank_balance
|
1278
|
-
assert_not_nil b.world_population
|
1279
|
-
assert_not_nil b.my_house_population
|
1280
|
-
assert_not_nil b.value_of_e
|
1281
|
-
|
1282
|
-
# TODO: set world_population >= 2**62 to cover 64-bit platforms and test
|
1283
|
-
# is_a?(Bignum)
|
1284
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1285
|
-
assert_kind_of Integer, b.world_population
|
1286
|
-
else
|
1287
|
-
assert_kind_of BigDecimal, b.world_population
|
1288
|
-
end
|
1289
|
-
assert_equal 6000000000, b.world_population
|
1290
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1291
|
-
assert_kind_of Fixnum, b.my_house_population
|
1292
|
-
else
|
1293
|
-
assert_kind_of BigDecimal, b.my_house_population
|
1294
|
-
end
|
1295
|
-
assert_equal 3, b.my_house_population
|
1296
|
-
assert_kind_of BigDecimal, b.bank_balance
|
1297
|
-
assert_equal BigDecimal("1586.43"), b.bank_balance
|
1298
|
-
assert_kind_of BigDecimal, b.big_bank_balance
|
1299
|
-
assert_equal BigDecimal("1000234000567.95"), b.big_bank_balance
|
1300
|
-
|
1301
|
-
# This one is fun. The 'value_of_e' field is defined as 'DECIMAL' with
|
1302
|
-
# precision/scale explicitly left out. By the SQL standard, numbers
|
1303
|
-
# assigned to this field should be truncated but that's seldom respected.
|
1304
|
-
if current_adapter?(:PostgreSQLAdapter)
|
1305
|
-
# - PostgreSQL changes the SQL spec on columns declared simply as
|
1306
|
-
# "decimal" to something more useful: instead of being given a scale
|
1307
|
-
# of 0, they take on the compile-time limit for precision and scale,
|
1308
|
-
# so the following should succeed unless you have used really wacky
|
1309
|
-
# compilation options
|
1310
|
-
# - SQLite2 has the default behavior of preserving all data sent in,
|
1311
|
-
# so this happens there too
|
1312
|
-
assert_kind_of BigDecimal, b.value_of_e
|
1313
|
-
assert_equal BigDecimal("2.7182818284590452353602875"), b.value_of_e
|
1314
|
-
elsif current_adapter?(:SQLite3Adapter)
|
1315
|
-
# - SQLite3 stores a float, in violation of SQL
|
1316
|
-
assert_kind_of BigDecimal, b.value_of_e
|
1317
|
-
assert_in_delta BigDecimal("2.71828182845905"), b.value_of_e, 0.00000000000001
|
1318
|
-
else
|
1319
|
-
# - SQL standard is an integer
|
1320
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1321
|
-
assert_kind_of Fixnum, b.value_of_e
|
1322
|
-
else
|
1323
|
-
assert_kind_of BigDecimal, b.value_of_e
|
1324
|
-
end
|
1325
|
-
assert_equal 2, b.value_of_e
|
1326
|
-
end
|
1327
|
-
|
1328
|
-
GiveMeBigNumbers.down
|
1329
|
-
assert_raise(ActiveRecord::StatementInvalid) { BigNumber.find(:first) }
|
1330
|
-
end
|
1331
|
-
|
1332
|
-
def test_migrator
|
1333
|
-
assert !Person.column_methods_hash.include?(:last_name)
|
1334
|
-
assert !Reminder.table_exists?
|
1335
|
-
|
1336
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid")
|
1337
|
-
|
1338
|
-
assert_equal 3, ActiveRecord::Migrator.current_version
|
1339
|
-
Person.reset_column_information
|
1340
|
-
assert Person.column_methods_hash.include?(:last_name)
|
1341
|
-
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
|
1342
|
-
assert_equal "hello world", Reminder.find(:first).content
|
1343
|
-
|
1344
|
-
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid")
|
1345
|
-
|
1346
|
-
assert_equal 0, ActiveRecord::Migrator.current_version
|
1347
|
-
Person.reset_column_information
|
1348
|
-
assert !Person.column_methods_hash.include?(:last_name)
|
1349
|
-
assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
|
1350
|
-
end
|
1351
|
-
|
1352
|
-
def test_filtering_migrations
|
1353
|
-
assert !Person.column_methods_hash.include?(:last_name)
|
1354
|
-
assert !Reminder.table_exists?
|
1355
|
-
|
1356
|
-
name_filter = lambda { |migration| migration.name == "ValidPeopleHaveLastNames" }
|
1357
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", &name_filter)
|
1358
|
-
|
1359
|
-
Person.reset_column_information
|
1360
|
-
assert Person.column_methods_hash.include?(:last_name)
|
1361
|
-
assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
|
1362
|
-
|
1363
|
-
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", &name_filter)
|
1364
|
-
|
1365
|
-
Person.reset_column_information
|
1366
|
-
assert !Person.column_methods_hash.include?(:last_name)
|
1367
|
-
assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
|
1368
|
-
end
|
1369
|
-
|
1370
|
-
class MockMigration < ActiveRecord::Migration
|
1371
|
-
attr_reader :went_up, :went_down
|
1372
|
-
def initialize
|
1373
|
-
@went_up = false
|
1374
|
-
@went_down = false
|
1375
|
-
end
|
1376
|
-
|
1377
|
-
def up
|
1378
|
-
@went_up = true
|
1379
|
-
super
|
1380
|
-
end
|
1381
|
-
|
1382
|
-
def down
|
1383
|
-
@went_down = true
|
1384
|
-
super
|
1385
|
-
end
|
1386
|
-
end
|
1387
|
-
|
1388
|
-
def test_instance_based_migration_up
|
1389
|
-
migration = MockMigration.new
|
1390
|
-
assert !migration.went_up, 'have not gone up'
|
1391
|
-
assert !migration.went_down, 'have not gone down'
|
1392
|
-
|
1393
|
-
migration.migrate :up
|
1394
|
-
assert migration.went_up, 'have gone up'
|
1395
|
-
assert !migration.went_down, 'have not gone down'
|
1396
|
-
end
|
1397
|
-
|
1398
|
-
def test_instance_based_migration_down
|
1399
|
-
migration = MockMigration.new
|
1400
|
-
assert !migration.went_up, 'have not gone up'
|
1401
|
-
assert !migration.went_down, 'have not gone down'
|
1402
|
-
|
1403
|
-
migration.migrate :down
|
1404
|
-
assert !migration.went_up, 'have gone up'
|
1405
|
-
assert migration.went_down, 'have not gone down'
|
1406
|
-
end
|
1407
|
-
|
1408
|
-
def test_migrator_one_up
|
1409
|
-
assert !Person.column_methods_hash.include?(:last_name)
|
1410
|
-
assert !Reminder.table_exists?
|
1411
|
-
|
1412
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
|
1413
|
-
|
1414
|
-
Person.reset_column_information
|
1415
|
-
assert Person.column_methods_hash.include?(:last_name)
|
1416
|
-
assert !Reminder.table_exists?
|
1417
|
-
|
1418
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 2)
|
1419
|
-
|
1420
|
-
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
|
1421
|
-
assert_equal "hello world", Reminder.find(:first).content
|
1422
|
-
end
|
1423
|
-
|
1424
|
-
def test_migrator_one_down
|
1425
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid")
|
1426
|
-
|
1427
|
-
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 1)
|
1428
|
-
|
1429
|
-
Person.reset_column_information
|
1430
|
-
assert Person.column_methods_hash.include?(:last_name)
|
1431
|
-
assert !Reminder.table_exists?
|
1432
|
-
end
|
1433
|
-
|
1434
|
-
def test_migrator_one_up_one_down
|
1435
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
|
1436
|
-
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0)
|
1437
|
-
|
1438
|
-
assert !Person.column_methods_hash.include?(:last_name)
|
1439
|
-
assert !Reminder.table_exists?
|
1440
|
-
end
|
1441
|
-
|
1442
|
-
def test_migrator_double_up
|
1443
|
-
assert_equal(0, ActiveRecord::Migrator.current_version)
|
1444
|
-
ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1)
|
1445
|
-
assert_nothing_raised { ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1) }
|
1446
|
-
assert_equal(1, ActiveRecord::Migrator.current_version)
|
1447
|
-
end
|
1448
|
-
|
1449
|
-
def test_migrator_double_down
|
1450
|
-
assert_equal(0, ActiveRecord::Migrator.current_version)
|
1451
|
-
ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1)
|
1452
|
-
ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 1)
|
1453
|
-
assert_nothing_raised { ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 1) }
|
1454
|
-
assert_equal(0, ActiveRecord::Migrator.current_version)
|
1455
|
-
end
|
1456
|
-
|
1457
|
-
if ActiveRecord::Base.connection.supports_ddl_transactions?
|
1458
|
-
def test_migrator_one_up_with_exception_and_rollback
|
1459
|
-
assert !Person.column_methods_hash.include?(:last_name)
|
1460
|
-
|
1461
|
-
e = assert_raise(StandardError) do
|
1462
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/broken", 100)
|
1463
|
-
end
|
1464
|
-
|
1465
|
-
assert_equal "An error has occurred, this and all later migrations canceled:\n\nSomething broke", e.message
|
1466
|
-
|
1467
|
-
Person.reset_column_information
|
1468
|
-
assert !Person.column_methods_hash.include?(:last_name)
|
1469
|
-
end
|
1470
|
-
end
|
1471
|
-
|
1472
|
-
def test_finds_migrations
|
1473
|
-
migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations
|
1474
|
-
|
1475
|
-
[[1, 'ValidPeopleHaveLastNames'], [2, 'WeNeedReminders'], [3, 'InnocentJointable']].each_with_index do |pair, i|
|
1476
|
-
assert_equal migrations[i].version, pair.first
|
1477
|
-
assert_equal migrations[i].name, pair.last
|
1478
|
-
end
|
1479
|
-
end
|
1480
|
-
|
1481
|
-
def test_finds_migrations_in_subdirectories
|
1482
|
-
migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid_with_subdirectories").migrations
|
1483
|
-
|
1484
|
-
[[1, 'ValidPeopleHaveLastNames'], [2, 'WeNeedReminders'], [3, 'InnocentJointable']].each_with_index do |pair, i|
|
1485
|
-
assert_equal migrations[i].version, pair.first
|
1486
|
-
assert_equal migrations[i].name, pair.last
|
1487
|
-
end
|
1488
|
-
end
|
1489
|
-
|
1490
|
-
def test_finds_migrations_from_two_directories
|
1491
|
-
directories = [MIGRATIONS_ROOT + '/valid_with_timestamps', MIGRATIONS_ROOT + '/to_copy_with_timestamps']
|
1492
|
-
migrations = ActiveRecord::Migrator.new(:up, directories).migrations
|
1493
|
-
|
1494
|
-
[[20090101010101, "PeopleHaveHobbies"],
|
1495
|
-
[20090101010202, "PeopleHaveDescriptions"],
|
1496
|
-
[20100101010101, "ValidWithTimestampsPeopleHaveLastNames"],
|
1497
|
-
[20100201010101, "ValidWithTimestampsWeNeedReminders"],
|
1498
|
-
[20100301010101, "ValidWithTimestampsInnocentJointable"]].each_with_index do |pair, i|
|
1499
|
-
assert_equal pair.first, migrations[i].version
|
1500
|
-
assert_equal pair.last, migrations[i].name
|
1501
|
-
end
|
1502
|
-
end
|
1503
|
-
|
1504
|
-
def test_dump_schema_information_outputs_lexically_ordered_versions
|
1505
|
-
migration_path = MIGRATIONS_ROOT + '/valid_with_timestamps'
|
1506
|
-
ActiveRecord::Migrator.run(:up, migration_path, 20100301010101)
|
1507
|
-
ActiveRecord::Migrator.run(:up, migration_path, 20100201010101)
|
1508
|
-
|
1509
|
-
schema_info = ActiveRecord::Base.connection.dump_schema_information
|
1510
|
-
assert_match(/20100201010101.*20100301010101/m, schema_info)
|
1511
|
-
end
|
1512
|
-
|
1513
|
-
def test_finds_pending_migrations
|
1514
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_2", 1)
|
1515
|
-
migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/interleaved/pass_2").pending_migrations
|
1516
|
-
|
1517
|
-
assert_equal 1, migrations.size
|
1518
|
-
assert_equal migrations[0].version, 3
|
1519
|
-
assert_equal migrations[0].name, 'InterleavedInnocentJointable'
|
1520
|
-
end
|
1521
|
-
|
1522
|
-
def test_relative_migrations
|
1523
|
-
list = Dir.chdir(MIGRATIONS_ROOT) do
|
1524
|
-
ActiveRecord::Migrator.up("valid/", 1)
|
1525
|
-
end
|
1526
|
-
|
1527
|
-
migration_proxy = list.find { |item|
|
1528
|
-
item.name == 'ValidPeopleHaveLastNames'
|
1529
|
-
}
|
1530
|
-
assert migration_proxy, 'should find pending migration'
|
1531
|
-
end
|
1532
|
-
|
1533
|
-
def test_only_loads_pending_migrations
|
1534
|
-
# migrate up to 1
|
1535
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
|
1536
|
-
|
1537
|
-
proxies = ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", nil)
|
1538
|
-
|
1539
|
-
names = proxies.map(&:name)
|
1540
|
-
assert !names.include?('ValidPeopleHaveLastNames')
|
1541
|
-
assert names.include?('WeNeedReminders')
|
1542
|
-
assert names.include?('InnocentJointable')
|
1543
|
-
end
|
1544
|
-
|
1545
|
-
def test_target_version_zero_should_run_only_once
|
1546
|
-
# migrate up to 1
|
1547
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1)
|
1548
|
-
|
1549
|
-
# migrate down to 0
|
1550
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0)
|
1551
|
-
|
1552
|
-
# migrate down to 0 again
|
1553
|
-
proxies = ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0)
|
1554
|
-
assert_equal [], proxies
|
1555
|
-
end
|
1556
|
-
|
1557
|
-
def test_migrator_db_has_no_schema_migrations_table
|
1558
|
-
# Oracle adapter raises error if semicolon is present as last character
|
1559
|
-
if current_adapter?(:OracleAdapter)
|
1560
|
-
ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations")
|
1561
|
-
else
|
1562
|
-
ActiveRecord::Base.connection.execute("DROP TABLE schema_migrations;")
|
1563
|
-
end
|
1564
|
-
assert_nothing_raised do
|
1565
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1)
|
1566
|
-
end
|
1567
|
-
end
|
1568
|
-
|
1569
|
-
def test_migrator_verbosity
|
1570
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
|
1571
|
-
assert_not_equal 0, ActiveRecord::Migration.message_count
|
1572
|
-
ActiveRecord::Migration.message_count = 0
|
1573
|
-
|
1574
|
-
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0)
|
1575
|
-
assert_not_equal 0, ActiveRecord::Migration.message_count
|
1576
|
-
ActiveRecord::Migration.message_count = 0
|
1577
|
-
end
|
1578
|
-
|
1579
|
-
def test_migrator_verbosity_off
|
1580
|
-
ActiveRecord::Migration.verbose = false
|
1581
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
|
1582
|
-
assert_equal 0, ActiveRecord::Migration.message_count
|
1583
|
-
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0)
|
1584
|
-
assert_equal 0, ActiveRecord::Migration.message_count
|
1585
|
-
end
|
1586
|
-
|
1587
|
-
def test_migrator_going_down_due_to_version_target
|
1588
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
|
1589
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 0)
|
1590
|
-
|
1591
|
-
assert !Person.column_methods_hash.include?(:last_name)
|
1592
|
-
assert !Reminder.table_exists?
|
1593
|
-
|
1594
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid")
|
1595
|
-
|
1596
|
-
Person.reset_column_information
|
1597
|
-
assert Person.column_methods_hash.include?(:last_name)
|
1598
|
-
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
|
1599
|
-
assert_equal "hello world", Reminder.find(:first).content
|
1600
|
-
end
|
1601
|
-
|
1602
|
-
def test_migrator_rollback
|
1603
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid")
|
1604
|
-
assert_equal(3, ActiveRecord::Migrator.current_version)
|
1605
|
-
|
1606
|
-
ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
|
1607
|
-
assert_equal(2, ActiveRecord::Migrator.current_version)
|
1608
|
-
|
1609
|
-
ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
|
1610
|
-
assert_equal(1, ActiveRecord::Migrator.current_version)
|
1611
|
-
|
1612
|
-
ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
|
1613
|
-
assert_equal(0, ActiveRecord::Migrator.current_version)
|
1614
|
-
|
1615
|
-
ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
|
1616
|
-
assert_equal(0, ActiveRecord::Migrator.current_version)
|
1617
|
-
end
|
1618
|
-
|
1619
|
-
def test_migrator_forward
|
1620
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 1)
|
1621
|
-
assert_equal(1, ActiveRecord::Migrator.current_version)
|
1622
|
-
|
1623
|
-
ActiveRecord::Migrator.forward(MIGRATIONS_ROOT + "/valid", 2)
|
1624
|
-
assert_equal(3, ActiveRecord::Migrator.current_version)
|
1625
|
-
|
1626
|
-
ActiveRecord::Migrator.forward(MIGRATIONS_ROOT + "/valid")
|
1627
|
-
assert_equal(3, ActiveRecord::Migrator.current_version)
|
1628
|
-
end
|
1629
|
-
|
1630
|
-
def test_get_all_versions
|
1631
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid")
|
1632
|
-
assert_equal([1,2,3], ActiveRecord::Migrator.get_all_versions)
|
1633
|
-
|
1634
|
-
ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
|
1635
|
-
assert_equal([1,2], ActiveRecord::Migrator.get_all_versions)
|
1636
|
-
|
1637
|
-
ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
|
1638
|
-
assert_equal([1], ActiveRecord::Migrator.get_all_versions)
|
1639
|
-
|
1640
|
-
ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
|
1641
|
-
assert_equal([], ActiveRecord::Migrator.get_all_versions)
|
1642
|
-
end
|
1643
|
-
|
1644
|
-
def test_schema_migrations_table_name
|
1645
|
-
ActiveRecord::Base.table_name_prefix = "prefix_"
|
1646
|
-
ActiveRecord::Base.table_name_suffix = "_suffix"
|
1647
|
-
Reminder.reset_table_name
|
1648
|
-
assert_equal "prefix_schema_migrations_suffix", ActiveRecord::Migrator.schema_migrations_table_name
|
1649
|
-
ActiveRecord::Base.table_name_prefix = ""
|
1650
|
-
ActiveRecord::Base.table_name_suffix = ""
|
1651
|
-
Reminder.reset_table_name
|
1652
|
-
assert_equal "schema_migrations", ActiveRecord::Migrator.schema_migrations_table_name
|
1653
|
-
ensure
|
1654
|
-
ActiveRecord::Base.table_name_prefix = ""
|
1655
|
-
ActiveRecord::Base.table_name_suffix = ""
|
1656
|
-
end
|
1657
|
-
|
1658
|
-
def test_proper_table_name
|
1659
|
-
assert_equal "table", ActiveRecord::Migrator.proper_table_name('table')
|
1660
|
-
assert_equal "table", ActiveRecord::Migrator.proper_table_name(:table)
|
1661
|
-
assert_equal "reminders", ActiveRecord::Migrator.proper_table_name(Reminder)
|
1662
|
-
Reminder.reset_table_name
|
1663
|
-
assert_equal Reminder.table_name, ActiveRecord::Migrator.proper_table_name(Reminder)
|
1664
|
-
|
1665
|
-
# Use the model's own prefix/suffix if a model is given
|
1666
|
-
ActiveRecord::Base.table_name_prefix = "ARprefix_"
|
1667
|
-
ActiveRecord::Base.table_name_suffix = "_ARsuffix"
|
1668
|
-
Reminder.table_name_prefix = 'prefix_'
|
1669
|
-
Reminder.table_name_suffix = '_suffix'
|
1670
|
-
Reminder.reset_table_name
|
1671
|
-
assert_equal "prefix_reminders_suffix", ActiveRecord::Migrator.proper_table_name(Reminder)
|
1672
|
-
Reminder.table_name_prefix = ''
|
1673
|
-
Reminder.table_name_suffix = ''
|
1674
|
-
Reminder.reset_table_name
|
1675
|
-
|
1676
|
-
# Use AR::Base's prefix/suffix if string or symbol is given
|
1677
|
-
ActiveRecord::Base.table_name_prefix = "prefix_"
|
1678
|
-
ActiveRecord::Base.table_name_suffix = "_suffix"
|
1679
|
-
Reminder.reset_table_name
|
1680
|
-
assert_equal "prefix_table_suffix", ActiveRecord::Migrator.proper_table_name('table')
|
1681
|
-
assert_equal "prefix_table_suffix", ActiveRecord::Migrator.proper_table_name(:table)
|
1682
|
-
ActiveRecord::Base.table_name_prefix = ""
|
1683
|
-
ActiveRecord::Base.table_name_suffix = ""
|
1684
|
-
Reminder.reset_table_name
|
1685
|
-
end
|
1686
|
-
|
1687
|
-
def test_rename_table_with_prefix_and_suffix
|
1688
|
-
assert !Thing.table_exists?
|
1689
|
-
ActiveRecord::Base.table_name_prefix = 'prefix_'
|
1690
|
-
ActiveRecord::Base.table_name_suffix = '_suffix'
|
1691
|
-
Thing.reset_table_name
|
1692
|
-
Thing.reset_sequence_name
|
1693
|
-
WeNeedThings.up
|
1694
|
-
|
1695
|
-
assert Thing.create("content" => "hello world")
|
1696
|
-
assert_equal "hello world", Thing.find(:first).content
|
1697
|
-
|
1698
|
-
RenameThings.up
|
1699
|
-
Thing.table_name = "prefix_awesome_things_suffix"
|
1700
|
-
|
1701
|
-
assert_equal "hello world", Thing.find(:first).content
|
1702
|
-
ensure
|
1703
|
-
ActiveRecord::Base.table_name_prefix = ''
|
1704
|
-
ActiveRecord::Base.table_name_suffix = ''
|
1705
|
-
Thing.reset_table_name
|
1706
|
-
Thing.reset_sequence_name
|
1707
|
-
end
|
1708
|
-
|
1709
|
-
def test_add_drop_table_with_prefix_and_suffix
|
1710
|
-
assert !Reminder.table_exists?
|
1711
|
-
ActiveRecord::Base.table_name_prefix = 'prefix_'
|
1712
|
-
ActiveRecord::Base.table_name_suffix = '_suffix'
|
1713
|
-
Reminder.reset_table_name
|
1714
|
-
Reminder.reset_sequence_name
|
1715
|
-
WeNeedReminders.up
|
1716
|
-
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
|
1717
|
-
assert_equal "hello world", Reminder.find(:first).content
|
1718
|
-
|
1719
|
-
WeNeedReminders.down
|
1720
|
-
assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
|
1721
|
-
ensure
|
1722
|
-
ActiveRecord::Base.table_name_prefix = ''
|
1723
|
-
ActiveRecord::Base.table_name_suffix = ''
|
1724
|
-
Reminder.reset_table_name
|
1725
|
-
Reminder.reset_sequence_name
|
1726
|
-
end
|
1727
|
-
|
1728
|
-
def test_create_table_with_binary_column
|
1729
|
-
Person.connection.drop_table :binary_testings rescue nil
|
1730
|
-
|
1731
|
-
assert_nothing_raised {
|
1732
|
-
Person.connection.create_table :binary_testings do |t|
|
1733
|
-
t.column "data", :binary, :null => false
|
1734
|
-
end
|
1735
|
-
}
|
1736
|
-
|
1737
|
-
columns = Person.connection.columns(:binary_testings)
|
1738
|
-
data_column = columns.detect { |c| c.name == "data" }
|
1739
|
-
|
1740
|
-
if current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter)
|
1741
|
-
assert_equal '', data_column.default
|
1742
|
-
else
|
1743
|
-
assert_nil data_column.default
|
1744
|
-
end
|
1745
|
-
|
1746
|
-
Person.connection.drop_table :binary_testings rescue nil
|
1747
|
-
end
|
1748
|
-
|
1749
|
-
def test_migrator_with_duplicates
|
1750
|
-
assert_raise(ActiveRecord::DuplicateMigrationVersionError) do
|
1751
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate", nil)
|
1752
|
-
end
|
1753
|
-
end
|
1754
|
-
|
1755
|
-
def test_migrator_with_duplicate_names
|
1756
|
-
assert_raise(ActiveRecord::DuplicateMigrationNameError, "Multiple migrations have the name Chunky") do
|
1757
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate_names", nil)
|
1758
|
-
end
|
1759
|
-
end
|
1760
|
-
|
1761
|
-
def test_migrator_with_missing_version_numbers
|
1762
|
-
assert_raise(ActiveRecord::UnknownMigrationVersionError) do
|
1763
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/missing", 500)
|
1764
|
-
end
|
1765
|
-
end
|
1766
|
-
|
1767
|
-
def test_create_table_with_custom_sequence_name
|
1768
|
-
return unless current_adapter? :OracleAdapter
|
1769
|
-
|
1770
|
-
# table name is 29 chars, the standard sequence name will
|
1771
|
-
# be 33 chars and should be shortened
|
1772
|
-
assert_nothing_raised do
|
1773
|
-
begin
|
1774
|
-
Person.connection.create_table :table_with_name_thats_just_ok do |t|
|
1775
|
-
t.column :foo, :string, :null => false
|
1776
|
-
end
|
1777
|
-
ensure
|
1778
|
-
Person.connection.drop_table :table_with_name_thats_just_ok rescue nil
|
1779
|
-
end
|
1780
|
-
end
|
1781
|
-
|
1782
|
-
# should be all good w/ a custom sequence name
|
1783
|
-
assert_nothing_raised do
|
1784
|
-
begin
|
1785
|
-
Person.connection.create_table :table_with_name_thats_just_ok,
|
1786
|
-
:sequence_name => 'suitably_short_seq' do |t|
|
1787
|
-
t.column :foo, :string, :null => false
|
1788
|
-
end
|
1789
|
-
|
1790
|
-
Person.connection.execute("select suitably_short_seq.nextval from dual")
|
1791
|
-
|
1792
|
-
ensure
|
1793
|
-
Person.connection.drop_table :table_with_name_thats_just_ok,
|
1794
|
-
:sequence_name => 'suitably_short_seq' rescue nil
|
1795
|
-
end
|
1796
|
-
end
|
1797
|
-
|
1798
|
-
# confirm the custom sequence got dropped
|
1799
|
-
assert_raise(ActiveRecord::StatementInvalid) do
|
1800
|
-
Person.connection.execute("select suitably_short_seq.nextval from dual")
|
1801
|
-
end
|
1802
|
-
end
|
1803
|
-
|
1804
|
-
protected
|
1805
|
-
def with_env_tz(new_tz = 'US/Eastern')
|
1806
|
-
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
|
1807
|
-
yield
|
1808
|
-
ensure
|
1809
|
-
old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
|
1810
|
-
end
|
1811
|
-
|
1812
|
-
end
|
1813
|
-
|
1814
|
-
class MigrationLoggerTest < ActiveRecord::TestCase
|
1815
|
-
def test_migration_should_be_run_without_logger
|
1816
|
-
previous_logger = ActiveRecord::Base.logger
|
1817
|
-
ActiveRecord::Base.logger = nil
|
1818
|
-
assert_nothing_raised do
|
1819
|
-
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/valid")
|
1820
|
-
end
|
1821
|
-
ensure
|
1822
|
-
ActiveRecord::Base.logger = previous_logger
|
1823
|
-
end
|
1824
|
-
end
|
1825
|
-
|
1826
|
-
class InterleavedMigrationsTest < ActiveRecord::TestCase
|
1827
|
-
def test_migrator_interleaved_migrations
|
1828
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_1")
|
1829
|
-
|
1830
|
-
assert_nothing_raised do
|
1831
|
-
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_2")
|
1832
|
-
end
|
1833
|
-
|
1834
|
-
Person.reset_column_information
|
1835
|
-
assert Person.column_methods_hash.include?(:last_name)
|
1836
|
-
|
1837
|
-
assert_nothing_raised do
|
1838
|
-
proxies = ActiveRecord::Migrator.down(
|
1839
|
-
MIGRATIONS_ROOT + "/interleaved/pass_3")
|
1840
|
-
names = proxies.map(&:name)
|
1841
|
-
assert names.include?('InterleavedPeopleHaveLastNames')
|
1842
|
-
assert names.include?('InterleavedInnocentJointable')
|
1843
|
-
end
|
1844
|
-
end
|
1845
|
-
end
|
1846
|
-
|
1847
|
-
class ReservedWordsMigrationTest < ActiveRecord::TestCase
|
1848
|
-
def test_drop_index_from_table_named_values
|
1849
|
-
connection = Person.connection
|
1850
|
-
connection.create_table :values, :force => true do |t|
|
1851
|
-
t.integer :value
|
1852
|
-
end
|
1853
|
-
|
1854
|
-
assert_nothing_raised do
|
1855
|
-
connection.add_index :values, :value
|
1856
|
-
connection.remove_index :values, :column => :value
|
1857
|
-
end
|
1858
|
-
|
1859
|
-
connection.drop_table :values rescue nil
|
1860
|
-
end
|
1861
|
-
end
|
1862
|
-
|
1863
|
-
|
1864
|
-
class ChangeTableMigrationsTest < ActiveRecord::TestCase
|
1865
|
-
def setup
|
1866
|
-
@connection = Person.connection
|
1867
|
-
@connection.create_table :delete_me, :force => true do |t|
|
1868
|
-
end
|
1869
|
-
end
|
1870
|
-
|
1871
|
-
def teardown
|
1872
|
-
Person.connection.drop_table :delete_me rescue nil
|
1873
|
-
end
|
1874
|
-
|
1875
|
-
def test_references_column_type_adds_id
|
1876
|
-
with_change_table do |t|
|
1877
|
-
@connection.expects(:add_column).with(:delete_me, 'customer_id', :integer, {})
|
1878
|
-
t.references :customer
|
1879
|
-
end
|
1880
|
-
end
|
1881
|
-
|
1882
|
-
def test_remove_references_column_type_removes_id
|
1883
|
-
with_change_table do |t|
|
1884
|
-
@connection.expects(:remove_column).with(:delete_me, 'customer_id')
|
1885
|
-
t.remove_references :customer
|
1886
|
-
end
|
1887
|
-
end
|
1888
|
-
|
1889
|
-
def test_add_belongs_to_works_like_add_references
|
1890
|
-
with_change_table do |t|
|
1891
|
-
@connection.expects(:add_column).with(:delete_me, 'customer_id', :integer, {})
|
1892
|
-
t.belongs_to :customer
|
1893
|
-
end
|
1894
|
-
end
|
1895
|
-
|
1896
|
-
def test_remove_belongs_to_works_like_remove_references
|
1897
|
-
with_change_table do |t|
|
1898
|
-
@connection.expects(:remove_column).with(:delete_me, 'customer_id')
|
1899
|
-
t.remove_belongs_to :customer
|
1900
|
-
end
|
1901
|
-
end
|
1902
|
-
|
1903
|
-
def test_references_column_type_with_polymorphic_adds_type
|
1904
|
-
with_change_table do |t|
|
1905
|
-
@connection.expects(:add_column).with(:delete_me, 'taggable_type', :string, {})
|
1906
|
-
@connection.expects(:add_column).with(:delete_me, 'taggable_id', :integer, {})
|
1907
|
-
t.references :taggable, :polymorphic => true
|
1908
|
-
end
|
1909
|
-
end
|
1910
|
-
|
1911
|
-
def test_remove_references_column_type_with_polymorphic_removes_type
|
1912
|
-
with_change_table do |t|
|
1913
|
-
@connection.expects(:remove_column).with(:delete_me, 'taggable_type')
|
1914
|
-
@connection.expects(:remove_column).with(:delete_me, 'taggable_id')
|
1915
|
-
t.remove_references :taggable, :polymorphic => true
|
1916
|
-
end
|
1917
|
-
end
|
1918
|
-
|
1919
|
-
def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
|
1920
|
-
with_change_table do |t|
|
1921
|
-
@connection.expects(:add_column).with(:delete_me, 'taggable_type', :string, {:null => false})
|
1922
|
-
@connection.expects(:add_column).with(:delete_me, 'taggable_id', :integer, {:null => false})
|
1923
|
-
t.references :taggable, :polymorphic => true, :null => false
|
1924
|
-
end
|
1925
|
-
end
|
1926
|
-
|
1927
|
-
def test_remove_references_column_type_with_polymorphic_and_options_null_is_false_removes_table_flag
|
1928
|
-
with_change_table do |t|
|
1929
|
-
@connection.expects(:remove_column).with(:delete_me, 'taggable_type')
|
1930
|
-
@connection.expects(:remove_column).with(:delete_me, 'taggable_id')
|
1931
|
-
t.remove_references :taggable, :polymorphic => true, :null => false
|
1932
|
-
end
|
1933
|
-
end
|
1934
|
-
|
1935
|
-
def test_timestamps_creates_updated_at_and_created_at
|
1936
|
-
with_change_table do |t|
|
1937
|
-
@connection.expects(:add_timestamps).with(:delete_me)
|
1938
|
-
t.timestamps
|
1939
|
-
end
|
1940
|
-
end
|
1941
|
-
|
1942
|
-
def test_remove_timestamps_creates_updated_at_and_created_at
|
1943
|
-
with_change_table do |t|
|
1944
|
-
@connection.expects(:remove_timestamps).with(:delete_me)
|
1945
|
-
t.remove_timestamps
|
1946
|
-
end
|
1947
|
-
end
|
1948
|
-
|
1949
|
-
def string_column
|
1950
|
-
if current_adapter?(:PostgreSQLAdapter)
|
1951
|
-
"character varying(255)"
|
1952
|
-
elsif current_adapter?(:OracleAdapter)
|
1953
|
-
'VARCHAR2(255)'
|
1954
|
-
else
|
1955
|
-
'varchar(255)'
|
1956
|
-
end
|
1957
|
-
end
|
1958
|
-
|
1959
|
-
def integer_column
|
1960
|
-
if current_adapter?(:MysqlAdapter) or current_adapter?(:Mysql2Adapter)
|
1961
|
-
'int(11)'
|
1962
|
-
elsif current_adapter?(:OracleAdapter)
|
1963
|
-
'NUMBER(38)'
|
1964
|
-
else
|
1965
|
-
'integer'
|
1966
|
-
end
|
1967
|
-
end
|
1968
|
-
|
1969
|
-
def test_integer_creates_integer_column
|
1970
|
-
with_change_table do |t|
|
1971
|
-
@connection.expects(:add_column).with(:delete_me, :foo, integer_column, {})
|
1972
|
-
@connection.expects(:add_column).with(:delete_me, :bar, integer_column, {})
|
1973
|
-
t.integer :foo, :bar
|
1974
|
-
end
|
1975
|
-
end
|
1976
|
-
|
1977
|
-
def test_string_creates_string_column
|
1978
|
-
with_change_table do |t|
|
1979
|
-
@connection.expects(:add_column).with(:delete_me, :foo, string_column, {})
|
1980
|
-
@connection.expects(:add_column).with(:delete_me, :bar, string_column, {})
|
1981
|
-
t.string :foo, :bar
|
1982
|
-
end
|
1983
|
-
end
|
1984
|
-
|
1985
|
-
def test_column_creates_column
|
1986
|
-
with_change_table do |t|
|
1987
|
-
@connection.expects(:add_column).with(:delete_me, :bar, :integer, {})
|
1988
|
-
t.column :bar, :integer
|
1989
|
-
end
|
1990
|
-
end
|
1991
|
-
|
1992
|
-
def test_column_creates_column_with_options
|
1993
|
-
with_change_table do |t|
|
1994
|
-
@connection.expects(:add_column).with(:delete_me, :bar, :integer, {:null => false})
|
1995
|
-
t.column :bar, :integer, :null => false
|
1996
|
-
end
|
1997
|
-
end
|
1998
|
-
|
1999
|
-
def test_index_creates_index
|
2000
|
-
with_change_table do |t|
|
2001
|
-
@connection.expects(:add_index).with(:delete_me, :bar, {})
|
2002
|
-
t.index :bar
|
2003
|
-
end
|
2004
|
-
end
|
2005
|
-
|
2006
|
-
def test_index_creates_index_with_options
|
2007
|
-
with_change_table do |t|
|
2008
|
-
@connection.expects(:add_index).with(:delete_me, :bar, {:unique => true})
|
2009
|
-
t.index :bar, :unique => true
|
2010
|
-
end
|
2011
|
-
end
|
2012
|
-
|
2013
|
-
def test_index_exists
|
2014
|
-
with_change_table do |t|
|
2015
|
-
@connection.expects(:index_exists?).with(:delete_me, :bar, {})
|
2016
|
-
t.index_exists?(:bar)
|
2017
|
-
end
|
2018
|
-
end
|
2019
|
-
|
2020
|
-
def test_index_exists_with_options
|
2021
|
-
with_change_table do |t|
|
2022
|
-
@connection.expects(:index_exists?).with(:delete_me, :bar, {:unique => true})
|
2023
|
-
t.index_exists?(:bar, :unique => true)
|
2024
|
-
end
|
2025
|
-
end
|
2026
|
-
|
2027
|
-
def test_change_changes_column
|
2028
|
-
with_change_table do |t|
|
2029
|
-
@connection.expects(:change_column).with(:delete_me, :bar, :string, {})
|
2030
|
-
t.change :bar, :string
|
2031
|
-
end
|
2032
|
-
end
|
2033
|
-
|
2034
|
-
def test_change_changes_column_with_options
|
2035
|
-
with_change_table do |t|
|
2036
|
-
@connection.expects(:change_column).with(:delete_me, :bar, :string, {:null => true})
|
2037
|
-
t.change :bar, :string, :null => true
|
2038
|
-
end
|
2039
|
-
end
|
2040
|
-
|
2041
|
-
def test_change_default_changes_column
|
2042
|
-
with_change_table do |t|
|
2043
|
-
@connection.expects(:change_column_default).with(:delete_me, :bar, :string)
|
2044
|
-
t.change_default :bar, :string
|
2045
|
-
end
|
2046
|
-
end
|
2047
|
-
|
2048
|
-
def test_remove_drops_single_column
|
2049
|
-
with_change_table do |t|
|
2050
|
-
@connection.expects(:remove_column).with(:delete_me, [:bar])
|
2051
|
-
t.remove :bar
|
2052
|
-
end
|
2053
|
-
end
|
2054
|
-
|
2055
|
-
def test_remove_drops_multiple_columns
|
2056
|
-
with_change_table do |t|
|
2057
|
-
@connection.expects(:remove_column).with(:delete_me, [:bar, :baz])
|
2058
|
-
t.remove :bar, :baz
|
2059
|
-
end
|
2060
|
-
end
|
2061
|
-
|
2062
|
-
def test_remove_index_removes_index_with_options
|
2063
|
-
with_change_table do |t|
|
2064
|
-
@connection.expects(:remove_index).with(:delete_me, {:unique => true})
|
2065
|
-
t.remove_index :unique => true
|
2066
|
-
end
|
2067
|
-
end
|
2068
|
-
|
2069
|
-
def test_rename_renames_column
|
2070
|
-
with_change_table do |t|
|
2071
|
-
@connection.expects(:rename_column).with(:delete_me, :bar, :baz)
|
2072
|
-
t.rename :bar, :baz
|
2073
|
-
end
|
2074
|
-
end
|
2075
|
-
|
2076
|
-
protected
|
2077
|
-
def with_change_table
|
2078
|
-
Person.connection.change_table :delete_me do |t|
|
2079
|
-
yield t
|
2080
|
-
end
|
2081
|
-
end
|
2082
|
-
end
|
2083
|
-
|
2084
|
-
if ActiveRecord::Base.connection.supports_bulk_alter?
|
2085
|
-
class BulkAlterTableMigrationsTest < ActiveRecord::TestCase
|
2086
|
-
def setup
|
2087
|
-
@connection = Person.connection
|
2088
|
-
@connection.create_table(:delete_me, :force => true) {|t| }
|
2089
|
-
end
|
2090
|
-
|
2091
|
-
def teardown
|
2092
|
-
Person.connection.drop_table(:delete_me) rescue nil
|
2093
|
-
end
|
2094
|
-
|
2095
|
-
def test_adding_multiple_columns
|
2096
|
-
assert_queries(1) do
|
2097
|
-
with_bulk_change_table do |t|
|
2098
|
-
t.column :name, :string
|
2099
|
-
t.string :qualification, :experience
|
2100
|
-
t.integer :age, :default => 0
|
2101
|
-
t.date :birthdate
|
2102
|
-
t.timestamps
|
2103
|
-
end
|
2104
|
-
end
|
2105
|
-
|
2106
|
-
assert_equal 8, columns.size
|
2107
|
-
[:name, :qualification, :experience].each {|s| assert_equal :string, column(s).type }
|
2108
|
-
assert_equal 0, column(:age).default
|
2109
|
-
end
|
2110
|
-
|
2111
|
-
def test_removing_columns
|
2112
|
-
with_bulk_change_table do |t|
|
2113
|
-
t.string :qualification, :experience
|
2114
|
-
end
|
2115
|
-
|
2116
|
-
[:qualification, :experience].each {|c| assert column(c) }
|
2117
|
-
|
2118
|
-
assert_queries(1) do
|
2119
|
-
with_bulk_change_table do |t|
|
2120
|
-
t.remove :qualification, :experience
|
2121
|
-
t.string :qualification_experience
|
2122
|
-
end
|
2123
|
-
end
|
2124
|
-
|
2125
|
-
[:qualification, :experience].each {|c| assert ! column(c) }
|
2126
|
-
assert column(:qualification_experience)
|
2127
|
-
end
|
2128
|
-
|
2129
|
-
def test_adding_indexes
|
2130
|
-
with_bulk_change_table do |t|
|
2131
|
-
t.string :username
|
2132
|
-
t.string :name
|
2133
|
-
t.integer :age
|
2134
|
-
end
|
2135
|
-
|
2136
|
-
# Adding an index fires a query every time to check if an index already exists or not
|
2137
|
-
assert_queries(3) do
|
2138
|
-
with_bulk_change_table do |t|
|
2139
|
-
t.index :username, :unique => true, :name => :awesome_username_index
|
2140
|
-
t.index [:name, :age]
|
2141
|
-
end
|
2142
|
-
end
|
2143
|
-
|
2144
|
-
assert_equal 2, indexes.size
|
2145
|
-
|
2146
|
-
name_age_index = index(:index_delete_me_on_name_and_age)
|
2147
|
-
assert_equal ['name', 'age'].sort, name_age_index.columns.sort
|
2148
|
-
assert ! name_age_index.unique
|
2149
|
-
|
2150
|
-
assert index(:awesome_username_index).unique
|
2151
|
-
end
|
2152
|
-
|
2153
|
-
def test_removing_index
|
2154
|
-
with_bulk_change_table do |t|
|
2155
|
-
t.string :name
|
2156
|
-
t.index :name
|
2157
|
-
end
|
2158
|
-
|
2159
|
-
assert index(:index_delete_me_on_name)
|
2160
|
-
|
2161
|
-
assert_queries(3) do
|
2162
|
-
with_bulk_change_table do |t|
|
2163
|
-
t.remove_index :name
|
2164
|
-
t.index :name, :name => :new_name_index, :unique => true
|
2165
|
-
end
|
2166
|
-
end
|
2167
|
-
|
2168
|
-
assert ! index(:index_delete_me_on_name)
|
2169
|
-
|
2170
|
-
new_name_index = index(:new_name_index)
|
2171
|
-
assert new_name_index.unique
|
2172
|
-
end
|
2173
|
-
|
2174
|
-
def test_changing_columns
|
2175
|
-
with_bulk_change_table do |t|
|
2176
|
-
t.string :name
|
2177
|
-
t.date :birthdate
|
2178
|
-
end
|
2179
|
-
|
2180
|
-
assert ! column(:name).default
|
2181
|
-
assert_equal :date, column(:birthdate).type
|
2182
|
-
|
2183
|
-
# One query for columns (delete_me table)
|
2184
|
-
# One query for primary key (delete_me table)
|
2185
|
-
# One query to do the bulk change
|
2186
|
-
assert_queries(3) do
|
2187
|
-
with_bulk_change_table do |t|
|
2188
|
-
t.change :name, :string, :default => 'NONAME'
|
2189
|
-
t.change :birthdate, :datetime
|
2190
|
-
end
|
2191
|
-
end
|
2192
|
-
|
2193
|
-
assert_equal 'NONAME', column(:name).default
|
2194
|
-
assert_equal :datetime, column(:birthdate).type
|
2195
|
-
end
|
2196
|
-
|
2197
|
-
protected
|
2198
|
-
|
2199
|
-
def with_bulk_change_table
|
2200
|
-
# Reset columns/indexes cache as we're changing the table
|
2201
|
-
@columns = @indexes = nil
|
2202
|
-
|
2203
|
-
Person.connection.change_table(:delete_me, :bulk => true) do |t|
|
2204
|
-
yield t
|
2205
|
-
end
|
2206
|
-
end
|
2207
|
-
|
2208
|
-
def column(name)
|
2209
|
-
columns.detect {|c| c.name == name.to_s }
|
2210
|
-
end
|
2211
|
-
|
2212
|
-
def columns
|
2213
|
-
@columns ||= Person.connection.columns('delete_me')
|
2214
|
-
end
|
2215
|
-
|
2216
|
-
def index(name)
|
2217
|
-
indexes.detect {|i| i.name == name.to_s }
|
2218
|
-
end
|
2219
|
-
|
2220
|
-
def indexes
|
2221
|
-
@indexes ||= Person.connection.indexes('delete_me')
|
2222
|
-
end
|
2223
|
-
end # AlterTableMigrationsTest
|
2224
|
-
|
2225
|
-
end
|
2226
|
-
|
2227
|
-
class CopyMigrationsTest < ActiveRecord::TestCase
|
2228
|
-
def setup
|
2229
|
-
end
|
2230
|
-
|
2231
|
-
def clear
|
2232
|
-
ActiveRecord::Base.timestamped_migrations = true
|
2233
|
-
to_delete = Dir[@migrations_path + "/*.rb"] - @existing_migrations
|
2234
|
-
File.delete(*to_delete)
|
2235
|
-
end
|
2236
|
-
|
2237
|
-
def test_copying_migrations_without_timestamps
|
2238
|
-
ActiveRecord::Base.timestamped_migrations = false
|
2239
|
-
@migrations_path = MIGRATIONS_ROOT + "/valid"
|
2240
|
-
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
2241
|
-
|
2242
|
-
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"})
|
2243
|
-
assert File.exists?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
|
2244
|
-
assert File.exists?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
|
2245
|
-
assert_equal [@migrations_path + "/4_people_have_hobbies.bukkits.rb", @migrations_path + "/5_people_have_descriptions.bukkits.rb"], copied.map(&:filename)
|
2246
|
-
|
2247
|
-
expected = "# This migration comes from bukkits (originally 1)"
|
2248
|
-
assert_equal expected, IO.readlines(@migrations_path + "/4_people_have_hobbies.bukkits.rb")[0].chomp
|
2249
|
-
|
2250
|
-
files_count = Dir[@migrations_path + "/*.rb"].length
|
2251
|
-
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"})
|
2252
|
-
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
2253
|
-
assert copied.empty?
|
2254
|
-
ensure
|
2255
|
-
clear
|
2256
|
-
end
|
2257
|
-
|
2258
|
-
def test_copying_migrations_without_timestamps_from_2_sources
|
2259
|
-
ActiveRecord::Base.timestamped_migrations = false
|
2260
|
-
@migrations_path = MIGRATIONS_ROOT + "/valid"
|
2261
|
-
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
2262
|
-
|
2263
|
-
sources = ActiveSupport::OrderedHash.new
|
2264
|
-
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy"
|
2265
|
-
sources[:omg] = MIGRATIONS_ROOT + "/to_copy2"
|
2266
|
-
ActiveRecord::Migration.copy(@migrations_path, sources)
|
2267
|
-
assert File.exists?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
|
2268
|
-
assert File.exists?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
|
2269
|
-
assert File.exists?(@migrations_path + "/6_create_articles.omg.rb")
|
2270
|
-
assert File.exists?(@migrations_path + "/7_create_comments.omg.rb")
|
2271
|
-
|
2272
|
-
files_count = Dir[@migrations_path + "/*.rb"].length
|
2273
|
-
ActiveRecord::Migration.copy(@migrations_path, sources)
|
2274
|
-
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
2275
|
-
ensure
|
2276
|
-
clear
|
2277
|
-
end
|
2278
|
-
|
2279
|
-
def test_copying_migrations_with_timestamps
|
2280
|
-
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
2281
|
-
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
2282
|
-
|
2283
|
-
Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
|
2284
|
-
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
2285
|
-
assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
|
2286
|
-
assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
|
2287
|
-
expected = [@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb",
|
2288
|
-
@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb"]
|
2289
|
-
assert_equal expected, copied.map(&:filename)
|
2290
|
-
|
2291
|
-
files_count = Dir[@migrations_path + "/*.rb"].length
|
2292
|
-
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
2293
|
-
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
2294
|
-
assert copied.empty?
|
2295
|
-
end
|
2296
|
-
ensure
|
2297
|
-
clear
|
2298
|
-
end
|
2299
|
-
|
2300
|
-
def test_copying_migrations_with_timestamps_from_2_sources
|
2301
|
-
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
2302
|
-
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
2303
|
-
|
2304
|
-
sources = ActiveSupport::OrderedHash.new
|
2305
|
-
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
|
2306
|
-
sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_timestamps2"
|
2307
|
-
|
2308
|
-
Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
|
2309
|
-
copied = ActiveRecord::Migration.copy(@migrations_path, sources)
|
2310
|
-
assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
|
2311
|
-
assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
|
2312
|
-
assert File.exists?(@migrations_path + "/20100726101012_create_articles.omg.rb")
|
2313
|
-
assert File.exists?(@migrations_path + "/20100726101013_create_comments.omg.rb")
|
2314
|
-
assert_equal 4, copied.length
|
2315
|
-
|
2316
|
-
files_count = Dir[@migrations_path + "/*.rb"].length
|
2317
|
-
ActiveRecord::Migration.copy(@migrations_path, sources)
|
2318
|
-
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
2319
|
-
end
|
2320
|
-
ensure
|
2321
|
-
clear
|
2322
|
-
end
|
2323
|
-
|
2324
|
-
def test_copying_migrations_with_timestamps_to_destination_with_timestamps_in_future
|
2325
|
-
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
2326
|
-
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
2327
|
-
|
2328
|
-
Time.travel_to(Time.utc(2010, 2, 20, 10, 10, 10)) do
|
2329
|
-
ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
2330
|
-
assert File.exists?(@migrations_path + "/20100301010102_people_have_hobbies.bukkits.rb")
|
2331
|
-
assert File.exists?(@migrations_path + "/20100301010103_people_have_descriptions.bukkits.rb")
|
2332
|
-
|
2333
|
-
files_count = Dir[@migrations_path + "/*.rb"].length
|
2334
|
-
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
2335
|
-
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
2336
|
-
assert copied.empty?
|
2337
|
-
end
|
2338
|
-
ensure
|
2339
|
-
clear
|
2340
|
-
end
|
2341
|
-
|
2342
|
-
def test_skipping_migrations
|
2343
|
-
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
2344
|
-
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
2345
|
-
|
2346
|
-
sources = ActiveSupport::OrderedHash.new
|
2347
|
-
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
|
2348
|
-
sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_name_collision"
|
2349
|
-
|
2350
|
-
skipped = []
|
2351
|
-
on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
|
2352
|
-
copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
|
2353
|
-
assert_equal 2, copied.length
|
2354
|
-
|
2355
|
-
assert_equal 1, skipped.length
|
2356
|
-
assert_equal ["omg PeopleHaveHobbies"], skipped
|
2357
|
-
ensure
|
2358
|
-
clear
|
2359
|
-
end
|
2360
|
-
|
2361
|
-
def test_skip_is_not_called_if_migrations_are_from_the_same_plugin
|
2362
|
-
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
2363
|
-
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
2364
|
-
|
2365
|
-
sources = ActiveSupport::OrderedHash.new
|
2366
|
-
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
|
2367
|
-
|
2368
|
-
skipped = []
|
2369
|
-
on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
|
2370
|
-
copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
|
2371
|
-
ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
|
2372
|
-
|
2373
|
-
assert_equal 2, copied.length
|
2374
|
-
assert_equal 0, skipped.length
|
2375
|
-
ensure
|
2376
|
-
clear
|
2377
|
-
end
|
2378
|
-
|
2379
|
-
def test_copying_migrations_to_non_existing_directory
|
2380
|
-
@migrations_path = MIGRATIONS_ROOT + "/non_existing"
|
2381
|
-
@existing_migrations = []
|
2382
|
-
|
2383
|
-
Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
|
2384
|
-
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
2385
|
-
assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
|
2386
|
-
assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
|
2387
|
-
assert_equal 2, copied.length
|
2388
|
-
end
|
2389
|
-
ensure
|
2390
|
-
clear
|
2391
|
-
Dir.delete(@migrations_path)
|
2392
|
-
end
|
2393
|
-
|
2394
|
-
def test_copying_migrations_to_empty_directory
|
2395
|
-
@migrations_path = MIGRATIONS_ROOT + "/empty"
|
2396
|
-
@existing_migrations = []
|
2397
|
-
|
2398
|
-
Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
|
2399
|
-
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
2400
|
-
assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
|
2401
|
-
assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
|
2402
|
-
assert_equal 2, copied.length
|
2403
|
-
end
|
2404
|
-
ensure
|
2405
|
-
clear
|
2406
|
-
end
|
2407
|
-
end
|
2408
|
-
end
|
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
|
+
require 'models/computer'
|
9
|
+
|
10
|
+
require MIGRATIONS_ROOT + "/valid/2_we_need_reminders"
|
11
|
+
require MIGRATIONS_ROOT + "/rename/1_we_need_things"
|
12
|
+
require MIGRATIONS_ROOT + "/rename/2_rename_things"
|
13
|
+
require MIGRATIONS_ROOT + "/decimal/1_give_me_big_numbers"
|
14
|
+
|
15
|
+
class BigNumber < ActiveRecord::Base
|
16
|
+
unless current_adapter?(:PostgreSQLAdapter, :SQLite3Adapter)
|
17
|
+
attribute :value_of_e, Type::Integer.new
|
18
|
+
end
|
19
|
+
attribute :my_house_population, Type::Integer.new
|
20
|
+
end
|
21
|
+
|
22
|
+
class Reminder < ActiveRecord::Base; end
|
23
|
+
|
24
|
+
class Thing < ActiveRecord::Base; end
|
25
|
+
|
26
|
+
class MigrationTest < ActiveRecord::TestCase
|
27
|
+
self.use_transactional_fixtures = false
|
28
|
+
|
29
|
+
fixtures :people
|
30
|
+
|
31
|
+
if (current_adapter?(:IBM_DBAdapter))
|
32
|
+
#Rename is supported only for server zOS 9 , DB2 COBRA and Informix
|
33
|
+
server_type = ActiveRecord::Base.connection.servertype.class.name
|
34
|
+
@ibm_db_rename_supported = server_type.include?('::IBM_DB2_LUW_COBRA') ||
|
35
|
+
server_type.class.name.include?('::IBM_IDS') ||
|
36
|
+
(server_type.include?('IBM_DB2_ZOS') && !server_type.include?('IBM_DB2_ZOS_8'))
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup
|
40
|
+
super
|
41
|
+
%w(reminders people_reminders prefix_reminders_suffix p_things_s).each do |table|
|
42
|
+
Reminder.connection.drop_table(table) rescue nil
|
43
|
+
end
|
44
|
+
Reminder.reset_column_information
|
45
|
+
@verbose_was, ActiveRecord::Migration.verbose = ActiveRecord::Migration.verbose, false
|
46
|
+
ActiveRecord::Base.connection.schema_cache.clear!
|
47
|
+
end
|
48
|
+
|
49
|
+
teardown do
|
50
|
+
ActiveRecord::Base.table_name_prefix = ""
|
51
|
+
ActiveRecord::Base.table_name_suffix = ""
|
52
|
+
|
53
|
+
ActiveRecord::Base.connection.initialize_schema_migrations_table
|
54
|
+
ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
|
55
|
+
|
56
|
+
%w(things awesome_things prefix_things_suffix p_awesome_things_s ).each do |table|
|
57
|
+
Thing.connection.drop_table(table) rescue nil
|
58
|
+
end
|
59
|
+
Thing.reset_column_information
|
60
|
+
|
61
|
+
%w(reminders people_reminders prefix_reminders_suffix).each do |table|
|
62
|
+
Reminder.connection.drop_table(table) rescue nil
|
63
|
+
end
|
64
|
+
Reminder.reset_table_name
|
65
|
+
Reminder.reset_column_information
|
66
|
+
|
67
|
+
%w(last_name key bio age height wealth birthday favorite_day
|
68
|
+
moment_of_truth male administrator funny).each do |column|
|
69
|
+
Person.connection.remove_column('people', column) rescue nil
|
70
|
+
end
|
71
|
+
Person.connection.remove_column("people", "first_name") rescue nil
|
72
|
+
Person.connection.remove_column("people", "middle_name") rescue nil
|
73
|
+
Person.connection.add_column("people", "first_name", :string)
|
74
|
+
Person.reset_column_information
|
75
|
+
|
76
|
+
ActiveRecord::Migration.verbose = @verbose_was
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_migrator_versions
|
80
|
+
migrations_path = MIGRATIONS_ROOT + "/valid"
|
81
|
+
old_path = ActiveRecord::Migrator.migrations_paths
|
82
|
+
ActiveRecord::Migrator.migrations_paths = migrations_path
|
83
|
+
|
84
|
+
ActiveRecord::Migrator.up(migrations_path)
|
85
|
+
assert_equal 3, ActiveRecord::Migrator.current_version
|
86
|
+
assert_equal 3, ActiveRecord::Migrator.last_version
|
87
|
+
assert_equal false, ActiveRecord::Migrator.needs_migration?
|
88
|
+
|
89
|
+
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid")
|
90
|
+
assert_equal 0, ActiveRecord::Migrator.current_version
|
91
|
+
assert_equal 3, ActiveRecord::Migrator.last_version
|
92
|
+
assert_equal true, ActiveRecord::Migrator.needs_migration?
|
93
|
+
|
94
|
+
ActiveRecord::SchemaMigration.create!(:version => ActiveRecord::Migrator.last_version)
|
95
|
+
assert_equal true, ActiveRecord::Migrator.needs_migration?
|
96
|
+
ensure
|
97
|
+
ActiveRecord::Migrator.migrations_paths = old_path
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_migration_detection_without_schema_migration_table
|
101
|
+
ActiveRecord::Base.connection.drop_table('schema_migrations') if ActiveRecord::Base.connection.table_exists?('schema_migrations')
|
102
|
+
|
103
|
+
migrations_path = MIGRATIONS_ROOT + "/valid"
|
104
|
+
old_path = ActiveRecord::Migrator.migrations_paths
|
105
|
+
ActiveRecord::Migrator.migrations_paths = migrations_path
|
106
|
+
|
107
|
+
assert_equal true, ActiveRecord::Migrator.needs_migration?
|
108
|
+
ensure
|
109
|
+
ActiveRecord::Migrator.migrations_paths = old_path
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_any_migrations
|
113
|
+
old_path = ActiveRecord::Migrator.migrations_paths
|
114
|
+
ActiveRecord::Migrator.migrations_paths = MIGRATIONS_ROOT + "/valid"
|
115
|
+
|
116
|
+
assert ActiveRecord::Migrator.any_migrations?
|
117
|
+
|
118
|
+
ActiveRecord::Migrator.migrations_paths = MIGRATIONS_ROOT + "/empty"
|
119
|
+
|
120
|
+
assert_not ActiveRecord::Migrator.any_migrations?
|
121
|
+
ensure
|
122
|
+
ActiveRecord::Migrator.migrations_paths = old_path
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_migration_version
|
126
|
+
ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/version_check", 20131219224947)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_create_table_with_force_true_does_not_drop_nonexisting_table
|
130
|
+
if Person.connection.table_exists?(:testings2)
|
131
|
+
Person.connection.drop_table :testings2
|
132
|
+
end
|
133
|
+
|
134
|
+
# using a copy as we need the drop_table method to
|
135
|
+
# continue to work for the ensure block of the test
|
136
|
+
temp_conn = Person.connection.dup
|
137
|
+
|
138
|
+
assert_not_equal temp_conn, Person.connection
|
139
|
+
|
140
|
+
temp_conn.create_table :testings2, :force => true do |t|
|
141
|
+
t.column :foo, :string
|
142
|
+
end
|
143
|
+
ensure
|
144
|
+
Person.connection.drop_table :testings2 rescue nil
|
145
|
+
end
|
146
|
+
|
147
|
+
def connection
|
148
|
+
ActiveRecord::Base.connection
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_migration_instance_has_connection
|
152
|
+
migration = Class.new(ActiveRecord::Migration).new
|
153
|
+
assert_equal connection, migration.connection
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_method_missing_delegates_to_connection
|
157
|
+
migration = Class.new(ActiveRecord::Migration) {
|
158
|
+
def connection
|
159
|
+
Class.new {
|
160
|
+
def create_table; "hi mom!"; end
|
161
|
+
}.new
|
162
|
+
end
|
163
|
+
}.new
|
164
|
+
|
165
|
+
assert_equal "hi mom!", migration.method_missing(:create_table)
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_add_table_with_decimals
|
169
|
+
Person.connection.drop_table :big_numbers rescue nil
|
170
|
+
|
171
|
+
assert !BigNumber.table_exists?
|
172
|
+
GiveMeBigNumbers.up
|
173
|
+
|
174
|
+
assert BigNumber.create(
|
175
|
+
:bank_balance => 1586.43,
|
176
|
+
:big_bank_balance => BigDecimal("1000234000567.95"),
|
177
|
+
:world_population => 6000000000,
|
178
|
+
:my_house_population => 3,
|
179
|
+
:value_of_e => BigDecimal("2.7182818284590452353602875")
|
180
|
+
)
|
181
|
+
|
182
|
+
b = BigNumber.first
|
183
|
+
assert_not_nil b
|
184
|
+
|
185
|
+
assert_not_nil b.bank_balance
|
186
|
+
assert_not_nil b.big_bank_balance
|
187
|
+
assert_not_nil b.world_population
|
188
|
+
assert_not_nil b.my_house_population
|
189
|
+
assert_not_nil b.value_of_e
|
190
|
+
|
191
|
+
# TODO: set world_population >= 2**62 to cover 64-bit platforms and test
|
192
|
+
# is_a?(Bignum)
|
193
|
+
unless current_adapter?(:IBM_DBAdapter)
|
194
|
+
assert_kind_of Integer, b.world_population
|
195
|
+
else
|
196
|
+
assert_kind_of BigDecimal, b.world_population
|
197
|
+
end
|
198
|
+
assert_equal 6000000000, b.world_population
|
199
|
+
unless current_adapter?(:IBM_DBAdapter)
|
200
|
+
assert_kind_of Fixnum, b.my_house_population
|
201
|
+
else
|
202
|
+
assert_kind_of BigDecimal, b.my_house_population
|
203
|
+
end
|
204
|
+
assert_equal 3, b.my_house_population
|
205
|
+
assert_kind_of BigDecimal, b.bank_balance
|
206
|
+
assert_equal BigDecimal("1586.43"), b.bank_balance
|
207
|
+
assert_kind_of BigDecimal, b.big_bank_balance
|
208
|
+
assert_equal BigDecimal("1000234000567.95"), b.big_bank_balance
|
209
|
+
|
210
|
+
# This one is fun. The 'value_of_e' field is defined as 'DECIMAL' with
|
211
|
+
# precision/scale explicitly left out. By the SQL standard, numbers
|
212
|
+
# assigned to this field should be truncated but that's seldom respected.
|
213
|
+
if current_adapter?(:PostgreSQLAdapter)
|
214
|
+
# - PostgreSQL changes the SQL spec on columns declared simply as
|
215
|
+
# "decimal" to something more useful: instead of being given a scale
|
216
|
+
# of 0, they take on the compile-time limit for precision and scale,
|
217
|
+
# so the following should succeed unless you have used really wacky
|
218
|
+
# compilation options
|
219
|
+
# - SQLite2 has the default behavior of preserving all data sent in,
|
220
|
+
# so this happens there too
|
221
|
+
assert_kind_of BigDecimal, b.value_of_e
|
222
|
+
assert_equal BigDecimal("2.7182818284590452353602875"), b.value_of_e
|
223
|
+
elsif current_adapter?(:SQLite3Adapter)
|
224
|
+
# - SQLite3 stores a float, in violation of SQL
|
225
|
+
assert_kind_of BigDecimal, b.value_of_e
|
226
|
+
assert_in_delta BigDecimal("2.71828182845905"), b.value_of_e, 0.00000000000001
|
227
|
+
else
|
228
|
+
# - SQL standard is an integer
|
229
|
+
unless current_adapter?(:IBM_DBAdapter)
|
230
|
+
assert_kind_of Fixnum, b.value_of_e
|
231
|
+
else
|
232
|
+
assert_kind_of BigDecimal, b.value_of_e
|
233
|
+
end
|
234
|
+
assert_equal 2, b.value_of_e
|
235
|
+
end
|
236
|
+
|
237
|
+
GiveMeBigNumbers.down
|
238
|
+
assert_raise(ActiveRecord::StatementInvalid) { BigNumber.first }
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_filtering_migrations
|
242
|
+
assert_no_column Person, :last_name
|
243
|
+
assert !Reminder.table_exists?
|
244
|
+
|
245
|
+
name_filter = lambda { |migration| migration.name == "ValidPeopleHaveLastNames" }
|
246
|
+
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", &name_filter)
|
247
|
+
|
248
|
+
assert_column Person, :last_name
|
249
|
+
assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
|
250
|
+
|
251
|
+
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", &name_filter)
|
252
|
+
|
253
|
+
assert_no_column Person, :last_name
|
254
|
+
assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
|
255
|
+
end
|
256
|
+
|
257
|
+
class MockMigration < ActiveRecord::Migration
|
258
|
+
attr_reader :went_up, :went_down
|
259
|
+
def initialize
|
260
|
+
@went_up = false
|
261
|
+
@went_down = false
|
262
|
+
end
|
263
|
+
|
264
|
+
def up
|
265
|
+
@went_up = true
|
266
|
+
super
|
267
|
+
end
|
268
|
+
|
269
|
+
def down
|
270
|
+
@went_down = true
|
271
|
+
super
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_instance_based_migration_up
|
276
|
+
migration = MockMigration.new
|
277
|
+
assert !migration.went_up, 'have not gone up'
|
278
|
+
assert !migration.went_down, 'have not gone down'
|
279
|
+
|
280
|
+
migration.migrate :up
|
281
|
+
assert migration.went_up, 'have gone up'
|
282
|
+
assert !migration.went_down, 'have not gone down'
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_instance_based_migration_down
|
286
|
+
migration = MockMigration.new
|
287
|
+
assert !migration.went_up, 'have not gone up'
|
288
|
+
assert !migration.went_down, 'have not gone down'
|
289
|
+
|
290
|
+
migration.migrate :down
|
291
|
+
assert !migration.went_up, 'have gone up'
|
292
|
+
assert migration.went_down, 'have not gone down'
|
293
|
+
end
|
294
|
+
|
295
|
+
if ActiveRecord::Base.connection.supports_ddl_transactions?
|
296
|
+
def test_migrator_one_up_with_exception_and_rollback
|
297
|
+
assert_no_column Person, :last_name
|
298
|
+
|
299
|
+
migration = Class.new(ActiveRecord::Migration) {
|
300
|
+
def version; 100 end
|
301
|
+
def migrate(x)
|
302
|
+
add_column "people", "last_name", :string
|
303
|
+
raise 'Something broke'
|
304
|
+
end
|
305
|
+
}.new
|
306
|
+
|
307
|
+
migrator = ActiveRecord::Migrator.new(:up, [migration], 100)
|
308
|
+
|
309
|
+
e = assert_raise(StandardError) { migrator.migrate }
|
310
|
+
|
311
|
+
assert_equal "An error has occurred, this and all later migrations canceled:\n\nSomething broke", e.message
|
312
|
+
|
313
|
+
assert_no_column Person, :last_name,
|
314
|
+
"On error, the Migrator should revert schema changes but it did not."
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_migrator_one_up_with_exception_and_rollback_using_run
|
318
|
+
assert_no_column Person, :last_name
|
319
|
+
|
320
|
+
migration = Class.new(ActiveRecord::Migration) {
|
321
|
+
def version; 100 end
|
322
|
+
def migrate(x)
|
323
|
+
add_column "people", "last_name", :string
|
324
|
+
raise 'Something broke'
|
325
|
+
end
|
326
|
+
}.new
|
327
|
+
|
328
|
+
migrator = ActiveRecord::Migrator.new(:up, [migration], 100)
|
329
|
+
|
330
|
+
e = assert_raise(StandardError) { migrator.run }
|
331
|
+
|
332
|
+
assert_equal "An error has occurred, this migration was canceled:\n\nSomething broke", e.message
|
333
|
+
|
334
|
+
assert_no_column Person, :last_name,
|
335
|
+
"On error, the Migrator should revert schema changes but it did not."
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_migration_without_transaction
|
339
|
+
assert_no_column Person, :last_name
|
340
|
+
|
341
|
+
migration = Class.new(ActiveRecord::Migration) {
|
342
|
+
self.disable_ddl_transaction!
|
343
|
+
|
344
|
+
def version; 101 end
|
345
|
+
def migrate(x)
|
346
|
+
add_column "people", "last_name", :string
|
347
|
+
raise 'Something broke'
|
348
|
+
end
|
349
|
+
}.new
|
350
|
+
|
351
|
+
migrator = ActiveRecord::Migrator.new(:up, [migration], 101)
|
352
|
+
e = assert_raise(StandardError) { migrator.migrate }
|
353
|
+
assert_equal "An error has occurred, all later migrations canceled:\n\nSomething broke", e.message
|
354
|
+
|
355
|
+
assert_column Person, :last_name,
|
356
|
+
"without ddl transactions, the Migrator should not rollback on error but it did."
|
357
|
+
ensure
|
358
|
+
Person.reset_column_information
|
359
|
+
if Person.column_names.include?('last_name')
|
360
|
+
Person.connection.remove_column('people', 'last_name')
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_schema_migrations_table_name
|
366
|
+
original_schema_migrations_table_name = ActiveRecord::Migrator.schema_migrations_table_name
|
367
|
+
|
368
|
+
assert_equal "schema_migrations", ActiveRecord::Migrator.schema_migrations_table_name
|
369
|
+
ActiveRecord::Base.table_name_prefix = "prefix_"
|
370
|
+
ActiveRecord::Base.table_name_suffix = "_suffix"
|
371
|
+
Reminder.reset_table_name
|
372
|
+
assert_equal "prefix_schema_migrations_suffix", ActiveRecord::Migrator.schema_migrations_table_name
|
373
|
+
ActiveRecord::Base.schema_migrations_table_name = "changed"
|
374
|
+
Reminder.reset_table_name
|
375
|
+
assert_equal "prefix_changed_suffix", ActiveRecord::Migrator.schema_migrations_table_name
|
376
|
+
ActiveRecord::Base.table_name_prefix = ""
|
377
|
+
ActiveRecord::Base.table_name_suffix = ""
|
378
|
+
Reminder.reset_table_name
|
379
|
+
assert_equal "changed", ActiveRecord::Migrator.schema_migrations_table_name
|
380
|
+
ensure
|
381
|
+
ActiveRecord::Base.schema_migrations_table_name = original_schema_migrations_table_name
|
382
|
+
Reminder.reset_table_name
|
383
|
+
end
|
384
|
+
|
385
|
+
def test_proper_table_name_on_migration
|
386
|
+
reminder_class = new_isolated_reminder_class
|
387
|
+
migration = ActiveRecord::Migration.new
|
388
|
+
assert_equal "table", migration.proper_table_name('table')
|
389
|
+
assert_equal "table", migration.proper_table_name(:table)
|
390
|
+
assert_equal "reminders", migration.proper_table_name(reminder_class)
|
391
|
+
reminder_class.reset_table_name
|
392
|
+
assert_equal reminder_class.table_name, migration.proper_table_name(reminder_class)
|
393
|
+
|
394
|
+
# Use the model's own prefix/suffix if a model is given
|
395
|
+
ActiveRecord::Base.table_name_prefix = "ARprefix_"
|
396
|
+
ActiveRecord::Base.table_name_suffix = "_ARsuffix"
|
397
|
+
reminder_class.table_name_prefix = 'prefix_'
|
398
|
+
reminder_class.table_name_suffix = '_suffix'
|
399
|
+
reminder_class.reset_table_name
|
400
|
+
assert_equal "prefix_reminders_suffix", migration.proper_table_name(reminder_class)
|
401
|
+
reminder_class.table_name_prefix = ''
|
402
|
+
reminder_class.table_name_suffix = ''
|
403
|
+
reminder_class.reset_table_name
|
404
|
+
|
405
|
+
# Use AR::Base's prefix/suffix if string or symbol is given
|
406
|
+
ActiveRecord::Base.table_name_prefix = "prefix_"
|
407
|
+
ActiveRecord::Base.table_name_suffix = "_suffix"
|
408
|
+
reminder_class.reset_table_name
|
409
|
+
assert_equal "prefix_table_suffix", migration.proper_table_name('table', migration.table_name_options)
|
410
|
+
assert_equal "prefix_table_suffix", migration.proper_table_name(:table, migration.table_name_options)
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_rename_table_with_prefix_and_suffix
|
414
|
+
assert !Thing.table_exists?
|
415
|
+
ActiveRecord::Base.table_name_prefix = 'p_'
|
416
|
+
ActiveRecord::Base.table_name_suffix = '_s'
|
417
|
+
Thing.reset_table_name
|
418
|
+
Thing.reset_sequence_name
|
419
|
+
WeNeedThings.up
|
420
|
+
|
421
|
+
assert Thing.create("content" => "hello world")
|
422
|
+
assert_equal "hello world", Thing.first.content
|
423
|
+
|
424
|
+
RenameThings.up
|
425
|
+
Thing.table_name = "p_awesome_things_s"
|
426
|
+
|
427
|
+
assert_equal "hello world", Thing.first.content
|
428
|
+
ensure
|
429
|
+
Thing.reset_table_name
|
430
|
+
Thing.reset_sequence_name
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_add_drop_table_with_prefix_and_suffix
|
434
|
+
assert !Reminder.table_exists?
|
435
|
+
ActiveRecord::Base.table_name_prefix = 'prefix_'
|
436
|
+
ActiveRecord::Base.table_name_suffix = '_suffix'
|
437
|
+
Reminder.reset_table_name
|
438
|
+
Reminder.reset_sequence_name
|
439
|
+
WeNeedReminders.up
|
440
|
+
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
|
441
|
+
assert_equal "hello world", Reminder.first.content
|
442
|
+
|
443
|
+
WeNeedReminders.down
|
444
|
+
assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
|
445
|
+
ensure
|
446
|
+
Reminder.reset_sequence_name
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_create_table_with_binary_column
|
450
|
+
Person.connection.drop_table :binary_testings rescue nil
|
451
|
+
|
452
|
+
assert_nothing_raised {
|
453
|
+
Person.connection.create_table :binary_testings do |t|
|
454
|
+
t.column "data", :binary, :null => false
|
455
|
+
end
|
456
|
+
}
|
457
|
+
|
458
|
+
columns = Person.connection.columns(:binary_testings)
|
459
|
+
data_column = columns.detect { |c| c.name == "data" }
|
460
|
+
|
461
|
+
assert_nil data_column.default
|
462
|
+
|
463
|
+
Person.connection.drop_table :binary_testings rescue nil
|
464
|
+
end
|
465
|
+
|
466
|
+
unless mysql_enforcing_gtid_consistency?
|
467
|
+
def test_create_table_with_query
|
468
|
+
Person.connection.drop_table :table_from_query_testings rescue nil
|
469
|
+
Person.connection.create_table(:person, force: true)
|
470
|
+
|
471
|
+
Person.connection.create_table :table_from_query_testings, as: "SELECT id FROM person"
|
472
|
+
|
473
|
+
columns = Person.connection.columns(:table_from_query_testings)
|
474
|
+
assert_equal 1, columns.length
|
475
|
+
assert_equal "id", columns.first.name
|
476
|
+
|
477
|
+
Person.connection.drop_table :table_from_query_testings rescue nil
|
478
|
+
end
|
479
|
+
|
480
|
+
def test_create_table_with_query_from_relation
|
481
|
+
Person.connection.drop_table :table_from_query_testings rescue nil
|
482
|
+
Person.connection.create_table(:person, force: true)
|
483
|
+
|
484
|
+
Person.connection.create_table :table_from_query_testings, as: Person.select(:id)
|
485
|
+
|
486
|
+
columns = Person.connection.columns(:table_from_query_testings)
|
487
|
+
assert_equal 1, columns.length
|
488
|
+
assert_equal "id", columns.first.name
|
489
|
+
|
490
|
+
Person.connection.drop_table :table_from_query_testings rescue nil
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
if current_adapter? :OracleAdapter
|
495
|
+
def test_create_table_with_custom_sequence_name
|
496
|
+
# table name is 29 chars, the standard sequence name will
|
497
|
+
# be 33 chars and should be shortened
|
498
|
+
assert_nothing_raised do
|
499
|
+
begin
|
500
|
+
Person.connection.create_table :table_with_name_thats_just_ok do |t|
|
501
|
+
t.column :foo, :string, :null => false
|
502
|
+
end
|
503
|
+
ensure
|
504
|
+
Person.connection.drop_table :table_with_name_thats_just_ok rescue nil
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
# should be all good w/ a custom sequence name
|
509
|
+
assert_nothing_raised do
|
510
|
+
begin
|
511
|
+
Person.connection.create_table :table_with_name_thats_just_ok,
|
512
|
+
:sequence_name => 'suitably_short_seq' do |t|
|
513
|
+
t.column :foo, :string, :null => false
|
514
|
+
end
|
515
|
+
|
516
|
+
Person.connection.execute("select suitably_short_seq.nextval from dual")
|
517
|
+
|
518
|
+
ensure
|
519
|
+
Person.connection.drop_table :table_with_name_thats_just_ok,
|
520
|
+
:sequence_name => 'suitably_short_seq' rescue nil
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
# confirm the custom sequence got dropped
|
525
|
+
assert_raise(ActiveRecord::StatementInvalid) do
|
526
|
+
Person.connection.execute("select suitably_short_seq.nextval from dual")
|
527
|
+
end
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
531
|
+
if current_adapter?(:MysqlAdapter, :Mysql2Adapter, :PostgreSQLAdapter)
|
532
|
+
def test_out_of_range_limit_should_raise
|
533
|
+
Person.connection.drop_table :test_limits rescue nil
|
534
|
+
assert_raise(ActiveRecord::ActiveRecordError, "integer limit didn't raise") do
|
535
|
+
Person.connection.create_table :test_integer_limits, :force => true do |t|
|
536
|
+
t.column :bigone, :integer, :limit => 10
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
unless current_adapter?(:PostgreSQLAdapter)
|
541
|
+
assert_raise(ActiveRecord::ActiveRecordError, "text limit didn't raise") do
|
542
|
+
Person.connection.create_table :test_text_limits, :force => true do |t|
|
543
|
+
t.column :bigtext, :text, :limit => 0xfffffffff
|
544
|
+
end
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
Person.connection.drop_table :test_limits rescue nil
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
552
|
+
protected
|
553
|
+
# This is needed to isolate class_attribute assignments like `table_name_prefix`
|
554
|
+
# for each test case.
|
555
|
+
def new_isolated_reminder_class
|
556
|
+
Class.new(Reminder) {
|
557
|
+
def self.name; "Reminder"; end
|
558
|
+
def self.base_class; self; end
|
559
|
+
}
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
class ReservedWordsMigrationTest < ActiveRecord::TestCase
|
564
|
+
def test_drop_index_from_table_named_values
|
565
|
+
connection = Person.connection
|
566
|
+
connection.create_table :values, :force => true do |t|
|
567
|
+
t.integer :value
|
568
|
+
end
|
569
|
+
|
570
|
+
assert_nothing_raised do
|
571
|
+
connection.add_index :values, :value
|
572
|
+
connection.remove_index :values, :column => :value
|
573
|
+
end
|
574
|
+
|
575
|
+
connection.drop_table :values rescue nil
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
class ExplicitlyNamedIndexMigrationTest < ActiveRecord::TestCase
|
580
|
+
def test_drop_index_by_name
|
581
|
+
connection = Person.connection
|
582
|
+
connection.create_table :values, force: true do |t|
|
583
|
+
t.integer :value
|
584
|
+
end
|
585
|
+
|
586
|
+
assert_nothing_raised ArgumentError do
|
587
|
+
connection.add_index :values, :value, name: 'a_different_name'
|
588
|
+
connection.remove_index :values, column: :value, name: 'a_different_name'
|
589
|
+
end
|
590
|
+
|
591
|
+
connection.drop_table :values rescue nil
|
592
|
+
end
|
593
|
+
end
|
594
|
+
|
595
|
+
if ActiveRecord::Base.connection.supports_bulk_alter?
|
596
|
+
class BulkAlterTableMigrationsTest < ActiveRecord::TestCase
|
597
|
+
def setup
|
598
|
+
@connection = Person.connection
|
599
|
+
@connection.create_table(:delete_me, :force => true) {|t| }
|
600
|
+
Person.reset_column_information
|
601
|
+
Person.reset_sequence_name
|
602
|
+
end
|
603
|
+
|
604
|
+
teardown do
|
605
|
+
Person.connection.drop_table(:delete_me) rescue nil
|
606
|
+
end
|
607
|
+
|
608
|
+
def test_adding_multiple_columns
|
609
|
+
assert_queries(1) do
|
610
|
+
with_bulk_change_table do |t|
|
611
|
+
t.column :name, :string
|
612
|
+
t.string :qualification, :experience
|
613
|
+
t.integer :age, :default => 0
|
614
|
+
t.date :birthdate
|
615
|
+
t.timestamps null: true
|
616
|
+
end
|
617
|
+
end
|
618
|
+
|
619
|
+
assert_equal 8, columns.size
|
620
|
+
[:name, :qualification, :experience].each {|s| assert_equal :string, column(s).type }
|
621
|
+
assert_equal '0', column(:age).default
|
622
|
+
end
|
623
|
+
|
624
|
+
def test_removing_columns
|
625
|
+
with_bulk_change_table do |t|
|
626
|
+
t.string :qualification, :experience
|
627
|
+
end
|
628
|
+
|
629
|
+
[:qualification, :experience].each {|c| assert column(c) }
|
630
|
+
|
631
|
+
assert_queries(1) do
|
632
|
+
with_bulk_change_table do |t|
|
633
|
+
t.remove :qualification, :experience
|
634
|
+
t.string :qualification_experience
|
635
|
+
end
|
636
|
+
end
|
637
|
+
|
638
|
+
[:qualification, :experience].each {|c| assert ! column(c) }
|
639
|
+
assert column(:qualification_experience)
|
640
|
+
end
|
641
|
+
|
642
|
+
def test_adding_indexes
|
643
|
+
with_bulk_change_table do |t|
|
644
|
+
t.string :username
|
645
|
+
t.string :name
|
646
|
+
t.integer :age
|
647
|
+
end
|
648
|
+
|
649
|
+
# Adding an index fires a query every time to check if an index already exists or not
|
650
|
+
assert_queries(3) do
|
651
|
+
with_bulk_change_table do |t|
|
652
|
+
t.index :username, :unique => true, :name => :awesome_username_index
|
653
|
+
t.index [:name, :age]
|
654
|
+
end
|
655
|
+
end
|
656
|
+
|
657
|
+
assert_equal 2, indexes.size
|
658
|
+
|
659
|
+
name_age_index = index(:index_delete_me_on_name_and_age)
|
660
|
+
assert_equal ['name', 'age'].sort, name_age_index.columns.sort
|
661
|
+
assert ! name_age_index.unique
|
662
|
+
|
663
|
+
assert index(:awesome_username_index).unique
|
664
|
+
end
|
665
|
+
|
666
|
+
def test_removing_index
|
667
|
+
with_bulk_change_table do |t|
|
668
|
+
t.string :name
|
669
|
+
t.index :name
|
670
|
+
end
|
671
|
+
|
672
|
+
assert index(:index_delete_me_on_name)
|
673
|
+
|
674
|
+
assert_queries(3) do
|
675
|
+
with_bulk_change_table do |t|
|
676
|
+
t.remove_index :name
|
677
|
+
t.index :name, :name => :new_name_index, :unique => true
|
678
|
+
end
|
679
|
+
end
|
680
|
+
|
681
|
+
assert ! index(:index_delete_me_on_name)
|
682
|
+
|
683
|
+
new_name_index = index(:new_name_index)
|
684
|
+
assert new_name_index.unique
|
685
|
+
end
|
686
|
+
|
687
|
+
def test_changing_columns
|
688
|
+
with_bulk_change_table do |t|
|
689
|
+
t.string :name
|
690
|
+
t.date :birthdate
|
691
|
+
end
|
692
|
+
|
693
|
+
assert ! column(:name).default
|
694
|
+
assert_equal :date, column(:birthdate).type
|
695
|
+
|
696
|
+
# One query for columns (delete_me table)
|
697
|
+
# One query for primary key (delete_me table)
|
698
|
+
# One query to do the bulk change
|
699
|
+
assert_queries(3, :ignore_none => true) do
|
700
|
+
with_bulk_change_table do |t|
|
701
|
+
t.change :name, :string, :default => 'NONAME'
|
702
|
+
t.change :birthdate, :datetime
|
703
|
+
end
|
704
|
+
end
|
705
|
+
|
706
|
+
assert_equal 'NONAME', column(:name).default
|
707
|
+
assert_equal :datetime, column(:birthdate).type
|
708
|
+
end
|
709
|
+
|
710
|
+
protected
|
711
|
+
|
712
|
+
def with_bulk_change_table
|
713
|
+
# Reset columns/indexes cache as we're changing the table
|
714
|
+
@columns = @indexes = nil
|
715
|
+
|
716
|
+
Person.connection.change_table(:delete_me, :bulk => true) do |t|
|
717
|
+
yield t
|
718
|
+
end
|
719
|
+
end
|
720
|
+
|
721
|
+
def column(name)
|
722
|
+
columns.detect {|c| c.name == name.to_s }
|
723
|
+
end
|
724
|
+
|
725
|
+
def columns
|
726
|
+
@columns ||= Person.connection.columns('delete_me')
|
727
|
+
end
|
728
|
+
|
729
|
+
def index(name)
|
730
|
+
indexes.detect {|i| i.name == name.to_s }
|
731
|
+
end
|
732
|
+
|
733
|
+
def indexes
|
734
|
+
@indexes ||= Person.connection.indexes('delete_me')
|
735
|
+
end
|
736
|
+
end # AlterTableMigrationsTest
|
737
|
+
|
738
|
+
end
|
739
|
+
|
740
|
+
class CopyMigrationsTest < ActiveRecord::TestCase
|
741
|
+
def setup
|
742
|
+
end
|
743
|
+
|
744
|
+
def clear
|
745
|
+
ActiveRecord::Base.timestamped_migrations = true
|
746
|
+
to_delete = Dir[@migrations_path + "/*.rb"] - @existing_migrations
|
747
|
+
File.delete(*to_delete)
|
748
|
+
end
|
749
|
+
|
750
|
+
def test_copying_migrations_without_timestamps
|
751
|
+
ActiveRecord::Base.timestamped_migrations = false
|
752
|
+
@migrations_path = MIGRATIONS_ROOT + "/valid"
|
753
|
+
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
754
|
+
|
755
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"})
|
756
|
+
assert File.exist?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
|
757
|
+
assert File.exist?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
|
758
|
+
assert_equal [@migrations_path + "/4_people_have_hobbies.bukkits.rb", @migrations_path + "/5_people_have_descriptions.bukkits.rb"], copied.map(&:filename)
|
759
|
+
|
760
|
+
expected = "# This migration comes from bukkits (originally 1)"
|
761
|
+
assert_equal expected, IO.readlines(@migrations_path + "/4_people_have_hobbies.bukkits.rb")[0].chomp
|
762
|
+
|
763
|
+
files_count = Dir[@migrations_path + "/*.rb"].length
|
764
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"})
|
765
|
+
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
766
|
+
assert copied.empty?
|
767
|
+
ensure
|
768
|
+
clear
|
769
|
+
end
|
770
|
+
|
771
|
+
def test_copying_migrations_without_timestamps_from_2_sources
|
772
|
+
ActiveRecord::Base.timestamped_migrations = false
|
773
|
+
@migrations_path = MIGRATIONS_ROOT + "/valid"
|
774
|
+
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
775
|
+
|
776
|
+
sources = {}
|
777
|
+
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy"
|
778
|
+
sources[:omg] = MIGRATIONS_ROOT + "/to_copy2"
|
779
|
+
ActiveRecord::Migration.copy(@migrations_path, sources)
|
780
|
+
assert File.exist?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
|
781
|
+
assert File.exist?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
|
782
|
+
assert File.exist?(@migrations_path + "/6_create_articles.omg.rb")
|
783
|
+
assert File.exist?(@migrations_path + "/7_create_comments.omg.rb")
|
784
|
+
|
785
|
+
files_count = Dir[@migrations_path + "/*.rb"].length
|
786
|
+
ActiveRecord::Migration.copy(@migrations_path, sources)
|
787
|
+
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
788
|
+
ensure
|
789
|
+
clear
|
790
|
+
end
|
791
|
+
|
792
|
+
def test_copying_migrations_with_timestamps
|
793
|
+
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
794
|
+
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
795
|
+
|
796
|
+
travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
|
797
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
798
|
+
assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
|
799
|
+
assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
|
800
|
+
expected = [@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb",
|
801
|
+
@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb"]
|
802
|
+
assert_equal expected, copied.map(&:filename)
|
803
|
+
|
804
|
+
files_count = Dir[@migrations_path + "/*.rb"].length
|
805
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
806
|
+
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
807
|
+
assert copied.empty?
|
808
|
+
end
|
809
|
+
ensure
|
810
|
+
clear
|
811
|
+
end
|
812
|
+
|
813
|
+
def test_copying_migrations_with_timestamps_from_2_sources
|
814
|
+
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
815
|
+
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
816
|
+
|
817
|
+
sources = {}
|
818
|
+
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
|
819
|
+
sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_timestamps2"
|
820
|
+
|
821
|
+
travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
|
822
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, sources)
|
823
|
+
assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
|
824
|
+
assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
|
825
|
+
assert File.exist?(@migrations_path + "/20100726101012_create_articles.omg.rb")
|
826
|
+
assert File.exist?(@migrations_path + "/20100726101013_create_comments.omg.rb")
|
827
|
+
assert_equal 4, copied.length
|
828
|
+
|
829
|
+
files_count = Dir[@migrations_path + "/*.rb"].length
|
830
|
+
ActiveRecord::Migration.copy(@migrations_path, sources)
|
831
|
+
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
832
|
+
end
|
833
|
+
ensure
|
834
|
+
clear
|
835
|
+
end
|
836
|
+
|
837
|
+
def test_copying_migrations_with_timestamps_to_destination_with_timestamps_in_future
|
838
|
+
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
839
|
+
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
840
|
+
|
841
|
+
travel_to(Time.utc(2010, 2, 20, 10, 10, 10)) do
|
842
|
+
ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
843
|
+
assert File.exist?(@migrations_path + "/20100301010102_people_have_hobbies.bukkits.rb")
|
844
|
+
assert File.exist?(@migrations_path + "/20100301010103_people_have_descriptions.bukkits.rb")
|
845
|
+
|
846
|
+
files_count = Dir[@migrations_path + "/*.rb"].length
|
847
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
848
|
+
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
849
|
+
assert copied.empty?
|
850
|
+
end
|
851
|
+
ensure
|
852
|
+
clear
|
853
|
+
end
|
854
|
+
|
855
|
+
def test_copying_migrations_preserving_magic_comments
|
856
|
+
ActiveRecord::Base.timestamped_migrations = false
|
857
|
+
@migrations_path = MIGRATIONS_ROOT + "/valid"
|
858
|
+
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
859
|
+
|
860
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/magic"})
|
861
|
+
assert File.exist?(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")
|
862
|
+
assert_equal [@migrations_path + "/4_currencies_have_symbols.bukkits.rb"], copied.map(&:filename)
|
863
|
+
|
864
|
+
expected = "# coding: ISO-8859-15\n# This migration comes from bukkits (originally 1)"
|
865
|
+
assert_equal expected, IO.readlines(@migrations_path + "/4_currencies_have_symbols.bukkits.rb")[0..1].join.chomp
|
866
|
+
|
867
|
+
files_count = Dir[@migrations_path + "/*.rb"].length
|
868
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/magic"})
|
869
|
+
assert_equal files_count, Dir[@migrations_path + "/*.rb"].length
|
870
|
+
assert copied.empty?
|
871
|
+
ensure
|
872
|
+
clear
|
873
|
+
end
|
874
|
+
|
875
|
+
def test_skipping_migrations
|
876
|
+
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
877
|
+
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
878
|
+
|
879
|
+
sources = {}
|
880
|
+
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
|
881
|
+
sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_name_collision"
|
882
|
+
|
883
|
+
skipped = []
|
884
|
+
on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
|
885
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
|
886
|
+
assert_equal 2, copied.length
|
887
|
+
|
888
|
+
assert_equal 1, skipped.length
|
889
|
+
assert_equal ["omg PeopleHaveHobbies"], skipped
|
890
|
+
ensure
|
891
|
+
clear
|
892
|
+
end
|
893
|
+
|
894
|
+
def test_skip_is_not_called_if_migrations_are_from_the_same_plugin
|
895
|
+
@migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
|
896
|
+
@existing_migrations = Dir[@migrations_path + "/*.rb"]
|
897
|
+
|
898
|
+
sources = {}
|
899
|
+
sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
|
900
|
+
|
901
|
+
skipped = []
|
902
|
+
on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
|
903
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
|
904
|
+
ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
|
905
|
+
|
906
|
+
assert_equal 2, copied.length
|
907
|
+
assert_equal 0, skipped.length
|
908
|
+
ensure
|
909
|
+
clear
|
910
|
+
end
|
911
|
+
|
912
|
+
def test_copying_migrations_to_non_existing_directory
|
913
|
+
@migrations_path = MIGRATIONS_ROOT + "/non_existing"
|
914
|
+
@existing_migrations = []
|
915
|
+
|
916
|
+
travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
|
917
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
918
|
+
assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
|
919
|
+
assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
|
920
|
+
assert_equal 2, copied.length
|
921
|
+
end
|
922
|
+
ensure
|
923
|
+
clear
|
924
|
+
Dir.delete(@migrations_path)
|
925
|
+
end
|
926
|
+
|
927
|
+
def test_copying_migrations_to_empty_directory
|
928
|
+
@migrations_path = MIGRATIONS_ROOT + "/empty"
|
929
|
+
@existing_migrations = []
|
930
|
+
|
931
|
+
travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
|
932
|
+
copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
|
933
|
+
assert File.exist?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
|
934
|
+
assert File.exist?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
|
935
|
+
assert_equal 2, copied.length
|
936
|
+
end
|
937
|
+
ensure
|
938
|
+
clear
|
939
|
+
end
|
940
|
+
|
941
|
+
def test_check_pending_with_stdlib_logger
|
942
|
+
old, ActiveRecord::Base.logger = ActiveRecord::Base.logger, ::Logger.new($stdout)
|
943
|
+
quietly do
|
944
|
+
assert_nothing_raised { ActiveRecord::Migration::CheckPending.new(Proc.new {}).call({}) }
|
945
|
+
end
|
946
|
+
ensure
|
947
|
+
ActiveRecord::Base.logger = old
|
948
|
+
end
|
949
|
+
|
950
|
+
private
|
951
|
+
|
952
|
+
def quietly
|
953
|
+
silence_stream(STDOUT) do
|
954
|
+
silence_stream(STDERR) do
|
955
|
+
yield
|
956
|
+
end
|
957
|
+
end
|
958
|
+
end
|
959
|
+
end
|