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