activerecord 2.3.18 → 3.2.22
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +1014 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +222 -0
- data/examples/performance.rb +100 -126
- data/examples/simple.rb +14 -0
- data/lib/active_record/aggregations.rb +93 -99
- data/lib/active_record/associations/alias_tracker.rb +76 -0
- data/lib/active_record/associations/association.rb +247 -0
- data/lib/active_record/associations/association_scope.rb +134 -0
- data/lib/active_record/associations/belongs_to_association.rb +54 -61
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +17 -59
- data/lib/active_record/associations/builder/association.rb +55 -0
- data/lib/active_record/associations/builder/belongs_to.rb +88 -0
- data/lib/active_record/associations/builder/collection_association.rb +75 -0
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +57 -0
- data/lib/active_record/associations/builder/has_many.rb +71 -0
- data/lib/active_record/associations/builder/has_one.rb +62 -0
- data/lib/active_record/associations/builder/singular_association.rb +32 -0
- data/lib/active_record/associations/collection_association.rb +580 -0
- data/lib/active_record/associations/collection_proxy.rb +133 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +39 -119
- data/lib/active_record/associations/has_many_association.rb +60 -79
- data/lib/active_record/associations/has_many_through_association.rb +127 -206
- data/lib/active_record/associations/has_one_association.rb +55 -114
- data/lib/active_record/associations/has_one_through_association.rb +25 -26
- data/lib/active_record/associations/join_dependency/join_association.rb +159 -0
- data/lib/active_record/associations/join_dependency/join_base.rb +24 -0
- data/lib/active_record/associations/join_dependency/join_part.rb +78 -0
- data/lib/active_record/associations/join_dependency.rb +214 -0
- data/lib/active_record/associations/join_helper.rb +55 -0
- data/lib/active_record/associations/preloader/association.rb +125 -0
- data/lib/active_record/associations/preloader/belongs_to.rb +17 -0
- data/lib/active_record/associations/preloader/collection_association.rb +24 -0
- data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +60 -0
- data/lib/active_record/associations/preloader/has_many.rb +17 -0
- data/lib/active_record/associations/preloader/has_many_through.rb +15 -0
- data/lib/active_record/associations/preloader/has_one.rb +23 -0
- data/lib/active_record/associations/preloader/has_one_through.rb +9 -0
- data/lib/active_record/associations/preloader/singular_association.rb +21 -0
- data/lib/active_record/associations/preloader/through_association.rb +67 -0
- data/lib/active_record/associations/preloader.rb +181 -0
- data/lib/active_record/associations/singular_association.rb +64 -0
- data/lib/active_record/associations/through_association.rb +87 -0
- data/lib/active_record/associations.rb +693 -1337
- data/lib/active_record/attribute_assignment.rb +221 -0
- data/lib/active_record/attribute_methods/before_type_cast.rb +31 -0
- data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +32 -0
- data/lib/active_record/attribute_methods/dirty.rb +111 -0
- data/lib/active_record/attribute_methods/primary_key.rb +114 -0
- data/lib/active_record/attribute_methods/query.rb +39 -0
- data/lib/active_record/attribute_methods/read.rb +136 -0
- data/lib/active_record/attribute_methods/serialization.rb +120 -0
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +65 -0
- data/lib/active_record/attribute_methods/write.rb +70 -0
- data/lib/active_record/attribute_methods.rb +211 -339
- data/lib/active_record/autosave_association.rb +179 -149
- data/lib/active_record/base.rb +401 -2907
- data/lib/active_record/callbacks.rb +91 -176
- data/lib/active_record/coders/yaml_column.rb +41 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +236 -119
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +110 -58
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +12 -11
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +175 -74
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +31 -35
- data/lib/active_record/connection_adapters/abstract/quoting.rb +71 -21
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +81 -311
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +194 -78
- data/lib/active_record/connection_adapters/abstract_adapter.rb +130 -83
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +676 -0
- data/lib/active_record/connection_adapters/column.rb +296 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +280 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +272 -493
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +650 -405
- data/lib/active_record/connection_adapters/schema_cache.rb +69 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +30 -9
- data/lib/active_record/connection_adapters/sqlite_adapter.rb +276 -147
- data/lib/active_record/connection_adapters/statement_pool.rb +40 -0
- data/lib/active_record/counter_cache.rb +123 -0
- data/lib/active_record/dynamic_finder_match.rb +41 -14
- data/lib/active_record/dynamic_matchers.rb +84 -0
- data/lib/active_record/dynamic_scope_match.rb +13 -15
- data/lib/active_record/errors.rb +195 -0
- data/lib/active_record/explain.rb +86 -0
- data/lib/active_record/explain_subscriber.rb +25 -0
- data/lib/active_record/fixtures/file.rb +65 -0
- data/lib/active_record/fixtures.rb +695 -770
- data/lib/active_record/identity_map.rb +162 -0
- data/lib/active_record/inheritance.rb +174 -0
- data/lib/active_record/integration.rb +60 -0
- data/lib/active_record/locale/en.yml +9 -27
- data/lib/active_record/locking/optimistic.rb +76 -73
- data/lib/active_record/locking/pessimistic.rb +32 -10
- data/lib/active_record/log_subscriber.rb +72 -0
- data/lib/active_record/migration/command_recorder.rb +105 -0
- data/lib/active_record/migration.rb +415 -205
- data/lib/active_record/model_schema.rb +368 -0
- data/lib/active_record/nested_attributes.rb +153 -63
- data/lib/active_record/observer.rb +27 -103
- data/lib/active_record/persistence.rb +376 -0
- data/lib/active_record/query_cache.rb +49 -8
- data/lib/active_record/querying.rb +58 -0
- data/lib/active_record/railtie.rb +131 -0
- data/lib/active_record/railties/console_sandbox.rb +6 -0
- data/lib/active_record/railties/controller_runtime.rb +49 -0
- data/lib/active_record/railties/databases.rake +659 -0
- data/lib/active_record/railties/jdbcmysql_error.rb +16 -0
- data/lib/active_record/readonly_attributes.rb +26 -0
- data/lib/active_record/reflection.rb +269 -120
- data/lib/active_record/relation/batches.rb +90 -0
- data/lib/active_record/relation/calculations.rb +372 -0
- data/lib/active_record/relation/delegation.rb +49 -0
- data/lib/active_record/relation/finder_methods.rb +402 -0
- data/lib/active_record/relation/predicate_builder.rb +63 -0
- data/lib/active_record/relation/query_methods.rb +417 -0
- data/lib/active_record/relation/spawn_methods.rb +180 -0
- data/lib/active_record/relation.rb +537 -0
- data/lib/active_record/result.rb +40 -0
- data/lib/active_record/sanitization.rb +194 -0
- data/lib/active_record/schema.rb +9 -6
- data/lib/active_record/schema_dumper.rb +55 -32
- data/lib/active_record/scoping/default.rb +142 -0
- data/lib/active_record/scoping/named.rb +200 -0
- data/lib/active_record/scoping.rb +152 -0
- data/lib/active_record/serialization.rb +8 -91
- data/lib/active_record/serializers/xml_serializer.rb +43 -197
- data/lib/active_record/session_store.rb +129 -103
- data/lib/active_record/store.rb +52 -0
- data/lib/active_record/test_case.rb +30 -23
- data/lib/active_record/timestamp.rb +95 -52
- data/lib/active_record/transactions.rb +212 -66
- data/lib/active_record/translation.rb +22 -0
- data/lib/active_record/validations/associated.rb +43 -0
- data/lib/active_record/validations/uniqueness.rb +180 -0
- data/lib/active_record/validations.rb +43 -1106
- data/lib/active_record/version.rb +5 -4
- data/lib/active_record.rb +121 -48
- data/lib/rails/generators/active_record/migration/migration_generator.rb +25 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb +34 -0
- data/lib/rails/generators/active_record/migration.rb +15 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +47 -0
- data/lib/rails/generators/active_record/model/templates/migration.rb +15 -0
- data/lib/rails/generators/active_record/model/templates/model.rb +12 -0
- data/lib/rails/generators/active_record/model/templates/module.rb +7 -0
- data/lib/rails/generators/active_record/observer/observer_generator.rb +15 -0
- data/lib/rails/generators/active_record/observer/templates/observer.rb +4 -0
- data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +25 -0
- data/lib/rails/generators/active_record/session_migration/templates/migration.rb +12 -0
- data/lib/rails/generators/active_record.rb +25 -0
- metadata +187 -363
- data/CHANGELOG +0 -5904
- data/README +0 -351
- data/RUNNING_UNIT_TESTS +0 -36
- data/Rakefile +0 -268
- data/install.rb +0 -30
- data/lib/active_record/association_preload.rb +0 -406
- data/lib/active_record/associations/association_collection.rb +0 -533
- data/lib/active_record/associations/association_proxy.rb +0 -288
- data/lib/active_record/batches.rb +0 -85
- data/lib/active_record/calculations.rb +0 -321
- data/lib/active_record/dirty.rb +0 -183
- data/lib/active_record/named_scope.rb +0 -197
- data/lib/active_record/serializers/json_serializer.rb +0 -91
- data/lib/activerecord.rb +0 -2
- data/test/assets/example.log +0 -1
- data/test/assets/flowers.jpg +0 -0
- data/test/cases/aaa_create_tables_test.rb +0 -24
- data/test/cases/active_schema_test_mysql.rb +0 -122
- data/test/cases/active_schema_test_postgresql.rb +0 -24
- data/test/cases/adapter_test.rb +0 -144
- data/test/cases/aggregations_test.rb +0 -167
- data/test/cases/ar_schema_test.rb +0 -32
- data/test/cases/associations/belongs_to_associations_test.rb +0 -438
- data/test/cases/associations/callbacks_test.rb +0 -161
- data/test/cases/associations/cascaded_eager_loading_test.rb +0 -131
- data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +0 -36
- data/test/cases/associations/eager_load_nested_include_test.rb +0 -131
- data/test/cases/associations/eager_load_nested_polymorphic_include.rb +0 -19
- data/test/cases/associations/eager_singularization_test.rb +0 -145
- data/test/cases/associations/eager_test.rb +0 -852
- data/test/cases/associations/extension_test.rb +0 -62
- data/test/cases/associations/habtm_join_table_test.rb +0 -56
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +0 -827
- data/test/cases/associations/has_many_associations_test.rb +0 -1273
- data/test/cases/associations/has_many_through_associations_test.rb +0 -360
- data/test/cases/associations/has_one_associations_test.rb +0 -330
- data/test/cases/associations/has_one_through_associations_test.rb +0 -209
- data/test/cases/associations/inner_join_association_test.rb +0 -93
- data/test/cases/associations/inverse_associations_test.rb +0 -566
- data/test/cases/associations/join_model_test.rb +0 -712
- data/test/cases/associations_test.rb +0 -282
- data/test/cases/attribute_methods_test.rb +0 -305
- data/test/cases/autosave_association_test.rb +0 -1218
- data/test/cases/base_test.rb +0 -2166
- data/test/cases/batches_test.rb +0 -81
- data/test/cases/binary_test.rb +0 -30
- data/test/cases/calculations_test.rb +0 -360
- data/test/cases/callbacks_observers_test.rb +0 -38
- data/test/cases/callbacks_test.rb +0 -438
- data/test/cases/class_inheritable_attributes_test.rb +0 -32
- data/test/cases/column_alias_test.rb +0 -17
- data/test/cases/column_definition_test.rb +0 -70
- data/test/cases/connection_pool_test.rb +0 -25
- data/test/cases/connection_test_firebird.rb +0 -8
- data/test/cases/connection_test_mysql.rb +0 -65
- data/test/cases/copy_table_test_sqlite.rb +0 -80
- data/test/cases/counter_cache_test.rb +0 -84
- data/test/cases/database_statements_test.rb +0 -12
- data/test/cases/datatype_test_postgresql.rb +0 -204
- data/test/cases/date_time_test.rb +0 -37
- data/test/cases/default_test_firebird.rb +0 -16
- data/test/cases/defaults_test.rb +0 -111
- data/test/cases/deprecated_finder_test.rb +0 -30
- data/test/cases/dirty_test.rb +0 -316
- data/test/cases/finder_respond_to_test.rb +0 -76
- data/test/cases/finder_test.rb +0 -1098
- data/test/cases/fixtures_test.rb +0 -661
- data/test/cases/helper.rb +0 -68
- data/test/cases/i18n_test.rb +0 -46
- data/test/cases/inheritance_test.rb +0 -262
- data/test/cases/invalid_date_test.rb +0 -24
- data/test/cases/json_serialization_test.rb +0 -219
- data/test/cases/lifecycle_test.rb +0 -193
- data/test/cases/locking_test.rb +0 -350
- data/test/cases/method_scoping_test.rb +0 -704
- data/test/cases/migration_test.rb +0 -1649
- data/test/cases/migration_test_firebird.rb +0 -124
- data/test/cases/mixin_test.rb +0 -96
- data/test/cases/modules_test.rb +0 -109
- data/test/cases/multiple_db_test.rb +0 -85
- data/test/cases/named_scope_test.rb +0 -372
- data/test/cases/nested_attributes_test.rb +0 -840
- data/test/cases/pk_test.rb +0 -119
- data/test/cases/pooled_connections_test.rb +0 -103
- data/test/cases/query_cache_test.rb +0 -129
- data/test/cases/readonly_test.rb +0 -107
- data/test/cases/reflection_test.rb +0 -234
- data/test/cases/reload_models_test.rb +0 -22
- data/test/cases/repair_helper.rb +0 -50
- data/test/cases/reserved_word_test_mysql.rb +0 -176
- data/test/cases/sanitize_test.rb +0 -25
- data/test/cases/schema_authorization_test_postgresql.rb +0 -75
- data/test/cases/schema_dumper_test.rb +0 -211
- data/test/cases/schema_test_postgresql.rb +0 -178
- data/test/cases/serialization_test.rb +0 -47
- data/test/cases/sp_test_mysql.rb +0 -16
- data/test/cases/synonym_test_oracle.rb +0 -17
- data/test/cases/timestamp_test.rb +0 -75
- data/test/cases/transactions_test.rb +0 -543
- data/test/cases/unconnected_test.rb +0 -32
- data/test/cases/validations_i18n_test.rb +0 -925
- data/test/cases/validations_test.rb +0 -1684
- data/test/cases/xml_serialization_test.rb +0 -240
- data/test/cases/yaml_serialization_test.rb +0 -11
- data/test/config.rb +0 -5
- data/test/connections/jdbc_jdbcderby/connection.rb +0 -18
- data/test/connections/jdbc_jdbch2/connection.rb +0 -18
- data/test/connections/jdbc_jdbchsqldb/connection.rb +0 -18
- data/test/connections/jdbc_jdbcmysql/connection.rb +0 -26
- data/test/connections/jdbc_jdbcpostgresql/connection.rb +0 -26
- data/test/connections/jdbc_jdbcsqlite3/connection.rb +0 -25
- data/test/connections/native_db2/connection.rb +0 -25
- data/test/connections/native_firebird/connection.rb +0 -26
- data/test/connections/native_frontbase/connection.rb +0 -27
- data/test/connections/native_mysql/connection.rb +0 -25
- data/test/connections/native_openbase/connection.rb +0 -21
- data/test/connections/native_oracle/connection.rb +0 -27
- data/test/connections/native_postgresql/connection.rb +0 -21
- data/test/connections/native_sqlite/connection.rb +0 -25
- data/test/connections/native_sqlite3/connection.rb +0 -25
- data/test/connections/native_sqlite3/in_memory_connection.rb +0 -18
- data/test/connections/native_sybase/connection.rb +0 -23
- data/test/fixtures/accounts.yml +0 -29
- data/test/fixtures/all/developers.yml +0 -0
- data/test/fixtures/all/people.csv +0 -0
- data/test/fixtures/all/tasks.yml +0 -0
- data/test/fixtures/author_addresses.yml +0 -5
- data/test/fixtures/author_favorites.yml +0 -4
- data/test/fixtures/authors.yml +0 -9
- data/test/fixtures/binaries.yml +0 -132
- data/test/fixtures/books.yml +0 -7
- data/test/fixtures/categories/special_categories.yml +0 -9
- data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +0 -4
- data/test/fixtures/categories.yml +0 -14
- data/test/fixtures/categories_ordered.yml +0 -7
- data/test/fixtures/categories_posts.yml +0 -23
- data/test/fixtures/categorizations.yml +0 -17
- data/test/fixtures/clubs.yml +0 -6
- data/test/fixtures/comments.yml +0 -59
- data/test/fixtures/companies.yml +0 -56
- data/test/fixtures/computers.yml +0 -4
- data/test/fixtures/courses.yml +0 -7
- data/test/fixtures/customers.yml +0 -26
- data/test/fixtures/developers.yml +0 -21
- data/test/fixtures/developers_projects.yml +0 -17
- data/test/fixtures/edges.yml +0 -6
- data/test/fixtures/entrants.yml +0 -14
- data/test/fixtures/faces.yml +0 -11
- data/test/fixtures/fk_test_has_fk.yml +0 -3
- data/test/fixtures/fk_test_has_pk.yml +0 -2
- data/test/fixtures/funny_jokes.yml +0 -10
- data/test/fixtures/interests.yml +0 -33
- data/test/fixtures/items.yml +0 -4
- data/test/fixtures/jobs.yml +0 -7
- data/test/fixtures/legacy_things.yml +0 -3
- data/test/fixtures/mateys.yml +0 -4
- data/test/fixtures/member_types.yml +0 -6
- data/test/fixtures/members.yml +0 -6
- data/test/fixtures/memberships.yml +0 -20
- data/test/fixtures/men.yml +0 -5
- data/test/fixtures/minimalistics.yml +0 -2
- data/test/fixtures/mixed_case_monkeys.yml +0 -6
- data/test/fixtures/mixins.yml +0 -29
- data/test/fixtures/movies.yml +0 -7
- data/test/fixtures/naked/csv/accounts.csv +0 -1
- data/test/fixtures/naked/yml/accounts.yml +0 -1
- data/test/fixtures/naked/yml/companies.yml +0 -1
- data/test/fixtures/naked/yml/courses.yml +0 -1
- data/test/fixtures/organizations.yml +0 -5
- data/test/fixtures/owners.yml +0 -7
- data/test/fixtures/parrots.yml +0 -27
- data/test/fixtures/parrots_pirates.yml +0 -7
- data/test/fixtures/people.yml +0 -15
- data/test/fixtures/pets.yml +0 -14
- data/test/fixtures/pirates.yml +0 -9
- data/test/fixtures/polymorphic_designs.yml +0 -19
- data/test/fixtures/polymorphic_prices.yml +0 -19
- data/test/fixtures/posts.yml +0 -52
- data/test/fixtures/price_estimates.yml +0 -7
- data/test/fixtures/projects.yml +0 -7
- data/test/fixtures/readers.yml +0 -9
- data/test/fixtures/references.yml +0 -17
- data/test/fixtures/reserved_words/distinct.yml +0 -5
- data/test/fixtures/reserved_words/distincts_selects.yml +0 -11
- data/test/fixtures/reserved_words/group.yml +0 -14
- data/test/fixtures/reserved_words/select.yml +0 -8
- data/test/fixtures/reserved_words/values.yml +0 -7
- data/test/fixtures/ships.yml +0 -5
- data/test/fixtures/sponsors.yml +0 -9
- data/test/fixtures/subscribers.yml +0 -7
- data/test/fixtures/subscriptions.yml +0 -12
- data/test/fixtures/taggings.yml +0 -28
- data/test/fixtures/tags.yml +0 -7
- data/test/fixtures/tasks.yml +0 -7
- data/test/fixtures/tees.yml +0 -4
- data/test/fixtures/ties.yml +0 -4
- data/test/fixtures/topics.yml +0 -42
- data/test/fixtures/toys.yml +0 -4
- data/test/fixtures/treasures.yml +0 -10
- data/test/fixtures/vertices.yml +0 -4
- data/test/fixtures/warehouse-things.yml +0 -3
- data/test/fixtures/zines.yml +0 -5
- data/test/migrations/broken/100_migration_that_raises_exception.rb +0 -10
- data/test/migrations/decimal/1_give_me_big_numbers.rb +0 -15
- data/test/migrations/duplicate/1_people_have_last_names.rb +0 -9
- data/test/migrations/duplicate/2_we_need_reminders.rb +0 -12
- data/test/migrations/duplicate/3_foo.rb +0 -7
- data/test/migrations/duplicate/3_innocent_jointable.rb +0 -12
- data/test/migrations/duplicate_names/20080507052938_chunky.rb +0 -7
- data/test/migrations/duplicate_names/20080507053028_chunky.rb +0 -7
- data/test/migrations/interleaved/pass_1/3_innocent_jointable.rb +0 -12
- data/test/migrations/interleaved/pass_2/1_people_have_last_names.rb +0 -9
- data/test/migrations/interleaved/pass_2/3_innocent_jointable.rb +0 -12
- data/test/migrations/interleaved/pass_3/1_people_have_last_names.rb +0 -9
- data/test/migrations/interleaved/pass_3/2_i_raise_on_down.rb +0 -8
- data/test/migrations/interleaved/pass_3/3_innocent_jointable.rb +0 -12
- data/test/migrations/missing/1000_people_have_middle_names.rb +0 -9
- data/test/migrations/missing/1_people_have_last_names.rb +0 -9
- data/test/migrations/missing/3_we_need_reminders.rb +0 -12
- data/test/migrations/missing/4_innocent_jointable.rb +0 -12
- data/test/migrations/valid/1_people_have_last_names.rb +0 -9
- data/test/migrations/valid/2_we_need_reminders.rb +0 -12
- data/test/migrations/valid/3_innocent_jointable.rb +0 -12
- data/test/models/author.rb +0 -151
- data/test/models/auto_id.rb +0 -4
- data/test/models/binary.rb +0 -2
- data/test/models/bird.rb +0 -9
- data/test/models/book.rb +0 -4
- data/test/models/categorization.rb +0 -5
- data/test/models/category.rb +0 -34
- data/test/models/citation.rb +0 -6
- data/test/models/club.rb +0 -13
- data/test/models/column_name.rb +0 -3
- data/test/models/comment.rb +0 -29
- data/test/models/company.rb +0 -173
- data/test/models/company_in_module.rb +0 -78
- data/test/models/computer.rb +0 -3
- data/test/models/contact.rb +0 -16
- data/test/models/contract.rb +0 -5
- data/test/models/course.rb +0 -3
- data/test/models/customer.rb +0 -73
- data/test/models/default.rb +0 -2
- data/test/models/developer.rb +0 -101
- data/test/models/edge.rb +0 -5
- data/test/models/entrant.rb +0 -3
- data/test/models/essay.rb +0 -3
- data/test/models/event.rb +0 -3
- data/test/models/event_author.rb +0 -8
- data/test/models/face.rb +0 -7
- data/test/models/guid.rb +0 -2
- data/test/models/interest.rb +0 -5
- data/test/models/invoice.rb +0 -4
- data/test/models/item.rb +0 -7
- data/test/models/job.rb +0 -5
- data/test/models/joke.rb +0 -3
- data/test/models/keyboard.rb +0 -3
- data/test/models/legacy_thing.rb +0 -3
- data/test/models/line_item.rb +0 -3
- data/test/models/man.rb +0 -9
- data/test/models/matey.rb +0 -4
- data/test/models/member.rb +0 -12
- data/test/models/member_detail.rb +0 -5
- data/test/models/member_type.rb +0 -3
- data/test/models/membership.rb +0 -9
- data/test/models/minimalistic.rb +0 -2
- data/test/models/mixed_case_monkey.rb +0 -3
- data/test/models/movie.rb +0 -5
- data/test/models/order.rb +0 -4
- data/test/models/organization.rb +0 -6
- data/test/models/owner.rb +0 -5
- data/test/models/parrot.rb +0 -22
- data/test/models/person.rb +0 -16
- data/test/models/pet.rb +0 -5
- data/test/models/pirate.rb +0 -80
- data/test/models/polymorphic_design.rb +0 -3
- data/test/models/polymorphic_price.rb +0 -3
- data/test/models/post.rb +0 -102
- data/test/models/price_estimate.rb +0 -3
- data/test/models/project.rb +0 -30
- data/test/models/reader.rb +0 -4
- data/test/models/reference.rb +0 -4
- data/test/models/reply.rb +0 -46
- data/test/models/ship.rb +0 -19
- data/test/models/ship_part.rb +0 -7
- data/test/models/sponsor.rb +0 -4
- data/test/models/subject.rb +0 -4
- data/test/models/subscriber.rb +0 -8
- data/test/models/subscription.rb +0 -4
- data/test/models/tag.rb +0 -7
- data/test/models/tagging.rb +0 -10
- data/test/models/task.rb +0 -3
- data/test/models/tee.rb +0 -4
- data/test/models/tie.rb +0 -4
- data/test/models/topic.rb +0 -80
- data/test/models/toy.rb +0 -6
- data/test/models/treasure.rb +0 -8
- data/test/models/vertex.rb +0 -9
- data/test/models/warehouse_thing.rb +0 -5
- data/test/models/zine.rb +0 -3
- data/test/schema/mysql_specific_schema.rb +0 -31
- data/test/schema/postgresql_specific_schema.rb +0 -114
- data/test/schema/schema.rb +0 -550
- data/test/schema/schema2.rb +0 -6
- data/test/schema/sqlite_specific_schema.rb +0 -25
@@ -1,925 +0,0 @@
|
|
1
|
-
require "cases/helper"
|
2
|
-
require 'models/topic'
|
3
|
-
require 'models/reply'
|
4
|
-
require 'models/person'
|
5
|
-
|
6
|
-
module ActiveRecordValidationsI18nTestHelper
|
7
|
-
def store_translations(*args)
|
8
|
-
data = args.extract_options!
|
9
|
-
locale = args.shift || 'en'
|
10
|
-
I18n.backend.send(:init_translations)
|
11
|
-
I18n.backend.store_translations(locale, :activerecord => data)
|
12
|
-
end
|
13
|
-
|
14
|
-
def delete_translation(key)
|
15
|
-
I18n.backend.instance_eval do
|
16
|
-
keys = I18n.send(:normalize_translation_keys, 'en', key, nil)
|
17
|
-
keys.inject(translations) { |result, k| keys.last == k ? result.delete(k.to_sym) : result[k.to_sym] }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def reset_callbacks(*models)
|
22
|
-
models.each do |model|
|
23
|
-
model.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
24
|
-
model.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
25
|
-
model.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
# ACTIVERECORD VALIDATIONS
|
32
|
-
#
|
33
|
-
# For each validation:
|
34
|
-
#
|
35
|
-
# * test expect that it adds an error with the appropriate arguments
|
36
|
-
# * test that it looks up the correct default message
|
37
|
-
|
38
|
-
class ActiveRecordValidationsI18nTests < ActiveSupport::TestCase
|
39
|
-
include ActiveRecordValidationsI18nTestHelper
|
40
|
-
|
41
|
-
def setup
|
42
|
-
reset_callbacks(Topic)
|
43
|
-
@topic = Topic.new
|
44
|
-
@reply = Reply.new
|
45
|
-
@old_load_path, @old_backend = I18n.load_path, I18n.backend
|
46
|
-
I18n.load_path.clear
|
47
|
-
I18n.backend = I18n::Backend::Simple.new
|
48
|
-
I18n.backend.store_translations('en', :activerecord => {:errors => {:messages => {:custom => nil}}})
|
49
|
-
end
|
50
|
-
|
51
|
-
def teardown
|
52
|
-
reset_callbacks(Topic)
|
53
|
-
I18n.load_path.replace(@old_load_path)
|
54
|
-
I18n.backend = @old_backend
|
55
|
-
end
|
56
|
-
|
57
|
-
def expect_error_added(model, attribute, type, options)
|
58
|
-
model.errors.expects(:add).with(attribute, type, options)
|
59
|
-
yield
|
60
|
-
model.valid?
|
61
|
-
end
|
62
|
-
|
63
|
-
def assert_message_translations(model, attribute, type, &block)
|
64
|
-
assert_default_message_translation(model, attribute, type, &block)
|
65
|
-
reset_callbacks(model.class)
|
66
|
-
model.errors.clear
|
67
|
-
assert_custom_message_translation(model, attribute, type, &block)
|
68
|
-
end
|
69
|
-
|
70
|
-
def assert_custom_message_translation(model, attribute, type)
|
71
|
-
store_translations(:errors => { :models => { model.class.name.underscore => { :attributes => { attribute => { type => 'custom message' } } } } })
|
72
|
-
yield
|
73
|
-
model.valid?
|
74
|
-
assert_equal 'custom message', model.errors.on(attribute)
|
75
|
-
end
|
76
|
-
|
77
|
-
def assert_default_message_translation(model, attribute, type)
|
78
|
-
store_translations(:errors => { :messages => { type => 'default message' } })
|
79
|
-
yield
|
80
|
-
model.valid?
|
81
|
-
assert_equal 'default message', model.errors.on(attribute)
|
82
|
-
end
|
83
|
-
|
84
|
-
def unique_topic
|
85
|
-
@unique ||= Topic.create(:title => 'unique!')
|
86
|
-
end
|
87
|
-
|
88
|
-
def replied_topic
|
89
|
-
@replied_topic ||= begin
|
90
|
-
topic = Topic.create(:title => "topic")
|
91
|
-
topic.replies << Reply.new
|
92
|
-
topic
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# validates_confirmation_of
|
97
|
-
|
98
|
-
test "#validates_confirmation_of given no custom message" do
|
99
|
-
expect_error_added(@topic, :title, :confirmation, :default => nil) do
|
100
|
-
Topic.validates_confirmation_of :title
|
101
|
-
@topic.title = 'title'
|
102
|
-
@topic.title_confirmation = 'foo'
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
test "#validates_confirmation_of given a custom message" do
|
107
|
-
expect_error_added(@topic, :title, :confirmation, :default => 'custom') do
|
108
|
-
Topic.validates_confirmation_of :title, :message => 'custom'
|
109
|
-
@topic.title_confirmation = 'foo'
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
test "#validates_confirmation_of finds the correct message translations" do
|
114
|
-
assert_message_translations(@topic, :title, :confirmation) do
|
115
|
-
Topic.validates_confirmation_of :title
|
116
|
-
@topic.title_confirmation = 'foo'
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# validates_acceptance_of
|
121
|
-
|
122
|
-
test "#validates_acceptance_of given no custom message" do
|
123
|
-
expect_error_added(@topic, :title, :accepted, :default => nil) do
|
124
|
-
Topic.validates_acceptance_of :title, :allow_nil => false
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
test "#validates_acceptance_of given a custom message" do
|
129
|
-
expect_error_added(@topic, :title, :accepted, :default => 'custom') do
|
130
|
-
Topic.validates_acceptance_of :title, :message => 'custom', :allow_nil => false
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
test "#validates_acceptance_of finds the correct message translations" do
|
135
|
-
assert_message_translations(@topic, :title, :accepted) do
|
136
|
-
Topic.validates_acceptance_of :title, :allow_nil => false
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# validates_presence_of
|
141
|
-
|
142
|
-
test "#validates_presence_of given no custom message" do
|
143
|
-
expect_error_added(@topic, :title, :blank, :default => nil) do
|
144
|
-
Topic.validates_presence_of :title
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
test "#validates_presence_of given a custom message" do
|
149
|
-
expect_error_added(@topic, :title, :blank, :default => 'custom') do
|
150
|
-
Topic.validates_presence_of :title, :message => 'custom'
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
test "#validates_presence_of finds the correct message translations" do
|
155
|
-
assert_message_translations(@topic, :title, :blank) do
|
156
|
-
Topic.validates_presence_of :title
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# validates_length_of :too_short
|
161
|
-
|
162
|
-
test "#validates_length_of (:too_short) and no custom message" do
|
163
|
-
expect_error_added(@topic, :title, :too_short, :default => nil, :count => 3) do
|
164
|
-
Topic.validates_length_of :title, :within => 3..5
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
test "#validates_length_of (:too_short) and a custom message" do
|
169
|
-
expect_error_added(@topic, :title, :too_short, :default => 'custom', :count => 3) do
|
170
|
-
Topic.validates_length_of :title, :within => 3..5, :too_short => 'custom'
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
test "#validates_length_of (:too_short) finds the correct message translations" do
|
175
|
-
assert_message_translations(@topic, :title, :too_short) do
|
176
|
-
Topic.validates_length_of :title, :within => 3..5
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# validates_length_of :too_long
|
181
|
-
|
182
|
-
test "#validates_length_of (:too_long) and no custom message" do
|
183
|
-
expect_error_added(@topic, :title, :too_long, :default => nil, :count => 5) do
|
184
|
-
Topic.validates_length_of :title, :within => 3..5
|
185
|
-
@topic.title = 'this title is too long'
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
test "#validates_length_of (:too_long) and a custom message" do
|
190
|
-
expect_error_added(@topic, :title, :too_long, :default => 'custom', :count => 5) do
|
191
|
-
Topic.validates_length_of :title, :within => 3..5, :too_long => 'custom'
|
192
|
-
@topic.title = 'this title is too long'
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
test "#validates_length_of (:too_long) finds the correct message translations" do
|
197
|
-
assert_message_translations(@topic, :title, :too_long) do
|
198
|
-
Topic.validates_length_of :title, :within => 3..5
|
199
|
-
@topic.title = 'this title is too long'
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
# validates_length_of :is
|
204
|
-
|
205
|
-
test "#validates_length_of (:is) and no custom message" do
|
206
|
-
expect_error_added(@topic, :title, :wrong_length, :default => nil, :count => 5) do
|
207
|
-
Topic.validates_length_of :title, :is => 5
|
208
|
-
@topic.title = 'this title has the wrong length'
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
test "#validates_length_of (:is) and a custom message" do
|
213
|
-
expect_error_added(@topic, :title, :wrong_length, :default => 'custom', :count => 5) do
|
214
|
-
Topic.validates_length_of :title, :is => 5, :wrong_length => 'custom'
|
215
|
-
@topic.title = 'this title has the wrong length'
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
test "#validates_length_of (:is) finds the correct message translations" do
|
220
|
-
assert_message_translations(@topic, :title, :wrong_length) do
|
221
|
-
Topic.validates_length_of :title, :is => 5
|
222
|
-
@topic.title = 'this title has the wrong length'
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
# validates_uniqueness_of
|
227
|
-
|
228
|
-
test "#validates_uniqueness_of and no custom message" do
|
229
|
-
expect_error_added(@topic, :title, :taken, :default => nil, :value => 'unique!') do
|
230
|
-
Topic.validates_uniqueness_of :title
|
231
|
-
@topic.title = unique_topic.title
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
test "#validates_uniqueness_of and a custom message" do
|
236
|
-
expect_error_added(@topic, :title, :taken, :default => 'custom', :value => 'unique!') do
|
237
|
-
Topic.validates_uniqueness_of :title, :message => 'custom'
|
238
|
-
@topic.title = unique_topic.title
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
test "#validates_uniqueness_of finds the correct message translations" do
|
243
|
-
assert_message_translations(@topic, :title, :taken) do
|
244
|
-
Topic.validates_uniqueness_of :title
|
245
|
-
@topic.title = unique_topic.title
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
# validates_format_of
|
250
|
-
|
251
|
-
test "#validates_format_of and no custom message" do
|
252
|
-
expect_error_added(@topic, :title, :invalid, :default => nil, :value => '72x') do
|
253
|
-
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
|
254
|
-
@topic.title = '72x'
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
test "#validates_format_of and a custom message" do
|
259
|
-
expect_error_added(@topic, :title, :invalid, :default => 'custom', :value => '72x') do
|
260
|
-
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/, :message => 'custom'
|
261
|
-
@topic.title = '72x'
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
test "#validates_format_of finds the correct message translations" do
|
266
|
-
assert_message_translations(@topic, :title, :invalid) do
|
267
|
-
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
|
268
|
-
@topic.title = '72x'
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
# validates_inclusion_of
|
273
|
-
|
274
|
-
test "#validates_inclusion_of and no custom message" do
|
275
|
-
list = %w(a b c)
|
276
|
-
expect_error_added(@topic, :title, :inclusion, :default => nil, :value => 'z') do
|
277
|
-
Topic.validates_inclusion_of :title, :in => list
|
278
|
-
@topic.title = 'z'
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
test "#validates_inclusion_of and a custom message" do
|
283
|
-
list = %w(a b c)
|
284
|
-
expect_error_added(@topic, :title, :inclusion, :default => 'custom', :value => 'z') do
|
285
|
-
Topic.validates_inclusion_of :title, :in => list, :message => 'custom'
|
286
|
-
@topic.title = 'z'
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
test "#validates_inclusion_of finds the correct message translations" do
|
291
|
-
list = %w(a b c)
|
292
|
-
assert_message_translations(@topic, :title, :inclusion) do
|
293
|
-
Topic.validates_inclusion_of :title, :in => list
|
294
|
-
@topic.title = 'z'
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
# validates_exclusion_of
|
299
|
-
|
300
|
-
test "#validates_exclusion_of and no custom message" do
|
301
|
-
list = %w(a b c)
|
302
|
-
expect_error_added(@topic, :title, :exclusion, :default => nil, :value => 'a') do
|
303
|
-
Topic.validates_exclusion_of :title, :in => list
|
304
|
-
@topic.title = 'a'
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
test "#validates_exclusion_of and a custom message" do
|
309
|
-
list = %w(a b c)
|
310
|
-
expect_error_added(@topic, :title, :exclusion, :default => 'custom', :value => 'a') do
|
311
|
-
Topic.validates_exclusion_of :title, :in => list, :message => 'custom'
|
312
|
-
@topic.title = 'a'
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
test "#validates_exclusion_of finds the correct message translations" do
|
317
|
-
list = %w(a b c)
|
318
|
-
assert_message_translations(@topic, :title, :exclusion) do
|
319
|
-
Topic.validates_exclusion_of :title, :in => list
|
320
|
-
@topic.title = 'a'
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
# validates_numericality_of :not_a_number, without :only_integer
|
325
|
-
|
326
|
-
test "#validates_numericality_of (:not_a_number, w/o :only_integer) no custom message" do
|
327
|
-
expect_error_added(@topic, :title, :not_a_number, :default => nil, :value => 'a') do
|
328
|
-
Topic.validates_numericality_of :title
|
329
|
-
@topic.title = 'a'
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
test "#validates_numericality_of (:not_a_number, w/o :only_integer) and a custom message" do
|
334
|
-
expect_error_added(@topic, :title, :not_a_number, :default => 'custom', :value => 'a') do
|
335
|
-
Topic.validates_numericality_of :title, :message => 'custom'
|
336
|
-
@topic.title = 'a'
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
test "#validates_numericality_of (:not_a_number, w/o :only_integer) finds the correct message translations" do
|
341
|
-
assert_message_translations(@topic, :title, :not_a_number) do
|
342
|
-
Topic.validates_numericality_of :title
|
343
|
-
@topic.title = 'a'
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
# validates_numericality_of :not_a_number, with :only_integer
|
348
|
-
|
349
|
-
test "#validates_numericality_of (:not_a_number, with :only_integer) no custom message" do
|
350
|
-
expect_error_added(@topic, :title, :not_a_number, :default => nil, :value => 'a') do
|
351
|
-
Topic.validates_numericality_of :title, :only_integer => true
|
352
|
-
@topic.title = 'a'
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
test "#validates_numericality_of (:not_a_number, with :only_integer) and a custom message" do
|
357
|
-
expect_error_added(@topic, :title, :not_a_number, :default => 'custom', :value => 'a') do
|
358
|
-
Topic.validates_numericality_of :title, :only_integer => true, :message => 'custom'
|
359
|
-
@topic.title = 'a'
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
test "#validates_numericality_of (:not_a_number, with :only_integer) finds the correct message translations" do
|
364
|
-
assert_message_translations(@topic, :title, :not_a_number) do
|
365
|
-
Topic.validates_numericality_of :title, :only_integer => true
|
366
|
-
@topic.title = 'a'
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
# validates_numericality_of :odd
|
371
|
-
|
372
|
-
test "#validates_numericality_of (:odd) no custom message" do
|
373
|
-
expect_error_added(@topic, :title, :odd, :default => nil, :value => 0) do
|
374
|
-
Topic.validates_numericality_of :title, :only_integer => true, :odd => true
|
375
|
-
@topic.title = 0
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
test "#validates_numericality_of (:odd) and a custom message" do
|
380
|
-
expect_error_added(@topic, :title, :odd, :default => 'custom', :value => 0) do
|
381
|
-
Topic.validates_numericality_of :title, :only_integer => true, :odd => true, :message => 'custom'
|
382
|
-
@topic.title = 0
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
test "#validates_numericality_of (:odd) finds the correct message translations" do
|
387
|
-
assert_message_translations(@topic, :title, :odd) do
|
388
|
-
Topic.validates_numericality_of :title, :only_integer => true, :odd => true
|
389
|
-
@topic.title = 0
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
# validates_numericality_of :even
|
394
|
-
|
395
|
-
test "#validates_numericality_of (:even) no custom message" do
|
396
|
-
expect_error_added(@topic, :title, :even, :default => nil, :value => 1) do
|
397
|
-
Topic.validates_numericality_of :title, :only_integer => true, :even => true
|
398
|
-
@topic.title = 1
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
test "#validates_numericality_of (:even) and a custom message" do
|
403
|
-
expect_error_added(@topic, :title, :even, :default => 'custom', :value => 1) do
|
404
|
-
Topic.validates_numericality_of :title, :only_integer => true, :even => true, :message => 'custom'
|
405
|
-
@topic.title = 1
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
|
-
test "#validates_numericality_of (:even) finds the correct message translations" do
|
410
|
-
assert_message_translations(@topic, :title, :even) do
|
411
|
-
Topic.validates_numericality_of :title, :only_integer => true, :even => true
|
412
|
-
@topic.title = 1
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
# validates_numericality_of :less_than
|
417
|
-
|
418
|
-
test "#validates_numericality_of (:less_than) no custom message" do
|
419
|
-
expect_error_added(@topic, :title, :less_than, :default => nil, :value => 1, :count => 0) do
|
420
|
-
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
|
421
|
-
@topic.title = 1
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
test "#validates_numericality_of (:less_than) and a custom message" do
|
426
|
-
expect_error_added(@topic, :title, :less_than, :default => 'custom', :value => 1, :count => 0) do
|
427
|
-
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0, :message => 'custom'
|
428
|
-
@topic.title = 1
|
429
|
-
end
|
430
|
-
end
|
431
|
-
|
432
|
-
test "#validates_numericality_of (:less_than) finds the correct message translations" do
|
433
|
-
assert_message_translations(@topic, :title, :less_than) do
|
434
|
-
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
|
435
|
-
@topic.title = 1
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
# validates_associated
|
440
|
-
|
441
|
-
test "#validates_associated no custom message" do
|
442
|
-
expect_error_added(replied_topic, :replies, :invalid, :default => nil, :value => replied_topic.replies) do
|
443
|
-
Topic.validates_associated :replies
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
test "#validates_associated and a custom message" do
|
448
|
-
expect_error_added(replied_topic, :replies, :invalid, :default => 'custom', :value => replied_topic.replies) do
|
449
|
-
Topic.validates_associated :replies, :message => 'custom'
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
test "#validates_associated finds the correct message translations" do
|
454
|
-
assert_message_translations(replied_topic, :replies, :invalid) do
|
455
|
-
Topic.validates_associated :replies
|
456
|
-
end
|
457
|
-
end
|
458
|
-
end
|
459
|
-
|
460
|
-
|
461
|
-
# ACTIVERECORD ERROR
|
462
|
-
#
|
463
|
-
# * test that it passes given interpolation arguments, the human model name and human attribute name
|
464
|
-
# * test that it looks messages up with the the correct keys
|
465
|
-
# * test that it looks up the correct default messages
|
466
|
-
|
467
|
-
class ActiveRecordErrorI18nTests < ActiveSupport::TestCase
|
468
|
-
include ActiveRecordValidationsI18nTestHelper
|
469
|
-
|
470
|
-
def setup
|
471
|
-
@reply = Reply.new
|
472
|
-
@old_backend, I18n.backend = I18n.backend, I18n::Backend::Simple.new
|
473
|
-
end
|
474
|
-
|
475
|
-
def teardown
|
476
|
-
I18n.backend = @old_backend
|
477
|
-
I18n.locale = nil
|
478
|
-
end
|
479
|
-
|
480
|
-
def assert_error_message(message, *args)
|
481
|
-
assert_equal message, ActiveRecord::Error.new(@reply, *args).message
|
482
|
-
end
|
483
|
-
|
484
|
-
def assert_full_message(message, *args)
|
485
|
-
assert_equal message, ActiveRecord::Error.new(@reply, *args).full_message
|
486
|
-
end
|
487
|
-
|
488
|
-
test ":default is only given to message if a symbol is supplied" do
|
489
|
-
store_translations(:errors => { :messages => { :"foo bar" => "You fooed: %{value}." } })
|
490
|
-
@reply.errors.add(:title, :inexistent, :default => "foo bar")
|
491
|
-
assert_equal "foo bar", @reply.errors[:title]
|
492
|
-
end
|
493
|
-
|
494
|
-
test "#generate_message passes the model attribute value for interpolation" do
|
495
|
-
store_translations(:errors => { :messages => { :foo => "You fooed: %{value}." } })
|
496
|
-
@reply.title = "da title"
|
497
|
-
assert_error_message 'You fooed: da title.', :title, :foo
|
498
|
-
end
|
499
|
-
|
500
|
-
test "#generate_message passes the human_name of the model for interpolation" do
|
501
|
-
store_translations(
|
502
|
-
:errors => { :messages => { :foo => "You fooed: %{model}." } },
|
503
|
-
:models => { :topic => 'da topic' }
|
504
|
-
)
|
505
|
-
assert_error_message 'You fooed: da topic.', :title, :foo
|
506
|
-
end
|
507
|
-
|
508
|
-
test "#generate_message passes the human_name of the attribute for interpolation" do
|
509
|
-
store_translations(
|
510
|
-
:errors => { :messages => { :foo => "You fooed: %{attribute}." } },
|
511
|
-
:attributes => { :topic => { :title => 'da topic title' } }
|
512
|
-
)
|
513
|
-
assert_error_message 'You fooed: da topic title.', :title, :foo
|
514
|
-
end
|
515
|
-
|
516
|
-
# generate_message will look up the key for the error message (e.g. :blank) in these namespaces:
|
517
|
-
#
|
518
|
-
# activerecord.errors.models.reply.attributes.title
|
519
|
-
# activerecord.errors.models.reply
|
520
|
-
# activerecord.errors.models.topic.attributes.title
|
521
|
-
# activerecord.errors.models.topic
|
522
|
-
# [default from class level :validates_foo statement if this is a String]
|
523
|
-
# activerecord.errors.messages
|
524
|
-
|
525
|
-
test "#generate_message key fallbacks (given a String as key)" do
|
526
|
-
store_translations(
|
527
|
-
:errors => {
|
528
|
-
:models => {
|
529
|
-
:reply => {
|
530
|
-
:attributes => { :title => { :custom => 'activerecord.errors.models.reply.attributes.title.custom' } },
|
531
|
-
:custom => 'activerecord.errors.models.reply.custom'
|
532
|
-
},
|
533
|
-
:topic => {
|
534
|
-
:attributes => { :title => { :custom => 'activerecord.errors.models.topic.attributes.title.custom' } },
|
535
|
-
:custom => 'activerecord.errors.models.topic.custom'
|
536
|
-
}
|
537
|
-
},
|
538
|
-
:messages => {
|
539
|
-
:custom => 'activerecord.errors.messages.custom',
|
540
|
-
:kaputt => 'activerecord.errors.messages.kaputt'
|
541
|
-
}
|
542
|
-
}
|
543
|
-
)
|
544
|
-
|
545
|
-
assert_error_message 'activerecord.errors.models.reply.attributes.title.custom', :title, :kaputt, :message => 'custom'
|
546
|
-
delete_translation :'activerecord.errors.models.reply.attributes.title.custom'
|
547
|
-
|
548
|
-
assert_error_message 'activerecord.errors.models.reply.custom', :title, :kaputt, :message => 'custom'
|
549
|
-
delete_translation :'activerecord.errors.models.reply.custom'
|
550
|
-
|
551
|
-
assert_error_message 'activerecord.errors.models.topic.attributes.title.custom', :title, :kaputt, :message => 'custom'
|
552
|
-
delete_translation :'activerecord.errors.models.topic.attributes.title.custom'
|
553
|
-
|
554
|
-
assert_error_message 'activerecord.errors.models.topic.custom', :title, :kaputt, :message => 'custom'
|
555
|
-
delete_translation :'activerecord.errors.models.topic.custom'
|
556
|
-
|
557
|
-
assert_error_message 'activerecord.errors.messages.custom', :title, :kaputt, :message => 'custom'
|
558
|
-
delete_translation :'activerecord.errors.messages.custom'
|
559
|
-
|
560
|
-
# Implementing this would clash with the AR default behaviour of using validates_foo :message => 'foo'
|
561
|
-
# as an untranslated string. I.e. at this point we can either fall back to the given string from the
|
562
|
-
# class-level macro (validates_*) or fall back to the default message for this validation type.
|
563
|
-
# assert_error_message 'activerecord.errors.messages.kaputt', :title, :kaputt, :message => 'custom'
|
564
|
-
|
565
|
-
assert_error_message 'custom', :title, :kaputt, :message => 'custom'
|
566
|
-
end
|
567
|
-
|
568
|
-
test "#generate_message key fallbacks (given a Symbol as key)" do
|
569
|
-
store_translations(
|
570
|
-
:errors => {
|
571
|
-
:models => {
|
572
|
-
:reply => {
|
573
|
-
:attributes => { :title => { :kaputt => 'activerecord.errors.models.reply.attributes.title.kaputt' } },
|
574
|
-
:kaputt => 'activerecord.errors.models.reply.kaputt'
|
575
|
-
},
|
576
|
-
:topic => {
|
577
|
-
:attributes => { :title => { :kaputt => 'activerecord.errors.models.topic.attributes.title.kaputt' } },
|
578
|
-
:kaputt => 'activerecord.errors.models.topic.kaputt'
|
579
|
-
}
|
580
|
-
},
|
581
|
-
:messages => {
|
582
|
-
:kaputt => 'activerecord.errors.messages.kaputt'
|
583
|
-
}
|
584
|
-
}
|
585
|
-
)
|
586
|
-
|
587
|
-
assert_error_message 'activerecord.errors.models.reply.attributes.title.kaputt', :title, :kaputt
|
588
|
-
delete_translation :'activerecord.errors.models.reply.attributes.title.kaputt'
|
589
|
-
|
590
|
-
assert_error_message 'activerecord.errors.models.reply.kaputt', :title, :kaputt
|
591
|
-
delete_translation :'activerecord.errors.models.reply.kaputt'
|
592
|
-
|
593
|
-
assert_error_message 'activerecord.errors.models.topic.attributes.title.kaputt', :title, :kaputt
|
594
|
-
delete_translation :'activerecord.errors.models.topic.attributes.title.kaputt'
|
595
|
-
|
596
|
-
assert_error_message 'activerecord.errors.models.topic.kaputt', :title, :kaputt
|
597
|
-
delete_translation :'activerecord.errors.models.topic.kaputt'
|
598
|
-
|
599
|
-
assert_error_message 'activerecord.errors.messages.kaputt', :title, :kaputt
|
600
|
-
end
|
601
|
-
|
602
|
-
# full_messages
|
603
|
-
|
604
|
-
test "#full_message with no format present" do
|
605
|
-
store_translations(:errors => { :messages => { :kaputt => 'is kaputt' } })
|
606
|
-
assert_full_message 'Title is kaputt', :title, :kaputt
|
607
|
-
end
|
608
|
-
|
609
|
-
test "#full_message with a format present" do
|
610
|
-
store_translations(:errors => { :messages => { :kaputt => 'is kaputt' }, :full_messages => { :format => '%{attribute}: %{message}' } })
|
611
|
-
assert_full_message 'Title: is kaputt', :title, :kaputt
|
612
|
-
end
|
613
|
-
|
614
|
-
test "#full_message with a type specific format present" do
|
615
|
-
store_translations(:errors => { :messages => { :kaputt => 'is kaputt' }, :full_messages => { :kaputt => '%{attribute} %{message}!' } })
|
616
|
-
assert_full_message 'Title is kaputt!', :title, :kaputt
|
617
|
-
end
|
618
|
-
|
619
|
-
test "#full_message with class-level specified custom message" do
|
620
|
-
store_translations(:errors => { :messages => { :broken => 'is kaputt' }, :full_messages => { :broken => '%{attribute} %{message}?!' } })
|
621
|
-
assert_full_message 'Title is kaputt?!', :title, :kaputt, :message => :broken
|
622
|
-
end
|
623
|
-
|
624
|
-
test "#full_message with different scope" do
|
625
|
-
store_translations(:my_errors => { :messages => { :kaputt => 'is kaputt' } })
|
626
|
-
assert_full_message 'Title is kaputt', :title, :kaputt, :scope => [:activerecord, :my_errors]
|
627
|
-
|
628
|
-
store_translations(:my_errors => { :full_messages => { :kaputt => '%{attribute} %{message}!' } })
|
629
|
-
assert_full_message 'Title is kaputt!', :title, :kaputt, :scope => [:activerecord, :my_errors]
|
630
|
-
end
|
631
|
-
|
632
|
-
# switch locales
|
633
|
-
|
634
|
-
test "#message allows to switch locales" do
|
635
|
-
store_translations(:en, :errors => { :messages => { :kaputt => 'is kaputt' } })
|
636
|
-
store_translations(:de, :errors => { :messages => { :kaputt => 'ist kaputt' } })
|
637
|
-
|
638
|
-
assert_error_message 'is kaputt', :title, :kaputt
|
639
|
-
I18n.locale = :de
|
640
|
-
assert_error_message 'ist kaputt', :title, :kaputt
|
641
|
-
I18n.locale = :en
|
642
|
-
assert_error_message 'is kaputt', :title, :kaputt
|
643
|
-
end
|
644
|
-
|
645
|
-
test "#full_message allows to switch locales" do
|
646
|
-
store_translations(:en, :errors => { :messages => { :kaputt => 'is kaputt' } }, :attributes => { :topic => { :title => 'The title' } })
|
647
|
-
store_translations(:de, :errors => { :messages => { :kaputt => 'ist kaputt' } }, :attributes => { :topic => { :title => 'Der Titel' } })
|
648
|
-
|
649
|
-
assert_full_message 'The title is kaputt', :title, :kaputt
|
650
|
-
I18n.locale = :de
|
651
|
-
assert_full_message 'Der Titel ist kaputt', :title, :kaputt
|
652
|
-
I18n.locale = :en
|
653
|
-
assert_full_message 'The title is kaputt', :title, :kaputt
|
654
|
-
end
|
655
|
-
end
|
656
|
-
|
657
|
-
# ACTIVERECORD DEFAULT ERROR MESSAGES
|
658
|
-
#
|
659
|
-
# * test that Error generates the default error messages
|
660
|
-
|
661
|
-
class ActiveRecordDefaultErrorMessagesI18nTests < ActiveSupport::TestCase
|
662
|
-
def assert_default_error_message(message, *args)
|
663
|
-
assert_equal message, error_message(*args)
|
664
|
-
end
|
665
|
-
|
666
|
-
def error_message(*args)
|
667
|
-
ActiveRecord::Error.new(Topic.new, :title, *args).message
|
668
|
-
end
|
669
|
-
|
670
|
-
# used by: validates_inclusion_of
|
671
|
-
test "default error message: inclusion" do
|
672
|
-
assert_default_error_message 'is not included in the list', :inclusion, :value => 'title'
|
673
|
-
end
|
674
|
-
|
675
|
-
# used by: validates_exclusion_of
|
676
|
-
test "default error message: exclusion" do
|
677
|
-
assert_default_error_message 'is reserved', :exclusion, :value => 'title'
|
678
|
-
end
|
679
|
-
|
680
|
-
# used by: validates_associated and validates_format_of
|
681
|
-
test "default error message: invalid" do
|
682
|
-
assert_default_error_message 'is invalid', :invalid, :value => 'title'
|
683
|
-
end
|
684
|
-
|
685
|
-
# used by: validates_confirmation_of
|
686
|
-
test "default error message: confirmation" do
|
687
|
-
assert_default_error_message "doesn't match confirmation", :confirmation, :default => nil
|
688
|
-
end
|
689
|
-
|
690
|
-
# used by: validates_acceptance_of
|
691
|
-
test "default error message: accepted" do
|
692
|
-
assert_default_error_message "must be accepted", :accepted
|
693
|
-
end
|
694
|
-
|
695
|
-
# used by: add_on_empty
|
696
|
-
test "default error message: empty" do
|
697
|
-
assert_default_error_message "can't be empty", :empty
|
698
|
-
end
|
699
|
-
|
700
|
-
# used by: add_on_blank
|
701
|
-
test "default error message: blank" do
|
702
|
-
assert_default_error_message "can't be blank", :blank
|
703
|
-
end
|
704
|
-
|
705
|
-
# used by: validates_length_of
|
706
|
-
test "default error message: too_long" do
|
707
|
-
assert_default_error_message "is too long (maximum is 10 characters)", :too_long, :count => 10
|
708
|
-
end
|
709
|
-
|
710
|
-
# used by: validates_length_of
|
711
|
-
test "default error message: too_short" do
|
712
|
-
assert_default_error_message "is too short (minimum is 10 characters)", :too_short, :count => 10
|
713
|
-
end
|
714
|
-
|
715
|
-
# used by: validates_length_of
|
716
|
-
test "default error message: wrong_length" do
|
717
|
-
assert_default_error_message "is the wrong length (should be 10 characters)", :wrong_length, :count => 10
|
718
|
-
end
|
719
|
-
|
720
|
-
# used by: validates_uniqueness_of
|
721
|
-
test "default error message: taken" do
|
722
|
-
assert_default_error_message "has already been taken", :taken, :value => 'title'
|
723
|
-
end
|
724
|
-
|
725
|
-
# used by: validates_numericality_of
|
726
|
-
test "default error message: not_a_number" do
|
727
|
-
assert_default_error_message "is not a number", :not_a_number, :value => 'title'
|
728
|
-
end
|
729
|
-
|
730
|
-
# used by: validates_numericality_of
|
731
|
-
test "default error message: greater_than" do
|
732
|
-
assert_default_error_message "must be greater than 10", :greater_than, :value => 'title', :count => 10
|
733
|
-
end
|
734
|
-
|
735
|
-
# used by: validates_numericality_of
|
736
|
-
test "default error message: greater_than_or_equal_to" do
|
737
|
-
assert_default_error_message "must be greater than or equal to 10", :greater_than_or_equal_to, :value => 'title', :count => 10
|
738
|
-
end
|
739
|
-
|
740
|
-
# used by: validates_numericality_of
|
741
|
-
test "default error message: equal_to" do
|
742
|
-
assert_default_error_message "must be equal to 10", :equal_to, :value => 'title', :count => 10
|
743
|
-
end
|
744
|
-
|
745
|
-
# used by: validates_numericality_of
|
746
|
-
test "default error message: less_than" do
|
747
|
-
assert_default_error_message "must be less than 10", :less_than, :value => 'title', :count => 10
|
748
|
-
end
|
749
|
-
|
750
|
-
# used by: validates_numericality_of
|
751
|
-
test "default error message: less_than_or_equal_to" do
|
752
|
-
assert_default_error_message "must be less than or equal to 10", :less_than_or_equal_to, :value => 'title', :count => 10
|
753
|
-
end
|
754
|
-
|
755
|
-
# used by: validates_numericality_of
|
756
|
-
test "default error message: odd" do
|
757
|
-
assert_default_error_message "must be odd", :odd, :value => 'title', :count => 10
|
758
|
-
end
|
759
|
-
|
760
|
-
# used by: validates_numericality_of
|
761
|
-
test "default error message: even" do
|
762
|
-
assert_default_error_message "must be even", :even, :value => 'title', :count => 10
|
763
|
-
end
|
764
|
-
|
765
|
-
test "custom message string interpolation" do
|
766
|
-
assert_equal 'custom message title', error_message(:invalid, :default => 'custom message %{value}', :value => 'title')
|
767
|
-
end
|
768
|
-
end
|
769
|
-
|
770
|
-
# ACTIVERECORD VALIDATION ERROR MESSAGES - FULL STACK
|
771
|
-
#
|
772
|
-
# * test a few combinations full stack to ensure the tests above are correct
|
773
|
-
|
774
|
-
class I18nPerson < Person
|
775
|
-
end
|
776
|
-
|
777
|
-
class ActiveRecordValidationsI18nFullStackTests < ActiveSupport::TestCase
|
778
|
-
include ActiveRecordValidationsI18nTestHelper
|
779
|
-
|
780
|
-
def setup
|
781
|
-
reset_callbacks(I18nPerson)
|
782
|
-
@old_backend, I18n.backend = I18n.backend, I18n::Backend::Simple.new
|
783
|
-
@person = I18nPerson.new
|
784
|
-
end
|
785
|
-
|
786
|
-
def teardown
|
787
|
-
reset_callbacks(I18nPerson)
|
788
|
-
I18n.backend = @old_backend
|
789
|
-
end
|
790
|
-
|
791
|
-
def assert_name_invalid(message)
|
792
|
-
yield
|
793
|
-
@person.valid?
|
794
|
-
assert_equal message, @person.errors.on(:name)
|
795
|
-
end
|
796
|
-
|
797
|
-
# Symbols as class-level validation messages
|
798
|
-
|
799
|
-
test "Symbol as class level validation message translated per attribute (translation on child class)" do
|
800
|
-
assert_name_invalid("is broken") do
|
801
|
-
store_translations :errors => {:models => {:i18n_person => {:attributes => {:name => {:broken => "is broken"}}}}}
|
802
|
-
I18nPerson.validates_presence_of :name, :message => :broken
|
803
|
-
end
|
804
|
-
end
|
805
|
-
|
806
|
-
test "Symbol as class level validation message translated per attribute (translation on base class)" do
|
807
|
-
assert_name_invalid("is broken") do
|
808
|
-
store_translations :errors => {:models => {:person => {:attributes => {:name => {:broken => "is broken"}}}}}
|
809
|
-
I18nPerson.validates_presence_of :name, :message => :broken
|
810
|
-
end
|
811
|
-
end
|
812
|
-
|
813
|
-
test "Symbol as class level validation message translated per model (translation on child class)" do
|
814
|
-
assert_name_invalid("is broken") do
|
815
|
-
store_translations :errors => {:models => {:i18n_person => {:broken => "is broken"}}}
|
816
|
-
I18nPerson.validates_presence_of :name, :message => :broken
|
817
|
-
end
|
818
|
-
end
|
819
|
-
|
820
|
-
test "Symbol as class level validation message translated per model (translation on base class)" do
|
821
|
-
assert_name_invalid("is broken") do
|
822
|
-
store_translations :errors => {:models => {:person => {:broken => "is broken"}}}
|
823
|
-
I18nPerson.validates_presence_of :name, :message => :broken
|
824
|
-
end
|
825
|
-
end
|
826
|
-
|
827
|
-
test "Symbol as class level validation message translated as error message" do
|
828
|
-
assert_name_invalid("is broken") do
|
829
|
-
store_translations :errors => {:messages => {:broken => "is broken"}}
|
830
|
-
I18nPerson.validates_presence_of :name, :message => :broken
|
831
|
-
end
|
832
|
-
end
|
833
|
-
|
834
|
-
# Strings as class-level validation messages
|
835
|
-
|
836
|
-
test "String as class level validation message translated per attribute (translation on child class)" do
|
837
|
-
assert_name_invalid("is broken") do
|
838
|
-
store_translations :errors => {:models => {:i18n_person => {:attributes => {:name => {"is broken" => "is broken"}}}}}
|
839
|
-
I18nPerson.validates_presence_of :name, :message => "is broken"
|
840
|
-
end
|
841
|
-
end
|
842
|
-
|
843
|
-
test "String as class level validation message translated per attribute (translation on base class)" do
|
844
|
-
assert_name_invalid("is broken") do
|
845
|
-
store_translations :errors => {:models => {:person => {:attributes => {:name => {"is broken" => "is broken"}}}}}
|
846
|
-
I18nPerson.validates_presence_of :name, :message => "is broken"
|
847
|
-
end
|
848
|
-
end
|
849
|
-
|
850
|
-
test "String as class level validation message translated per model (translation on child class)" do
|
851
|
-
assert_name_invalid("is broken") do
|
852
|
-
store_translations :errors => {:models => {:i18n_person => {"is broken" => "is broken"}}}
|
853
|
-
I18nPerson.validates_presence_of :name, :message => "is broken"
|
854
|
-
end
|
855
|
-
end
|
856
|
-
|
857
|
-
test "String as class level validation message translated per model (translation on base class)" do
|
858
|
-
assert_name_invalid("is broken") do
|
859
|
-
store_translations :errors => {:models => {:person => {"is broken" => "is broken"}}}
|
860
|
-
I18nPerson.validates_presence_of :name, :message => "is broken"
|
861
|
-
end
|
862
|
-
end
|
863
|
-
|
864
|
-
test "String as class level validation message translated as error message" do
|
865
|
-
assert_name_invalid("is broken") do
|
866
|
-
store_translations :errors => {:messages => {"is broken" => "is broken"}}
|
867
|
-
I18nPerson.validates_presence_of :name, :message => "is broken"
|
868
|
-
end
|
869
|
-
end
|
870
|
-
|
871
|
-
test "String as class level validation message not translated (uses message as default)" do
|
872
|
-
assert_name_invalid("is broken!") do
|
873
|
-
I18nPerson.validates_presence_of :name, :message => "is broken!"
|
874
|
-
end
|
875
|
-
end
|
876
|
-
end
|
877
|
-
|
878
|
-
class ActiveRecordValidationsI18nFullMessagesFullStackTests < ActiveSupport::TestCase
|
879
|
-
include ActiveRecordValidationsI18nTestHelper
|
880
|
-
|
881
|
-
def setup
|
882
|
-
reset_callbacks(I18nPerson)
|
883
|
-
@old_backend, I18n.backend = I18n.backend, I18n::Backend::Simple.new
|
884
|
-
@person = I18nPerson.new
|
885
|
-
end
|
886
|
-
|
887
|
-
def teardown
|
888
|
-
reset_callbacks(I18nPerson)
|
889
|
-
I18n.backend = @old_backend
|
890
|
-
end
|
891
|
-
|
892
|
-
def assert_full_message(message)
|
893
|
-
yield
|
894
|
-
@person.valid?
|
895
|
-
assert_equal message, @person.errors.full_messages.join
|
896
|
-
end
|
897
|
-
|
898
|
-
test "full_message format stored per custom error message key" do
|
899
|
-
assert_full_message("Name is broken!") do
|
900
|
-
store_translations :errors => { :messages => { :broken => 'is broken' }, :full_messages => { :broken => '%{attribute} %{message}!' } }
|
901
|
-
I18nPerson.validates_presence_of :name, :message => :broken
|
902
|
-
end
|
903
|
-
end
|
904
|
-
|
905
|
-
test "full_message format stored per error type" do
|
906
|
-
assert_full_message("Name can't be blank!") do
|
907
|
-
store_translations :errors => { :full_messages => { :blank => '%{attribute} %{message}!' } }
|
908
|
-
I18nPerson.validates_presence_of :name
|
909
|
-
end
|
910
|
-
end
|
911
|
-
# ActiveRecord#RecordInvalid exception
|
912
|
-
|
913
|
-
test "full_message format stored as default" do
|
914
|
-
assert_full_message("Name: can't be blank") do
|
915
|
-
store_translations :errors => { :full_messages => { :format => '%{attribute}: %{message}' } }
|
916
|
-
I18nPerson.validates_presence_of :name
|
917
|
-
end
|
918
|
-
end
|
919
|
-
test "RecordInvalid exception can be localized" do
|
920
|
-
topic = Topic.new
|
921
|
-
topic.errors.add(:title, :invalid)
|
922
|
-
topic.errors.add(:title, :blank)
|
923
|
-
assert_equal "Validation failed: Title is invalid, Title can't be blank", ActiveRecord::RecordInvalid.new(topic).message
|
924
|
-
end
|
925
|
-
end
|