ibm_db 3.0.4 → 5.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES +8 -1
- data/LICENSE +1 -1
- data/ParameterizedQueries README +6 -6
- data/README +38 -55
- data/ext/Makefile +266 -0
- data/ext/extconf.rb +34 -3
- data/ext/gil_release_version +3 -0
- data/ext/ibm_db.c +106 -111
- data/ext/ibm_db.o +0 -0
- data/ext/ibm_db.so +0 -0
- data/ext/mkmf.log +103 -0
- data/ext/ruby_ibm_db_cli.o +0 -0
- data/ext/unicode_support_version +3 -0
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +911 -527
- data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
- data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
- data/test/cases/adapter_test.rb +148 -58
- data/test/cases/adapters/mysql2/active_schema_test.rb +193 -0
- data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
- data/test/cases/adapters/mysql2/boolean_test.rb +100 -0
- data/test/cases/adapters/mysql2/case_sensitivity_test.rb +63 -0
- data/test/cases/adapters/mysql2/charset_collation_test.rb +54 -0
- data/test/cases/adapters/mysql2/connection_test.rb +210 -0
- data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +45 -0
- data/test/cases/adapters/mysql2/enum_test.rb +26 -0
- data/test/cases/adapters/mysql2/explain_test.rb +21 -0
- data/test/cases/adapters/mysql2/json_test.rb +195 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +83 -0
- data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
- data/test/cases/adapters/mysql2/schema_migrations_test.rb +59 -0
- data/test/cases/adapters/mysql2/schema_test.rb +126 -0
- data/test/cases/adapters/mysql2/sp_test.rb +36 -0
- data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
- data/test/cases/adapters/mysql2/table_options_test.rb +42 -0
- data/test/cases/adapters/mysql2/unsigned_type_test.rb +66 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +98 -0
- data/test/cases/adapters/postgresql/array_test.rb +339 -0
- data/test/cases/adapters/postgresql/bit_string_test.rb +82 -0
- data/test/cases/adapters/postgresql/bytea_test.rb +134 -0
- data/test/cases/adapters/postgresql/case_insensitive_test.rb +26 -0
- data/test/cases/adapters/postgresql/change_schema_test.rb +38 -0
- data/test/cases/adapters/postgresql/cidr_test.rb +25 -0
- data/test/cases/adapters/postgresql/citext_test.rb +78 -0
- data/test/cases/adapters/postgresql/collation_test.rb +53 -0
- data/test/cases/adapters/postgresql/composite_test.rb +132 -0
- data/test/cases/adapters/postgresql/connection_test.rb +257 -0
- data/test/cases/adapters/postgresql/datatype_test.rb +92 -0
- data/test/cases/adapters/postgresql/domain_test.rb +47 -0
- data/test/cases/adapters/postgresql/enum_test.rb +91 -0
- data/test/cases/adapters/postgresql/explain_test.rb +20 -0
- data/test/cases/adapters/postgresql/extension_migration_test.rb +63 -0
- data/test/cases/adapters/postgresql/full_text_test.rb +44 -0
- data/test/cases/adapters/postgresql/geometric_test.rb +378 -0
- data/test/cases/adapters/postgresql/hstore_test.rb +382 -0
- data/test/cases/adapters/postgresql/infinity_test.rb +69 -0
- data/test/cases/adapters/postgresql/integer_test.rb +25 -0
- data/test/cases/adapters/postgresql/json_test.rb +237 -0
- data/test/cases/adapters/postgresql/ltree_test.rb +53 -0
- data/test/cases/adapters/postgresql/money_test.rb +96 -0
- data/test/cases/adapters/postgresql/network_test.rb +94 -0
- data/test/cases/adapters/postgresql/numbers_test.rb +49 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +405 -0
- data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
- data/test/cases/adapters/postgresql/quoting_test.rb +44 -0
- data/test/cases/adapters/postgresql/range_test.rb +343 -0
- data/test/cases/adapters/postgresql/referential_integrity_test.rb +111 -0
- data/test/cases/adapters/postgresql/rename_table_test.rb +34 -0
- data/test/cases/adapters/postgresql/schema_authorization_test.rb +119 -0
- data/test/cases/adapters/postgresql/schema_test.rb +597 -0
- data/test/cases/adapters/postgresql/serial_test.rb +154 -0
- data/test/cases/adapters/postgresql/statement_pool_test.rb +41 -0
- data/test/cases/adapters/postgresql/timestamp_test.rb +90 -0
- data/test/cases/adapters/postgresql/type_lookup_test.rb +33 -0
- data/test/cases/adapters/postgresql/utils_test.rb +62 -0
- data/test/cases/adapters/postgresql/uuid_test.rb +294 -0
- data/test/cases/adapters/postgresql/xml_test.rb +54 -0
- data/test/cases/adapters/sqlite3/collation_test.rb +53 -0
- data/test/cases/adapters/sqlite3/copy_table_test.rb +98 -0
- data/test/cases/adapters/sqlite3/explain_test.rb +21 -0
- data/test/cases/adapters/sqlite3/quoting_test.rb +101 -0
- data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +441 -0
- data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
- data/test/cases/adapters/sqlite3/statement_pool_test.rb +20 -0
- data/test/cases/aggregations_test.rb +11 -1
- data/test/cases/ar_schema_test.rb +35 -50
- data/test/cases/associations/association_scope_test.rb +1 -6
- data/test/cases/associations/belongs_to_associations_test.rb +122 -10
- data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +41 -0
- data/test/cases/associations/callbacks_test.rb +5 -7
- data/test/cases/associations/cascaded_eager_loading_test.rb +1 -1
- data/test/cases/associations/eager_load_nested_include_test.rb +1 -3
- data/test/cases/associations/eager_test.rb +176 -73
- data/test/cases/associations/extension_test.rb +7 -2
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +104 -32
- data/test/cases/associations/has_many_associations_test.rb +382 -43
- data/test/cases/associations/has_many_through_associations_test.rb +108 -41
- data/test/cases/associations/has_one_associations_test.rb +105 -8
- data/test/cases/associations/has_one_through_associations_test.rb +6 -3
- data/test/cases/associations/inner_join_association_test.rb +3 -3
- data/test/cases/associations/inverse_associations_test.rb +51 -11
- data/test/cases/associations/join_model_test.rb +59 -36
- data/test/cases/associations/left_outer_join_association_test.rb +88 -0
- data/test/cases/associations/nested_through_associations_test.rb +2 -2
- data/test/cases/associations/required_test.rb +25 -5
- data/test/cases/associations_test.rb +39 -34
- data/test/cases/attribute_decorators_test.rb +9 -8
- data/test/cases/attribute_methods/read_test.rb +5 -5
- data/test/cases/attribute_methods_test.rb +97 -40
- data/test/cases/attribute_set_test.rb +74 -4
- data/test/cases/attribute_test.rb +84 -18
- data/test/cases/attributes_test.rb +151 -34
- data/test/cases/autosave_association_test.rb +149 -36
- data/test/cases/base_test.rb +311 -236
- data/test/cases/batches_test.rb +299 -22
- data/test/cases/binary_test.rb +2 -10
- data/test/cases/bind_parameter_test.rb +76 -66
- data/test/cases/cache_key_test.rb +26 -0
- data/test/cases/calculations_test.rb +167 -15
- data/test/cases/callbacks_test.rb +161 -68
- data/test/cases/coders/json_test.rb +15 -0
- data/test/cases/collection_cache_key_test.rb +115 -0
- data/test/cases/column_definition_test.rb +26 -57
- data/test/cases/comment_test.rb +145 -0
- data/test/cases/connection_adapters/adapter_leasing_test.rb +5 -3
- data/test/cases/connection_adapters/connection_handler_test.rb +128 -21
- data/test/cases/connection_adapters/connection_specification_test.rb +1 -1
- data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +0 -38
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -1
- data/test/cases/connection_adapters/schema_cache_test.rb +8 -3
- data/test/cases/connection_adapters/type_lookup_test.rb +15 -7
- data/test/cases/connection_management_test.rb +46 -56
- data/test/cases/connection_pool_test.rb +195 -20
- data/test/cases/connection_specification/resolver_test.rb +15 -0
- data/test/cases/counter_cache_test.rb +10 -5
- data/test/cases/custom_locking_test.rb +1 -1
- data/test/cases/database_statements_test.rb +18 -3
- data/test/cases/{invalid_date_test.rb → date_test.rb} +13 -1
- data/test/cases/date_time_precision_test.rb +107 -0
- data/test/cases/defaults_test.rb +85 -89
- data/test/cases/dirty_test.rb +32 -44
- data/test/cases/disconnected_test.rb +4 -2
- data/test/cases/enum_test.rb +178 -24
- data/test/cases/errors_test.rb +16 -0
- data/test/cases/explain_test.rb +32 -21
- data/test/cases/finder_test.rb +279 -151
- data/test/cases/fixture_set/file_test.rb +18 -0
- data/test/cases/fixtures_test.rb +123 -32
- data/test/cases/forbidden_attributes_protection_test.rb +69 -3
- data/test/cases/helper.rb +10 -16
- data/test/cases/hot_compatibility_test.rb +89 -1
- data/test/cases/inheritance_test.rb +284 -53
- data/test/cases/integration_test.rb +23 -7
- data/test/cases/invalid_connection_test.rb +4 -2
- data/test/cases/invertible_migration_test.rb +124 -32
- data/test/cases/json_serialization_test.rb +11 -2
- data/test/cases/locking_test.rb +22 -6
- data/test/cases/log_subscriber_test.rb +106 -17
- data/test/cases/migration/change_schema_test.rb +118 -132
- data/test/cases/migration/change_table_test.rb +34 -2
- data/test/cases/migration/column_attributes_test.rb +7 -23
- data/test/cases/migration/column_positioning_test.rb +8 -8
- data/test/cases/migration/columns_test.rb +17 -11
- data/test/cases/migration/command_recorder_test.rb +47 -2
- data/test/cases/migration/compatibility_test.rb +118 -0
- data/test/cases/migration/create_join_table_test.rb +21 -12
- data/test/cases/migration/foreign_key_test.rb +68 -66
- data/test/cases/migration/index_test.rb +14 -12
- data/test/cases/migration/logger_test.rb +1 -1
- data/test/cases/migration/pending_migrations_test.rb +0 -1
- data/test/cases/migration/references_foreign_key_test.rb +114 -107
- data/test/cases/migration/references_index_test.rb +4 -4
- data/test/cases/migration/references_statements_test.rb +26 -6
- data/test/cases/migration/rename_table_test.rb +25 -25
- data/test/cases/migration_test.rb +279 -81
- data/test/cases/migrator_test.rb +91 -8
- data/test/cases/mixin_test.rb +0 -2
- data/test/cases/modules_test.rb +3 -4
- data/test/cases/multiparameter_attributes_test.rb +24 -2
- data/test/cases/multiple_db_test.rb +18 -11
- data/test/cases/nested_attributes_test.rb +74 -33
- data/test/cases/persistence_test.rb +102 -10
- data/test/cases/pooled_connections_test.rb +3 -3
- data/test/cases/primary_keys_test.rb +170 -31
- data/test/cases/query_cache_test.rb +216 -96
- data/test/cases/quoting_test.rb +65 -19
- data/test/cases/readonly_test.rb +2 -1
- data/test/cases/reflection_test.rb +77 -22
- data/test/cases/relation/delegation_test.rb +3 -8
- data/test/cases/relation/merging_test.rb +10 -14
- data/test/cases/relation/mutation_test.rb +42 -24
- data/test/cases/relation/or_test.rb +92 -0
- data/test/cases/relation/predicate_builder_test.rb +4 -2
- data/test/cases/relation/record_fetch_warning_test.rb +40 -0
- data/test/cases/relation/where_chain_test.rb +23 -99
- data/test/cases/relation/where_clause_test.rb +182 -0
- data/test/cases/relation/where_test.rb +45 -23
- data/test/cases/relation_test.rb +89 -58
- data/test/cases/relations_test.rb +249 -38
- data/test/cases/result_test.rb +10 -0
- data/test/cases/sanitize_test.rb +108 -15
- data/test/cases/schema_dumper_test.rb +119 -125
- data/test/cases/schema_loading_test.rb +52 -0
- data/test/cases/scoping/default_scoping_test.rb +113 -39
- data/test/cases/scoping/named_scoping_test.rb +46 -9
- data/test/cases/scoping/relation_scoping_test.rb +47 -4
- data/test/cases/secure_token_test.rb +32 -0
- data/test/cases/serialization_test.rb +1 -1
- data/test/cases/serialized_attribute_test.rb +93 -6
- data/test/cases/statement_cache_test.rb +38 -0
- data/test/cases/store_test.rb +2 -1
- data/test/cases/suppressor_test.rb +63 -0
- data/test/cases/tasks/database_tasks_test.rb +74 -8
- data/test/cases/tasks/mysql_rake_test.rb +143 -109
- data/test/cases/tasks/postgresql_rake_test.rb +71 -12
- data/test/cases/tasks/sqlite_rake_test.rb +30 -3
- data/test/cases/test_case.rb +28 -20
- data/test/cases/test_fixtures_test.rb +36 -0
- data/test/cases/time_precision_test.rb +103 -0
- data/test/cases/timestamp_test.rb +47 -14
- data/test/cases/touch_later_test.rb +121 -0
- data/test/cases/transaction_callbacks_test.rb +128 -62
- data/test/cases/transaction_isolation_test.rb +2 -2
- data/test/cases/transactions_test.rb +61 -43
- data/test/cases/type/adapter_specific_registry_test.rb +133 -0
- data/test/cases/type/date_time_test.rb +14 -0
- data/test/cases/type/integer_test.rb +2 -96
- data/test/cases/type/string_test.rb +0 -14
- data/test/cases/type_test.rb +39 -0
- data/test/cases/types_test.rb +1 -118
- data/test/cases/unconnected_test.rb +1 -1
- data/test/cases/validations/absence_validation_test.rb +73 -0
- data/test/cases/validations/association_validation_test.rb +13 -2
- data/test/cases/validations/i18n_validation_test.rb +6 -10
- data/test/cases/validations/length_validation_test.rb +62 -30
- data/test/cases/validations/presence_validation_test.rb +36 -1
- data/test/cases/validations/uniqueness_validation_test.rb +150 -36
- data/test/cases/validations_repair_helper.rb +2 -6
- data/test/cases/validations_test.rb +36 -7
- data/test/cases/view_test.rb +108 -5
- data/test/cases/yaml_serialization_test.rb +36 -1
- data/test/config.example.yml +97 -0
- data/test/fixtures/bad_posts.yml +9 -0
- data/test/fixtures/books.yml +20 -0
- data/test/fixtures/content.yml +3 -0
- data/test/fixtures/content_positions.yml +3 -0
- data/test/fixtures/dead_parrots.yml +5 -0
- data/test/fixtures/live_parrots.yml +4 -0
- data/test/fixtures/naked/yml/parrots.yml +2 -0
- data/test/fixtures/naked/yml/trees.yml +3 -0
- data/test/fixtures/nodes.yml +29 -0
- data/test/fixtures/other_comments.yml +6 -0
- data/test/fixtures/other_dogs.yml +2 -0
- data/test/fixtures/other_posts.yml +7 -0
- data/test/fixtures/price_estimates.yml +10 -1
- data/test/fixtures/trees.yml +3 -0
- data/test/migrations/10_urban/9_add_expressions.rb +1 -1
- data/test/migrations/decimal/1_give_me_big_numbers.rb +1 -1
- data/test/migrations/magic/1_currencies_have_symbols.rb +1 -1
- data/test/migrations/missing/1000_people_have_middle_names.rb +2 -2
- data/test/migrations/missing/1_people_have_last_names.rb +2 -2
- data/test/migrations/missing/3_we_need_reminders.rb +2 -2
- data/test/migrations/missing/4_innocent_jointable.rb +2 -2
- data/test/migrations/rename/1_we_need_things.rb +2 -2
- data/test/migrations/rename/2_rename_things.rb +2 -2
- data/test/migrations/to_copy/1_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy/2_people_have_descriptions.rb +1 -1
- data/test/migrations/to_copy2/1_create_articles.rb +1 -1
- data/test/migrations/to_copy2/2_create_comments.rb +1 -1
- data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +1 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +1 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +1 -1
- data/test/migrations/valid/1_valid_people_have_last_names.rb +1 -1
- data/test/migrations/valid/2_we_need_reminders.rb +2 -2
- data/test/migrations/valid/3_innocent_jointable.rb +2 -2
- data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +1 -1
- data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -2
- data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +2 -2
- data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +1 -1
- data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +1 -1
- data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +1 -1
- data/test/migrations/version_check/20131219224947_migration_version_check.rb +1 -1
- data/test/models/admin/randomly_named_c1.rb +6 -2
- data/test/models/aircraft.rb +1 -0
- data/test/models/author.rb +4 -7
- data/test/models/bird.rb +1 -1
- data/test/models/book.rb +5 -0
- data/test/models/bulb.rb +2 -1
- data/test/models/car.rb +3 -0
- data/test/models/cat.rb +10 -0
- data/test/models/chef.rb +5 -0
- data/test/models/club.rb +2 -0
- data/test/models/comment.rb +17 -5
- data/test/models/company.rb +7 -2
- data/test/models/company_in_module.rb +1 -1
- data/test/models/contact.rb +1 -1
- data/test/models/content.rb +40 -0
- data/test/models/customer.rb +8 -2
- data/test/models/developer.rb +22 -0
- data/test/models/face.rb +1 -1
- data/test/models/guitar.rb +4 -0
- data/test/models/hotel.rb +5 -0
- data/test/models/member.rb +1 -0
- data/test/models/member_detail.rb +4 -3
- data/test/models/mentor.rb +3 -0
- data/test/models/mocktail_designer.rb +2 -0
- data/test/models/node.rb +5 -0
- data/test/models/non_primary_key.rb +2 -0
- data/test/models/notification.rb +3 -0
- data/test/models/other_dog.rb +5 -0
- data/test/models/owner.rb +4 -1
- data/test/models/parrot.rb +6 -7
- data/test/models/person.rb +0 -1
- data/test/models/pet.rb +3 -0
- data/test/models/pet_treasure.rb +6 -0
- data/test/models/pirate.rb +3 -3
- data/test/models/post.rb +18 -9
- data/test/models/project.rb +11 -0
- data/test/models/randomly_named_c1.rb +1 -1
- data/test/models/recipe.rb +3 -0
- data/test/models/ship.rb +8 -2
- data/test/models/tag.rb +6 -0
- data/test/models/topic.rb +2 -8
- data/test/models/tree.rb +3 -0
- data/test/models/tuning_peg.rb +4 -0
- data/test/models/user.rb +14 -0
- data/test/models/uuid_item.rb +6 -0
- data/test/schema/mysql2_specific_schema.rb +33 -23
- data/test/schema/oracle_specific_schema.rb +1 -4
- data/test/schema/postgresql_specific_schema.rb +36 -124
- data/test/schema/schema.rb +183 -64
- data/test/schema/schema.rb.original +1057 -0
- data/test/schema/sqlite_specific_schema.rb +1 -5
- data/test/support/connection.rb +1 -0
- data/test/support/schema_dumping_helper.rb +1 -1
- data/test/support/yaml_compatibility_fixtures/rails_4_1.yml +22 -0
- data/test/support/yaml_compatibility_fixtures/rails_4_2_0.yml +182 -0
- metadata +145 -26
- data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +0 -26
- data/test/cases/attribute_methods/serialization_test.rb +0 -29
- data/test/cases/migration/change_schema_test - Copy.rb +0 -448
- data/test/cases/migration/foreign_key_test - Changed.rb +0 -325
- data/test/cases/migration/table_and_index_test.rb +0 -24
- data/test/cases/relation/where_test2.rb +0 -36
- data/test/cases/type/decimal_test.rb +0 -51
- data/test/cases/type/unsigned_integer_test.rb +0 -18
- data/test/cases/xml_serialization_test.rb +0 -457
- data/test/fixtures/naked/csv/accounts.csv +0 -1
- data/test/schema/mysql_specific_schema.rb +0 -70
@@ -1,2 +1,5 @@
|
|
1
1
|
#rb file to support alising of adapter name as ibmdb [without underscore] that will require ibm_db_adapter.rb
|
2
|
-
require 'active_record/connection_adapters/ibm_db_adapter'
|
2
|
+
require 'active_record/connection_adapters/ibm_db_adapter'
|
3
|
+
|
4
|
+
require 'active_record/connection_adapters/ibm_schema_dumper'
|
5
|
+
|
@@ -7,7 +7,7 @@ module ActiveRecord
|
|
7
7
|
|
8
8
|
module ConnectionAdapters
|
9
9
|
class FakeAdapter < AbstractAdapter
|
10
|
-
attr_accessor :
|
10
|
+
attr_accessor :data_sources, :primary_keys
|
11
11
|
|
12
12
|
@columns = Hash.new { |h,k| h[k] = [] }
|
13
13
|
class << self
|
@@ -16,21 +16,20 @@ module ActiveRecord
|
|
16
16
|
|
17
17
|
def initialize(connection, logger)
|
18
18
|
super
|
19
|
-
@
|
19
|
+
@data_sources = []
|
20
20
|
@primary_keys = {}
|
21
21
|
@columns = self.class.columns
|
22
22
|
end
|
23
23
|
|
24
24
|
def primary_key(table)
|
25
|
-
@primary_keys[table]
|
25
|
+
@primary_keys[table] || "id"
|
26
26
|
end
|
27
27
|
|
28
28
|
def merge_column(table_name, name, sql_type = nil, options = {})
|
29
29
|
@columns[table_name] << ActiveRecord::ConnectionAdapters::Column.new(
|
30
30
|
name.to_s,
|
31
31
|
options[:default],
|
32
|
-
|
33
|
-
sql_type.to_s,
|
32
|
+
fetch_type_metadata(sql_type),
|
34
33
|
options[:null])
|
35
34
|
end
|
36
35
|
|
@@ -38,6 +37,10 @@ module ActiveRecord
|
|
38
37
|
@columns[table_name]
|
39
38
|
end
|
40
39
|
|
40
|
+
def data_source_exists?(*)
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
41
44
|
def active?
|
42
45
|
true
|
43
46
|
end
|
data/test/cases/adapter_test.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require "cases/helper"
|
4
2
|
require "models/book"
|
5
3
|
require "models/post"
|
6
4
|
require "models/author"
|
5
|
+
require "models/event"
|
7
6
|
|
8
7
|
module ActiveRecord
|
9
8
|
class AdapterTest < ActiveRecord::TestCase
|
10
|
-
def setup
|
9
|
+
def setup
|
11
10
|
@connection = ActiveRecord::Base.connection
|
12
11
|
end
|
13
12
|
|
14
13
|
##
|
15
14
|
# PostgreSQL does not support null bytes in strings
|
16
|
-
unless current_adapter?(:PostgreSQLAdapter)
|
15
|
+
unless current_adapter?(:PostgreSQLAdapter, :IBM_DBAdapter) ||
|
16
|
+
(current_adapter?(:SQLite3Adapter) && !ActiveRecord::Base.connection.prepared_statements)
|
17
17
|
def test_update_prepared_statement
|
18
18
|
b = Book.create(name: "my \x00 book")
|
19
19
|
b.reload
|
@@ -24,18 +24,49 @@ module ActiveRecord
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
unless current_adapter?(:IBM_DBAdapter)
|
28
|
+
def test_create_record_with_pk_as_zero
|
29
|
+
Book.create(id: 0)
|
30
|
+
assert_equal 0, Book.find(0).id
|
31
|
+
assert_nothing_raised { Book.destroy(0) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
27
35
|
def test_tables
|
28
|
-
tables =
|
36
|
+
tables = nil
|
37
|
+
ActiveSupport::Deprecation.silence { tables = @connection.tables }
|
29
38
|
assert tables.include?("accounts")
|
30
39
|
assert tables.include?("authors")
|
31
40
|
assert tables.include?("tasks")
|
32
41
|
assert tables.include?("topics")
|
33
42
|
end
|
34
43
|
|
44
|
+
|
35
45
|
def test_table_exists?
|
36
|
-
|
37
|
-
|
38
|
-
|
46
|
+
ActiveSupport::Deprecation.silence do
|
47
|
+
assert @connection.table_exists?("accounts")
|
48
|
+
assert !@connection.table_exists?("nonexistingtable")
|
49
|
+
assert !@connection.table_exists?(nil)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_table_exists_checking_both_tables_and_views_is_deprecated
|
54
|
+
assert_deprecated { @connection.table_exists?("accounts") }
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_data_sources
|
58
|
+
data_sources = @connection.data_sources
|
59
|
+
assert data_sources.include?("accounts")
|
60
|
+
assert data_sources.include?("authors")
|
61
|
+
assert data_sources.include?("tasks")
|
62
|
+
assert data_sources.include?("topics")
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_data_source_exists?
|
66
|
+
assert @connection.data_source_exists?("accounts")
|
67
|
+
assert @connection.data_source_exists?(:accounts)
|
68
|
+
assert_not @connection.data_source_exists?("nonexistingtable")
|
69
|
+
assert_not @connection.data_source_exists?(nil)
|
39
70
|
end
|
40
71
|
|
41
72
|
def test_indexes
|
@@ -59,13 +90,26 @@ module ActiveRecord
|
|
59
90
|
@connection.remove_index(:accounts, :name => idx_name) rescue nil
|
60
91
|
end
|
61
92
|
|
93
|
+
unless current_adapter?(:IBM_DBAdapter)
|
94
|
+
def test_remove_index_when_name_and_wrong_column_name_specified
|
95
|
+
index_name = "accounts_idx"
|
96
|
+
|
97
|
+
@connection.add_index :accounts, :firm_id, :name => index_name
|
98
|
+
assert_raises ArgumentError do
|
99
|
+
@connection.remove_index :accounts, :name => index_name, :column => :wrong_column_name
|
100
|
+
end
|
101
|
+
ensure
|
102
|
+
@connection.remove_index(:accounts, :name => index_name)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
62
106
|
def test_current_database
|
63
107
|
if @connection.respond_to?(:current_database)
|
64
108
|
assert_equal ARTest.connection_config['arunit']['database'], @connection.current_database
|
65
109
|
end
|
66
110
|
end
|
67
111
|
|
68
|
-
if current_adapter?(:
|
112
|
+
if current_adapter?(:Mysql2Adapter)
|
69
113
|
def test_charset
|
70
114
|
assert_not_nil @connection.charset
|
71
115
|
assert_not_equal 'character_set_database', @connection.charset
|
@@ -135,17 +179,21 @@ module ActiveRecord
|
|
135
179
|
assert_nothing_raised { sub.save! }
|
136
180
|
end
|
137
181
|
end
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
182
|
+
|
183
|
+
unless current_adapter?(:IBM_DBAdapter)
|
184
|
+
def test_uniqueness_violations_are_translated_to_specific_exception
|
185
|
+
@connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
|
186
|
+
error = assert_raises(ActiveRecord::RecordNotUnique) do
|
187
|
+
@connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
|
188
|
+
end
|
189
|
+
|
190
|
+
assert_not_nil error.cause
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
unless current_adapter?(:SQLite3Adapter, :IBM_DBAdapter)
|
147
195
|
def test_foreign_key_violations_are_translated_to_specific_exception
|
148
|
-
assert_raises(ActiveRecord::InvalidForeignKey) do
|
196
|
+
error = assert_raises(ActiveRecord::InvalidForeignKey) do
|
149
197
|
# Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
|
150
198
|
if @connection.prefetch_primary_key?
|
151
199
|
id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
|
@@ -154,6 +202,8 @@ module ActiveRecord
|
|
154
202
|
@connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
|
155
203
|
end
|
156
204
|
end
|
205
|
+
|
206
|
+
assert_not_nil error.cause
|
157
207
|
end
|
158
208
|
|
159
209
|
def test_foreign_key_violations_are_translated_to_specific_exception_with_validate_false
|
@@ -161,11 +211,21 @@ module ActiveRecord
|
|
161
211
|
self.table_name = 'fk_test_has_fk'
|
162
212
|
end
|
163
213
|
|
164
|
-
assert_raises(ActiveRecord::InvalidForeignKey) do
|
214
|
+
error = assert_raises(ActiveRecord::InvalidForeignKey) do
|
165
215
|
has_fk = klass_has_fk.new
|
166
216
|
has_fk.fk_id = 1231231231
|
167
217
|
has_fk.save(validate: false)
|
168
218
|
end
|
219
|
+
|
220
|
+
assert_not_nil error.cause
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_value_limit_violations_are_translated_to_specific_exception
|
224
|
+
error = assert_raises(ActiveRecord::ValueTooLong) do
|
225
|
+
Event.create(title: 'abcdefgh')
|
226
|
+
end
|
227
|
+
|
228
|
+
assert_not_nil error.cause
|
169
229
|
end
|
170
230
|
end
|
171
231
|
|
@@ -191,44 +251,69 @@ module ActiveRecord
|
|
191
251
|
assert result.is_a?(ActiveRecord::Result)
|
192
252
|
end
|
193
253
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
assert_equal "foo", @connection.select_value(query)
|
202
|
-
assert_equal ["foo"], @connection.select_values(query)
|
254
|
+
if ActiveRecord::Base.connection.prepared_statements
|
255
|
+
def test_select_all_with_legacy_binds
|
256
|
+
post = Post.create!(title: "foo", body: "bar")
|
257
|
+
expected = @connection.select_all("SELECT * FROM posts WHERE id = #{post.id}")
|
258
|
+
result = @connection.select_all("SELECT * FROM posts WHERE id = #{Arel::Nodes::BindParam.new.to_sql}", nil, [[nil, post.id]])
|
259
|
+
assert_equal expected.to_hash, result.to_hash
|
260
|
+
end
|
203
261
|
end
|
204
262
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
263
|
+
unless current_adapter?(:IBM_DBAdapter)
|
264
|
+
def test_select_methods_passing_a_association_relation
|
265
|
+
author = Author.create!(name: 'john')
|
266
|
+
Post.create!(author: author, title: 'foo', body: 'bar')
|
267
|
+
query = author.posts.where(title: 'foo').select(:title)
|
268
|
+
assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bound_attributes))
|
269
|
+
assert_equal({"title" => "foo"}, @connection.select_one(query))
|
270
|
+
assert @connection.select_all(query).is_a?(ActiveRecord::Result)
|
271
|
+
assert_equal "foo", @connection.select_value(query)
|
272
|
+
assert_equal ["foo"], @connection.select_values(query)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
unless current_adapter?(:IBM_DBAdapter)
|
277
|
+
def test_select_methods_passing_a_relation
|
278
|
+
Post.create!(title: 'foo', body: 'bar')
|
279
|
+
query = Post.where(title: 'foo').select(:title)
|
280
|
+
assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bound_attributes))
|
281
|
+
assert_equal({"title" => "foo"}, @connection.select_one(query))
|
282
|
+
assert @connection.select_all(query).is_a?(ActiveRecord::Result)
|
283
|
+
assert_equal "foo", @connection.select_value(query)
|
284
|
+
assert_equal ["foo"], @connection.select_values(query)
|
285
|
+
end
|
286
|
+
end
|
214
287
|
|
215
288
|
test "type_to_sql returns a String for unmapped types" do
|
216
289
|
assert_equal "special_db_type", @connection.type_to_sql(:special_db_type)
|
217
290
|
end
|
218
291
|
|
219
|
-
unless current_adapter?(:PostgreSQLAdapter)
|
292
|
+
unless current_adapter?(:PostgreSQLAdapter, :IBM_DBAdapter)
|
220
293
|
def test_log_invalid_encoding
|
221
|
-
assert_raise ActiveRecord::StatementInvalid do
|
222
|
-
@connection.send :log, "SELECT '
|
223
|
-
raise '
|
294
|
+
error = assert_raise ActiveRecord::StatementInvalid do
|
295
|
+
@connection.send :log, "SELECT 'ы' FROM DUAL" do
|
296
|
+
raise 'ы'.force_encoding(Encoding::ASCII_8BIT)
|
224
297
|
end
|
225
298
|
end
|
299
|
+
|
300
|
+
assert_not_nil error.cause
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
if current_adapter?(:Mysql2Adapter, :SQLite3Adapter)
|
305
|
+
def test_tables_returning_both_tables_and_views_is_deprecated
|
306
|
+
assert_deprecated { @connection.tables }
|
226
307
|
end
|
227
308
|
end
|
309
|
+
|
310
|
+
def test_passing_arguments_to_tables_is_deprecated
|
311
|
+
assert_deprecated { @connection.tables(:books) }
|
312
|
+
end
|
228
313
|
end
|
229
314
|
|
230
315
|
class AdapterTestWithoutTransaction < ActiveRecord::TestCase
|
231
|
-
self.
|
316
|
+
self.use_transactional_tests = false
|
232
317
|
|
233
318
|
class Klass < ActiveRecord::Base
|
234
319
|
end
|
@@ -242,20 +327,25 @@ module ActiveRecord
|
|
242
327
|
Klass.remove_connection
|
243
328
|
end
|
244
329
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
330
|
+
unless current_adapter?(:IBM_DBAdapter)
|
331
|
+
unless in_memory_db?
|
332
|
+
test "transaction state is reset after a reconnect" do
|
333
|
+
@connection.begin_transaction
|
334
|
+
assert @connection.transaction_open?
|
335
|
+
@connection.reconnect!
|
336
|
+
assert !@connection.transaction_open?
|
337
|
+
end
|
338
|
+
|
339
|
+
test "transaction state is reset after a disconnect" do
|
340
|
+
@connection.begin_transaction
|
341
|
+
assert @connection.transaction_open?
|
342
|
+
@connection.disconnect!
|
343
|
+
assert !@connection.transaction_open?
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
260
348
|
end
|
349
|
+
|
350
|
+
|
261
351
|
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
require 'support/connection_helper'
|
3
|
+
|
4
|
+
class Mysql2ActiveSchemaTest < ActiveRecord::Mysql2TestCase
|
5
|
+
include ConnectionHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
ActiveRecord::Base.connection.singleton_class.class_eval do
|
9
|
+
alias_method :execute_without_stub, :execute
|
10
|
+
def execute(sql, name = nil) return sql end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
teardown do
|
15
|
+
reset_connection
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_add_index
|
19
|
+
# add_index calls data_source_exists? and index_name_exists? which can't work since execute is stubbed
|
20
|
+
def (ActiveRecord::Base.connection).data_source_exists?(*); true; end
|
21
|
+
def (ActiveRecord::Base.connection).index_name_exists?(*); false; end
|
22
|
+
|
23
|
+
expected = "CREATE INDEX `index_people_on_last_name` ON `people` (`last_name`) "
|
24
|
+
assert_equal expected, add_index(:people, :last_name, :length => nil)
|
25
|
+
|
26
|
+
expected = "CREATE INDEX `index_people_on_last_name` ON `people` (`last_name`(10)) "
|
27
|
+
assert_equal expected, add_index(:people, :last_name, :length => 10)
|
28
|
+
|
29
|
+
expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(15)) "
|
30
|
+
assert_equal expected, add_index(:people, [:last_name, :first_name], length: 15)
|
31
|
+
assert_equal expected, add_index(:people, ["last_name", "first_name"], length: 15)
|
32
|
+
|
33
|
+
expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`) "
|
34
|
+
assert_equal expected, add_index(:people, [:last_name, :first_name], length: { last_name: 15 })
|
35
|
+
assert_equal expected, add_index(:people, ["last_name", "first_name"], length: { last_name: 15 })
|
36
|
+
|
37
|
+
expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(10)) "
|
38
|
+
assert_equal expected, add_index(:people, [:last_name, :first_name], length: { last_name: 15, first_name: 10 })
|
39
|
+
assert_equal expected, add_index(:people, ["last_name", :first_name], length: { last_name: 15, "first_name" => 10 })
|
40
|
+
|
41
|
+
%w(SPATIAL FULLTEXT UNIQUE).each do |type|
|
42
|
+
expected = "CREATE #{type} INDEX `index_people_on_last_name` ON `people` (`last_name`) "
|
43
|
+
assert_equal expected, add_index(:people, :last_name, :type => type)
|
44
|
+
end
|
45
|
+
|
46
|
+
%w(btree hash).each do |using|
|
47
|
+
expected = "CREATE INDEX `index_people_on_last_name` USING #{using} ON `people` (`last_name`) "
|
48
|
+
assert_equal expected, add_index(:people, :last_name, :using => using)
|
49
|
+
end
|
50
|
+
|
51
|
+
expected = "CREATE INDEX `index_people_on_last_name` USING btree ON `people` (`last_name`(10)) "
|
52
|
+
assert_equal expected, add_index(:people, :last_name, :length => 10, :using => :btree)
|
53
|
+
|
54
|
+
expected = "CREATE INDEX `index_people_on_last_name` USING btree ON `people` (`last_name`(10)) ALGORITHM = COPY"
|
55
|
+
assert_equal expected, add_index(:people, :last_name, :length => 10, using: :btree, algorithm: :copy)
|
56
|
+
|
57
|
+
assert_raise ArgumentError do
|
58
|
+
add_index(:people, :last_name, algorithm: :coyp)
|
59
|
+
end
|
60
|
+
|
61
|
+
expected = "CREATE INDEX `index_people_on_last_name_and_first_name` USING btree ON `people` (`last_name`(15), `first_name`(15)) "
|
62
|
+
assert_equal expected, add_index(:people, [:last_name, :first_name], :length => 15, :using => :btree)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_index_in_create
|
66
|
+
def (ActiveRecord::Base.connection).data_source_exists?(*); false; end
|
67
|
+
|
68
|
+
%w(SPATIAL FULLTEXT UNIQUE).each do |type|
|
69
|
+
expected = "CREATE TABLE `people` (#{type} INDEX `index_people_on_last_name` (`last_name`)) ENGINE=InnoDB"
|
70
|
+
actual = ActiveRecord::Base.connection.create_table(:people, id: false) do |t|
|
71
|
+
t.index :last_name, type: type
|
72
|
+
end
|
73
|
+
assert_equal expected, actual
|
74
|
+
end
|
75
|
+
|
76
|
+
expected = "CREATE TABLE `people` ( INDEX `index_people_on_last_name` USING btree (`last_name`(10))) ENGINE=InnoDB"
|
77
|
+
actual = ActiveRecord::Base.connection.create_table(:people, id: false) do |t|
|
78
|
+
t.index :last_name, length: 10, using: :btree
|
79
|
+
end
|
80
|
+
assert_equal expected, actual
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_index_in_bulk_change
|
84
|
+
def (ActiveRecord::Base.connection).data_source_exists?(*); true; end
|
85
|
+
def (ActiveRecord::Base.connection).index_name_exists?(*); false; end
|
86
|
+
|
87
|
+
%w(SPATIAL FULLTEXT UNIQUE).each do |type|
|
88
|
+
expected = "ALTER TABLE `people` ADD #{type} INDEX `index_people_on_last_name` (`last_name`)"
|
89
|
+
actual = ActiveRecord::Base.connection.change_table(:people, bulk: true) do |t|
|
90
|
+
t.index :last_name, type: type
|
91
|
+
end
|
92
|
+
assert_equal expected, actual
|
93
|
+
end
|
94
|
+
|
95
|
+
expected = "ALTER TABLE `peaple` ADD INDEX `index_peaple_on_last_name` USING btree (`last_name`(10)), ALGORITHM = COPY"
|
96
|
+
actual = ActiveRecord::Base.connection.change_table(:peaple, bulk: true) do |t|
|
97
|
+
t.index :last_name, length: 10, using: :btree, algorithm: :copy
|
98
|
+
end
|
99
|
+
assert_equal expected, actual
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_drop_table
|
103
|
+
assert_equal "DROP TABLE `people`", drop_table(:people)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_create_mysql_database_with_encoding
|
107
|
+
assert_equal "CREATE DATABASE `matt` DEFAULT CHARACTER SET `utf8`", create_database(:matt)
|
108
|
+
assert_equal "CREATE DATABASE `aimonetti` DEFAULT CHARACTER SET `latin1`", create_database(:aimonetti, {:charset => 'latin1'})
|
109
|
+
assert_equal "CREATE DATABASE `matt_aimonetti` DEFAULT CHARACTER SET `big5` COLLATE `big5_chinese_ci`", create_database(:matt_aimonetti, {:charset => :big5, :collation => :big5_chinese_ci})
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_recreate_mysql_database_with_encoding
|
113
|
+
create_database(:luca, {:charset => 'latin1'})
|
114
|
+
assert_equal "CREATE DATABASE `luca` DEFAULT CHARACTER SET `latin1`", recreate_database(:luca, {:charset => 'latin1'})
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_add_column
|
118
|
+
assert_equal "ALTER TABLE `people` ADD `last_name` varchar(255)", add_column(:people, :last_name, :string)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_add_column_with_limit
|
122
|
+
assert_equal "ALTER TABLE `people` ADD `key` varchar(32)", add_column(:people, :key, :string, :limit => 32)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_drop_table_with_specific_database
|
126
|
+
assert_equal "DROP TABLE `otherdb`.`people`", drop_table('otherdb.people')
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_add_timestamps
|
130
|
+
with_real_execute do
|
131
|
+
begin
|
132
|
+
ActiveRecord::Base.connection.create_table :delete_me
|
133
|
+
ActiveRecord::Base.connection.add_timestamps :delete_me, null: true
|
134
|
+
assert column_present?('delete_me', 'updated_at', 'datetime')
|
135
|
+
assert column_present?('delete_me', 'created_at', 'datetime')
|
136
|
+
ensure
|
137
|
+
ActiveRecord::Base.connection.drop_table :delete_me rescue nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_remove_timestamps
|
143
|
+
with_real_execute do
|
144
|
+
begin
|
145
|
+
ActiveRecord::Base.connection.create_table :delete_me do |t|
|
146
|
+
t.timestamps null: true
|
147
|
+
end
|
148
|
+
ActiveRecord::Base.connection.remove_timestamps :delete_me, { null: true }
|
149
|
+
assert !column_present?('delete_me', 'updated_at', 'datetime')
|
150
|
+
assert !column_present?('delete_me', 'created_at', 'datetime')
|
151
|
+
ensure
|
152
|
+
ActiveRecord::Base.connection.drop_table :delete_me rescue nil
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_indexes_in_create
|
158
|
+
ActiveRecord::Base.connection.stubs(:data_source_exists?).with(:temp).returns(false)
|
159
|
+
ActiveRecord::Base.connection.stubs(:index_name_exists?).with(:index_temp_on_zip).returns(false)
|
160
|
+
|
161
|
+
expected = "CREATE TEMPORARY TABLE `temp` ( INDEX `index_temp_on_zip` (`zip`)) ENGINE=InnoDB AS SELECT id, name, zip FROM a_really_complicated_query"
|
162
|
+
actual = ActiveRecord::Base.connection.create_table(:temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query") do |t|
|
163
|
+
t.index :zip
|
164
|
+
end
|
165
|
+
|
166
|
+
assert_equal expected, actual
|
167
|
+
end
|
168
|
+
|
169
|
+
private
|
170
|
+
def with_real_execute
|
171
|
+
ActiveRecord::Base.connection.singleton_class.class_eval do
|
172
|
+
alias_method :execute_with_stub, :execute
|
173
|
+
remove_method :execute
|
174
|
+
alias_method :execute, :execute_without_stub
|
175
|
+
end
|
176
|
+
|
177
|
+
yield
|
178
|
+
ensure
|
179
|
+
ActiveRecord::Base.connection.singleton_class.class_eval do
|
180
|
+
remove_method :execute
|
181
|
+
alias_method :execute, :execute_with_stub
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def method_missing(method_symbol, *arguments)
|
186
|
+
ActiveRecord::Base.connection.send(method_symbol, *arguments)
|
187
|
+
end
|
188
|
+
|
189
|
+
def column_present?(table_name, column_name, type)
|
190
|
+
results = ActiveRecord::Base.connection.select_all("SHOW FIELDS FROM #{table_name} LIKE '#{column_name}'")
|
191
|
+
results.first && results.first['Type'] == type
|
192
|
+
end
|
193
|
+
end
|