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
@@ -123,6 +123,24 @@ END
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
def test_removes_fixture_config_row
|
127
|
+
File.open(::File.join(FIXTURES_ROOT, 'other_posts.yml')) do |fh|
|
128
|
+
assert_equal(['second_welcome'], fh.each.map { |name, _| name })
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_extracts_model_class_from_config_row
|
133
|
+
File.open(::File.join(FIXTURES_ROOT, 'other_posts.yml')) do |fh|
|
134
|
+
assert_equal 'Post', fh.model_class
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_erb_filename
|
139
|
+
filename = 'filename.yaml'
|
140
|
+
erb = File.new(filename).send(:prepare_erb, "<% Rails.env %>\n")
|
141
|
+
assert_equal erb.filename, filename
|
142
|
+
end
|
143
|
+
|
126
144
|
private
|
127
145
|
def tmp_yaml(name, contents)
|
128
146
|
t = Tempfile.new name
|
data/test/cases/fixtures_test.rb
CHANGED
@@ -7,16 +7,18 @@ require 'models/binary'
|
|
7
7
|
require 'models/book'
|
8
8
|
require 'models/bulb'
|
9
9
|
require 'models/category'
|
10
|
+
require 'models/comment'
|
10
11
|
require 'models/company'
|
11
12
|
require 'models/computer'
|
12
13
|
require 'models/course'
|
13
14
|
require 'models/developer'
|
14
|
-
require
|
15
|
+
require "models/dog"
|
16
|
+
require 'models/doubloon'
|
15
17
|
require 'models/joke'
|
16
18
|
require 'models/matey'
|
19
|
+
require "models/other_dog"
|
17
20
|
require 'models/parrot'
|
18
21
|
require 'models/pirate'
|
19
|
-
require 'models/doubloon'
|
20
22
|
require 'models/post'
|
21
23
|
require 'models/randomly_named_c1'
|
22
24
|
require 'models/reply'
|
@@ -29,10 +31,10 @@ require 'tempfile'
|
|
29
31
|
|
30
32
|
class FixturesTest < ActiveRecord::TestCase
|
31
33
|
self.use_instantiated_fixtures = true
|
32
|
-
self.
|
34
|
+
self.use_transactional_tests = false
|
33
35
|
|
34
36
|
# other_topics fixture should not be included here
|
35
|
-
fixtures :topics, :developers, :accounts, :tasks, :categories, :funny_jokes, :binaries, :traffic_lights
|
37
|
+
fixtures :topics, :developers, :accounts, :tasks, :categories, :funny_jokes, :binaries, :traffic_lights
|
36
38
|
|
37
39
|
FIXTURES = %w( accounts binaries companies customers
|
38
40
|
developers developers_projects entrants
|
@@ -184,7 +186,6 @@ class FixturesTest < ActiveRecord::TestCase
|
|
184
186
|
end
|
185
187
|
|
186
188
|
def test_fixtures_from_root_yml_with_instantiation
|
187
|
-
# assert_equal 2, @accounts.size
|
188
189
|
assert_equal 50, @unknown.credit_limit
|
189
190
|
end
|
190
191
|
|
@@ -217,6 +218,17 @@ class FixturesTest < ActiveRecord::TestCase
|
|
217
218
|
end
|
218
219
|
end
|
219
220
|
|
221
|
+
def test_yaml_file_with_invalid_column
|
222
|
+
e = assert_raise(ActiveRecord::Fixture::FixtureError) do
|
223
|
+
ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/naked/yml", "parrots")
|
224
|
+
end
|
225
|
+
assert_equal(%(table "parrots" has no column named "arrr".), e.message)
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_yaml_file_with_symbol_columns
|
229
|
+
ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/naked/yml", "trees")
|
230
|
+
end
|
231
|
+
|
220
232
|
def test_omap_fixtures
|
221
233
|
assert_nothing_raised do
|
222
234
|
fixtures = ActiveRecord::FixtureSet.new(Account.connection, 'categories', Category, FIXTURES_ROOT + "/categories_ordered")
|
@@ -252,18 +264,19 @@ class FixturesTest < ActiveRecord::TestCase
|
|
252
264
|
def test_fixtures_are_set_up_with_database_env_variable
|
253
265
|
db_url_tmp = ENV['DATABASE_URL']
|
254
266
|
ENV['DATABASE_URL'] = "sqlite3::memory:"
|
255
|
-
ActiveRecord::Base.
|
256
|
-
|
257
|
-
|
267
|
+
ActiveRecord::Base.stub(:configurations, {}) do
|
268
|
+
test_case = Class.new(ActiveRecord::TestCase) do
|
269
|
+
fixtures :accounts
|
258
270
|
|
259
|
-
|
260
|
-
|
271
|
+
def test_fixtures
|
272
|
+
assert accounts(:signals37)
|
273
|
+
end
|
261
274
|
end
|
262
|
-
end
|
263
275
|
|
264
|
-
|
276
|
+
result = test_case.new(:test_fixtures).run
|
265
277
|
|
266
|
-
|
278
|
+
assert result.passed?, "Expected #{result.name} to pass:\n#{result}"
|
279
|
+
end
|
267
280
|
ensure
|
268
281
|
ENV['DATABASE_URL'] = db_url_tmp
|
269
282
|
end
|
@@ -401,9 +414,11 @@ class FixturesWithoutInstantiationTest < ActiveRecord::TestCase
|
|
401
414
|
end
|
402
415
|
|
403
416
|
def test_reloading_fixtures_through_accessor_methods
|
417
|
+
topic = Struct.new(:title)
|
404
418
|
assert_equal "The First Topic", topics(:first).title
|
405
|
-
@loaded_fixtures['topics']['first']
|
406
|
-
|
419
|
+
assert_called(@loaded_fixtures['topics']['first'], :find, returns: topic.new("Fresh Topic!")) do
|
420
|
+
assert_equal "Fresh Topic!", topics(:first, true).title
|
421
|
+
end
|
407
422
|
end
|
408
423
|
end
|
409
424
|
|
@@ -420,7 +435,7 @@ end
|
|
420
435
|
|
421
436
|
class TransactionalFixturesTest < ActiveRecord::TestCase
|
422
437
|
self.use_instantiated_fixtures = true
|
423
|
-
self.
|
438
|
+
self.use_transactional_tests = true
|
424
439
|
|
425
440
|
fixtures :topics
|
426
441
|
|
@@ -466,7 +481,6 @@ class SetupSubclassTest < SetupTest
|
|
466
481
|
end
|
467
482
|
end
|
468
483
|
|
469
|
-
|
470
484
|
class OverlappingFixturesTest < ActiveRecord::TestCase
|
471
485
|
fixtures :topics, :developers
|
472
486
|
fixtures :developers, :accounts
|
@@ -507,12 +521,44 @@ class OverRideFixtureMethodTest < ActiveRecord::TestCase
|
|
507
521
|
end
|
508
522
|
end
|
509
523
|
|
524
|
+
class FixtureWithSetModelClassTest < ActiveRecord::TestCase
|
525
|
+
fixtures :other_posts, :other_comments
|
526
|
+
|
527
|
+
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
528
|
+
# and thus takes into account the +set_model_class+.
|
529
|
+
self.use_transactional_tests = false
|
530
|
+
|
531
|
+
def test_uses_fixture_class_defined_in_yaml
|
532
|
+
assert_kind_of Post, other_posts(:second_welcome)
|
533
|
+
end
|
534
|
+
|
535
|
+
def test_loads_the_associations_to_fixtures_with_set_model_class
|
536
|
+
post = other_posts(:second_welcome)
|
537
|
+
comment = other_comments(:second_greetings)
|
538
|
+
assert_equal [comment], post.comments
|
539
|
+
assert_equal post, comment.post
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
class SetFixtureClassPrevailsTest < ActiveRecord::TestCase
|
544
|
+
set_fixture_class bad_posts: Post
|
545
|
+
fixtures :bad_posts
|
546
|
+
|
547
|
+
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
548
|
+
# and thus takes into account the +set_model_class+.
|
549
|
+
self.use_transactional_tests = false
|
550
|
+
|
551
|
+
def test_uses_set_fixture_class
|
552
|
+
assert_kind_of Post, bad_posts(:bad_welcome)
|
553
|
+
end
|
554
|
+
end
|
555
|
+
|
510
556
|
class CheckSetTableNameFixturesTest < ActiveRecord::TestCase
|
511
557
|
set_fixture_class :funny_jokes => Joke
|
512
558
|
fixtures :funny_jokes
|
513
559
|
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
514
560
|
# and thus takes into account our set_fixture_class
|
515
|
-
self.
|
561
|
+
self.use_transactional_tests = false
|
516
562
|
|
517
563
|
def test_table_method
|
518
564
|
assert_kind_of Joke, funny_jokes(:a_joke)
|
@@ -524,7 +570,7 @@ class FixtureNameIsNotTableNameFixturesTest < ActiveRecord::TestCase
|
|
524
570
|
fixtures :items
|
525
571
|
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
526
572
|
# and thus takes into account our set_fixture_class
|
527
|
-
self.
|
573
|
+
self.use_transactional_tests = false
|
528
574
|
|
529
575
|
def test_named_accessor
|
530
576
|
assert_kind_of Book, items(:dvd)
|
@@ -536,7 +582,7 @@ class FixtureNameIsNotTableNameMultipleFixturesTest < ActiveRecord::TestCase
|
|
536
582
|
fixtures :items, :funny_jokes
|
537
583
|
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
538
584
|
# and thus takes into account our set_fixture_class
|
539
|
-
self.
|
585
|
+
self.use_transactional_tests = false
|
540
586
|
|
541
587
|
def test_named_accessor_of_differently_named_fixture
|
542
588
|
assert_kind_of Book, items(:dvd)
|
@@ -550,7 +596,7 @@ end
|
|
550
596
|
class CustomConnectionFixturesTest < ActiveRecord::TestCase
|
551
597
|
set_fixture_class :courses => Course
|
552
598
|
fixtures :courses
|
553
|
-
self.
|
599
|
+
self.use_transactional_tests = false
|
554
600
|
|
555
601
|
def test_leaky_destroy
|
556
602
|
assert_nothing_raised { courses(:ruby) }
|
@@ -565,7 +611,7 @@ end
|
|
565
611
|
class TransactionalFixturesOnCustomConnectionTest < ActiveRecord::TestCase
|
566
612
|
set_fixture_class :courses => Course
|
567
613
|
fixtures :courses
|
568
|
-
self.
|
614
|
+
self.use_transactional_tests = true
|
569
615
|
|
570
616
|
def test_leaky_destroy
|
571
617
|
assert_nothing_raised { courses(:ruby) }
|
@@ -581,7 +627,7 @@ class InvalidTableNameFixturesTest < ActiveRecord::TestCase
|
|
581
627
|
fixtures :funny_jokes
|
582
628
|
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
583
629
|
# and thus takes into account our lack of set_fixture_class
|
584
|
-
self.
|
630
|
+
self.use_transactional_tests = false
|
585
631
|
|
586
632
|
def test_raises_error
|
587
633
|
assert_raise ActiveRecord::FixtureClassNotFound do
|
@@ -595,7 +641,7 @@ class CheckEscapedYamlFixturesTest < ActiveRecord::TestCase
|
|
595
641
|
fixtures :funny_jokes
|
596
642
|
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
597
643
|
# and thus takes into account our set_fixture_class
|
598
|
-
self.
|
644
|
+
self.use_transactional_tests = false
|
599
645
|
|
600
646
|
def test_proper_escaped_fixture
|
601
647
|
assert_equal "The \\n Aristocrats\nAte the candy\n", funny_jokes(:another_joke).name
|
@@ -665,7 +711,7 @@ class LoadAllFixturesWithPathnameTest < ActiveRecord::TestCase
|
|
665
711
|
end
|
666
712
|
|
667
713
|
class FasterFixturesTest < ActiveRecord::TestCase
|
668
|
-
self.
|
714
|
+
self.use_transactional_tests = false
|
669
715
|
fixtures :categories, :authors
|
670
716
|
|
671
717
|
def load_extra_fixture(name)
|
@@ -691,7 +737,8 @@ class FasterFixturesTest < ActiveRecord::TestCase
|
|
691
737
|
end
|
692
738
|
|
693
739
|
class FoxyFixturesTest < ActiveRecord::TestCase
|
694
|
-
fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers,
|
740
|
+
fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers,
|
741
|
+
:developers, :"admin/accounts", :"admin/users", :live_parrots, :dead_parrots, :books
|
695
742
|
|
696
743
|
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
697
744
|
require 'models/uuid_parent'
|
@@ -811,6 +858,10 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
|
811
858
|
assert_equal("X marks the spot!", pirates(:mark).catchphrase)
|
812
859
|
end
|
813
860
|
|
861
|
+
def test_supports_label_interpolation_for_integer_label
|
862
|
+
assert_equal("#1 pirate!", pirates(1).catchphrase)
|
863
|
+
end
|
864
|
+
|
814
865
|
def test_supports_polymorphic_belongs_to
|
815
866
|
assert_equal(pirates(:redbeard), treasures(:sapphire).looter)
|
816
867
|
assert_equal(parrots(:louis), treasures(:ruby).looter)
|
@@ -827,10 +878,23 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
|
827
878
|
assert_equal pirates(:blackbeard), parrots(:polly).killer
|
828
879
|
end
|
829
880
|
|
881
|
+
def test_supports_sti_with_respective_files
|
882
|
+
assert_kind_of LiveParrot, live_parrots(:dusty)
|
883
|
+
assert_kind_of DeadParrot, dead_parrots(:deadbird)
|
884
|
+
assert_equal pirates(:blackbeard), dead_parrots(:deadbird).killer
|
885
|
+
end
|
886
|
+
|
830
887
|
def test_namespaced_models
|
831
888
|
assert admin_accounts(:signals37).users.include?(admin_users(:david))
|
832
889
|
assert_equal 2, admin_accounts(:signals37).users.size
|
833
890
|
end
|
891
|
+
|
892
|
+
def test_resolves_enums
|
893
|
+
assert books(:awdr).published?
|
894
|
+
assert books(:awdr).read?
|
895
|
+
assert books(:rfr).proposed?
|
896
|
+
assert books(:ddd).published?
|
897
|
+
end
|
834
898
|
end
|
835
899
|
|
836
900
|
class ActiveSupportSubclassWithFixturesTest < ActiveRecord::TestCase
|
@@ -849,9 +913,9 @@ class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase
|
|
849
913
|
set_fixture_class :randomly_named_a9 =>
|
850
914
|
ClassNameThatDoesNotFollowCONVENTIONS,
|
851
915
|
:'admin/randomly_named_a9' =>
|
852
|
-
Admin::
|
916
|
+
Admin::ClassNameThatDoesNotFollowCONVENTIONS1,
|
853
917
|
'admin/randomly_named_b0' =>
|
854
|
-
Admin::
|
918
|
+
Admin::ClassNameThatDoesNotFollowCONVENTIONS2
|
855
919
|
|
856
920
|
fixtures :randomly_named_a9, 'admin/randomly_named_a9',
|
857
921
|
:'admin/randomly_named_b0'
|
@@ -862,15 +926,15 @@ class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase
|
|
862
926
|
end
|
863
927
|
|
864
928
|
def test_named_accessor_for_randomly_named_namespaced_fixture_and_class
|
865
|
-
assert_kind_of Admin::
|
929
|
+
assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS1,
|
866
930
|
admin_randomly_named_a9(:first_instance)
|
867
|
-
assert_kind_of Admin::
|
931
|
+
assert_kind_of Admin::ClassNameThatDoesNotFollowCONVENTIONS2,
|
868
932
|
admin_randomly_named_b0(:second_instance)
|
869
933
|
end
|
870
934
|
|
871
935
|
def test_table_name_is_defined_in_the_model
|
872
|
-
assert_equal '
|
873
|
-
assert_equal '
|
936
|
+
assert_equal 'randomly_named_table2', ActiveRecord::FixtureSet::all_loaded_fixtures["admin/randomly_named_a9"].table_name
|
937
|
+
assert_equal 'randomly_named_table2', Admin::ClassNameThatDoesNotFollowCONVENTIONS1.table_name
|
874
938
|
end
|
875
939
|
end
|
876
940
|
|
@@ -895,3 +959,30 @@ class FixturesWithAbstractBelongsTo < ActiveRecord::TestCase
|
|
895
959
|
assert_equal pirates(:blackbeard), doubloons(:blackbeards_doubloon).pirate
|
896
960
|
end
|
897
961
|
end
|
962
|
+
|
963
|
+
class FixtureClassNamesTest < ActiveRecord::TestCase
|
964
|
+
def setup
|
965
|
+
@saved_cache = self.fixture_class_names.dup
|
966
|
+
end
|
967
|
+
|
968
|
+
def teardown
|
969
|
+
self.fixture_class_names.replace(@saved_cache)
|
970
|
+
end
|
971
|
+
|
972
|
+
test "fixture_class_names returns nil for unregistered identifier" do
|
973
|
+
assert_nil self.fixture_class_names['unregistered_identifier']
|
974
|
+
end
|
975
|
+
end
|
976
|
+
|
977
|
+
class SameNameDifferentDatabaseFixturesTest < ActiveRecord::TestCase
|
978
|
+
fixtures :dogs, :other_dogs
|
979
|
+
|
980
|
+
test "fixtures are properly loaded" do
|
981
|
+
# Force loading the fixtures again to reproduce issue
|
982
|
+
ActiveRecord::FixtureSet.reset_cache
|
983
|
+
create_fixtures("dogs", "other_dogs")
|
984
|
+
|
985
|
+
assert_kind_of Dog, dogs(:sophie)
|
986
|
+
assert_kind_of OtherDog, other_dogs(:lassie)
|
987
|
+
end
|
988
|
+
end
|
@@ -1,14 +1,20 @@
|
|
1
1
|
require 'cases/helper'
|
2
2
|
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
-
|
3
|
+
|
4
4
|
require 'models/company'
|
5
|
+
require 'models/person'
|
6
|
+
require 'models/ship'
|
7
|
+
require 'models/ship_part'
|
8
|
+
require 'models/treasure'
|
5
9
|
|
6
|
-
class ProtectedParams
|
10
|
+
class ProtectedParams
|
7
11
|
attr_accessor :permitted
|
8
12
|
alias :permitted? :permitted
|
9
13
|
|
14
|
+
delegate :keys, :key?, :has_key?, :empty?, to: :@parameters
|
15
|
+
|
10
16
|
def initialize(attributes)
|
11
|
-
|
17
|
+
@parameters = attributes.with_indifferent_access
|
12
18
|
@permitted = false
|
13
19
|
end
|
14
20
|
|
@@ -17,6 +23,18 @@ class ProtectedParams < ActiveSupport::HashWithIndifferentAccess
|
|
17
23
|
self
|
18
24
|
end
|
19
25
|
|
26
|
+
def [](key)
|
27
|
+
@parameters[key]
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_h
|
31
|
+
@parameters
|
32
|
+
end
|
33
|
+
|
34
|
+
def stringify_keys
|
35
|
+
dup
|
36
|
+
end
|
37
|
+
|
20
38
|
def dup
|
21
39
|
super.tap do |duplicate|
|
22
40
|
duplicate.instance_variable_set :@permitted, @permitted
|
@@ -75,6 +93,13 @@ class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase
|
|
75
93
|
end
|
76
94
|
end
|
77
95
|
|
96
|
+
def test_create_with_works_with_permitted_params
|
97
|
+
params = ProtectedParams.new(first_name: 'Guille').permit!
|
98
|
+
|
99
|
+
person = Person.create_with(params).create!
|
100
|
+
assert_equal 'Guille', person.first_name
|
101
|
+
end
|
102
|
+
|
78
103
|
def test_create_with_works_with_params_values
|
79
104
|
params = ProtectedParams.new(first_name: 'Guille')
|
80
105
|
|
@@ -90,10 +115,51 @@ class ForbiddenAttributesProtectionTest < ActiveRecord::TestCase
|
|
90
115
|
end
|
91
116
|
end
|
92
117
|
|
118
|
+
def test_where_works_with_permitted_params
|
119
|
+
params = ProtectedParams.new(first_name: 'Guille').permit!
|
120
|
+
|
121
|
+
person = Person.where(params).create!
|
122
|
+
assert_equal 'Guille', person.first_name
|
123
|
+
end
|
124
|
+
|
93
125
|
def test_where_works_with_params_values
|
94
126
|
params = ProtectedParams.new(first_name: 'Guille')
|
95
127
|
|
96
128
|
person = Person.where(first_name: params[:first_name]).create!
|
97
129
|
assert_equal 'Guille', person.first_name
|
98
130
|
end
|
131
|
+
|
132
|
+
def test_where_not_checks_permitted
|
133
|
+
params = ProtectedParams.new(first_name: 'Guille', gender: 'm')
|
134
|
+
|
135
|
+
assert_raises(ActiveModel::ForbiddenAttributesError) do
|
136
|
+
Person.where().not(params)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_where_not_works_with_permitted_params
|
141
|
+
params = ProtectedParams.new(first_name: 'Guille').permit!
|
142
|
+
Person.create!(params)
|
143
|
+
assert_empty Person.where.not(params).select {|p| p.first_name == 'Guille' }
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_strong_params_style_objects_work_with_singular_associations
|
147
|
+
params = ProtectedParams.new( name: "Stern", ship_attributes: ProtectedParams.new(name: "The Black Rock").permit!).permit!
|
148
|
+
part = ShipPart.new(params)
|
149
|
+
|
150
|
+
assert_equal "Stern", part.name
|
151
|
+
assert_equal "The Black Rock", part.ship.name
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_strong_params_style_objects_work_with_collection_associations
|
155
|
+
params = ProtectedParams.new(
|
156
|
+
trinkets_attributes: ProtectedParams.new(
|
157
|
+
"0" => ProtectedParams.new(name: "Necklace").permit!,
|
158
|
+
"1" => ProtectedParams.new(name: "Spoon").permit! ) ).permit!
|
159
|
+
part = ShipPart.new(params)
|
160
|
+
|
161
|
+
assert_equal "Necklace", part.trinkets[0].name
|
162
|
+
assert_equal "Spoon", part.trinkets[1].name
|
163
|
+
end
|
164
|
+
|
99
165
|
end
|