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,308 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
require 'models/developer'
|
3
|
+
require 'models/owner'
|
4
|
+
require 'models/pet'
|
5
|
+
require 'models/toy'
|
6
|
+
require 'models/car'
|
7
|
+
require 'models/task'
|
8
|
+
|
9
|
+
class TimestampTest < ActiveRecord::TestCase
|
10
|
+
fixtures :developers, :owners, :pets, :toys, :cars, :tasks
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@developer = Developer.first
|
14
|
+
@developer.update_columns(updated_at: Time.now.prev_month)
|
15
|
+
@previously_updated_at = @developer.updated_at
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_saving_a_changed_record_updates_its_timestamp
|
19
|
+
@developer.name = "Jack Bauer"
|
20
|
+
@developer.save!
|
21
|
+
|
22
|
+
assert_not_equal @previously_updated_at, @developer.updated_at
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_saving_a_unchanged_record_doesnt_update_its_timestamp
|
26
|
+
@developer.save!
|
27
|
+
|
28
|
+
assert_equal @previously_updated_at, @developer.updated_at
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_touching_a_record_updates_its_timestamp
|
32
|
+
previous_salary = @developer.salary
|
33
|
+
@developer.salary = previous_salary + 10000
|
34
|
+
@developer.touch
|
35
|
+
|
36
|
+
assert_not_equal @previously_updated_at, @developer.updated_at
|
37
|
+
assert_equal previous_salary + 10000, @developer.salary
|
38
|
+
assert @developer.salary_changed?, 'developer salary should have changed'
|
39
|
+
assert @developer.changed?, 'developer should be marked as changed'
|
40
|
+
@developer.reload
|
41
|
+
assert_equal previous_salary, @developer.salary
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_touching_a_record_with_default_scope_that_excludes_it_updates_its_timestamp
|
45
|
+
developer = @developer.becomes(DeveloperCalledJamis)
|
46
|
+
|
47
|
+
developer.touch
|
48
|
+
assert_not_equal @previously_updated_at, developer.updated_at
|
49
|
+
developer.reload
|
50
|
+
assert_not_equal @previously_updated_at, developer.updated_at
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_saving_when_record_timestamps_is_false_doesnt_update_its_timestamp
|
54
|
+
Developer.record_timestamps = false
|
55
|
+
@developer.name = "John Smith"
|
56
|
+
@developer.save!
|
57
|
+
|
58
|
+
assert_equal @previously_updated_at, @developer.updated_at
|
59
|
+
ensure
|
60
|
+
Developer.record_timestamps = true
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_saving_when_instance_record_timestamps_is_false_doesnt_update_its_timestamp
|
64
|
+
@developer.record_timestamps = false
|
65
|
+
assert Developer.record_timestamps
|
66
|
+
|
67
|
+
@developer.name = "John Smith"
|
68
|
+
@developer.save!
|
69
|
+
|
70
|
+
assert_equal @previously_updated_at, @developer.updated_at
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_touching_an_attribute_updates_timestamp
|
74
|
+
previously_created_at = @developer.created_at
|
75
|
+
@developer.touch(:created_at)
|
76
|
+
|
77
|
+
assert !@developer.created_at_changed? , 'created_at should not be changed'
|
78
|
+
assert !@developer.changed?, 'record should not be changed'
|
79
|
+
assert_not_equal previously_created_at, @developer.created_at
|
80
|
+
assert_not_equal @previously_updated_at, @developer.updated_at
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_touching_an_attribute_updates_it
|
84
|
+
task = Task.first
|
85
|
+
previous_value = task.ending
|
86
|
+
task.touch(:ending)
|
87
|
+
assert_not_equal previous_value, task.ending
|
88
|
+
assert_in_delta Time.now, task.ending, 1
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_touching_a_record_without_timestamps_is_unexceptional
|
92
|
+
assert_nothing_raised { Car.first.touch }
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
|
96
|
+
pet = Pet.first
|
97
|
+
owner = pet.owner
|
98
|
+
previously_owner_updated_at = owner.updated_at
|
99
|
+
|
100
|
+
pet.name = "Fluffy the Third"
|
101
|
+
pet.save
|
102
|
+
|
103
|
+
assert_not_equal previously_owner_updated_at, pet.owner.updated_at
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_destroying_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
|
107
|
+
pet = Pet.first
|
108
|
+
owner = pet.owner
|
109
|
+
previously_owner_updated_at = owner.updated_at
|
110
|
+
|
111
|
+
pet.destroy
|
112
|
+
|
113
|
+
assert_not_equal previously_owner_updated_at, pet.owner.updated_at
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_saving_a_new_record_belonging_to_invalid_parent_with_touch_should_not_raise_exception
|
117
|
+
klass = Class.new(Owner) do
|
118
|
+
def self.name; 'Owner'; end
|
119
|
+
validate { errors.add(:base, :invalid) }
|
120
|
+
end
|
121
|
+
|
122
|
+
pet = Pet.new(owner: klass.new)
|
123
|
+
pet.save!
|
124
|
+
|
125
|
+
assert pet.owner.new_record?
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_saving_a_record_with_a_belongs_to_that_specifies_touching_a_specific_attribute_the_parent_should_update_that_attribute
|
129
|
+
klass = Class.new(ActiveRecord::Base) do
|
130
|
+
def self.name; 'Pet'; end
|
131
|
+
belongs_to :owner, :touch => :happy_at
|
132
|
+
end
|
133
|
+
|
134
|
+
pet = klass.first
|
135
|
+
owner = pet.owner
|
136
|
+
previously_owner_happy_at = owner.happy_at
|
137
|
+
|
138
|
+
pet.name = "Fluffy the Third"
|
139
|
+
pet.save
|
140
|
+
|
141
|
+
assert_not_equal previously_owner_happy_at, pet.owner.happy_at
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_touching_a_record_with_a_belongs_to_that_uses_a_counter_cache_should_update_the_parent
|
145
|
+
klass = Class.new(ActiveRecord::Base) do
|
146
|
+
def self.name; 'Pet'; end
|
147
|
+
belongs_to :owner, :counter_cache => :use_count, :touch => true
|
148
|
+
end
|
149
|
+
|
150
|
+
pet = klass.first
|
151
|
+
owner = pet.owner
|
152
|
+
owner.update_columns(happy_at: 3.days.ago)
|
153
|
+
previously_owner_updated_at = owner.updated_at
|
154
|
+
|
155
|
+
pet.name = "I'm a parrot"
|
156
|
+
pet.save
|
157
|
+
|
158
|
+
assert_not_equal previously_owner_updated_at, pet.owner.updated_at
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_touching_a_record_touches_parent_record_and_grandparent_record
|
162
|
+
klass = Class.new(ActiveRecord::Base) do
|
163
|
+
def self.name; 'Toy'; end
|
164
|
+
belongs_to :pet, :touch => true
|
165
|
+
end
|
166
|
+
|
167
|
+
toy = klass.first
|
168
|
+
pet = toy.pet
|
169
|
+
owner = pet.owner
|
170
|
+
time = 3.days.ago
|
171
|
+
|
172
|
+
owner.update_columns(updated_at: time)
|
173
|
+
toy.touch
|
174
|
+
owner.reload
|
175
|
+
|
176
|
+
assert_not_equal time, owner.updated_at
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_touching_a_record_touches_polymorphic_record
|
180
|
+
klass = Class.new(ActiveRecord::Base) do
|
181
|
+
def self.name; 'Toy'; end
|
182
|
+
end
|
183
|
+
|
184
|
+
wheel_klass = Class.new(ActiveRecord::Base) do
|
185
|
+
def self.name; 'Wheel'; end
|
186
|
+
belongs_to :wheelable, :polymorphic => true, :touch => true
|
187
|
+
end
|
188
|
+
|
189
|
+
toy = klass.first
|
190
|
+
time = 3.days.ago
|
191
|
+
toy.update_columns(updated_at: time)
|
192
|
+
|
193
|
+
wheel = wheel_klass.new
|
194
|
+
wheel.wheelable = toy
|
195
|
+
wheel.save
|
196
|
+
wheel.touch
|
197
|
+
|
198
|
+
assert_not_equal time, toy.updated_at
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_changing_parent_of_a_record_touches_both_new_and_old_parent_record
|
202
|
+
klass = Class.new(ActiveRecord::Base) do
|
203
|
+
def self.name; 'Toy'; end
|
204
|
+
belongs_to :pet, touch: true
|
205
|
+
end
|
206
|
+
|
207
|
+
toy1 = klass.find(1)
|
208
|
+
old_pet = toy1.pet
|
209
|
+
|
210
|
+
toy2 = klass.find(2)
|
211
|
+
new_pet = toy2.pet
|
212
|
+
time = 3.days.ago.at_beginning_of_hour
|
213
|
+
|
214
|
+
old_pet.update_columns(updated_at: time)
|
215
|
+
new_pet.update_columns(updated_at: time)
|
216
|
+
|
217
|
+
toy1.pet = new_pet
|
218
|
+
toy1.save!
|
219
|
+
|
220
|
+
old_pet.reload
|
221
|
+
new_pet.reload
|
222
|
+
|
223
|
+
assert_not_equal time, new_pet.updated_at
|
224
|
+
assert_not_equal time, old_pet.updated_at
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_changing_parent_of_a_record_touches_both_new_and_old_polymorphic_parent_record
|
228
|
+
klass = Class.new(ActiveRecord::Base) do
|
229
|
+
def self.name; 'Toy'; end
|
230
|
+
end
|
231
|
+
|
232
|
+
wheel_klass = Class.new(ActiveRecord::Base) do
|
233
|
+
def self.name; 'Wheel'; end
|
234
|
+
belongs_to :wheelable, :polymorphic => true, :touch => true
|
235
|
+
end
|
236
|
+
|
237
|
+
toy1 = klass.find(1)
|
238
|
+
toy2 = klass.find(2)
|
239
|
+
|
240
|
+
wheel = wheel_klass.new
|
241
|
+
wheel.wheelable = toy1
|
242
|
+
wheel.save!
|
243
|
+
|
244
|
+
time = 3.days.ago.at_beginning_of_hour
|
245
|
+
|
246
|
+
toy1.update_columns(updated_at: time)
|
247
|
+
toy2.update_columns(updated_at: time)
|
248
|
+
|
249
|
+
wheel.wheelable = toy2
|
250
|
+
wheel.save!
|
251
|
+
|
252
|
+
toy1.reload
|
253
|
+
toy2.reload
|
254
|
+
|
255
|
+
assert_not_equal time, toy1.updated_at
|
256
|
+
assert_not_equal time, toy2.updated_at
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_clearing_association_touches_the_old_record
|
260
|
+
klass = Class.new(ActiveRecord::Base) do
|
261
|
+
def self.name; 'Toy'; end
|
262
|
+
belongs_to :pet, touch: true
|
263
|
+
end
|
264
|
+
|
265
|
+
toy = klass.find(1)
|
266
|
+
pet = toy.pet
|
267
|
+
time = 3.days.ago.at_beginning_of_hour
|
268
|
+
|
269
|
+
pet.update_columns(updated_at: time)
|
270
|
+
|
271
|
+
toy.pet = nil
|
272
|
+
toy.save!
|
273
|
+
|
274
|
+
pet.reload
|
275
|
+
|
276
|
+
assert_not_equal time, pet.updated_at
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_timestamp_attributes_for_create
|
280
|
+
toy = Toy.first
|
281
|
+
assert_equal toy.send(:timestamp_attributes_for_create), [:created_at, :created_on]
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_timestamp_attributes_for_update
|
285
|
+
toy = Toy.first
|
286
|
+
assert_equal toy.send(:timestamp_attributes_for_update), [:updated_at, :updated_on]
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_all_timestamp_attributes
|
290
|
+
toy = Toy.first
|
291
|
+
assert_equal toy.send(:all_timestamp_attributes), [:created_at, :created_on, :updated_at, :updated_on]
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_timestamp_attributes_for_create_in_model
|
295
|
+
toy = Toy.first
|
296
|
+
assert_equal toy.send(:timestamp_attributes_for_create_in_model), [:created_at]
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_timestamp_attributes_for_update_in_model
|
300
|
+
toy = Toy.first
|
301
|
+
assert_equal toy.send(:timestamp_attributes_for_update_in_model), [:updated_at]
|
302
|
+
end
|
303
|
+
|
304
|
+
def test_all_timestamp_attributes_in_model
|
305
|
+
toy = Toy.first
|
306
|
+
assert_equal toy.send(:all_timestamp_attributes_in_model), [:created_at, :updated_at]
|
307
|
+
end
|
308
|
+
end
|
@@ -0,0 +1,317 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
require 'models/topic'
|
3
|
+
|
4
|
+
class TransactionCallbacksTest < ActiveRecord::TestCase
|
5
|
+
self.use_transactional_fixtures = false
|
6
|
+
fixtures :topics
|
7
|
+
|
8
|
+
class ReplyWithCallbacks < ActiveRecord::Base
|
9
|
+
self.table_name = :topics
|
10
|
+
|
11
|
+
belongs_to :topic, foreign_key: "parent_id"
|
12
|
+
|
13
|
+
validates_presence_of :content
|
14
|
+
|
15
|
+
after_commit :do_after_commit, on: :create
|
16
|
+
|
17
|
+
def history
|
18
|
+
@history ||= []
|
19
|
+
end
|
20
|
+
|
21
|
+
def do_after_commit
|
22
|
+
history << :commit_on_create
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class TopicWithCallbacks < ActiveRecord::Base
|
27
|
+
self.table_name = :topics
|
28
|
+
|
29
|
+
has_many :replies, class_name: "ReplyWithCallbacks", foreign_key: "parent_id"
|
30
|
+
|
31
|
+
after_commit{|record| record.send(:do_after_commit, nil)}
|
32
|
+
after_commit(:on => :create){|record| record.send(:do_after_commit, :create)}
|
33
|
+
after_commit(:on => :update){|record| record.send(:do_after_commit, :update)}
|
34
|
+
after_commit(:on => :destroy){|record| record.send(:do_after_commit, :destroy)}
|
35
|
+
after_rollback{|record| record.send(:do_after_rollback, nil)}
|
36
|
+
after_rollback(:on => :create){|record| record.send(:do_after_rollback, :create)}
|
37
|
+
after_rollback(:on => :update){|record| record.send(:do_after_rollback, :update)}
|
38
|
+
after_rollback(:on => :destroy){|record| record.send(:do_after_rollback, :destroy)}
|
39
|
+
|
40
|
+
def history
|
41
|
+
@history ||= []
|
42
|
+
end
|
43
|
+
|
44
|
+
def after_commit_block(on = nil, &block)
|
45
|
+
@after_commit ||= {}
|
46
|
+
@after_commit[on] ||= []
|
47
|
+
@after_commit[on] << block
|
48
|
+
end
|
49
|
+
|
50
|
+
def after_rollback_block(on = nil, &block)
|
51
|
+
@after_rollback ||= {}
|
52
|
+
@after_rollback[on] ||= []
|
53
|
+
@after_rollback[on] << block
|
54
|
+
end
|
55
|
+
|
56
|
+
def do_after_commit(on)
|
57
|
+
blocks = @after_commit[on] if defined?(@after_commit)
|
58
|
+
blocks.each{|b| b.call(self)} if blocks
|
59
|
+
end
|
60
|
+
|
61
|
+
def do_after_rollback(on)
|
62
|
+
blocks = @after_rollback[on] if defined?(@after_rollback)
|
63
|
+
blocks.each{|b| b.call(self)} if blocks
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def setup
|
68
|
+
@first, @second = TopicWithCallbacks.find(1, 3).sort_by { |t| t.id }
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_call_after_commit_after_transaction_commits
|
72
|
+
@first.after_commit_block{|r| r.history << :after_commit}
|
73
|
+
@first.after_rollback_block{|r| r.history << :after_rollback}
|
74
|
+
|
75
|
+
@first.save!
|
76
|
+
assert_equal [:after_commit], @first.history
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_only_call_after_commit_on_update_after_transaction_commits_for_existing_record
|
80
|
+
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
81
|
+
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
82
|
+
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
83
|
+
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
84
|
+
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
85
|
+
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
86
|
+
|
87
|
+
@first.save!
|
88
|
+
assert_equal [:commit_on_update], @first.history
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_only_call_after_commit_on_destroy_after_transaction_commits_for_destroyed_record
|
92
|
+
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
93
|
+
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
94
|
+
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
95
|
+
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
96
|
+
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
97
|
+
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
98
|
+
|
99
|
+
@first.destroy
|
100
|
+
assert_equal [:commit_on_destroy], @first.history
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_only_call_after_commit_on_create_after_transaction_commits_for_new_record
|
104
|
+
@new_record = TopicWithCallbacks.new(:title => "New topic", :written_on => Date.today)
|
105
|
+
@new_record.after_commit_block(:create){|r| r.history << :commit_on_create}
|
106
|
+
@new_record.after_commit_block(:update){|r| r.history << :commit_on_update}
|
107
|
+
@new_record.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
108
|
+
@new_record.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
109
|
+
@new_record.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
110
|
+
@new_record.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
111
|
+
|
112
|
+
@new_record.save!
|
113
|
+
assert_equal [:commit_on_create], @new_record.history
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_only_call_after_commit_on_create_after_transaction_commits_for_new_record_if_create_succeeds_creating_through_association
|
117
|
+
topic = TopicWithCallbacks.create!(:title => "New topic", :written_on => Date.today)
|
118
|
+
reply = topic.replies.create
|
119
|
+
|
120
|
+
assert_equal [], reply.history
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_call_after_rollback_after_transaction_rollsback
|
124
|
+
@first.after_commit_block{|r| r.history << :after_commit}
|
125
|
+
@first.after_rollback_block{|r| r.history << :after_rollback}
|
126
|
+
|
127
|
+
Topic.transaction do
|
128
|
+
@first.save!
|
129
|
+
raise ActiveRecord::Rollback
|
130
|
+
end
|
131
|
+
|
132
|
+
assert_equal [:after_rollback], @first.history
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_only_call_after_rollback_on_update_after_transaction_rollsback_for_existing_record
|
136
|
+
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
137
|
+
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
138
|
+
@first.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
139
|
+
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
140
|
+
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
141
|
+
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
142
|
+
|
143
|
+
Topic.transaction do
|
144
|
+
@first.save!
|
145
|
+
raise ActiveRecord::Rollback
|
146
|
+
end
|
147
|
+
|
148
|
+
assert_equal [:rollback_on_update], @first.history
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_only_call_after_rollback_on_destroy_after_transaction_rollsback_for_destroyed_record
|
152
|
+
@first.after_commit_block(:create){|r| r.history << :commit_on_create}
|
153
|
+
@first.after_commit_block(:update){|r| r.history << :commit_on_update}
|
154
|
+
@first.after_commit_block(:destroy){|r| r.history << :commit_on_update}
|
155
|
+
@first.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
156
|
+
@first.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
157
|
+
@first.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
158
|
+
|
159
|
+
Topic.transaction do
|
160
|
+
@first.destroy
|
161
|
+
raise ActiveRecord::Rollback
|
162
|
+
end
|
163
|
+
|
164
|
+
assert_equal [:rollback_on_destroy], @first.history
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_only_call_after_rollback_on_create_after_transaction_rollsback_for_new_record
|
168
|
+
@new_record = TopicWithCallbacks.new(:title => "New topic", :written_on => Date.today)
|
169
|
+
@new_record.after_commit_block(:create){|r| r.history << :commit_on_create}
|
170
|
+
@new_record.after_commit_block(:update){|r| r.history << :commit_on_update}
|
171
|
+
@new_record.after_commit_block(:destroy){|r| r.history << :commit_on_destroy}
|
172
|
+
@new_record.after_rollback_block(:create){|r| r.history << :rollback_on_create}
|
173
|
+
@new_record.after_rollback_block(:update){|r| r.history << :rollback_on_update}
|
174
|
+
@new_record.after_rollback_block(:destroy){|r| r.history << :rollback_on_destroy}
|
175
|
+
|
176
|
+
Topic.transaction do
|
177
|
+
@new_record.save!
|
178
|
+
raise ActiveRecord::Rollback
|
179
|
+
end
|
180
|
+
|
181
|
+
assert_equal [:rollback_on_create], @new_record.history
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_call_after_rollback_when_commit_fails
|
185
|
+
@first.class.connection.class.send(:alias_method, :real_method_commit_db_transaction, :commit_db_transaction)
|
186
|
+
begin
|
187
|
+
@first.class.connection.class.class_eval do
|
188
|
+
def commit_db_transaction; raise "boom!"; end
|
189
|
+
end
|
190
|
+
|
191
|
+
@first.after_commit_block{|r| r.history << :after_commit}
|
192
|
+
@first.after_rollback_block{|r| r.history << :after_rollback}
|
193
|
+
|
194
|
+
assert !@first.save rescue nil
|
195
|
+
assert_equal [:after_rollback], @first.history
|
196
|
+
ensure
|
197
|
+
@first.class.connection.class.send(:remove_method, :commit_db_transaction)
|
198
|
+
@first.class.connection.class.send(:alias_method, :commit_db_transaction, :real_method_commit_db_transaction)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_only_call_after_rollback_on_records_rolled_back_to_a_savepoint
|
203
|
+
def @first.rollbacks(i=0); @rollbacks ||= 0; @rollbacks += i if i; end
|
204
|
+
def @first.commits(i=0); @commits ||= 0; @commits += i if i; end
|
205
|
+
@first.after_rollback_block{|r| r.rollbacks(1)}
|
206
|
+
@first.after_commit_block{|r| r.commits(1)}
|
207
|
+
|
208
|
+
def @second.rollbacks(i=0); @rollbacks ||= 0; @rollbacks += i if i; end
|
209
|
+
def @second.commits(i=0); @commits ||= 0; @commits += i if i; end
|
210
|
+
@second.after_rollback_block{|r| r.rollbacks(1)}
|
211
|
+
@second.after_commit_block{|r| r.commits(1)}
|
212
|
+
|
213
|
+
Topic.transaction do
|
214
|
+
@first.save!
|
215
|
+
Topic.transaction(:requires_new => true) do
|
216
|
+
@second.save!
|
217
|
+
raise ActiveRecord::Rollback
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
assert_equal 1, @first.commits
|
222
|
+
assert_equal 0, @first.rollbacks
|
223
|
+
assert_equal 0, @second.commits
|
224
|
+
assert_equal 1, @second.rollbacks
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_only_call_after_rollback_on_records_rolled_back_to_a_savepoint_when_release_savepoint_fails
|
228
|
+
def @first.rollbacks(i=0); @rollbacks ||= 0; @rollbacks += i if i; end
|
229
|
+
def @first.commits(i=0); @commits ||= 0; @commits += i if i; end
|
230
|
+
|
231
|
+
@first.after_rollback_block{|r| r.rollbacks(1)}
|
232
|
+
@first.after_commit_block{|r| r.commits(1)}
|
233
|
+
|
234
|
+
Topic.transaction do
|
235
|
+
@first.save
|
236
|
+
Topic.transaction(:requires_new => true) do
|
237
|
+
@first.save!
|
238
|
+
raise ActiveRecord::Rollback
|
239
|
+
end
|
240
|
+
Topic.transaction(:requires_new => true) do
|
241
|
+
@first.save!
|
242
|
+
raise ActiveRecord::Rollback
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
assert_equal 1, @first.commits
|
247
|
+
assert_equal 2, @first.rollbacks
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_after_transaction_callbacks_should_prevent_callbacks_from_being_called
|
251
|
+
def @first.last_after_transaction_error=(e); @last_transaction_error = e; end
|
252
|
+
def @first.last_after_transaction_error; @last_transaction_error; end
|
253
|
+
@first.after_commit_block{|r| r.last_after_transaction_error = :commit; raise "fail!";}
|
254
|
+
@first.after_rollback_block{|r| r.last_after_transaction_error = :rollback; raise "fail!";}
|
255
|
+
@second.after_commit_block{|r| r.history << :after_commit}
|
256
|
+
@second.after_rollback_block{|r| r.history << :after_rollback}
|
257
|
+
|
258
|
+
Topic.transaction do
|
259
|
+
@first.save!
|
260
|
+
@second.save!
|
261
|
+
end
|
262
|
+
assert_equal :commit, @first.last_after_transaction_error
|
263
|
+
assert_equal [:after_commit], @second.history
|
264
|
+
|
265
|
+
@second.history.clear
|
266
|
+
Topic.transaction do
|
267
|
+
@first.save!
|
268
|
+
@second.save!
|
269
|
+
raise ActiveRecord::Rollback
|
270
|
+
end
|
271
|
+
assert_equal :rollback, @first.last_after_transaction_error
|
272
|
+
assert_equal [:after_rollback], @second.history
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_after_rollback_callbacks_should_validate_on_condition
|
276
|
+
assert_raise(ArgumentError) { Topic.send(:after_rollback, :on => :save) }
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_after_commit_callbacks_should_validate_on_condition
|
280
|
+
assert_raise(ArgumentError) { Topic.send(:after_commit, :on => :save) }
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
class CallbacksOnMultipleActionsTest < ActiveRecord::TestCase
|
285
|
+
self.use_transactional_fixtures = false
|
286
|
+
|
287
|
+
class TopicWithCallbacksOnMultipleActions < ActiveRecord::Base
|
288
|
+
self.table_name = :topics
|
289
|
+
|
290
|
+
after_commit(on: [:create, :destroy]) { |record| record.history << :create_and_destroy }
|
291
|
+
after_commit(on: [:create, :update]) { |record| record.history << :create_and_update }
|
292
|
+
after_commit(on: [:update, :destroy]) { |record| record.history << :update_and_destroy }
|
293
|
+
|
294
|
+
def clear_history
|
295
|
+
@history = []
|
296
|
+
end
|
297
|
+
|
298
|
+
def history
|
299
|
+
@history ||= []
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_after_commit_on_multiple_actions
|
304
|
+
topic = TopicWithCallbacksOnMultipleActions.new
|
305
|
+
topic.save
|
306
|
+
assert_equal [:create_and_update, :create_and_destroy], topic.history
|
307
|
+
|
308
|
+
topic.clear_history
|
309
|
+
topic.approved = true
|
310
|
+
topic.save
|
311
|
+
assert_equal [:update_and_destroy, :create_and_update], topic.history
|
312
|
+
|
313
|
+
topic.clear_history
|
314
|
+
topic.destroy
|
315
|
+
assert_equal [:update_and_destroy, :create_and_destroy], topic.history
|
316
|
+
end
|
317
|
+
end
|