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,64 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
+
require 'models/person'
|
4
|
+
require 'models/company'
|
5
|
+
|
6
|
+
class ProtectedParams < ActiveSupport::HashWithIndifferentAccess
|
7
|
+
attr_accessor :permitted
|
8
|
+
alias :permitted? :permitted
|
9
|
+
|
10
|
+
def initialize(attributes)
|
11
|
+
super(attributes)
|
12
|
+
@permitted = false
|
13
|
+
end
|
14
|
+
|
15
|
+
def permit!
|
16
|
+
@permitted = true
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def dup
|
21
|
+
super.tap do |duplicate|
|
22
|
+
duplicate.instance_variable_set :@permitted, @permitted
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase
|
28
|
+
def test_forbidden_attributes_cannot_be_used_for_mass_assignment
|
29
|
+
params = ProtectedParams.new(first_name: 'Guille', gender: 'm')
|
30
|
+
assert_raises(ActiveModel::ForbiddenAttributesError) do
|
31
|
+
Person.new(params)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_permitted_attributes_can_be_used_for_mass_assignment
|
36
|
+
params = ProtectedParams.new(first_name: 'Guille', gender: 'm')
|
37
|
+
params.permit!
|
38
|
+
person = Person.new(params)
|
39
|
+
|
40
|
+
assert_equal 'Guille', person.first_name
|
41
|
+
assert_equal 'm', person.gender
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_forbidden_attributes_cannot_be_used_for_sti_inheritance_column
|
45
|
+
params = ProtectedParams.new(type: 'Client')
|
46
|
+
assert_raises(ActiveModel::ForbiddenAttributesError) do
|
47
|
+
Company.new(params)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_permitted_attributes_can_be_used_for_sti_inheritance_column
|
52
|
+
params = ProtectedParams.new(type: 'Client')
|
53
|
+
params.permit!
|
54
|
+
person = Company.new(params)
|
55
|
+
assert_equal person.class, Client
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_regular_hash_should_still_be_used_for_mass_assignment
|
59
|
+
person = Person.new(first_name: 'Guille', gender: 'm')
|
60
|
+
|
61
|
+
assert_equal 'Guille', person.first_name
|
62
|
+
assert_equal 'm', person.gender
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
require "models/lesson"
|
3
|
+
require "models/student"
|
4
|
+
|
5
|
+
class HabtmDestroyOrderTest < ActiveRecord::TestCase
|
6
|
+
test "may not delete a lesson with students" do
|
7
|
+
sicp = Lesson.new(:name => "SICP")
|
8
|
+
ben = Student.new(:name => "Ben Bitdiddle")
|
9
|
+
sicp.students << ben
|
10
|
+
sicp.save!
|
11
|
+
assert_raises LessonError do
|
12
|
+
assert_no_difference('Lesson.count') do
|
13
|
+
sicp.destroy
|
14
|
+
end
|
15
|
+
end
|
16
|
+
assert !sicp.destroyed?
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'should not raise error if have foreign key in the join table' do
|
20
|
+
student = Student.new(:name => "Ben Bitdiddle")
|
21
|
+
lesson = Lesson.new(:name => "SICP")
|
22
|
+
lesson.students << student
|
23
|
+
lesson.save!
|
24
|
+
assert_nothing_raised do
|
25
|
+
student.destroy
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test "not destroying a student with lessons leaves student<=>lesson association intact" do
|
30
|
+
# test a normal before_destroy doesn't destroy the habtm joins
|
31
|
+
begin
|
32
|
+
sicp = Lesson.new(:name => "SICP")
|
33
|
+
ben = Student.new(:name => "Ben Bitdiddle")
|
34
|
+
# add a before destroy to student
|
35
|
+
Student.class_eval do
|
36
|
+
before_destroy do
|
37
|
+
raise ActiveRecord::Rollback unless lessons.empty?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
ben.lessons << sicp
|
41
|
+
ben.save!
|
42
|
+
ben.destroy
|
43
|
+
assert !ben.reload.lessons.empty?
|
44
|
+
ensure
|
45
|
+
# get rid of it so Student is still like it was
|
46
|
+
Student.reset_callbacks(:destroy)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
test "not destroying a lesson with students leaves student<=>lesson association intact" do
|
51
|
+
# test a more aggressive before_destroy doesn't destroy the habtm joins and still throws the exception
|
52
|
+
sicp = Lesson.new(:name => "SICP")
|
53
|
+
ben = Student.new(:name => "Ben Bitdiddle")
|
54
|
+
sicp.students << ben
|
55
|
+
sicp.save!
|
56
|
+
assert_raises LessonError do
|
57
|
+
sicp.destroy
|
58
|
+
end
|
59
|
+
assert !sicp.reload.students.empty?
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require File.expand_path('../../../../load_paths', __FILE__)
|
2
|
+
|
3
|
+
require 'config'
|
4
|
+
|
5
|
+
require 'active_support/testing/autorun'
|
6
|
+
require 'stringio'
|
7
|
+
|
8
|
+
require 'active_record'
|
9
|
+
require 'cases/test_case'
|
10
|
+
require 'active_support/dependencies'
|
11
|
+
require 'active_support/logger'
|
12
|
+
|
13
|
+
require 'support/config'
|
14
|
+
require 'support/connection'
|
15
|
+
|
16
|
+
# TODO: Move all these random hacks into the ARTest namespace and into the support/ dir
|
17
|
+
|
18
|
+
Thread.abort_on_exception = true
|
19
|
+
|
20
|
+
# Show backtraces for deprecated behavior for quicker cleanup.
|
21
|
+
ActiveSupport::Deprecation.debug = true
|
22
|
+
|
23
|
+
# Connect to the database
|
24
|
+
ARTest.connect
|
25
|
+
|
26
|
+
# Quote "type" if it's a reserved word for the current connection.
|
27
|
+
QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type')
|
28
|
+
|
29
|
+
def current_adapter?(*types)
|
30
|
+
types.any? do |type|
|
31
|
+
ActiveRecord::ConnectionAdapters.const_defined?(type) &&
|
32
|
+
ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters.const_get(type))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def in_memory_db?
|
37
|
+
current_adapter?(:SQLite3Adapter) &&
|
38
|
+
ActiveRecord::Base.connection_pool.spec.config[:database] == ":memory:"
|
39
|
+
end
|
40
|
+
|
41
|
+
def supports_savepoints?
|
42
|
+
ActiveRecord::Base.connection.supports_savepoints?
|
43
|
+
end
|
44
|
+
|
45
|
+
def with_env_tz(new_tz = 'US/Eastern')
|
46
|
+
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
|
47
|
+
yield
|
48
|
+
ensure
|
49
|
+
old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
|
50
|
+
end
|
51
|
+
|
52
|
+
def with_active_record_default_timezone(zone)
|
53
|
+
old_zone, ActiveRecord::Base.default_timezone = ActiveRecord::Base.default_timezone, zone
|
54
|
+
yield
|
55
|
+
ensure
|
56
|
+
ActiveRecord::Base.default_timezone = old_zone
|
57
|
+
end
|
58
|
+
|
59
|
+
unless ENV['FIXTURE_DEBUG']
|
60
|
+
module ActiveRecord::TestFixtures::ClassMethods
|
61
|
+
def try_to_load_dependency_with_silence(*args)
|
62
|
+
old = ActiveRecord::Base.logger.level
|
63
|
+
ActiveRecord::Base.logger.level = ActiveSupport::Logger::ERROR
|
64
|
+
try_to_load_dependency_without_silence(*args)
|
65
|
+
ActiveRecord::Base.logger.level = old
|
66
|
+
end
|
67
|
+
|
68
|
+
alias_method_chain :try_to_load_dependency, :silence
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
require "cases/validations_repair_helper"
|
73
|
+
class ActiveSupport::TestCase
|
74
|
+
include ActiveRecord::TestFixtures
|
75
|
+
include ActiveRecord::ValidationsRepairHelper
|
76
|
+
|
77
|
+
self.fixture_path = FIXTURES_ROOT
|
78
|
+
self.use_instantiated_fixtures = false
|
79
|
+
self.use_transactional_fixtures = true
|
80
|
+
|
81
|
+
def create_fixtures(*fixture_set_names, &block)
|
82
|
+
ActiveRecord::FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, fixture_class_names, &block)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def load_schema
|
87
|
+
# silence verbose schema loading
|
88
|
+
original_stdout = $stdout
|
89
|
+
$stdout = StringIO.new
|
90
|
+
|
91
|
+
adapter_name = ActiveRecord::Base.connection.adapter_name.downcase
|
92
|
+
adapter_specific_schema_file = SCHEMA_ROOT + "/#{adapter_name}_specific_schema.rb"
|
93
|
+
|
94
|
+
load SCHEMA_ROOT + "/schema.rb"
|
95
|
+
|
96
|
+
if File.exists?(adapter_specific_schema_file)
|
97
|
+
load adapter_specific_schema_file
|
98
|
+
end
|
99
|
+
ensure
|
100
|
+
$stdout = original_stdout
|
101
|
+
end
|
102
|
+
|
103
|
+
load_schema
|
104
|
+
|
105
|
+
class << Time
|
106
|
+
unless method_defined? :now_before_time_travel
|
107
|
+
alias_method :now_before_time_travel, :now
|
108
|
+
end
|
109
|
+
|
110
|
+
def now
|
111
|
+
(@now ||= nil) || now_before_time_travel
|
112
|
+
end
|
113
|
+
|
114
|
+
def travel_to(time, &block)
|
115
|
+
@now = time
|
116
|
+
block.call
|
117
|
+
ensure
|
118
|
+
@now = nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
module LogIntercepter
|
123
|
+
attr_accessor :logged, :intercepted
|
124
|
+
def self.extended(base)
|
125
|
+
base.logged = []
|
126
|
+
end
|
127
|
+
def log(sql, name, binds = [], &block)
|
128
|
+
if @intercepted
|
129
|
+
@logged << [sql, name, binds]
|
130
|
+
yield
|
131
|
+
else
|
132
|
+
super(sql, name,binds, &block)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
module InTimeZone
|
138
|
+
private
|
139
|
+
|
140
|
+
def in_time_zone(zone)
|
141
|
+
old_zone = Time.zone
|
142
|
+
old_tz = ActiveRecord::Base.time_zone_aware_attributes
|
143
|
+
|
144
|
+
Time.zone = zone ? ActiveSupport::TimeZone[zone] : nil
|
145
|
+
ActiveRecord::Base.time_zone_aware_attributes = !zone.nil?
|
146
|
+
yield
|
147
|
+
ensure
|
148
|
+
Time.zone = old_zone
|
149
|
+
ActiveRecord::Base.time_zone_aware_attributes = old_tz
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
|
3
|
+
class HotCompatibilityTest < ActiveRecord::TestCase
|
4
|
+
self.use_transactional_fixtures = false
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@klass = Class.new(ActiveRecord::Base) do
|
8
|
+
connection.create_table :hot_compatibilities do |t|
|
9
|
+
t.string :foo
|
10
|
+
t.string :bar
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.name; 'HotCompatibility'; end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
teardown do
|
18
|
+
@klass.connection.drop_table :hot_compatibilities
|
19
|
+
end
|
20
|
+
|
21
|
+
test "insert after remove_column" do
|
22
|
+
# warm cache
|
23
|
+
@klass.create!
|
24
|
+
|
25
|
+
# we have 3 columns
|
26
|
+
assert_equal 3, @klass.columns.length
|
27
|
+
|
28
|
+
# remove one of them
|
29
|
+
@klass.connection.remove_column :hot_compatibilities, :bar
|
30
|
+
|
31
|
+
# we still have 3 columns in the cache
|
32
|
+
assert_equal 3, @klass.columns.length
|
33
|
+
|
34
|
+
# but we can successfully create a record so long as we don't
|
35
|
+
# reference the removed column
|
36
|
+
record = @klass.create! foo: 'foo'
|
37
|
+
record.reload
|
38
|
+
assert_equal 'foo', record.foo
|
39
|
+
end
|
40
|
+
|
41
|
+
test "update after remove_column" do
|
42
|
+
record = @klass.create! foo: 'foo'
|
43
|
+
assert_equal 3, @klass.columns.length
|
44
|
+
@klass.connection.remove_column :hot_compatibilities, :bar
|
45
|
+
assert_equal 3, @klass.columns.length
|
46
|
+
|
47
|
+
record.reload
|
48
|
+
assert_equal 'foo', record.foo
|
49
|
+
record.foo = 'bar'
|
50
|
+
record.save!
|
51
|
+
record.reload
|
52
|
+
assert_equal 'bar', record.foo
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
require 'models/topic'
|
3
|
+
require 'models/reply'
|
4
|
+
|
5
|
+
class ActiveRecordI18nTests < ActiveRecord::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
I18n.backend = I18n::Backend::Simple.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_translated_model_attributes
|
12
|
+
I18n.backend.store_translations 'en', :activerecord => {:attributes => {:topic => {:title => 'topic title attribute'} } }
|
13
|
+
assert_equal 'topic title attribute', Topic.human_attribute_name('title')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_translated_model_attributes_with_symbols
|
17
|
+
I18n.backend.store_translations 'en', :activerecord => {:attributes => {:topic => {:title => 'topic title attribute'} } }
|
18
|
+
assert_equal 'topic title attribute', Topic.human_attribute_name(:title)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_translated_model_attributes_with_sti
|
22
|
+
I18n.backend.store_translations 'en', :activerecord => {:attributes => {:reply => {:title => 'reply title attribute'} } }
|
23
|
+
assert_equal 'reply title attribute', Reply.human_attribute_name('title')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_translated_model_attributes_with_sti_fallback
|
27
|
+
I18n.backend.store_translations 'en', :activerecord => {:attributes => {:topic => {:title => 'topic title attribute'} } }
|
28
|
+
assert_equal 'topic title attribute', Reply.human_attribute_name('title')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_translated_model_names
|
32
|
+
I18n.backend.store_translations 'en', :activerecord => {:models => {:topic => 'topic model'} }
|
33
|
+
assert_equal 'topic model', Topic.model_name.human
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_translated_model_names_with_sti
|
37
|
+
I18n.backend.store_translations 'en', :activerecord => {:models => {:reply => 'reply model'} }
|
38
|
+
assert_equal 'reply model', Reply.model_name.human
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_translated_model_names_with_sti_fallback
|
42
|
+
I18n.backend.store_translations 'en', :activerecord => {:models => {:topic => 'topic model'} }
|
43
|
+
assert_equal 'topic model', Reply.model_name.human
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,355 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
require 'models/company'
|
3
|
+
require 'models/person'
|
4
|
+
require 'models/post'
|
5
|
+
require 'models/project'
|
6
|
+
require 'models/subscriber'
|
7
|
+
require 'models/vegetables'
|
8
|
+
|
9
|
+
class InheritanceTest < ActiveRecord::TestCase
|
10
|
+
fixtures :companies, :projects, :subscribers, :accounts, :vegetables
|
11
|
+
|
12
|
+
def test_class_with_store_full_sti_class_returns_full_name
|
13
|
+
old = ActiveRecord::Base.store_full_sti_class
|
14
|
+
ActiveRecord::Base.store_full_sti_class = true
|
15
|
+
assert_equal 'Namespaced::Company', Namespaced::Company.sti_name
|
16
|
+
ensure
|
17
|
+
ActiveRecord::Base.store_full_sti_class = old
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_class_with_blank_sti_name
|
21
|
+
company = Company.first
|
22
|
+
company = company.dup
|
23
|
+
company.extend(Module.new {
|
24
|
+
def read_attribute(name)
|
25
|
+
return ' ' if name == 'type'
|
26
|
+
super
|
27
|
+
end
|
28
|
+
})
|
29
|
+
company.save!
|
30
|
+
company = Company.all.to_a.find { |x| x.id == company.id }
|
31
|
+
assert_equal ' ', company.type
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_class_without_store_full_sti_class_returns_demodulized_name
|
35
|
+
old = ActiveRecord::Base.store_full_sti_class
|
36
|
+
ActiveRecord::Base.store_full_sti_class = false
|
37
|
+
assert_equal 'Company', Namespaced::Company.sti_name
|
38
|
+
ensure
|
39
|
+
ActiveRecord::Base.store_full_sti_class = old
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_should_store_demodulized_class_name_with_store_full_sti_class_option_disabled
|
43
|
+
old = ActiveRecord::Base.store_full_sti_class
|
44
|
+
ActiveRecord::Base.store_full_sti_class = false
|
45
|
+
item = Namespaced::Company.new
|
46
|
+
assert_equal 'Company', item[:type]
|
47
|
+
ensure
|
48
|
+
ActiveRecord::Base.store_full_sti_class = old
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_store_full_class_name_with_store_full_sti_class_option_enabled
|
52
|
+
old = ActiveRecord::Base.store_full_sti_class
|
53
|
+
ActiveRecord::Base.store_full_sti_class = true
|
54
|
+
item = Namespaced::Company.new
|
55
|
+
assert_equal 'Namespaced::Company', item[:type]
|
56
|
+
ensure
|
57
|
+
ActiveRecord::Base.store_full_sti_class = old
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_different_namespace_subclass_should_load_correctly_with_store_full_sti_class_option
|
61
|
+
old = ActiveRecord::Base.store_full_sti_class
|
62
|
+
ActiveRecord::Base.store_full_sti_class = true
|
63
|
+
item = Namespaced::Company.create :name => "Wolverine 2"
|
64
|
+
assert_not_nil Company.find(item.id)
|
65
|
+
assert_not_nil Namespaced::Company.find(item.id)
|
66
|
+
ensure
|
67
|
+
ActiveRecord::Base.store_full_sti_class = old
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_company_descends_from_active_record
|
71
|
+
assert !ActiveRecord::Base.descends_from_active_record?
|
72
|
+
assert AbstractCompany.descends_from_active_record?, 'AbstractCompany should descend from ActiveRecord::Base'
|
73
|
+
assert Company.descends_from_active_record?, 'Company should descend from ActiveRecord::Base'
|
74
|
+
assert !Class.new(Company).descends_from_active_record?, 'Company subclass should not descend from ActiveRecord::Base'
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_inheritance_base_class
|
78
|
+
assert_equal Post, Post.base_class
|
79
|
+
assert_equal Post, SpecialPost.base_class
|
80
|
+
assert_equal Post, StiPost.base_class
|
81
|
+
assert_equal SubStiPost, SubStiPost.base_class
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_abstract_inheritance_base_class
|
85
|
+
assert_equal LoosePerson, LoosePerson.base_class
|
86
|
+
assert_equal LooseDescendant, LooseDescendant.base_class
|
87
|
+
assert_equal TightPerson, TightPerson.base_class
|
88
|
+
assert_equal TightPerson, TightDescendant.base_class
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_base_class_activerecord_error
|
92
|
+
klass = Class.new { include ActiveRecord::Inheritance }
|
93
|
+
assert_raise(ActiveRecord::ActiveRecordError) { klass.base_class }
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_a_bad_type_column
|
97
|
+
#SQLServer need to turn Identity Insert On before manually inserting into the Identity column
|
98
|
+
if current_adapter?(:SybaseAdapter)
|
99
|
+
Company.connection.execute "SET IDENTITY_INSERT companies ON"
|
100
|
+
end
|
101
|
+
Company.connection.insert "INSERT INTO companies (id, #{QUOTED_TYPE}, name) VALUES(100, 'bad_class!', 'Not happening')"
|
102
|
+
|
103
|
+
#We then need to turn it back Off before continuing.
|
104
|
+
if current_adapter?(:SybaseAdapter)
|
105
|
+
Company.connection.execute "SET IDENTITY_INSERT companies OFF"
|
106
|
+
end
|
107
|
+
assert_raise(ActiveRecord::SubclassNotFound) { Company.find(100) }
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_inheritance_find
|
111
|
+
assert_kind_of Firm, Company.find(1), "37signals should be a firm"
|
112
|
+
assert_kind_of Firm, Firm.find(1), "37signals should be a firm"
|
113
|
+
assert_kind_of Client, Company.find(2), "Summit should be a client"
|
114
|
+
assert_kind_of Client, Client.find(2), "Summit should be a client"
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_alt_inheritance_find
|
118
|
+
assert_kind_of Cucumber, Vegetable.find(1)
|
119
|
+
assert_kind_of Cucumber, Cucumber.find(1)
|
120
|
+
assert_kind_of Cabbage, Vegetable.find(2)
|
121
|
+
assert_kind_of Cabbage, Cabbage.find(2)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_alt_becomes_works_with_sti
|
125
|
+
vegetable = Vegetable.find(1)
|
126
|
+
assert_kind_of Vegetable, vegetable
|
127
|
+
cabbage = vegetable.becomes(Cabbage)
|
128
|
+
assert_kind_of Cabbage, cabbage
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_inheritance_find_all
|
132
|
+
companies = Company.all.merge!(:order => 'id').to_a
|
133
|
+
assert_kind_of Firm, companies[0], "37signals should be a firm"
|
134
|
+
assert_kind_of Client, companies[1], "Summit should be a client"
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_alt_inheritance_find_all
|
138
|
+
companies = Vegetable.all.merge!(:order => 'id').to_a
|
139
|
+
assert_kind_of Cucumber, companies[0]
|
140
|
+
assert_kind_of Cabbage, companies[1]
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_inheritance_save
|
144
|
+
firm = Firm.new
|
145
|
+
firm.name = "Next Angle"
|
146
|
+
firm.save
|
147
|
+
|
148
|
+
next_angle = Company.find(firm.id)
|
149
|
+
assert_kind_of Firm, next_angle, "Next Angle should be a firm"
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_alt_inheritance_save
|
153
|
+
cabbage = Cabbage.new(:name => 'Savoy')
|
154
|
+
cabbage.save!
|
155
|
+
|
156
|
+
savoy = Vegetable.find(cabbage.id)
|
157
|
+
assert_kind_of Cabbage, savoy
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_inheritance_new_with_default_class
|
161
|
+
company = Company.new
|
162
|
+
assert_equal Company, company.class
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_inheritance_new_with_base_class
|
166
|
+
company = Company.new(:type => 'Company')
|
167
|
+
assert_equal Company, company.class
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_inheritance_new_with_subclass
|
171
|
+
firm = Company.new(:type => 'Firm')
|
172
|
+
assert_equal Firm, firm.class
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_new_with_abstract_class
|
176
|
+
e = assert_raises(NotImplementedError) do
|
177
|
+
AbstractCompany.new
|
178
|
+
end
|
179
|
+
assert_equal("AbstractCompany is an abstract class and can not be instantiated.", e.message)
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_new_with_ar_base
|
183
|
+
e = assert_raises(NotImplementedError) do
|
184
|
+
ActiveRecord::Base.new
|
185
|
+
end
|
186
|
+
assert_equal("ActiveRecord::Base is an abstract class and can not be instantiated.", e.message)
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_new_with_invalid_type
|
190
|
+
assert_raise(ActiveRecord::SubclassNotFound) { Company.new(:type => 'InvalidType') }
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_new_with_unrelated_type
|
194
|
+
assert_raise(ActiveRecord::SubclassNotFound) { Company.new(:type => 'Account') }
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_new_with_complex_inheritance
|
198
|
+
assert_nothing_raised { Client.new(type: 'VerySpecialClient') }
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_new_with_autoload_paths
|
202
|
+
path = File.expand_path('../../models/autoloadable', __FILE__)
|
203
|
+
ActiveSupport::Dependencies.autoload_paths << path
|
204
|
+
|
205
|
+
firm = Company.new(:type => 'ExtraFirm')
|
206
|
+
assert_equal ExtraFirm, firm.class
|
207
|
+
ensure
|
208
|
+
ActiveSupport::Dependencies.autoload_paths.reject! { |p| p == path }
|
209
|
+
ActiveSupport::Dependencies.clear
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_inheritance_condition
|
213
|
+
assert_equal 10, Company.count
|
214
|
+
assert_equal 2, Firm.count
|
215
|
+
assert_equal 4, Client.count
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_alt_inheritance_condition
|
219
|
+
assert_equal 4, Vegetable.count
|
220
|
+
assert_equal 1, Cucumber.count
|
221
|
+
assert_equal 3, Cabbage.count
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_finding_incorrect_type_data
|
225
|
+
assert_raise(ActiveRecord::RecordNotFound) { Firm.find(2) }
|
226
|
+
assert_nothing_raised { Firm.find(1) }
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_alt_finding_incorrect_type_data
|
230
|
+
assert_raise(ActiveRecord::RecordNotFound) { Cucumber.find(2) }
|
231
|
+
assert_nothing_raised { Cucumber.find(1) }
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_update_all_within_inheritance
|
235
|
+
Client.update_all "name = 'I am a client'"
|
236
|
+
assert_equal "I am a client", Client.first.name
|
237
|
+
# Order by added as otherwise Oracle tests were failing because of different order of results
|
238
|
+
assert_equal "37signals", Firm.all.merge!(:order => "id").to_a.first.name
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_alt_update_all_within_inheritance
|
242
|
+
Cabbage.update_all "name = 'the cabbage'"
|
243
|
+
assert_equal "the cabbage", Cabbage.first.name
|
244
|
+
assert_equal ["my cucumber"], Cucumber.all.map(&:name).uniq
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_destroy_all_within_inheritance
|
248
|
+
Client.destroy_all
|
249
|
+
assert_equal 0, Client.count
|
250
|
+
assert_equal 2, Firm.count
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_alt_destroy_all_within_inheritance
|
254
|
+
Cabbage.destroy_all
|
255
|
+
assert_equal 0, Cabbage.count
|
256
|
+
assert_equal 1, Cucumber.count
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_find_first_within_inheritance
|
260
|
+
assert_kind_of Firm, Company.all.merge!(:where => "name = '37signals'").first
|
261
|
+
assert_kind_of Firm, Firm.all.merge!(:where => "name = '37signals'").first
|
262
|
+
assert_nil Client.all.merge!(:where => "name = '37signals'").first
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_alt_find_first_within_inheritance
|
266
|
+
assert_kind_of Cabbage, Vegetable.all.merge!(:where => "name = 'his cabbage'").first
|
267
|
+
assert_kind_of Cabbage, Cabbage.all.merge!(:where => "name = 'his cabbage'").first
|
268
|
+
assert_nil Cucumber.all.merge!(:where => "name = 'his cabbage'").first
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_complex_inheritance
|
272
|
+
very_special_client = VerySpecialClient.create("name" => "veryspecial")
|
273
|
+
assert_equal very_special_client, VerySpecialClient.where("name = 'veryspecial'").first
|
274
|
+
assert_equal very_special_client, SpecialClient.all.merge!(:where => "name = 'veryspecial'").first
|
275
|
+
assert_equal very_special_client, Company.all.merge!(:where => "name = 'veryspecial'").first
|
276
|
+
assert_equal very_special_client, Client.all.merge!(:where => "name = 'veryspecial'").first
|
277
|
+
assert_equal 1, Client.all.merge!(:where => "name = 'Summit'").to_a.size
|
278
|
+
assert_equal very_special_client, Client.find(very_special_client.id)
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_alt_complex_inheritance
|
282
|
+
king_cole = KingCole.create("name" => "uniform heads")
|
283
|
+
assert_equal king_cole, KingCole.where("name = 'uniform heads'").first
|
284
|
+
assert_equal king_cole, GreenCabbage.all.merge!(:where => "name = 'uniform heads'").first
|
285
|
+
assert_equal king_cole, Cabbage.all.merge!(:where => "name = 'uniform heads'").first
|
286
|
+
assert_equal king_cole, Vegetable.all.merge!(:where => "name = 'uniform heads'").first
|
287
|
+
assert_equal 1, Cabbage.all.merge!(:where => "name = 'his cabbage'").to_a.size
|
288
|
+
assert_equal king_cole, Cabbage.find(king_cole.id)
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_eager_load_belongs_to_something_inherited
|
292
|
+
account = Account.all.merge!(:includes => :firm).find(1)
|
293
|
+
assert account.association_cache.key?(:firm), "nil proves eager load failed"
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_alt_eager_loading
|
297
|
+
cabbage = RedCabbage.all.merge!(:includes => :seller).find(4)
|
298
|
+
assert cabbage.association_cache.key?(:seller), "nil proves eager load failed"
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_eager_load_belongs_to_primary_key_quoting
|
302
|
+
con = Account.connection
|
303
|
+
assert_sql(/#{con.quote_table_name('companies')}.#{con.quote_column_name('id')} IN \(1\)/) do
|
304
|
+
Account.all.merge!(:includes => :firm).find(1)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_inherits_custom_primary_key
|
309
|
+
assert_equal Subscriber.primary_key, SpecialSubscriber.primary_key
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_inheritance_without_mapping
|
313
|
+
assert_kind_of SpecialSubscriber, SpecialSubscriber.find("webster132")
|
314
|
+
assert_nothing_raised { s = SpecialSubscriber.new("name" => "And breaaaaathe!"); s.id = 'roger'; s.save }
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
|
319
|
+
class InheritanceComputeTypeTest < ActiveRecord::TestCase
|
320
|
+
fixtures :companies
|
321
|
+
|
322
|
+
def setup
|
323
|
+
ActiveSupport::Dependencies.log_activity = true
|
324
|
+
end
|
325
|
+
|
326
|
+
def teardown
|
327
|
+
ActiveSupport::Dependencies.log_activity = false
|
328
|
+
self.class.const_remove :FirmOnTheFly rescue nil
|
329
|
+
Firm.const_remove :FirmOnTheFly rescue nil
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_instantiation_doesnt_try_to_require_corresponding_file
|
333
|
+
ActiveRecord::Base.store_full_sti_class = false
|
334
|
+
foo = Firm.first.clone
|
335
|
+
foo.type = 'FirmOnTheFly'
|
336
|
+
foo.save!
|
337
|
+
|
338
|
+
# Should fail without FirmOnTheFly in the type condition.
|
339
|
+
assert_raise(ActiveRecord::RecordNotFound) { Firm.find(foo.id) }
|
340
|
+
|
341
|
+
# Nest FirmOnTheFly in the test case where Dependencies won't see it.
|
342
|
+
self.class.const_set :FirmOnTheFly, Class.new(Firm)
|
343
|
+
assert_raise(ActiveRecord::SubclassNotFound) { Firm.find(foo.id) }
|
344
|
+
|
345
|
+
# Nest FirmOnTheFly in Firm where Dependencies will see it.
|
346
|
+
# This is analogous to nesting models in a migration.
|
347
|
+
Firm.const_set :FirmOnTheFly, Class.new(Firm)
|
348
|
+
|
349
|
+
# And instantiate will find the existing constant rather than trying
|
350
|
+
# to require firm_on_the_fly.
|
351
|
+
assert_nothing_raised { assert_kind_of Firm::FirmOnTheFly, Firm.find(foo.id) }
|
352
|
+
ensure
|
353
|
+
ActiveRecord::Base.store_full_sti_class = true
|
354
|
+
end
|
355
|
+
end
|