radiant 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of radiant might be problematic. Click here for more details.
- data/CHANGELOG +33 -1
- data/CONTRIBUTORS +15 -2
- data/INSTALL +9 -7
- data/README +11 -7
- data/app/controllers/admin/layouts_controller.rb +5 -2
- data/app/controllers/admin/pages_controller.rb +8 -5
- data/app/controllers/admin/snippets_controller.rb +5 -2
- data/app/controllers/application_controller.rb +7 -0
- data/app/helpers/admin/node_helper.rb +2 -2
- data/app/helpers/application_helper.rb +2 -2
- data/app/models/radiant/config.rb +36 -4
- data/app/models/standard_tags.rb +1 -1
- data/app/views/admin/layouts/index.html.haml +15 -12
- data/app/views/admin/page_parts/_page_part.html.haml +2 -2
- data/app/views/admin/pages/index.html.haml +1 -1
- data/app/views/admin/snippets/_form.html.haml +1 -1
- data/app/views/admin/snippets/index.html.haml +14 -10
- data/config/database.db2.yml +20 -0
- data/config/environment.rb +4 -4
- data/config/environments/test.rb +1 -2
- data/features/support/env.rb +2 -1
- data/lib/generators/extension/extension_generator.rb +5 -0
- data/lib/generators/extension/templates/RSpecRakefile +11 -8
- data/lib/generators/extension/templates/cucumber.yml +1 -0
- data/lib/generators/extension/templates/cucumber_env.rb +16 -0
- data/lib/generators/extension/templates/cucumber_paths.rb +14 -0
- data/lib/generators/extension/templates/extension.rb +1 -1
- data/lib/generators/instance/instance_generator.rb +1 -1
- data/lib/generators/instance/templates/databases/db2.yml +40 -0
- data/lib/generators/instance/templates/instance_environment.rb +6 -6
- data/lib/local_time.rb +3 -9
- data/lib/radiant.rb +1 -1
- data/lib/radiant/cache.rb +10 -8
- data/lib/radiant/extension.rb +36 -0
- data/lib/radiant/extension/script.rb +1 -1
- data/lib/radiant/extension_loader.rb +5 -1
- data/lib/radiant/initializer.rb +52 -4
- data/lib/task_support.rb +33 -0
- data/lib/tasks/cucumber.rake +5 -1
- data/lib/tasks/radiant_config.rake +18 -0
- data/lib/tasks/release.rake +1 -0
- data/public/javascripts/admin/admin.js +1 -1
- data/spec/controllers/admin/layouts_controller_spec.rb +18 -12
- data/spec/controllers/admin/pages_controller_spec.rb +35 -29
- data/spec/controllers/admin/snippets_controller_spec.rb +11 -5
- data/spec/controllers/admin/welcome_controller_spec.rb +1 -1
- data/spec/controllers/application_controller_spec.rb +18 -0
- data/spec/fixtures/radiant_config.yml +10 -0
- data/spec/generators/extension_generator_spec.rb +12 -0
- data/spec/helpers/admin/node_helper_spec.rb +6 -0
- data/spec/helpers/application_helper_spec.rb +1 -1
- data/spec/lib/radiant/extension_loader_spec.rb +17 -0
- data/spec/lib/radiant/extension_spec.rb +28 -0
- data/spec/lib/radiant/initializer_spec.rb +34 -0
- data/spec/lib/task_support_spec.rb +42 -0
- data/spec/models/page_spec.rb +6 -2
- data/spec/models/radiant/config_spec.rb +42 -1
- data/spec/models/standard_tags_spec.rb +2 -2
- data/test/fixtures/extensions/01_basic/app/metal/basic_metal.rb +9 -0
- data/test/fixtures/extensions/02_overriding/app/metal/basic_metal.rb +9 -0
- data/vendor/extensions/textile_filter/textile.html +2 -2
- data/vendor/plugins/dataset/CHANGELOG +2 -1
- data/vendor/plugins/dataset/Rakefile +3 -0
- data/vendor/plugins/dataset/VERSION.yml +2 -2
- data/vendor/plugins/dataset/dataset.gemspec +9 -3
- data/vendor/plugins/dataset/lib/dataset.rb +3 -0
- data/vendor/radius/lib/radius.rb +5 -0
- data/vendor/radius/test/radius_test.rb +6 -0
- data/vendor/rails/actionmailer/CHANGELOG +8 -0
- data/vendor/rails/actionmailer/Rakefile +3 -2
- data/vendor/rails/actionmailer/lib/action_mailer/base.rb +2 -1
- data/vendor/rails/actionmailer/lib/action_mailer/version.rb +1 -1
- data/vendor/rails/actionmailer/test/abstract_unit.rb +0 -3
- data/vendor/rails/actionmailer/test/mail_service_test.rb +3 -2
- data/vendor/rails/actionpack/CHANGELOG +16 -0
- data/vendor/rails/actionpack/Rakefile +5 -3
- data/vendor/rails/actionpack/lib/action_controller.rb +2 -7
- data/vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb +13 -3
- data/vendor/rails/actionpack/lib/action_controller/base.rb +12 -3
- data/vendor/rails/actionpack/lib/action_controller/caching.rb +1 -1
- data/vendor/rails/actionpack/lib/action_controller/caching/actions.rb +9 -1
- data/vendor/rails/actionpack/lib/action_controller/caching/sweeper.rb +45 -0
- data/vendor/rails/actionpack/lib/action_controller/caching/sweeping.rb +0 -42
- data/vendor/rails/actionpack/lib/action_controller/cookies.rb +1 -1
- data/vendor/rails/actionpack/lib/action_controller/dispatcher.rb +21 -6
- data/vendor/rails/actionpack/lib/action_controller/failsafe.rb +40 -6
- data/vendor/rails/actionpack/lib/action_controller/flash.rb +11 -3
- data/vendor/rails/actionpack/lib/action_controller/http_authentication.rb +7 -3
- data/vendor/rails/actionpack/lib/action_controller/integration.rb +5 -12
- data/vendor/rails/actionpack/lib/action_controller/middlewares.rb +0 -1
- data/vendor/rails/actionpack/lib/action_controller/params_parser.rb +6 -0
- data/vendor/rails/actionpack/lib/action_controller/reloader.rb +47 -7
- data/vendor/rails/actionpack/lib/action_controller/request.rb +6 -2
- data/vendor/rails/actionpack/lib/action_controller/request_forgery_protection.rb +2 -1
- data/vendor/rails/actionpack/lib/action_controller/resources.rb +17 -13
- data/vendor/rails/actionpack/lib/action_controller/response.rb +8 -2
- data/vendor/rails/actionpack/lib/action_controller/routing.rb +3 -0
- data/vendor/rails/actionpack/lib/action_controller/routing/route_set.rb +20 -6
- data/vendor/rails/actionpack/lib/action_controller/streaming.rb +4 -2
- data/vendor/rails/actionpack/lib/action_controller/test_process.rb +9 -1
- data/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb +1 -1
- data/vendor/rails/actionpack/lib/action_pack/version.rb +1 -1
- data/vendor/rails/actionpack/lib/action_view/helpers.rb +1 -1
- data/vendor/rails/actionpack/lib/action_view/helpers/asset_tag_helper.rb +21 -9
- data/vendor/rails/actionpack/lib/action_view/helpers/atom_feed_helper.rb +1 -1
- data/vendor/rails/actionpack/lib/action_view/helpers/date_helper.rb +2 -2
- data/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb +26 -12
- data/vendor/rails/actionpack/lib/action_view/helpers/form_options_helper.rb +71 -1
- data/vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb +10 -4
- data/vendor/rails/actionpack/lib/action_view/helpers/number_helper.rb +1 -1
- data/vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb +7 -7
- data/vendor/rails/actionpack/lib/action_view/helpers/scriptaculous_helper.rb +5 -5
- data/vendor/rails/actionpack/lib/action_view/helpers/tag_helper.rb +1 -1
- data/vendor/rails/actionpack/lib/action_view/helpers/text_helper.rb +23 -14
- data/vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb +2 -2
- data/vendor/rails/actionpack/lib/action_view/locale/en.yml +4 -0
- data/vendor/rails/actionpack/lib/action_view/paths.rb +1 -1
- data/vendor/rails/actionpack/lib/action_view/template.rb +22 -33
- data/vendor/rails/actionpack/test/abstract_unit.rb +17 -1
- data/vendor/rails/actionpack/test/activerecord/active_record_store_test.rb +3 -3
- data/vendor/rails/actionpack/test/controller/action_pack_assertions_test.rb +27 -0
- data/vendor/rails/actionpack/test/controller/caching_test.rb +40 -1
- data/vendor/rails/actionpack/test/controller/cookie_test.rb +16 -0
- data/vendor/rails/actionpack/test/controller/dispatcher_test.rb +59 -18
- data/vendor/rails/actionpack/test/controller/failsafe_test.rb +60 -0
- data/vendor/rails/actionpack/test/controller/filter_params_test.rb +3 -1
- data/vendor/rails/actionpack/test/controller/flash_test.rb +6 -1
- data/vendor/rails/actionpack/test/controller/http_basic_authentication_test.rb +25 -0
- data/vendor/rails/actionpack/test/controller/http_digest_authentication_test.rb +63 -9
- data/vendor/rails/actionpack/test/controller/integration_test.rb +31 -3
- data/vendor/rails/actionpack/test/controller/rack_test.rb +18 -1
- data/vendor/rails/actionpack/test/controller/redirect_test.rb +4 -1
- data/vendor/rails/actionpack/test/controller/reloader_test.rb +124 -0
- data/vendor/rails/actionpack/test/controller/render_test.rb +19 -9
- data/vendor/rails/actionpack/test/controller/request/json_params_parsing_test.rb +24 -4
- data/vendor/rails/actionpack/test/controller/request/multipart_params_parsing_test.rb +1 -62
- data/vendor/rails/actionpack/test/controller/request/test_request_test.rb +35 -0
- data/vendor/rails/actionpack/test/controller/request/url_encoded_params_parsing_test.rb +0 -38
- data/vendor/rails/actionpack/test/controller/request/xml_params_parsing_test.rb +15 -0
- data/vendor/rails/actionpack/test/controller/request_forgery_protection_test.rb +6 -5
- data/vendor/rails/actionpack/test/controller/request_test.rb +218 -230
- data/vendor/rails/actionpack/test/controller/resources_test.rb +52 -0
- data/vendor/rails/actionpack/test/controller/routing_test.rb +28 -2
- data/vendor/rails/actionpack/test/controller/send_file_test.rb +12 -2
- data/vendor/rails/actionpack/test/controller/session/cookie_store_test.rb +9 -32
- data/vendor/rails/actionpack/test/controller/test_test.rb +8 -0
- data/vendor/rails/actionpack/test/controller/url_rewriter_test.rb +29 -3
- data/vendor/rails/actionpack/test/fixtures/failsafe/500.html +1 -0
- data/vendor/rails/actionpack/test/fixtures/public/absolute/test.css +23 -0
- data/vendor/rails/actionpack/test/fixtures/public/absolute/test.js +63 -0
- data/vendor/rails/actionpack/test/template/active_record_helper_test.rb +1 -1
- data/vendor/rails/actionpack/test/template/asset_tag_helper_test.rb +46 -0
- data/vendor/rails/actionpack/test/template/atom_feed_helper_test.rb +29 -0
- data/vendor/rails/actionpack/test/template/form_helper_test.rb +143 -6
- data/vendor/rails/actionpack/test/template/form_options_helper_i18n_test.rb +27 -0
- data/vendor/rails/actionpack/test/template/form_options_helper_test.rb +56 -0
- data/vendor/rails/actionpack/test/template/form_tag_helper_test.rb +23 -6
- data/vendor/rails/actionpack/test/template/prototype_helper_test.rb +11 -11
- data/vendor/rails/actionpack/test/template/template_test.rb +32 -0
- data/vendor/rails/actionpack/test/template/text_helper_test.rb +23 -0
- data/vendor/rails/actionpack/test/template/url_helper_test.rb +8 -0
- data/vendor/rails/activerecord/CHANGELOG +18 -0
- data/vendor/rails/activerecord/Rakefile +26 -9
- data/vendor/rails/activerecord/examples/performance.rb +162 -0
- data/vendor/rails/activerecord/lib/active_record/associations.rb +104 -35
- data/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb +10 -5
- data/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb +2 -2
- data/vendor/rails/activerecord/lib/active_record/associations/belongs_to_association.rb +22 -4
- data/vendor/rails/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +5 -1
- data/vendor/rails/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +16 -0
- data/vendor/rails/activerecord/lib/active_record/associations/has_many_association.rb +1 -0
- data/vendor/rails/activerecord/lib/active_record/associations/has_many_through_association.rb +13 -3
- data/vendor/rails/activerecord/lib/active_record/associations/has_one_through_association.rb +15 -9
- data/vendor/rails/activerecord/lib/active_record/autosave_association.rb +15 -9
- data/vendor/rails/activerecord/lib/active_record/base.rb +34 -31
- data/vendor/rails/activerecord/lib/active_record/batches.rb +23 -15
- data/vendor/rails/activerecord/lib/active_record/calculations.rb +7 -13
- data/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +16 -2
- data/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +2 -2
- data/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +7 -0
- data/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +17 -8
- data/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +98 -35
- data/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +15 -0
- data/vendor/rails/activerecord/lib/active_record/dirty.rb +1 -1
- data/vendor/rails/activerecord/lib/active_record/fixtures.rb +14 -11
- data/vendor/rails/activerecord/lib/active_record/i18n_interpolation_deprecation.rb +1 -1
- data/vendor/rails/activerecord/lib/active_record/locale/en.yml +4 -0
- data/vendor/rails/activerecord/lib/active_record/named_scope.rb +3 -8
- data/vendor/rails/activerecord/lib/active_record/reflection.rb +1 -1
- data/vendor/rails/activerecord/lib/active_record/schema_dumper.rb +6 -3
- data/vendor/rails/activerecord/lib/active_record/serialization.rb +3 -2
- data/vendor/rails/activerecord/lib/active_record/serializers/json_serializer.rb +10 -18
- data/vendor/rails/activerecord/lib/active_record/serializers/xml_serializer.rb +6 -2
- data/vendor/rails/activerecord/lib/active_record/session_store.rb +9 -1
- data/vendor/rails/activerecord/lib/active_record/timestamp.rb +39 -9
- data/vendor/rails/activerecord/lib/active_record/validations.rb +149 -80
- data/vendor/rails/activerecord/lib/active_record/version.rb +1 -1
- data/vendor/rails/activerecord/test/cases/adapter_test.rb +12 -0
- data/vendor/rails/activerecord/test/cases/associations/belongs_to_associations_test.rb +102 -22
- data/vendor/rails/activerecord/test/cases/associations/eager_load_nested_include_test.rb +5 -5
- data/vendor/rails/activerecord/test/cases/associations/eager_test.rb +12 -0
- data/vendor/rails/activerecord/test/cases/associations/habtm_join_table_test.rb +56 -0
- data/vendor/rails/activerecord/test/cases/associations/has_many_associations_test.rb +62 -2
- data/vendor/rails/activerecord/test/cases/associations/has_many_through_associations_test.rb +46 -1
- data/vendor/rails/activerecord/test/cases/associations/has_one_through_associations_test.rb +18 -1
- data/vendor/rails/activerecord/test/cases/associations/inner_join_association_test.rb +5 -0
- data/vendor/rails/activerecord/test/cases/associations/join_model_test.rb +4 -4
- data/vendor/rails/activerecord/test/cases/autosave_association_test.rb +22 -0
- data/vendor/rails/activerecord/test/cases/base_test.rb +51 -6
- data/vendor/rails/activerecord/test/cases/calculations_test.rb +14 -14
- data/vendor/rails/activerecord/test/cases/column_definition_test.rb +34 -0
- data/vendor/rails/activerecord/test/cases/copy_table_test_sqlite.rb +5 -5
- data/vendor/rails/activerecord/test/cases/dirty_test.rb +10 -0
- data/vendor/rails/activerecord/test/cases/finder_test.rb +21 -50
- data/vendor/rails/activerecord/test/cases/fixtures_test.rb +6 -1
- data/vendor/rails/activerecord/test/cases/helper.rb +1 -2
- data/vendor/rails/activerecord/test/cases/i18n_test.rb +5 -0
- data/vendor/rails/activerecord/test/cases/json_serialization_test.rb +57 -57
- data/vendor/rails/activerecord/test/cases/method_scoping_test.rb +14 -4
- data/vendor/rails/activerecord/test/cases/migration_test.rb +39 -11
- data/vendor/rails/activerecord/test/cases/modules_test.rb +42 -0
- data/vendor/rails/activerecord/test/cases/named_scope_test.rb +6 -4
- data/vendor/rails/activerecord/test/cases/pk_test.rb +18 -0
- data/vendor/rails/activerecord/test/cases/reflection_test.rb +7 -7
- data/vendor/rails/activerecord/test/cases/schema_dumper_test.rb +35 -7
- data/vendor/rails/activerecord/test/cases/schema_test_postgresql.rb +76 -0
- data/vendor/rails/activerecord/test/cases/timestamp_test.rb +75 -0
- data/vendor/rails/activerecord/test/cases/validations_i18n_test.rb +656 -624
- data/vendor/rails/activerecord/test/cases/validations_test.rb +12 -2
- data/vendor/rails/activerecord/test/cases/xml_serialization_test.rb +20 -0
- data/vendor/rails/activerecord/test/fixtures/fixture_database.sqlite +0 -0
- data/vendor/rails/activerecord/test/fixtures/fixture_database.sqlite3 +0 -0
- data/vendor/rails/activerecord/test/fixtures/fixture_database_2.sqlite +0 -0
- data/vendor/rails/activerecord/test/fixtures/fixture_database_2.sqlite3 +0 -0
- data/vendor/rails/activerecord/test/fixtures/posts.yml +3 -0
- data/vendor/rails/activerecord/test/models/author.rb +5 -0
- data/vendor/rails/activerecord/test/models/comment.rb +5 -1
- data/vendor/rails/activerecord/test/models/company.rb +9 -7
- data/vendor/rails/activerecord/test/models/company_in_module.rb +1 -1
- data/vendor/rails/activerecord/test/models/contract.rb +5 -0
- data/vendor/rails/activerecord/test/models/developer.rb +10 -0
- data/vendor/rails/activerecord/test/models/essay.rb +3 -0
- data/vendor/rails/activerecord/test/models/organization.rb +2 -0
- data/vendor/rails/activerecord/test/models/pet.rb +1 -1
- data/vendor/rails/activerecord/test/models/project.rb +1 -1
- data/vendor/rails/activerecord/test/models/reply.rb +2 -1
- data/vendor/rails/activerecord/test/models/topic.rb +1 -2
- data/vendor/rails/activerecord/test/models/toy.rb +2 -0
- data/vendor/rails/activerecord/test/schema/postgresql_specific_schema.rb +13 -2
- data/vendor/rails/activerecord/test/schema/schema.rb +19 -0
- data/vendor/rails/activeresource/CHANGELOG +16 -0
- data/vendor/rails/activeresource/Rakefile +3 -2
- data/vendor/rails/activeresource/lib/active_resource/base.rb +89 -9
- data/vendor/rails/activeresource/lib/active_resource/connection.rb +73 -8
- data/vendor/rails/activeresource/lib/active_resource/exceptions.rb +66 -0
- data/vendor/rails/activeresource/lib/active_resource/formats/json_format.rb +2 -2
- data/vendor/rails/activeresource/lib/active_resource/validations.rb +20 -4
- data/vendor/rails/activeresource/lib/active_resource/version.rb +1 -1
- data/vendor/rails/activeresource/test/abstract_unit.rb +1 -3
- data/vendor/rails/activeresource/test/base/load_test.rb +16 -1
- data/vendor/rails/activeresource/test/base_errors_test.rb +56 -19
- data/vendor/rails/activeresource/test/base_test.rb +147 -0
- data/vendor/rails/activeresource/test/connection_test.rb +42 -0
- data/vendor/rails/activeresource/test/debug.log +7974 -0
- data/vendor/rails/activeresource/test/fixtures/proxy.rb +4 -0
- data/vendor/rails/activesupport/CHANGELOG +13 -0
- data/vendor/rails/activesupport/lib/active_support/all.rb +8 -0
- data/vendor/rails/activesupport/lib/active_support/cache.rb +14 -1
- data/vendor/rails/activesupport/lib/active_support/cache/mem_cache_store.rb +16 -10
- data/vendor/rails/activesupport/lib/active_support/cache/strategy/local_cache.rb +1 -1
- data/vendor/rails/activesupport/lib/active_support/core_ext/array/conversions.rb +1 -0
- data/vendor/rails/activesupport/lib/active_support/core_ext/date/calculations.rb +2 -1
- data/vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb +2 -4
- data/vendor/rails/activesupport/lib/active_support/core_ext/hash/conversions.rb +14 -4
- data/vendor/rails/activesupport/lib/active_support/core_ext/kernel/debugger.rb +4 -2
- data/vendor/rails/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb +2 -0
- data/vendor/rails/activesupport/lib/active_support/core_ext/module/delegation.rb +19 -5
- data/vendor/rails/activesupport/lib/active_support/core_ext/module/model_naming.rb +8 -6
- data/vendor/rails/activesupport/lib/active_support/core_ext/numeric/bytes.rb +15 -9
- data/vendor/rails/activesupport/lib/active_support/core_ext/string.rb +1 -0
- data/vendor/rails/activesupport/lib/active_support/core_ext/string/access.rb +29 -5
- data/vendor/rails/activesupport/lib/active_support/core_ext/string/bytesize.rb +5 -0
- data/vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb +7 -7
- data/vendor/rails/activesupport/lib/active_support/deprecation.rb +9 -9
- data/vendor/rails/activesupport/lib/active_support/duration.rb +4 -2
- data/vendor/rails/activesupport/lib/active_support/json.rb +1 -22
- data/vendor/rails/activesupport/lib/active_support/json/backends/jsongem.rb +38 -0
- data/vendor/rails/activesupport/lib/active_support/json/backends/yaml.rb +88 -0
- data/vendor/rails/activesupport/lib/active_support/json/decoding.rb +23 -72
- data/vendor/rails/activesupport/lib/active_support/json/encoders/date.rb +9 -8
- data/vendor/rails/activesupport/lib/active_support/json/encoders/date_time.rb +9 -8
- data/vendor/rails/activesupport/lib/active_support/json/encoders/enumerable.rb +14 -9
- data/vendor/rails/activesupport/lib/active_support/json/encoders/false_class.rb +4 -2
- data/vendor/rails/activesupport/lib/active_support/json/encoders/hash.rb +21 -11
- data/vendor/rails/activesupport/lib/active_support/json/encoders/nil_class.rb +4 -2
- data/vendor/rails/activesupport/lib/active_support/json/encoders/numeric.rb +16 -0
- data/vendor/rails/activesupport/lib/active_support/json/encoders/object.rb +6 -2
- data/vendor/rails/activesupport/lib/active_support/json/encoders/regexp.rb +4 -0
- data/vendor/rails/activesupport/lib/active_support/json/encoders/string.rb +5 -32
- data/vendor/rails/activesupport/lib/active_support/json/encoders/symbol.rb +2 -2
- data/vendor/rails/activesupport/lib/active_support/json/encoders/time.rb +9 -8
- data/vendor/rails/activesupport/lib/active_support/json/encoders/true_class.rb +4 -2
- data/vendor/rails/activesupport/lib/active_support/json/encoding.rb +80 -9
- data/vendor/rails/activesupport/lib/active_support/memoizable.rb +1 -1
- data/vendor/rails/activesupport/lib/active_support/message_verifier.rb +16 -3
- data/vendor/rails/activesupport/lib/active_support/multibyte.rb +30 -6
- data/vendor/rails/activesupport/lib/active_support/multibyte/chars.rb +23 -17
- data/vendor/rails/activesupport/lib/active_support/multibyte/utils.rb +61 -0
- data/vendor/rails/activesupport/lib/active_support/ordered_hash.rb +28 -0
- data/vendor/rails/activesupport/lib/active_support/test_case.rb +9 -8
- data/vendor/rails/activesupport/lib/active_support/testing/deprecation.rb +2 -0
- data/vendor/rails/activesupport/lib/active_support/time_with_zone.rb +9 -8
- data/vendor/rails/activesupport/lib/active_support/vendor.rb +6 -7
- data/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +0 -1
- data/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -1
- data/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -1
- data/vendor/rails/activesupport/lib/active_support/vendor/{memcache-client-1.6.5 → memcache-client-1.7.4}/memcache.rb +242 -70
- data/vendor/rails/activesupport/lib/active_support/version.rb +1 -1
- data/vendor/rails/activesupport/lib/active_support/xml_mini/jdom.rb +162 -0
- data/vendor/rails/railties/CHANGELOG +10 -0
- data/vendor/rails/railties/Rakefile +13 -9
- data/vendor/rails/railties/bin/about +2 -2
- data/vendor/rails/railties/bin/console +1 -1
- data/vendor/rails/railties/bin/dbconsole +1 -1
- data/vendor/rails/railties/bin/destroy +1 -1
- data/vendor/rails/railties/bin/generate +1 -1
- data/vendor/rails/railties/bin/performance/benchmarker +1 -1
- data/vendor/rails/railties/bin/performance/profiler +1 -1
- data/vendor/rails/railties/bin/plugin +1 -1
- data/vendor/rails/railties/bin/runner +1 -1
- data/vendor/rails/railties/bin/server +1 -1
- data/vendor/rails/railties/builtin/rails_info/rails/info.rb +4 -2
- data/vendor/rails/railties/configs/initializers/new_rails_defaults.rb +2 -0
- data/vendor/rails/railties/configs/routes.rb +1 -1
- data/vendor/rails/railties/configs/seeds.rb +7 -0
- data/vendor/rails/railties/environments/boot.rb +1 -1
- data/vendor/rails/railties/guides/files/javascripts/code_highlighter.js +188 -0
- data/vendor/rails/railties/guides/files/javascripts/guides.js +8 -0
- data/vendor/rails/railties/guides/files/javascripts/highlighters.js +90 -0
- data/vendor/rails/railties/guides/files/stylesheets/main.css +441 -0
- data/vendor/rails/railties/guides/files/stylesheets/print.css +52 -0
- data/vendor/rails/railties/guides/files/stylesheets/reset.css +43 -0
- data/vendor/rails/railties/guides/files/stylesheets/style.css +13 -0
- data/vendor/rails/railties/guides/files/stylesheets/syntax.css +31 -0
- data/vendor/rails/railties/guides/images/belongs_to.png +0 -0
- data/vendor/rails/railties/guides/images/book_icon.gif +0 -0
- data/vendor/rails/railties/guides/images/bullet.gif +0 -0
- data/vendor/rails/railties/guides/images/chapters_icon.gif +0 -0
- data/vendor/rails/railties/guides/images/check_bullet.gif +0 -0
- data/vendor/rails/railties/guides/images/credits_pic_blank.gif +0 -0
- data/vendor/rails/railties/guides/images/csrf.png +0 -0
- data/vendor/rails/railties/guides/images/customized_error_messages.png +0 -0
- data/vendor/rails/railties/guides/images/error_messages.png +0 -0
- data/vendor/rails/railties/guides/images/feature_tile.gif +0 -0
- data/vendor/rails/railties/guides/images/footer_tile.gif +0 -0
- data/vendor/rails/railties/guides/images/fxn.jpg +0 -0
- data/vendor/rails/railties/guides/images/grey_bullet.gif +0 -0
- data/vendor/rails/railties/guides/images/habtm.png +0 -0
- data/vendor/rails/railties/guides/images/has_many.png +0 -0
- data/vendor/rails/railties/guides/images/has_many_through.png +0 -0
- data/vendor/rails/railties/guides/images/has_one.png +0 -0
- data/vendor/rails/railties/guides/images/has_one_through.png +0 -0
- data/vendor/rails/railties/guides/images/header_backdrop.png +0 -0
- data/vendor/rails/railties/guides/images/header_tile.gif +0 -0
- data/vendor/rails/railties/guides/images/i18n/demo_localized_pirate.png +0 -0
- data/vendor/rails/railties/guides/images/i18n/demo_translated_en.png +0 -0
- data/vendor/rails/railties/guides/images/i18n/demo_translated_pirate.png +0 -0
- data/vendor/rails/railties/guides/images/i18n/demo_translation_missing.png +0 -0
- data/vendor/rails/railties/guides/images/i18n/demo_untranslated.png +0 -0
- data/vendor/rails/railties/guides/images/icons/README +5 -0
- data/vendor/rails/railties/guides/images/icons/callouts/1.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/10.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/11.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/12.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/13.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/14.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/15.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/2.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/3.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/4.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/5.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/6.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/7.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/8.png +0 -0
- data/vendor/rails/railties/guides/images/icons/callouts/9.png +0 -0
- data/vendor/rails/railties/guides/images/icons/caution.png +0 -0
- data/vendor/rails/railties/guides/images/icons/example.png +0 -0
- data/vendor/rails/railties/guides/images/icons/home.png +0 -0
- data/vendor/rails/railties/guides/images/icons/important.png +0 -0
- data/vendor/rails/railties/guides/images/icons/next.png +0 -0
- data/vendor/rails/railties/guides/images/icons/note.png +0 -0
- data/vendor/rails/railties/guides/images/icons/prev.png +0 -0
- data/vendor/rails/railties/guides/images/icons/tip.png +0 -0
- data/vendor/rails/railties/guides/images/icons/up.png +0 -0
- data/vendor/rails/railties/guides/images/icons/warning.png +0 -0
- data/vendor/rails/railties/guides/images/nav_arrow.gif +0 -0
- data/vendor/rails/railties/guides/images/polymorphic.png +0 -0
- data/vendor/rails/railties/guides/images/posts_index.png +0 -0
- data/vendor/rails/railties/guides/images/rails_guides_logo.gif +0 -0
- data/vendor/rails/railties/guides/images/rails_logo_remix.gif +0 -0
- data/vendor/rails/railties/guides/images/rails_welcome.png +0 -0
- data/vendor/rails/railties/guides/images/session_fixation.png +0 -0
- data/vendor/rails/railties/guides/images/tab_grey.gif +0 -0
- data/vendor/rails/railties/guides/images/tab_info.gif +0 -0
- data/vendor/rails/railties/guides/images/tab_note.gif +0 -0
- data/vendor/rails/railties/guides/images/tab_red.gif +0 -0
- data/vendor/rails/railties/guides/images/tab_yellow.gif +0 -0
- data/vendor/rails/railties/guides/images/tab_yellow.png +0 -0
- data/vendor/rails/railties/guides/images/validation_error_messages.png +0 -0
- data/vendor/rails/railties/guides/rails_guides.rb +42 -0
- data/vendor/rails/railties/guides/rails_guides/generator.rb +138 -0
- data/vendor/rails/railties/guides/rails_guides/helpers.rb +34 -0
- data/vendor/rails/railties/guides/rails_guides/indexer.rb +55 -0
- data/vendor/rails/railties/guides/rails_guides/textile_extensions.rb +41 -0
- data/vendor/rails/railties/guides/source/2_2_release_notes.textile +422 -0
- data/vendor/rails/railties/guides/source/2_3_release_notes.textile +610 -0
- data/vendor/rails/railties/guides/source/action_controller_overview.textile +776 -0
- data/vendor/rails/railties/guides/source/action_mailer_basics.textile +424 -0
- data/vendor/rails/railties/guides/source/active_record_basics.textile +135 -0
- data/vendor/rails/railties/guides/source/active_record_querying.textile +969 -0
- data/vendor/rails/railties/guides/source/activerecord_validations_callbacks.textile +1086 -0
- data/vendor/rails/railties/guides/source/association_basics.textile +1781 -0
- data/vendor/rails/railties/guides/source/caching_with_rails.textile +524 -0
- data/vendor/rails/railties/guides/source/command_line.textile +589 -0
- data/vendor/rails/railties/guides/source/configuring.textile +234 -0
- data/vendor/rails/railties/guides/source/contribute.textile +71 -0
- data/vendor/rails/railties/guides/source/contributing_to_rails.textile +239 -0
- data/vendor/rails/railties/guides/source/credits.erb.textile +52 -0
- data/vendor/rails/railties/guides/source/debugging_rails_applications.textile +709 -0
- data/vendor/rails/railties/guides/source/form_helpers.textile +766 -0
- data/vendor/rails/railties/guides/source/getting_started.textile +1297 -0
- data/vendor/rails/railties/guides/source/i18n.textile +912 -0
- data/vendor/rails/railties/guides/source/index.erb.textile +124 -0
- data/vendor/rails/railties/guides/source/layout.html.erb +103 -0
- data/vendor/rails/railties/guides/source/layouts_and_rendering.textile +979 -0
- data/vendor/rails/railties/guides/source/migrations.textile +591 -0
- data/vendor/rails/railties/guides/source/nested_model_forms.textile +222 -0
- data/vendor/rails/railties/guides/source/performance_testing.textile +531 -0
- data/vendor/rails/railties/guides/source/plugins.textile +1512 -0
- data/vendor/rails/railties/guides/source/rails_on_rack.textile +309 -0
- data/vendor/rails/railties/guides/source/routing.textile +903 -0
- data/vendor/rails/railties/guides/source/security.textile +986 -0
- data/vendor/rails/railties/guides/source/testing.textile +951 -0
- data/vendor/rails/railties/lib/commands/dbconsole.rb +8 -4
- data/vendor/rails/railties/lib/commands/performance/profiler.rb +1 -1
- data/vendor/rails/railties/lib/initializer.rb +27 -4
- data/vendor/rails/railties/lib/rails/gem_dependency.rb +35 -6
- data/vendor/rails/railties/lib/rails/plugin.rb +12 -0
- data/vendor/rails/railties/lib/rails/plugin/loader.rb +7 -0
- data/vendor/rails/railties/lib/rails/rack/metal.rb +1 -1
- data/vendor/rails/railties/lib/rails/version.rb +1 -1
- data/vendor/rails/railties/lib/rails_generator/base.rb +1 -1
- data/vendor/rails/railties/lib/rails_generator/generators/applications/app/app_generator.rb +5 -0
- data/vendor/rails/railties/lib/rails_generator/generators/applications/app/template_runner.rb +1 -1
- data/vendor/rails/railties/lib/rails_generator/generators/components/model/model_generator.rb +9 -2
- data/vendor/rails/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +1 -0
- data/vendor/rails/railties/lib/tasks/databases.rake +17 -4
- data/vendor/rails/railties/lib/tasks/gems.rake +19 -6
- data/vendor/rails/railties/lib/tasks/routes.rake +4 -3
- data/vendor/rails/railties/lib/test_help.rb +4 -1
- metadata +158 -58
- data/spec/lib/local_time_spec.rb +0 -40
- data/vendor/rails/actionpack/lib/action_controller/rewindable_input.rb +0 -28
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack.rb +0 -89
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +0 -22
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +0 -37
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +0 -37
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +0 -58
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +0 -124
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +0 -51
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +0 -55
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +0 -40
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +0 -480
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/builder.rb +0 -63
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +0 -36
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +0 -49
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +0 -61
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +0 -45
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +0 -29
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +0 -23
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +0 -85
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/directory.rb +0 -153
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/file.rb +0 -88
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler.rb +0 -48
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +0 -61
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +0 -8
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +0 -89
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +0 -55
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +0 -84
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +0 -59
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +0 -8
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +0 -18
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +0 -67
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/head.rb +0 -19
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/lint.rb +0 -462
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +0 -65
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/lock.rb +0 -16
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +0 -27
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/mime.rb +0 -204
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/mock.rb +0 -160
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +0 -57
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +0 -64
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/request.rb +0 -241
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/response.rb +0 -179
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +0 -142
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +0 -91
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +0 -109
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +0 -100
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +0 -349
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +0 -106
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/static.rb +0 -38
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +0 -55
- data/vendor/rails/actionpack/lib/action_controller/vendor/rack-1.0/rack/utils.rb +0 -392
@@ -319,10 +319,6 @@ class NamedScopeTest < ActiveRecord::TestCase
|
|
319
319
|
assert_equal [posts(:sti_comments)], Post.with_special_comments.with_post(4).all.uniq
|
320
320
|
end
|
321
321
|
|
322
|
-
def test_methods_invoked_within_scopes_should_respect_scope
|
323
|
-
assert_equal [], Topic.approved.by_rejected_ids.proxy_options[:conditions][:id]
|
324
|
-
end
|
325
|
-
|
326
322
|
def test_named_scopes_batch_finders
|
327
323
|
assert_equal 3, Topic.approved.count
|
328
324
|
|
@@ -336,6 +332,12 @@ class NamedScopeTest < ActiveRecord::TestCase
|
|
336
332
|
end
|
337
333
|
end
|
338
334
|
end
|
335
|
+
|
336
|
+
def test_table_names_for_chaining_scopes_with_and_without_table_name_included
|
337
|
+
assert_nothing_raised do
|
338
|
+
Comment.for_first_post.for_first_author.all
|
339
|
+
end
|
340
|
+
end
|
339
341
|
end
|
340
342
|
|
341
343
|
class DynamicScopeMatchTest < ActiveRecord::TestCase
|
@@ -98,4 +98,22 @@ class PrimaryKeysTest < ActiveRecord::TestCase
|
|
98
98
|
def test_instance_destroy_should_quote_pkey
|
99
99
|
assert_nothing_raised { MixedCaseMonkey.find(1).destroy }
|
100
100
|
end
|
101
|
+
|
102
|
+
def test_supports_primary_key
|
103
|
+
assert_nothing_raised NoMethodError do
|
104
|
+
ActiveRecord::Base.connection.supports_primary_key?
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_primary_key_returns_value_if_it_exists
|
109
|
+
if ActiveRecord::Base.connection.supports_primary_key?
|
110
|
+
assert_equal 'id', ActiveRecord::Base.connection.primary_key('developers')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_primary_key_returns_nil_if_it_does_not_exist
|
115
|
+
if ActiveRecord::Base.connection.supports_primary_key?
|
116
|
+
assert_nil ActiveRecord::Base.connection.primary_key('developers_projects')
|
117
|
+
end
|
118
|
+
end
|
101
119
|
end
|
@@ -21,25 +21,25 @@ class ReflectionTest < ActiveRecord::TestCase
|
|
21
21
|
|
22
22
|
def test_read_attribute_names
|
23
23
|
assert_equal(
|
24
|
-
%w( id title author_name author_email_address bonus_time written_on last_read content approved replies_count parent_id type ).sort,
|
24
|
+
%w( id title author_name author_email_address bonus_time written_on last_read content approved replies_count parent_id parent_title type ).sort,
|
25
25
|
@first.attribute_names
|
26
26
|
)
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_columns
|
30
|
-
assert_equal
|
30
|
+
assert_equal 13, Topic.columns.length
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_columns_are_returned_in_the_order_they_were_declared
|
34
34
|
column_names = Topic.columns.map { |column| column.name }
|
35
|
-
assert_equal %w(id title author_name author_email_address written_on bonus_time last_read content approved replies_count parent_id type), column_names
|
35
|
+
assert_equal %w(id title author_name author_email_address written_on bonus_time last_read content approved replies_count parent_id parent_title type), column_names
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_content_columns
|
39
39
|
content_columns = Topic.content_columns
|
40
40
|
content_column_names = content_columns.map {|column| column.name}
|
41
|
-
assert_equal
|
42
|
-
assert_equal %w(title author_name author_email_address written_on bonus_time last_read content approved).sort, content_column_names.sort
|
41
|
+
assert_equal 9, content_columns.length
|
42
|
+
assert_equal %w(title author_name author_email_address written_on bonus_time last_read content approved parent_title).sort, content_column_names.sort
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_column_string_type_and_limit
|
@@ -170,8 +170,8 @@ class ReflectionTest < ActiveRecord::TestCase
|
|
170
170
|
|
171
171
|
def test_reflection_of_all_associations
|
172
172
|
# FIXME these assertions bust a lot
|
173
|
-
assert_equal
|
174
|
-
assert_equal
|
173
|
+
assert_equal 30, Firm.reflect_on_all_associations.size
|
174
|
+
assert_equal 23, Firm.reflect_on_all_associations(:has_many).size
|
175
175
|
assert_equal 7, Firm.reflect_on_all_associations(:has_one).size
|
176
176
|
assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
|
177
177
|
end
|
@@ -22,6 +22,11 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
22
22
|
assert_no_match %r{create_table "sqlite_sequence"}, output
|
23
23
|
end
|
24
24
|
|
25
|
+
def test_schema_dump_includes_camelcase_table_name
|
26
|
+
output = standard_dump
|
27
|
+
assert_match %r{create_table "CamelCase"}, output
|
28
|
+
end
|
29
|
+
|
25
30
|
def assert_line_up(lines, pattern, required = false)
|
26
31
|
return assert(true) if lines.empty?
|
27
32
|
matches = lines.map { |line| line.match(pattern) }
|
@@ -147,19 +152,24 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
147
152
|
end
|
148
153
|
end
|
149
154
|
|
155
|
+
def test_schema_dumps_index_columns_in_right_order
|
156
|
+
index_definition = standard_dump.split(/\n/).grep(/add_index.*companies/).first.strip
|
157
|
+
assert_equal 'add_index "companies", ["firm_id", "type", "rating", "ruby_type"], :name => "company_index"', index_definition
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_schema_dump_should_honor_nonstandard_primary_keys
|
161
|
+
output = standard_dump
|
162
|
+
match = output.match(%r{create_table "movies"(.*)do})
|
163
|
+
assert_not_nil(match, "nonstandardpk table not found")
|
164
|
+
assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
|
165
|
+
end
|
166
|
+
|
150
167
|
if current_adapter?(:MysqlAdapter)
|
151
168
|
def test_schema_dump_should_not_add_default_value_for_mysql_text_field
|
152
169
|
output = standard_dump
|
153
170
|
assert_match %r{t.text\s+"body",\s+:null => false$}, output
|
154
171
|
end
|
155
172
|
|
156
|
-
def test_mysql_schema_dump_should_honor_nonstandard_primary_keys
|
157
|
-
output = standard_dump
|
158
|
-
match = output.match(%r{create_table "movies"(.*)do})
|
159
|
-
assert_not_nil(match, "nonstandardpk table not found")
|
160
|
-
assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
|
161
|
-
end
|
162
|
-
|
163
173
|
def test_schema_dump_includes_length_for_mysql_blob_and_text_fields
|
164
174
|
output = standard_dump
|
165
175
|
assert_match %r{t.binary\s+"tiny_blob",\s+:limit => 255$}, output
|
@@ -180,4 +190,22 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
180
190
|
output = stream.string
|
181
191
|
assert_match %r{:precision => 3,[[:space:]]+:scale => 2,[[:space:]]+:default => 2.78}, output
|
182
192
|
end
|
193
|
+
|
194
|
+
if current_adapter?(:PostgreSQLAdapter)
|
195
|
+
def test_schema_dump_includes_xml_shorthand_definition
|
196
|
+
output = standard_dump
|
197
|
+
if %r{create_table "postgresql_xml_data_type"} =~ output
|
198
|
+
assert_match %r{t.xml "data"}, output
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_schema_dump_keeps_id_column_when_id_is_false_and_id_column_added
|
204
|
+
output = standard_dump
|
205
|
+
match = output.match(%r{create_table "goofy_string_id"(.*)do.*\n(.*)\n})
|
206
|
+
assert_not_nil(match, "goofy_string_id table not found")
|
207
|
+
assert_match %r(:id => false), match[1], "no table id not preserved"
|
208
|
+
assert_match %r{t.string[[:space:]]+"id",[[:space:]]+:null => false$}, match[2], "non-primary key id column not preserved"
|
209
|
+
end
|
183
210
|
end
|
211
|
+
|
@@ -6,6 +6,7 @@ class SchemaTest < ActiveRecord::TestCase
|
|
6
6
|
SCHEMA_NAME = 'test_schema'
|
7
7
|
SCHEMA2_NAME = 'test_schema2'
|
8
8
|
TABLE_NAME = 'things'
|
9
|
+
CAPITALIZED_TABLE_NAME = 'Things'
|
9
10
|
INDEX_A_NAME = 'a_index_things_on_name'
|
10
11
|
INDEX_B_NAME = 'b_index_things_on_different_columns_in_each_schema'
|
11
12
|
INDEX_A_COLUMN = 'name'
|
@@ -18,9 +19,27 @@ class SchemaTest < ActiveRecord::TestCase
|
|
18
19
|
'moment timestamp without time zone default now()'
|
19
20
|
]
|
20
21
|
|
22
|
+
class Thing1 < ActiveRecord::Base
|
23
|
+
set_table_name "test_schema.things"
|
24
|
+
end
|
25
|
+
|
26
|
+
class Thing2 < ActiveRecord::Base
|
27
|
+
set_table_name "test_schema2.things"
|
28
|
+
end
|
29
|
+
|
30
|
+
class Thing3 < ActiveRecord::Base
|
31
|
+
set_table_name 'test_schema."things.table"'
|
32
|
+
end
|
33
|
+
|
34
|
+
class Thing4 < ActiveRecord::Base
|
35
|
+
set_table_name 'test_schema."Things"'
|
36
|
+
end
|
37
|
+
|
21
38
|
def setup
|
22
39
|
@connection = ActiveRecord::Base.connection
|
23
40
|
@connection.execute "CREATE SCHEMA #{SCHEMA_NAME} CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})"
|
41
|
+
@connection.execute "CREATE TABLE #{SCHEMA_NAME}.\"#{TABLE_NAME}.table\" (#{COLUMNS.join(',')})"
|
42
|
+
@connection.execute "CREATE TABLE #{SCHEMA_NAME}.\"#{CAPITALIZED_TABLE_NAME}\" (#{COLUMNS.join(',')})"
|
24
43
|
@connection.execute "CREATE SCHEMA #{SCHEMA2_NAME} CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})"
|
25
44
|
@connection.execute "CREATE INDEX #{INDEX_A_NAME} ON #{SCHEMA_NAME}.#{TABLE_NAME} USING btree (#{INDEX_A_COLUMN});"
|
26
45
|
@connection.execute "CREATE INDEX #{INDEX_A_NAME} ON #{SCHEMA2_NAME}.#{TABLE_NAME} USING btree (#{INDEX_A_COLUMN});"
|
@@ -39,6 +58,12 @@ class SchemaTest < ActiveRecord::TestCase
|
|
39
58
|
end
|
40
59
|
end
|
41
60
|
|
61
|
+
def test_with_schema_prefixed_capitalized_table_name
|
62
|
+
assert_nothing_raised do
|
63
|
+
assert_equal COLUMNS, columns("#{SCHEMA_NAME}.#{CAPITALIZED_TABLE_NAME}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
42
67
|
def test_with_schema_search_path
|
43
68
|
assert_nothing_raised do
|
44
69
|
with_schema_search_path(SCHEMA_NAME) do
|
@@ -47,6 +72,47 @@ class SchemaTest < ActiveRecord::TestCase
|
|
47
72
|
end
|
48
73
|
end
|
49
74
|
|
75
|
+
|
76
|
+
def test_proper_encoding_of_table_name
|
77
|
+
assert_equal '"table_name"', @connection.quote_table_name('table_name')
|
78
|
+
assert_equal '"table.name"', @connection.quote_table_name('"table.name"')
|
79
|
+
assert_equal '"schema_name"."table_name"', @connection.quote_table_name('schema_name.table_name')
|
80
|
+
assert_equal '"schema_name"."table.name"', @connection.quote_table_name('schema_name."table.name"')
|
81
|
+
assert_equal '"schema.name"."table_name"', @connection.quote_table_name('"schema.name".table_name')
|
82
|
+
assert_equal '"schema.name"."table.name"', @connection.quote_table_name('"schema.name"."table.name"')
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_classes_with_qualified_schema_name
|
86
|
+
assert_equal 0, Thing1.count
|
87
|
+
assert_equal 0, Thing2.count
|
88
|
+
assert_equal 0, Thing3.count
|
89
|
+
assert_equal 0, Thing4.count
|
90
|
+
|
91
|
+
Thing1.create(:id => 1, :name => "thing1", :email => "thing1@localhost", :moment => Time.now)
|
92
|
+
assert_equal 1, Thing1.count
|
93
|
+
assert_equal 0, Thing2.count
|
94
|
+
assert_equal 0, Thing3.count
|
95
|
+
assert_equal 0, Thing4.count
|
96
|
+
|
97
|
+
Thing2.create(:id => 1, :name => "thing1", :email => "thing1@localhost", :moment => Time.now)
|
98
|
+
assert_equal 1, Thing1.count
|
99
|
+
assert_equal 1, Thing2.count
|
100
|
+
assert_equal 0, Thing3.count
|
101
|
+
assert_equal 0, Thing4.count
|
102
|
+
|
103
|
+
Thing3.create(:id => 1, :name => "thing1", :email => "thing1@localhost", :moment => Time.now)
|
104
|
+
assert_equal 1, Thing1.count
|
105
|
+
assert_equal 1, Thing2.count
|
106
|
+
assert_equal 1, Thing3.count
|
107
|
+
assert_equal 0, Thing4.count
|
108
|
+
|
109
|
+
Thing4.create(:id => 1, :name => "thing1", :email => "thing1@localhost", :moment => Time.now)
|
110
|
+
assert_equal 1, Thing1.count
|
111
|
+
assert_equal 1, Thing2.count
|
112
|
+
assert_equal 1, Thing3.count
|
113
|
+
assert_equal 1, Thing4.count
|
114
|
+
end
|
115
|
+
|
50
116
|
def test_raise_on_unquoted_schema_name
|
51
117
|
assert_raise(ActiveRecord::StatementInvalid) do
|
52
118
|
with_schema_search_path '$user,public'
|
@@ -69,6 +135,16 @@ class SchemaTest < ActiveRecord::TestCase
|
|
69
135
|
do_dump_index_tests_for_schema(SCHEMA2_NAME, INDEX_A_COLUMN, INDEX_B_COLUMN_S2)
|
70
136
|
end
|
71
137
|
|
138
|
+
def test_with_uppercase_index_name
|
139
|
+
ActiveRecord::Base.connection.execute "CREATE INDEX \"things_Index\" ON #{SCHEMA_NAME}.things (name)"
|
140
|
+
assert_nothing_raised { ActiveRecord::Base.connection.remove_index :things, :name => "#{SCHEMA_NAME}.things_Index"}
|
141
|
+
|
142
|
+
ActiveRecord::Base.connection.execute "CREATE INDEX \"things_Index\" ON #{SCHEMA_NAME}.things (name)"
|
143
|
+
ActiveRecord::Base.connection.schema_search_path = SCHEMA_NAME
|
144
|
+
assert_nothing_raised { ActiveRecord::Base.connection.remove_index :things, :name => "things_Index"}
|
145
|
+
ActiveRecord::Base.connection.schema_search_path = "public"
|
146
|
+
end
|
147
|
+
|
72
148
|
private
|
73
149
|
def columns(table_name)
|
74
150
|
@connection.send(:column_definitions, table_name).map do |name, type, default|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
require 'models/developer'
|
3
|
+
require 'models/owner'
|
4
|
+
require 'models/pet'
|
5
|
+
|
6
|
+
class TimestampTest < ActiveRecord::TestCase
|
7
|
+
fixtures :developers, :owners, :pets
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@developer = Developer.first
|
11
|
+
@previously_updated_at = @developer.updated_at
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_saving_a_changed_record_updates_its_timestamp
|
15
|
+
@developer.name = "Jack Bauer"
|
16
|
+
@developer.save!
|
17
|
+
|
18
|
+
assert @previously_updated_at != @developer.updated_at
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_saving_a_unchanged_record_doesnt_update_its_timestamp
|
22
|
+
@developer.save!
|
23
|
+
|
24
|
+
assert @previously_updated_at == @developer.updated_at
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_touching_a_record_updates_its_timestamp
|
28
|
+
@developer.touch
|
29
|
+
|
30
|
+
assert @previously_updated_at != @developer.updated_at
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_touching_a_different_attribute
|
34
|
+
previously_created_at = @developer.created_at
|
35
|
+
@developer.touch(:created_at)
|
36
|
+
|
37
|
+
assert previously_created_at != @developer.created_at
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_saving_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
|
41
|
+
pet = Pet.first
|
42
|
+
owner = pet.owner
|
43
|
+
previously_owner_updated_at = owner.updated_at
|
44
|
+
|
45
|
+
pet.name = "Fluffy the Third"
|
46
|
+
pet.save
|
47
|
+
|
48
|
+
assert previously_owner_updated_at != pet.owner.updated_at
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_destroying_a_record_with_a_belongs_to_that_specifies_touching_the_parent_should_update_the_parent_updated_at
|
52
|
+
pet = Pet.first
|
53
|
+
owner = pet.owner
|
54
|
+
previously_owner_updated_at = owner.updated_at
|
55
|
+
|
56
|
+
pet.destroy
|
57
|
+
|
58
|
+
assert previously_owner_updated_at != pet.owner.updated_at
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_saving_a_record_with_a_belongs_to_that_specifies_touching_a_specific_attribute_the_parent_should_update_that_attribute
|
62
|
+
Pet.belongs_to :owner, :touch => :happy_at
|
63
|
+
|
64
|
+
pet = Pet.first
|
65
|
+
owner = pet.owner
|
66
|
+
previously_owner_happy_at = owner.happy_at
|
67
|
+
|
68
|
+
pet.name = "Fluffy the Third"
|
69
|
+
pet.save
|
70
|
+
|
71
|
+
assert previously_owner_happy_at != pet.owner.happy_at
|
72
|
+
ensure
|
73
|
+
Pet.belongs_to :owner, :touch => true
|
74
|
+
end
|
75
|
+
end
|
@@ -1,32 +1,20 @@
|
|
1
1
|
require "cases/helper"
|
2
2
|
require 'models/topic'
|
3
3
|
require 'models/reply'
|
4
|
+
require 'models/person'
|
4
5
|
|
5
|
-
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
I18n.
|
11
|
-
I18n.backend = I18n::Backend::Simple.new
|
12
|
-
I18n.backend.store_translations('en', :activerecord => {:errors => {:messages => {:custom => nil}}})
|
13
|
-
end
|
14
|
-
|
15
|
-
def teardown
|
16
|
-
reset_callbacks Topic
|
17
|
-
I18n.load_path.replace @old_load_path
|
18
|
-
I18n.backend = @old_backend
|
19
|
-
end
|
20
|
-
|
21
|
-
def unique_topic
|
22
|
-
@unique ||= Topic.create :title => 'unique!'
|
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)
|
23
12
|
end
|
24
13
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
topic
|
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] }
|
30
18
|
end
|
31
19
|
end
|
32
20
|
|
@@ -37,879 +25,923 @@ class ActiveRecordValidationsI18nTests < ActiveSupport::TestCase
|
|
37
25
|
model.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
38
26
|
end
|
39
27
|
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# DEPRECATIONS
|
40
31
|
|
41
|
-
|
32
|
+
class ActiveRecordValidationsI18nDeprecationsTests < ActiveSupport::TestCase
|
33
|
+
test "default_error_messages is deprecated and can be removed in Rails 3 / ActiveModel" do
|
42
34
|
assert_deprecated('ActiveRecord::Errors.default_error_messages') do
|
43
35
|
ActiveRecord::Errors.default_error_messages
|
44
36
|
end
|
45
37
|
end
|
46
38
|
|
47
|
-
|
39
|
+
test "%s interpolation syntax in error messages still works" do
|
48
40
|
ActiveSupport::Deprecation.silence do
|
49
41
|
result = I18n.t :does_not_exist, :default => "%s interpolation syntax is deprecated", :value => 'this'
|
50
42
|
assert_equal result, "this interpolation syntax is deprecated"
|
51
43
|
end
|
52
44
|
end
|
53
45
|
|
54
|
-
|
46
|
+
test "%s interpolation syntax in error messages is deprecated" do
|
55
47
|
assert_deprecated('using %s in messages') do
|
56
48
|
I18n.t :does_not_exist, :default => "%s interpolation syntax is deprected", :value => 'this'
|
57
49
|
end
|
58
50
|
end
|
59
51
|
|
60
|
-
|
52
|
+
test "%d interpolation syntax in error messages still works" do
|
61
53
|
ActiveSupport::Deprecation.silence do
|
62
54
|
result = I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprecated", :count => 2
|
63
55
|
assert_equal result, "2 interpolation syntaxes are deprecated"
|
64
56
|
end
|
65
57
|
end
|
66
58
|
|
67
|
-
|
59
|
+
test "%d interpolation syntax in error messages is deprecated" do
|
68
60
|
assert_deprecated('using %d in messages') do
|
69
61
|
I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprected", :count => 2
|
70
62
|
end
|
71
63
|
end
|
64
|
+
end
|
72
65
|
|
73
|
-
# ActiveRecord::Errors
|
74
|
-
def test_errors_generate_message_translates_custom_model_attribute_key
|
75
|
-
|
76
|
-
I18n.expects(:translate).with(
|
77
|
-
:topic,
|
78
|
-
{ :count => 1,
|
79
|
-
:default => ['Topic'],
|
80
|
-
:scope => [:activerecord, :models]
|
81
|
-
}
|
82
|
-
).returns('Topic')
|
83
|
-
|
84
|
-
I18n.expects(:translate).with(
|
85
|
-
:"topic.title",
|
86
|
-
{ :count => 1,
|
87
|
-
:default => ['Title'],
|
88
|
-
:scope => [:activerecord, :attributes]
|
89
|
-
}
|
90
|
-
).returns('Title')
|
91
|
-
|
92
|
-
I18n.expects(:translate).with(
|
93
|
-
:"models.topic.attributes.title.invalid",
|
94
|
-
:value => nil,
|
95
|
-
:scope => [:activerecord, :errors],
|
96
|
-
:default => [
|
97
|
-
:"models.topic.invalid",
|
98
|
-
'default from class def error 1',
|
99
|
-
:"messages.invalid"],
|
100
|
-
:attribute => "Title",
|
101
|
-
:model => "Topic"
|
102
|
-
).returns('default from class def error 1')
|
103
|
-
|
104
|
-
@topic.errors.generate_message :title, :invalid, :default => 'default from class def error 1'
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_errors_generate_message_translates_custom_model_attribute_keys_with_sti
|
108
|
-
|
109
|
-
I18n.expects(:translate).with(
|
110
|
-
:reply,
|
111
|
-
{ :count => 1,
|
112
|
-
:default => [:topic, 'Reply'],
|
113
|
-
:scope => [:activerecord, :models]
|
114
|
-
}
|
115
|
-
).returns('Reply')
|
116
|
-
|
117
|
-
I18n.expects(:translate).with(
|
118
|
-
:"reply.title",
|
119
|
-
{ :count => 1,
|
120
|
-
:default => [:'topic.title', 'Title'],
|
121
|
-
:scope => [:activerecord, :attributes]
|
122
|
-
}
|
123
|
-
).returns('Title')
|
124
66
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
:"models.topic.attributes.title.invalid",
|
132
|
-
:"models.topic.invalid",
|
133
|
-
'default from class def',
|
134
|
-
:"messages.invalid"],
|
135
|
-
:model => 'Reply',
|
136
|
-
:attribute => 'Title'
|
137
|
-
).returns("default from class def")
|
67
|
+
# ACTIVERECORD VALIDATIONS
|
68
|
+
#
|
69
|
+
# For each validation:
|
70
|
+
#
|
71
|
+
# * test expect that it adds an error with the appropriate arguments
|
72
|
+
# * test that it looks up the correct default message
|
138
73
|
|
139
|
-
|
74
|
+
class ActiveRecordValidationsI18nTests < ActiveSupport::TestCase
|
75
|
+
include ActiveRecordValidationsI18nTestHelper
|
140
76
|
|
77
|
+
def setup
|
78
|
+
reset_callbacks(Topic)
|
79
|
+
@topic = Topic.new
|
80
|
+
@reply = Reply.new
|
81
|
+
@old_load_path, @old_backend = I18n.load_path, I18n.backend
|
82
|
+
I18n.load_path.clear
|
83
|
+
I18n.backend = I18n::Backend::Simple.new
|
84
|
+
I18n.backend.store_translations('en', :activerecord => {:errors => {:messages => {:custom => nil}}})
|
141
85
|
end
|
142
86
|
|
143
|
-
def
|
144
|
-
|
145
|
-
|
87
|
+
def teardown
|
88
|
+
reset_callbacks(Topic)
|
89
|
+
I18n.load_path.replace(@old_load_path)
|
90
|
+
I18n.backend = @old_backend
|
146
91
|
end
|
147
92
|
|
148
|
-
def
|
149
|
-
|
150
|
-
|
93
|
+
def expect_error_added(model, attribute, type, options)
|
94
|
+
model.errors.expects(:add).with(attribute, type, options)
|
95
|
+
yield
|
96
|
+
model.valid?
|
151
97
|
end
|
152
98
|
|
153
|
-
def
|
154
|
-
|
155
|
-
|
99
|
+
def assert_message_translations(model, attribute, type, &block)
|
100
|
+
assert_default_message_translation(model, attribute, type, &block)
|
101
|
+
reset_callbacks(model.class)
|
102
|
+
model.errors.clear
|
103
|
+
assert_custom_message_translation(model, attribute, type, &block)
|
156
104
|
end
|
157
105
|
|
158
|
-
def
|
159
|
-
|
160
|
-
|
106
|
+
def assert_custom_message_translation(model, attribute, type)
|
107
|
+
store_translations(:errors => { :models => { model.class.name.underscore => { :attributes => { attribute => { type => 'custom message' } } } } })
|
108
|
+
yield
|
109
|
+
model.valid?
|
110
|
+
assert_equal 'custom message', model.errors.on(attribute)
|
161
111
|
end
|
162
112
|
|
163
|
-
def
|
164
|
-
|
165
|
-
|
166
|
-
|
113
|
+
def assert_default_message_translation(model, attribute, type)
|
114
|
+
store_translations(:errors => { :messages => { type => 'default message' } })
|
115
|
+
yield
|
116
|
+
model.valid?
|
117
|
+
assert_equal 'default message', model.errors.on(attribute)
|
167
118
|
end
|
168
119
|
|
169
|
-
|
170
|
-
|
171
|
-
def test_validates_confirmation_of_generates_message
|
172
|
-
Topic.validates_confirmation_of :title
|
173
|
-
@topic.title_confirmation = 'foo'
|
174
|
-
@topic.errors.expects(:generate_message).with(:title, :confirmation, {:default => nil})
|
175
|
-
@topic.valid?
|
120
|
+
def unique_topic
|
121
|
+
@unique ||= Topic.create(:title => 'unique!')
|
176
122
|
end
|
177
123
|
|
178
|
-
def
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
124
|
+
def replied_topic
|
125
|
+
@replied_topic ||= begin
|
126
|
+
topic = Topic.create(:title => "topic")
|
127
|
+
topic.replies << Reply.new
|
128
|
+
topic
|
129
|
+
end
|
183
130
|
end
|
184
131
|
|
185
|
-
#
|
132
|
+
# validates_confirmation_of
|
186
133
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
def test_validates_acceptance_of_generates_message_with_custom_default_message
|
194
|
-
Topic.validates_acceptance_of :title, :message => 'custom', :allow_nil => false
|
195
|
-
@topic.errors.expects(:generate_message).with(:title, :accepted, {:default => 'custom'})
|
196
|
-
@topic.valid?
|
134
|
+
test "#validates_confirmation_of given no custom message" do
|
135
|
+
expect_error_added(@topic, :title, :confirmation, :default => nil) do
|
136
|
+
Topic.validates_confirmation_of :title
|
137
|
+
@topic.title = 'title'
|
138
|
+
@topic.title_confirmation = 'foo'
|
139
|
+
end
|
197
140
|
end
|
198
141
|
|
199
|
-
#
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
@topic.valid?
|
142
|
+
test "#validates_confirmation_of given a custom message" do
|
143
|
+
expect_error_added(@topic, :title, :confirmation, :default => 'custom') do
|
144
|
+
Topic.validates_confirmation_of :title, :message => 'custom'
|
145
|
+
@topic.title_confirmation = 'foo'
|
146
|
+
end
|
205
147
|
end
|
206
148
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
149
|
+
test "#validates_confirmation_of finds the correct message translations" do
|
150
|
+
assert_message_translations(@topic, :title, :confirmation) do
|
151
|
+
Topic.validates_confirmation_of :title
|
152
|
+
@topic.title_confirmation = 'foo'
|
153
|
+
end
|
211
154
|
end
|
212
155
|
|
213
|
-
|
214
|
-
Topic.validates_length_of :title, :within => 3..5
|
215
|
-
@topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => nil})
|
216
|
-
@topic.valid?
|
217
|
-
end
|
156
|
+
# validates_acceptance_of
|
218
157
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
158
|
+
test "#validates_acceptance_of given no custom message" do
|
159
|
+
expect_error_added(@topic, :title, :accepted, :default => nil) do
|
160
|
+
Topic.validates_acceptance_of :title, :allow_nil => false
|
161
|
+
end
|
223
162
|
end
|
224
163
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
@topic.valid?
|
164
|
+
test "#validates_acceptance_of given a custom message" do
|
165
|
+
expect_error_added(@topic, :title, :accepted, :default => 'custom') do
|
166
|
+
Topic.validates_acceptance_of :title, :message => 'custom', :allow_nil => false
|
167
|
+
end
|
230
168
|
end
|
231
169
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
@topic.valid?
|
170
|
+
test "#validates_acceptance_of finds the correct message translations" do
|
171
|
+
assert_message_translations(@topic, :title, :accepted) do
|
172
|
+
Topic.validates_acceptance_of :title, :allow_nil => false
|
173
|
+
end
|
237
174
|
end
|
238
175
|
|
239
|
-
#
|
240
|
-
|
241
|
-
def test_validates_length_of_within_generates_message_with_title_too_short
|
242
|
-
Topic.validates_length_of :title, :within => 3..5
|
243
|
-
@topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => nil})
|
244
|
-
@topic.valid?
|
245
|
-
end
|
176
|
+
# validates_presence_of
|
246
177
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
178
|
+
test "#validates_presence_of given no custom message" do
|
179
|
+
expect_error_added(@topic, :title, :blank, :default => nil) do
|
180
|
+
Topic.validates_presence_of :title
|
181
|
+
end
|
251
182
|
end
|
252
183
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
@topic.valid?
|
184
|
+
test "#validates_presence_of given a custom message" do
|
185
|
+
expect_error_added(@topic, :title, :blank, :default => 'custom') do
|
186
|
+
Topic.validates_presence_of :title, :message => 'custom'
|
187
|
+
end
|
258
188
|
end
|
259
189
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
@topic.valid?
|
190
|
+
test "#validates_presence_of finds the correct message translations" do
|
191
|
+
assert_message_translations(@topic, :title, :blank) do
|
192
|
+
Topic.validates_presence_of :title
|
193
|
+
end
|
265
194
|
end
|
266
195
|
|
267
|
-
# validates_length_of :
|
196
|
+
# validates_length_of :too_short
|
268
197
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
198
|
+
test "#validates_length_of (:too_short) and no custom message" do
|
199
|
+
expect_error_added(@topic, :title, :too_short, :default => nil, :count => 3) do
|
200
|
+
Topic.validates_length_of :title, :within => 3..5
|
201
|
+
end
|
273
202
|
end
|
274
203
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
204
|
+
test "#validates_length_of (:too_short) and a custom message" do
|
205
|
+
expect_error_added(@topic, :title, :too_short, :default => 'custom', :count => 3) do
|
206
|
+
Topic.validates_length_of :title, :within => 3..5, :too_short => 'custom'
|
207
|
+
end
|
279
208
|
end
|
280
209
|
|
281
|
-
#
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
@topic.title = unique_topic.title
|
286
|
-
@topic.errors.expects(:generate_message).with(:title, :taken, {:default => nil, :value => 'unique!'})
|
287
|
-
@topic.valid?
|
210
|
+
test "#validates_length_of (:too_short) finds the correct message translations" do
|
211
|
+
assert_message_translations(@topic, :title, :too_short) do
|
212
|
+
Topic.validates_length_of :title, :within => 3..5
|
213
|
+
end
|
288
214
|
end
|
289
215
|
|
290
|
-
|
291
|
-
Topic.validates_uniqueness_of :title, :message => 'custom'
|
292
|
-
@topic.title = unique_topic.title
|
293
|
-
@topic.errors.expects(:generate_message).with(:title, :taken, {:default => 'custom', :value => 'unique!'})
|
294
|
-
@topic.valid?
|
295
|
-
end
|
216
|
+
# validates_length_of :too_long
|
296
217
|
|
297
|
-
#
|
218
|
+
test "#validates_length_of (:too_long) and no custom message" do
|
219
|
+
expect_error_added(@topic, :title, :too_long, :default => nil, :count => 5) do
|
220
|
+
Topic.validates_length_of :title, :within => 3..5
|
221
|
+
@topic.title = 'this title is too long'
|
222
|
+
end
|
223
|
+
end
|
298
224
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
225
|
+
test "#validates_length_of (:too_long) and a custom message" do
|
226
|
+
expect_error_added(@topic, :title, :too_long, :default => 'custom', :count => 5) do
|
227
|
+
Topic.validates_length_of :title, :within => 3..5, :too_long => 'custom'
|
228
|
+
@topic.title = 'this title is too long'
|
229
|
+
end
|
304
230
|
end
|
305
231
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
232
|
+
test "#validates_length_of (:too_long) finds the correct message translations" do
|
233
|
+
assert_message_translations(@topic, :title, :too_long) do
|
234
|
+
Topic.validates_length_of :title, :within => 3..5
|
235
|
+
@topic.title = 'this title is too long'
|
236
|
+
end
|
311
237
|
end
|
312
238
|
|
313
|
-
#
|
239
|
+
# validates_length_of :is
|
314
240
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
241
|
+
test "#validates_length_of (:is) and no custom message" do
|
242
|
+
expect_error_added(@topic, :title, :wrong_length, :default => nil, :count => 5) do
|
243
|
+
Topic.validates_length_of :title, :is => 5
|
244
|
+
@topic.title = 'this title has the wrong length'
|
245
|
+
end
|
320
246
|
end
|
321
247
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
248
|
+
test "#validates_length_of (:is) and a custom message" do
|
249
|
+
expect_error_added(@topic, :title, :wrong_length, :default => 'custom', :count => 5) do
|
250
|
+
Topic.validates_length_of :title, :is => 5, :wrong_length => 'custom'
|
251
|
+
@topic.title = 'this title has the wrong length'
|
252
|
+
end
|
327
253
|
end
|
328
254
|
|
329
|
-
#
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
@topic.errors.expects(:generate_message).with(:title, :exclusion, {:value => 'a', :default => nil})
|
335
|
-
@topic.valid?
|
255
|
+
test "#validates_length_of (:is) finds the correct message translations" do
|
256
|
+
assert_message_translations(@topic, :title, :wrong_length) do
|
257
|
+
Topic.validates_length_of :title, :is => 5
|
258
|
+
@topic.title = 'this title has the wrong length'
|
259
|
+
end
|
336
260
|
end
|
337
261
|
|
338
|
-
|
339
|
-
Topic.validates_exclusion_of :title, :in => %w(a b c), :message => 'custom'
|
340
|
-
@topic.title = 'a'
|
341
|
-
@topic.errors.expects(:generate_message).with(:title, :exclusion, {:value => 'a', :default => 'custom'})
|
342
|
-
@topic.valid?
|
343
|
-
end
|
262
|
+
# validates_uniqueness_of
|
344
263
|
|
345
|
-
#
|
264
|
+
test "#validates_uniqueness_of and no custom message" do
|
265
|
+
expect_error_added(@topic, :title, :taken, :default => nil, :value => 'unique!') do
|
266
|
+
Topic.validates_uniqueness_of :title
|
267
|
+
@topic.title = unique_topic.title
|
268
|
+
end
|
269
|
+
end
|
346
270
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
271
|
+
test "#validates_uniqueness_of and a custom message" do
|
272
|
+
expect_error_added(@topic, :title, :taken, :default => 'custom', :value => 'unique!') do
|
273
|
+
Topic.validates_uniqueness_of :title, :message => 'custom'
|
274
|
+
@topic.title = unique_topic.title
|
275
|
+
end
|
352
276
|
end
|
353
277
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
278
|
+
test "#validates_uniqueness_of finds the correct message translations" do
|
279
|
+
assert_message_translations(@topic, :title, :taken) do
|
280
|
+
Topic.validates_uniqueness_of :title
|
281
|
+
@topic.title = unique_topic.title
|
282
|
+
end
|
359
283
|
end
|
360
284
|
|
361
|
-
#
|
285
|
+
# validates_format_of
|
362
286
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
287
|
+
test "#validates_format_of and no custom message" do
|
288
|
+
expect_error_added(@topic, :title, :invalid, :default => nil, :value => '72x') do
|
289
|
+
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
|
290
|
+
@topic.title = '72x'
|
291
|
+
end
|
368
292
|
end
|
369
293
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
294
|
+
test "#validates_format_of and a custom message" do
|
295
|
+
expect_error_added(@topic, :title, :invalid, :default => 'custom', :value => '72x') do
|
296
|
+
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/, :message => 'custom'
|
297
|
+
@topic.title = '72x'
|
298
|
+
end
|
375
299
|
end
|
376
300
|
|
377
|
-
#
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
@topic.errors.expects(:generate_message).with(:title, :odd, {:value => 0, :default => nil})
|
383
|
-
@topic.valid?
|
301
|
+
test "#validates_format_of finds the correct message translations" do
|
302
|
+
assert_message_translations(@topic, :title, :invalid) do
|
303
|
+
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
|
304
|
+
@topic.title = '72x'
|
305
|
+
end
|
384
306
|
end
|
385
307
|
|
386
|
-
|
387
|
-
Topic.validates_numericality_of :title, :only_integer => true, :odd => true, :message => 'custom'
|
388
|
-
@topic.title = 0
|
389
|
-
@topic.errors.expects(:generate_message).with(:title, :odd, {:value => 0, :default => 'custom'})
|
390
|
-
@topic.valid?
|
391
|
-
end
|
308
|
+
# validates_inclusion_of
|
392
309
|
|
393
|
-
#
|
310
|
+
test "#validates_inclusion_of and no custom message" do
|
311
|
+
list = %w(a b c)
|
312
|
+
expect_error_added(@topic, :title, :inclusion, :default => nil, :value => 'z') do
|
313
|
+
Topic.validates_inclusion_of :title, :in => list
|
314
|
+
@topic.title = 'z'
|
315
|
+
end
|
316
|
+
end
|
394
317
|
|
395
|
-
|
396
|
-
|
397
|
-
@topic
|
398
|
-
|
399
|
-
|
318
|
+
test "#validates_inclusion_of and a custom message" do
|
319
|
+
list = %w(a b c)
|
320
|
+
expect_error_added(@topic, :title, :inclusion, :default => 'custom', :value => 'z') do
|
321
|
+
Topic.validates_inclusion_of :title, :in => list, :message => 'custom'
|
322
|
+
@topic.title = 'z'
|
323
|
+
end
|
400
324
|
end
|
401
325
|
|
402
|
-
|
403
|
-
|
404
|
-
@topic
|
405
|
-
|
406
|
-
|
326
|
+
test "#validates_inclusion_of finds the correct message translations" do
|
327
|
+
list = %w(a b c)
|
328
|
+
assert_message_translations(@topic, :title, :inclusion) do
|
329
|
+
Topic.validates_inclusion_of :title, :in => list
|
330
|
+
@topic.title = 'z'
|
331
|
+
end
|
407
332
|
end
|
408
333
|
|
409
|
-
#
|
334
|
+
# validates_exclusion_of
|
410
335
|
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
336
|
+
test "#validates_exclusion_of and no custom message" do
|
337
|
+
list = %w(a b c)
|
338
|
+
expect_error_added(@topic, :title, :exclusion, :default => nil, :value => 'a') do
|
339
|
+
Topic.validates_exclusion_of :title, :in => list
|
340
|
+
@topic.title = 'a'
|
341
|
+
end
|
415
342
|
end
|
416
343
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
344
|
+
test "#validates_exclusion_of and a custom message" do
|
345
|
+
list = %w(a b c)
|
346
|
+
expect_error_added(@topic, :title, :exclusion, :default => 'custom', :value => 'a') do
|
347
|
+
Topic.validates_exclusion_of :title, :in => list, :message => 'custom'
|
348
|
+
@topic.title = 'a'
|
349
|
+
end
|
421
350
|
end
|
422
351
|
|
423
|
-
#
|
352
|
+
test "#validates_exclusion_of finds the correct message translations" do
|
353
|
+
list = %w(a b c)
|
354
|
+
assert_message_translations(@topic, :title, :exclusion) do
|
355
|
+
Topic.validates_exclusion_of :title, :in => list
|
356
|
+
@topic.title = 'a'
|
357
|
+
end
|
358
|
+
end
|
424
359
|
|
425
|
-
|
426
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:confirmation => 'custom message'}}}}}}
|
427
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}}
|
360
|
+
# validates_numericality_of :not_a_number, without :only_integer
|
428
361
|
|
429
|
-
|
430
|
-
@topic
|
431
|
-
|
432
|
-
|
362
|
+
test "#validates_numericality_of (:not_a_number, w/o :only_integer) no custom message" do
|
363
|
+
expect_error_added(@topic, :title, :not_a_number, :default => nil, :value => 'a') do
|
364
|
+
Topic.validates_numericality_of :title
|
365
|
+
@topic.title = 'a'
|
366
|
+
end
|
433
367
|
end
|
434
368
|
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
@topic.valid?
|
441
|
-
assert_equal 'global message', @topic.errors.on(:title)
|
369
|
+
test "#validates_numericality_of (:not_a_number, w/o :only_integer) and a custom message" do
|
370
|
+
expect_error_added(@topic, :title, :not_a_number, :default => 'custom', :value => 'a') do
|
371
|
+
Topic.validates_numericality_of :title, :message => 'custom'
|
372
|
+
@topic.title = 'a'
|
373
|
+
end
|
442
374
|
end
|
443
375
|
|
444
|
-
#
|
376
|
+
test "#validates_numericality_of (:not_a_number, w/o :only_integer) finds the correct message translations" do
|
377
|
+
assert_message_translations(@topic, :title, :not_a_number) do
|
378
|
+
Topic.validates_numericality_of :title
|
379
|
+
@topic.title = 'a'
|
380
|
+
end
|
381
|
+
end
|
445
382
|
|
446
|
-
|
447
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:accepted => 'custom message'}}}}}}
|
448
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}}
|
383
|
+
# validates_numericality_of :not_a_number, with :only_integer
|
449
384
|
|
450
|
-
|
451
|
-
@topic
|
452
|
-
|
385
|
+
test "#validates_numericality_of (:not_a_number, with :only_integer) no custom message" do
|
386
|
+
expect_error_added(@topic, :title, :not_a_number, :default => nil, :value => 'a') do
|
387
|
+
Topic.validates_numericality_of :title, :only_integer => true
|
388
|
+
@topic.title = 'a'
|
389
|
+
end
|
453
390
|
end
|
454
391
|
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
assert_equal 'global message', @topic.errors.on(:title)
|
392
|
+
test "#validates_numericality_of (:not_a_number, with :only_integer) and a custom message" do
|
393
|
+
expect_error_added(@topic, :title, :not_a_number, :default => 'custom', :value => 'a') do
|
394
|
+
Topic.validates_numericality_of :title, :only_integer => true, :message => 'custom'
|
395
|
+
@topic.title = 'a'
|
396
|
+
end
|
461
397
|
end
|
462
398
|
|
463
|
-
#
|
399
|
+
test "#validates_numericality_of (:not_a_number, with :only_integer) finds the correct message translations" do
|
400
|
+
assert_message_translations(@topic, :title, :not_a_number) do
|
401
|
+
Topic.validates_numericality_of :title, :only_integer => true
|
402
|
+
@topic.title = 'a'
|
403
|
+
end
|
404
|
+
end
|
464
405
|
|
465
|
-
|
466
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:blank => 'custom message'}}}}}}
|
467
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:blank => 'global message'}}}
|
406
|
+
# validates_numericality_of :odd
|
468
407
|
|
469
|
-
|
470
|
-
@topic
|
471
|
-
|
408
|
+
test "#validates_numericality_of (:odd) no custom message" do
|
409
|
+
expect_error_added(@topic, :title, :odd, :default => nil, :value => 0) do
|
410
|
+
Topic.validates_numericality_of :title, :only_integer => true, :odd => true
|
411
|
+
@topic.title = 0
|
412
|
+
end
|
472
413
|
end
|
473
414
|
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
assert_equal 'global message', @topic.errors.on(:title)
|
415
|
+
test "#validates_numericality_of (:odd) and a custom message" do
|
416
|
+
expect_error_added(@topic, :title, :odd, :default => 'custom', :value => 0) do
|
417
|
+
Topic.validates_numericality_of :title, :only_integer => true, :odd => true, :message => 'custom'
|
418
|
+
@topic.title = 0
|
419
|
+
end
|
480
420
|
end
|
481
421
|
|
482
|
-
#
|
422
|
+
test "#validates_numericality_of (:odd) finds the correct message translations" do
|
423
|
+
assert_message_translations(@topic, :title, :odd) do
|
424
|
+
Topic.validates_numericality_of :title, :only_integer => true, :odd => true
|
425
|
+
@topic.title = 0
|
426
|
+
end
|
427
|
+
end
|
483
428
|
|
484
|
-
|
485
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:too_short => 'custom message'}}}}}}
|
486
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}}
|
429
|
+
# validates_numericality_of :even
|
487
430
|
|
488
|
-
|
489
|
-
@topic
|
490
|
-
|
431
|
+
test "#validates_numericality_of (:even) no custom message" do
|
432
|
+
expect_error_added(@topic, :title, :even, :default => nil, :value => 1) do
|
433
|
+
Topic.validates_numericality_of :title, :only_integer => true, :even => true
|
434
|
+
@topic.title = 1
|
435
|
+
end
|
491
436
|
end
|
492
437
|
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
assert_equal 'global message', @topic.errors.on(:title)
|
438
|
+
test "#validates_numericality_of (:even) and a custom message" do
|
439
|
+
expect_error_added(@topic, :title, :even, :default => 'custom', :value => 1) do
|
440
|
+
Topic.validates_numericality_of :title, :only_integer => true, :even => true, :message => 'custom'
|
441
|
+
@topic.title = 1
|
442
|
+
end
|
499
443
|
end
|
500
444
|
|
501
|
-
#
|
445
|
+
test "#validates_numericality_of (:even) finds the correct message translations" do
|
446
|
+
assert_message_translations(@topic, :title, :even) do
|
447
|
+
Topic.validates_numericality_of :title, :only_integer => true, :even => true
|
448
|
+
@topic.title = 1
|
449
|
+
end
|
450
|
+
end
|
502
451
|
|
503
|
-
|
504
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
|
505
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
|
452
|
+
# validates_numericality_of :less_than
|
506
453
|
|
507
|
-
|
508
|
-
@topic
|
509
|
-
|
454
|
+
test "#validates_numericality_of (:less_than) no custom message" do
|
455
|
+
expect_error_added(@topic, :title, :less_than, :default => nil, :value => 1, :count => 0) do
|
456
|
+
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
|
457
|
+
@topic.title = 1
|
458
|
+
end
|
510
459
|
end
|
511
460
|
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
assert_equal 'global message', @topic.errors.on(:title)
|
461
|
+
test "#validates_numericality_of (:less_than) and a custom message" do
|
462
|
+
expect_error_added(@topic, :title, :less_than, :default => 'custom', :value => 1, :count => 0) do
|
463
|
+
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0, :message => 'custom'
|
464
|
+
@topic.title = 1
|
465
|
+
end
|
518
466
|
end
|
519
467
|
|
520
|
-
#
|
468
|
+
test "#validates_numericality_of (:less_than) finds the correct message translations" do
|
469
|
+
assert_message_translations(@topic, :title, :less_than) do
|
470
|
+
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
|
471
|
+
@topic.title = 1
|
472
|
+
end
|
473
|
+
end
|
521
474
|
|
522
|
-
|
523
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
|
524
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
|
475
|
+
# validates_associated
|
525
476
|
|
526
|
-
|
527
|
-
|
528
|
-
|
477
|
+
test "#validates_associated no custom message" do
|
478
|
+
expect_error_added(replied_topic, :replies, :invalid, :default => nil, :value => replied_topic.replies) do
|
479
|
+
Topic.validates_associated :replies
|
480
|
+
end
|
529
481
|
end
|
530
482
|
|
531
|
-
|
532
|
-
|
483
|
+
test "#validates_associated and a custom message" do
|
484
|
+
expect_error_added(replied_topic, :replies, :invalid, :default => 'custom', :value => replied_topic.replies) do
|
485
|
+
Topic.validates_associated :replies, :message => 'custom'
|
486
|
+
end
|
487
|
+
end
|
533
488
|
|
534
|
-
|
535
|
-
|
536
|
-
|
489
|
+
test "#validates_associated finds the correct message translations" do
|
490
|
+
assert_message_translations(replied_topic, :replies, :invalid) do
|
491
|
+
Topic.validates_associated :replies
|
492
|
+
end
|
537
493
|
end
|
494
|
+
end
|
538
495
|
|
539
496
|
|
540
|
-
|
497
|
+
# ACTIVERECORD ERROR
|
498
|
+
#
|
499
|
+
# * test that it passes given interpolation arguments, the human model name and human attribute name
|
500
|
+
# * test that it looks messages up with the the correct keys
|
501
|
+
# * test that it looks up the correct default messages
|
541
502
|
|
542
|
-
|
543
|
-
|
544
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
|
503
|
+
class ActiveRecordErrorI18nTests < ActiveSupport::TestCase
|
504
|
+
include ActiveRecordValidationsI18nTestHelper
|
545
505
|
|
546
|
-
|
547
|
-
@
|
548
|
-
|
506
|
+
def setup
|
507
|
+
@reply = Reply.new
|
508
|
+
@old_backend, I18n.backend = I18n.backend, I18n::Backend::Simple.new
|
549
509
|
end
|
550
510
|
|
551
|
-
def
|
552
|
-
I18n.backend
|
553
|
-
|
554
|
-
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
|
555
|
-
@topic.valid?
|
556
|
-
assert_equal 'global message', @topic.errors.on(:title)
|
511
|
+
def teardown
|
512
|
+
I18n.backend = @old_backend
|
513
|
+
I18n.locale = nil
|
557
514
|
end
|
558
515
|
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:title => {:inclusion => 'custom message'}}}}}}
|
563
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}}
|
516
|
+
def assert_error_message(message, *args)
|
517
|
+
assert_equal message, ActiveRecord::Error.new(@reply, *args).message
|
518
|
+
end
|
564
519
|
|
565
|
-
|
566
|
-
@
|
567
|
-
assert_equal 'custom message', @topic.errors.on(:title)
|
520
|
+
def assert_full_message(message, *args)
|
521
|
+
assert_equal message, ActiveRecord::Error.new(@reply, *args).full_message
|
568
522
|
end
|
569
523
|
|
570
|
-
|
571
|
-
|
524
|
+
test "#generate_message passes the model attribute value for interpolation" do
|
525
|
+
store_translations(:errors => { :messages => { :foo => "You fooed: {{value}}." } })
|
526
|
+
@reply.title = "da title"
|
527
|
+
assert_error_message 'You fooed: da title.', :title, :foo
|
528
|
+
end
|
572
529
|
|
573
|
-
|
574
|
-
|
575
|
-
|
530
|
+
test "#generate_message passes the human_name of the model for interpolation" do
|
531
|
+
store_translations(
|
532
|
+
:errors => { :messages => { :foo => "You fooed: {{model}}." } },
|
533
|
+
:models => { :topic => 'da topic' }
|
534
|
+
)
|
535
|
+
assert_error_message 'You fooed: da topic.', :title, :foo
|
576
536
|
end
|
577
537
|
|
578
|
-
#
|
538
|
+
test "#generate_message passes the human_name of the attribute for interpolation" do
|
539
|
+
store_translations(
|
540
|
+
:errors => { :messages => { :foo => "You fooed: {{attribute}}." } },
|
541
|
+
:attributes => { :topic => { :title => 'da topic title' } }
|
542
|
+
)
|
543
|
+
assert_error_message 'You fooed: da topic title.', :title, :foo
|
544
|
+
end
|
579
545
|
|
580
|
-
|
581
|
-
|
582
|
-
|
546
|
+
# generate_message will look up the key for the error message (e.g. :blank) in these namespaces:
|
547
|
+
#
|
548
|
+
# activerecord.errors.models.reply.attributes.title
|
549
|
+
# activerecord.errors.models.reply
|
550
|
+
# activerecord.errors.models.topic.attributes.title
|
551
|
+
# activerecord.errors.models.topic
|
552
|
+
# [default from class level :validates_foo statement if this is a String]
|
553
|
+
# activerecord.errors.messages
|
583
554
|
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
555
|
+
test "#generate_message key fallbacks (given a String as key)" do
|
556
|
+
store_translations(
|
557
|
+
:errors => {
|
558
|
+
:models => {
|
559
|
+
:reply => {
|
560
|
+
:attributes => { :title => { :custom => 'activerecord.errors.models.reply.attributes.title.custom' } },
|
561
|
+
:custom => 'activerecord.errors.models.reply.custom'
|
562
|
+
},
|
563
|
+
:topic => {
|
564
|
+
:attributes => { :title => { :custom => 'activerecord.errors.models.topic.attributes.title.custom' } },
|
565
|
+
:custom => 'activerecord.errors.models.topic.custom'
|
566
|
+
}
|
567
|
+
},
|
568
|
+
:messages => {
|
569
|
+
:custom => 'activerecord.errors.messages.custom',
|
570
|
+
:kaputt => 'activerecord.errors.messages.kaputt'
|
571
|
+
}
|
572
|
+
}
|
573
|
+
)
|
589
574
|
|
590
|
-
|
591
|
-
|
575
|
+
assert_error_message 'activerecord.errors.models.reply.attributes.title.custom', :title, :kaputt, :message => 'custom'
|
576
|
+
delete_translation :'activerecord.errors.models.reply.attributes.title.custom'
|
592
577
|
|
593
|
-
|
594
|
-
|
595
|
-
@topic.valid?
|
596
|
-
assert_equal 'global message', @topic.errors.on(:title)
|
597
|
-
end
|
578
|
+
assert_error_message 'activerecord.errors.models.reply.custom', :title, :kaputt, :message => 'custom'
|
579
|
+
delete_translation :'activerecord.errors.models.reply.custom'
|
598
580
|
|
599
|
-
|
581
|
+
assert_error_message 'activerecord.errors.models.topic.attributes.title.custom', :title, :kaputt, :message => 'custom'
|
582
|
+
delete_translation :'activerecord.errors.models.topic.attributes.title.custom'
|
600
583
|
|
601
|
-
|
602
|
-
|
603
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
|
584
|
+
assert_error_message 'activerecord.errors.models.topic.custom', :title, :kaputt, :message => 'custom'
|
585
|
+
delete_translation :'activerecord.errors.models.topic.custom'
|
604
586
|
|
605
|
-
|
606
|
-
|
607
|
-
@topic.valid?
|
608
|
-
assert_equal 'custom message', @topic.errors.on(:title)
|
609
|
-
end
|
587
|
+
assert_error_message 'activerecord.errors.messages.custom', :title, :kaputt, :message => 'custom'
|
588
|
+
delete_translation :'activerecord.errors.messages.custom'
|
610
589
|
|
611
|
-
|
612
|
-
|
590
|
+
# Implementing this would clash with the AR default behaviour of using validates_foo :message => 'foo'
|
591
|
+
# as an untranslated string. I.e. at this point we can either fall back to the given string from the
|
592
|
+
# class-level macro (validates_*) or fall back to the default message for this validation type.
|
593
|
+
# assert_error_message 'activerecord.errors.messages.kaputt', :title, :kaputt, :message => 'custom'
|
613
594
|
|
614
|
-
|
615
|
-
@topic.title = 'a'
|
616
|
-
@topic.valid?
|
617
|
-
assert_equal 'global message', @topic.errors.on(:title)
|
595
|
+
assert_error_message 'custom', :title, :kaputt, :message => 'custom'
|
618
596
|
end
|
619
597
|
|
620
|
-
#
|
598
|
+
test "#generate_message key fallbacks (given a Symbol as key)" do
|
599
|
+
store_translations(
|
600
|
+
:errors => {
|
601
|
+
:models => {
|
602
|
+
:reply => {
|
603
|
+
:attributes => { :title => { :kaputt => 'activerecord.errors.models.reply.attributes.title.kaputt' } },
|
604
|
+
:kaputt => 'activerecord.errors.models.reply.kaputt'
|
605
|
+
},
|
606
|
+
:topic => {
|
607
|
+
:attributes => { :title => { :kaputt => 'activerecord.errors.models.topic.attributes.title.kaputt' } },
|
608
|
+
:kaputt => 'activerecord.errors.models.topic.kaputt'
|
609
|
+
}
|
610
|
+
},
|
611
|
+
:messages => {
|
612
|
+
:kaputt => 'activerecord.errors.messages.kaputt'
|
613
|
+
}
|
614
|
+
}
|
615
|
+
)
|
616
|
+
|
617
|
+
assert_error_message 'activerecord.errors.models.reply.attributes.title.kaputt', :title, :kaputt
|
618
|
+
delete_translation :'activerecord.errors.models.reply.attributes.title.kaputt'
|
621
619
|
|
622
|
-
|
623
|
-
|
624
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
|
620
|
+
assert_error_message 'activerecord.errors.models.reply.kaputt', :title, :kaputt
|
621
|
+
delete_translation :'activerecord.errors.models.reply.kaputt'
|
625
622
|
|
626
|
-
|
627
|
-
|
628
|
-
@topic.valid?
|
629
|
-
assert_equal 'custom message', @topic.errors.on(:title)
|
630
|
-
end
|
623
|
+
assert_error_message 'activerecord.errors.models.topic.attributes.title.kaputt', :title, :kaputt
|
624
|
+
delete_translation :'activerecord.errors.models.topic.attributes.title.kaputt'
|
631
625
|
|
632
|
-
|
633
|
-
|
626
|
+
assert_error_message 'activerecord.errors.models.topic.kaputt', :title, :kaputt
|
627
|
+
delete_translation :'activerecord.errors.models.topic.kaputt'
|
634
628
|
|
635
|
-
|
636
|
-
@topic.title = 'a'
|
637
|
-
@topic.valid?
|
638
|
-
assert_equal 'global message', @topic.errors.on(:title)
|
629
|
+
assert_error_message 'activerecord.errors.messages.kaputt', :title, :kaputt
|
639
630
|
end
|
640
631
|
|
641
|
-
#
|
632
|
+
# full_messages
|
642
633
|
|
643
|
-
|
644
|
-
|
645
|
-
|
634
|
+
test "#full_message with no format present" do
|
635
|
+
store_translations(:errors => { :messages => { :kaputt => 'is kaputt' } })
|
636
|
+
assert_full_message 'Title is kaputt', :title, :kaputt
|
637
|
+
end
|
646
638
|
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
assert_equal 'custom message', @topic.errors.on(:title)
|
639
|
+
test "#full_message with a format present" do
|
640
|
+
store_translations(:errors => { :messages => { :kaputt => 'is kaputt' }, :full_messages => { :format => '{{attribute}}: {{message}}' } })
|
641
|
+
assert_full_message 'Title: is kaputt', :title, :kaputt
|
651
642
|
end
|
652
643
|
|
653
|
-
|
654
|
-
|
644
|
+
test "#full_message with a type specific format present" do
|
645
|
+
store_translations(:errors => { :messages => { :kaputt => 'is kaputt' }, :full_messages => { :kaputt => '{{attribute}} {{message}}!' } })
|
646
|
+
assert_full_message 'Title is kaputt!', :title, :kaputt
|
647
|
+
end
|
655
648
|
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
assert_equal 'global message', @topic.errors.on(:title)
|
649
|
+
test "#full_message with class-level specified custom message" do
|
650
|
+
store_translations(:errors => { :messages => { :broken => 'is kaputt' }, :full_messages => { :broken => '{{attribute}} {{message}}?!' } })
|
651
|
+
assert_full_message 'Title is kaputt?!', :title, :kaputt, :message => :broken
|
660
652
|
end
|
661
653
|
|
662
|
-
#
|
654
|
+
# switch locales
|
663
655
|
|
664
|
-
|
665
|
-
|
666
|
-
|
656
|
+
test "#message allows to switch locales" do
|
657
|
+
store_translations(:en, :errors => { :messages => { :kaputt => 'is kaputt' } })
|
658
|
+
store_translations(:de, :errors => { :messages => { :kaputt => 'ist kaputt' } })
|
667
659
|
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
660
|
+
assert_error_message 'is kaputt', :title, :kaputt
|
661
|
+
I18n.locale = :de
|
662
|
+
assert_error_message 'ist kaputt', :title, :kaputt
|
663
|
+
I18n.locale = :en
|
664
|
+
assert_error_message 'is kaputt', :title, :kaputt
|
672
665
|
end
|
673
666
|
|
674
|
-
|
675
|
-
|
667
|
+
test "#full_message allows to switch locales" do
|
668
|
+
store_translations(:en, :errors => { :messages => { :kaputt => 'is kaputt' } }, :attributes => { :topic => { :title => 'The title' } })
|
669
|
+
store_translations(:de, :errors => { :messages => { :kaputt => 'ist kaputt' } }, :attributes => { :topic => { :title => 'Der Titel' } })
|
676
670
|
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
671
|
+
assert_full_message 'The title is kaputt', :title, :kaputt
|
672
|
+
I18n.locale = :de
|
673
|
+
assert_full_message 'Der Titel ist kaputt', :title, :kaputt
|
674
|
+
I18n.locale = :en
|
675
|
+
assert_full_message 'The title is kaputt', :title, :kaputt
|
681
676
|
end
|
677
|
+
end
|
682
678
|
|
679
|
+
# ACTIVERECORD DEFAULT ERROR MESSAGES
|
680
|
+
#
|
681
|
+
# * test that Error generates the default error messages
|
683
682
|
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:models => {:topic => {:attributes => {:replies => {:invalid => 'custom message'}}}}}}
|
688
|
-
I18n.backend.store_translations 'en', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
|
689
|
-
|
690
|
-
Topic.validates_associated :replies
|
691
|
-
replied_topic.valid?
|
692
|
-
assert_equal 'custom message', replied_topic.errors.on(:replies)
|
683
|
+
class ActiveRecordDefaultErrorMessagesI18nTests < ActiveSupport::TestCase
|
684
|
+
def assert_default_error_message(message, *args)
|
685
|
+
assert_equal message, error_message(*args)
|
693
686
|
end
|
694
687
|
|
695
|
-
def
|
696
|
-
|
688
|
+
def error_message(*args)
|
689
|
+
ActiveRecord::Error.new(Topic.new, :title, *args).message
|
690
|
+
end
|
697
691
|
|
698
|
-
|
699
|
-
|
700
|
-
|
692
|
+
# used by: validates_inclusion_of
|
693
|
+
test "default error message: inclusion" do
|
694
|
+
assert_default_error_message 'is not included in the list', :inclusion, :value => 'title'
|
701
695
|
end
|
702
696
|
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
@topic.title = nil
|
707
|
-
@topic.valid?
|
708
|
-
assert_equal "I am a custom error", @topic.errors.on(:title)
|
697
|
+
# used by: validates_exclusion_of
|
698
|
+
test "default error message: exclusion" do
|
699
|
+
assert_default_error_message 'is reserved', :exclusion, :value => 'title'
|
709
700
|
end
|
710
701
|
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
@topic.title = nil
|
715
|
-
@topic.valid?
|
716
|
-
assert_equal "I am a custom error", @topic.errors.on(:title)
|
702
|
+
# used by: validates_associated and validates_format_of
|
703
|
+
test "default error message: invalid" do
|
704
|
+
assert_default_error_message 'is invalid', :invalid, :value => 'title'
|
717
705
|
end
|
718
706
|
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
@topic.title = nil
|
723
|
-
@topic.valid?
|
724
|
-
assert_equal "I am a custom error", @topic.errors.on(:title)
|
707
|
+
# used by: validates_confirmation_of
|
708
|
+
test "default error message: confirmation" do
|
709
|
+
assert_default_error_message "doesn't match confirmation", :confirmation, :default => nil
|
725
710
|
end
|
726
711
|
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
@topic.valid?
|
731
|
-
assert_equal "I am a custom error", @topic.errors.on(:title)
|
712
|
+
# used by: validates_acceptance_of
|
713
|
+
test "default error message: accepted" do
|
714
|
+
assert_default_error_message "must be accepted", :accepted
|
732
715
|
end
|
733
716
|
|
734
|
-
|
717
|
+
# used by: add_on_empty
|
718
|
+
test "default error message: empty" do
|
719
|
+
assert_default_error_message "can't be empty", :empty
|
720
|
+
end
|
735
721
|
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
@topic = Topic.new
|
740
|
-
I18n.backend.store_translations :'en', {
|
741
|
-
:activerecord => {
|
742
|
-
:errors => {
|
743
|
-
:messages => {
|
744
|
-
:inclusion => "is not included in the list",
|
745
|
-
:exclusion => "is reserved",
|
746
|
-
:invalid => "is invalid",
|
747
|
-
:confirmation => "doesn't match confirmation",
|
748
|
-
:accepted => "must be accepted",
|
749
|
-
:empty => "can't be empty",
|
750
|
-
:blank => "can't be blank",
|
751
|
-
:too_long => "is too long (maximum is {{count}} characters)",
|
752
|
-
:too_short => "is too short (minimum is {{count}} characters)",
|
753
|
-
:wrong_length => "is the wrong length (should be {{count}} characters)",
|
754
|
-
:taken => "has already been taken",
|
755
|
-
:not_a_number => "is not a number",
|
756
|
-
:greater_than => "must be greater than {{count}}",
|
757
|
-
:greater_than_or_equal_to => "must be greater than or equal to {{count}}",
|
758
|
-
:equal_to => "must be equal to {{count}}",
|
759
|
-
:less_than => "must be less than {{count}}",
|
760
|
-
:less_than_or_equal_to => "must be less than or equal to {{count}}",
|
761
|
-
:odd => "must be odd",
|
762
|
-
:even => "must be even"
|
763
|
-
}
|
764
|
-
}
|
765
|
-
}
|
766
|
-
}
|
722
|
+
# used by: add_on_blank
|
723
|
+
test "default error message: blank" do
|
724
|
+
assert_default_error_message "can't be blank", :blank
|
767
725
|
end
|
768
726
|
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
model.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
773
|
-
model.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
|
774
|
-
end
|
727
|
+
# used by: validates_length_of
|
728
|
+
test "default error message: too_long" do
|
729
|
+
assert_default_error_message "is too long (maximum is 10 characters)", :too_long, :count => 10
|
775
730
|
end
|
776
731
|
|
777
|
-
#
|
778
|
-
|
779
|
-
|
732
|
+
# used by: validates_length_of
|
733
|
+
test "default error message: too_short" do
|
734
|
+
assert_default_error_message "is too short (minimum is 10 characters)", :too_short, :count => 10
|
780
735
|
end
|
781
736
|
|
782
|
-
|
783
|
-
|
737
|
+
# used by: validates_length_of
|
738
|
+
test "default error message: wrong_length" do
|
739
|
+
assert_default_error_message "is the wrong length (should be 10 characters)", :wrong_length, :count => 10
|
784
740
|
end
|
785
741
|
|
786
|
-
#
|
787
|
-
|
788
|
-
|
742
|
+
# used by: validates_uniqueness_of
|
743
|
+
test "default error message: taken" do
|
744
|
+
assert_default_error_message "has already been taken", :taken, :value => 'title'
|
789
745
|
end
|
790
746
|
|
791
|
-
|
792
|
-
|
747
|
+
# used by: validates_numericality_of
|
748
|
+
test "default error message: not_a_number" do
|
749
|
+
assert_default_error_message "is not a number", :not_a_number, :value => 'title'
|
793
750
|
end
|
794
751
|
|
795
|
-
#
|
796
|
-
|
797
|
-
|
798
|
-
assert_equal 'is invalid', @topic.errors.generate_message(:title, :invalid, :default => nil, :value => 'title')
|
752
|
+
# used by: validates_numericality_of
|
753
|
+
test "default error message: greater_than" do
|
754
|
+
assert_default_error_message "must be greater than 10", :greater_than, :value => 'title', :count => 10
|
799
755
|
end
|
800
756
|
|
801
|
-
|
802
|
-
|
757
|
+
# used by: validates_numericality_of
|
758
|
+
test "default error message: greater_than_or_equal_to" do
|
759
|
+
assert_default_error_message "must be greater than or equal to 10", :greater_than_or_equal_to, :value => 'title', :count => 10
|
803
760
|
end
|
804
761
|
|
805
|
-
#
|
806
|
-
|
807
|
-
|
762
|
+
# used by: validates_numericality_of
|
763
|
+
test "default error message: equal_to" do
|
764
|
+
assert_default_error_message "must be equal to 10", :equal_to, :value => 'title', :count => 10
|
808
765
|
end
|
809
766
|
|
810
|
-
|
811
|
-
|
767
|
+
# used by: validates_numericality_of
|
768
|
+
test "default error message: less_than" do
|
769
|
+
assert_default_error_message "must be less than 10", :less_than, :value => 'title', :count => 10
|
812
770
|
end
|
813
771
|
|
814
|
-
#
|
815
|
-
|
816
|
-
|
772
|
+
# used by: validates_numericality_of
|
773
|
+
test "default error message: less_than_or_equal_to" do
|
774
|
+
assert_default_error_message "must be less than or equal to 10", :less_than_or_equal_to, :value => 'title', :count => 10
|
817
775
|
end
|
818
776
|
|
819
|
-
|
820
|
-
|
777
|
+
# used by: validates_numericality_of
|
778
|
+
test "default error message: odd" do
|
779
|
+
assert_default_error_message "must be odd", :odd, :value => 'title', :count => 10
|
821
780
|
end
|
822
781
|
|
823
|
-
#
|
824
|
-
|
825
|
-
|
782
|
+
# used by: validates_numericality_of
|
783
|
+
test "default error message: even" do
|
784
|
+
assert_default_error_message "must be even", :even, :value => 'title', :count => 10
|
826
785
|
end
|
827
786
|
|
828
|
-
|
829
|
-
assert_equal 'custom message',
|
787
|
+
test "custom message string interpolation" do
|
788
|
+
assert_equal 'custom message title', error_message(:invalid, :default => 'custom message {{value}}', :value => 'title')
|
830
789
|
end
|
790
|
+
end
|
791
|
+
|
792
|
+
# ACTIVERECORD VALIDATION ERROR MESSAGES - FULL STACK
|
793
|
+
#
|
794
|
+
# * test a few combinations full stack to ensure the tests above are correct
|
831
795
|
|
832
|
-
|
833
|
-
|
834
|
-
|
796
|
+
class I18nPerson < Person
|
797
|
+
end
|
798
|
+
|
799
|
+
class ActiveRecordValidationsI18nFullStackTests < ActiveSupport::TestCase
|
800
|
+
include ActiveRecordValidationsI18nTestHelper
|
801
|
+
|
802
|
+
def setup
|
803
|
+
reset_callbacks(I18nPerson)
|
804
|
+
@old_backend, I18n.backend = I18n.backend, I18n::Backend::Simple.new
|
805
|
+
@person = I18nPerson.new
|
835
806
|
end
|
836
807
|
|
837
|
-
def
|
838
|
-
|
808
|
+
def teardown
|
809
|
+
reset_callbacks(I18nPerson)
|
810
|
+
I18n.backend = @old_backend
|
839
811
|
end
|
840
812
|
|
841
|
-
|
842
|
-
|
843
|
-
|
813
|
+
def assert_name_invalid(message)
|
814
|
+
yield
|
815
|
+
@person.valid?
|
816
|
+
assert_equal message, @person.errors.on(:name)
|
844
817
|
end
|
845
818
|
|
846
|
-
|
847
|
-
|
819
|
+
# Symbols as class-level validation messages
|
820
|
+
|
821
|
+
test "Symbol as class level validation message translated per attribute (translation on child class)" do
|
822
|
+
assert_name_invalid("is broken") do
|
823
|
+
store_translations :errors => {:models => {:i18n_person => {:attributes => {:name => {:broken => "is broken"}}}}}
|
824
|
+
I18nPerson.validates_presence_of :name, :message => :broken
|
825
|
+
end
|
848
826
|
end
|
849
827
|
|
850
|
-
|
851
|
-
|
852
|
-
|
828
|
+
test "Symbol as class level validation message translated per attribute (translation on base class)" do
|
829
|
+
assert_name_invalid("is broken") do
|
830
|
+
store_translations :errors => {:models => {:person => {:attributes => {:name => {:broken => "is broken"}}}}}
|
831
|
+
I18nPerson.validates_presence_of :name, :message => :broken
|
832
|
+
end
|
853
833
|
end
|
854
834
|
|
855
|
-
|
856
|
-
|
835
|
+
test "Symbol as class level validation message translated per model (translation on child class)" do
|
836
|
+
assert_name_invalid("is broken") do
|
837
|
+
store_translations :errors => {:models => {:i18n_person => {:broken => "is broken"}}}
|
838
|
+
I18nPerson.validates_presence_of :name, :message => :broken
|
839
|
+
end
|
857
840
|
end
|
858
841
|
|
859
|
-
|
860
|
-
|
861
|
-
|
842
|
+
test "Symbol as class level validation message translated per model (translation on base class)" do
|
843
|
+
assert_name_invalid("is broken") do
|
844
|
+
store_translations :errors => {:models => {:person => {:broken => "is broken"}}}
|
845
|
+
I18nPerson.validates_presence_of :name, :message => :broken
|
846
|
+
end
|
862
847
|
end
|
863
848
|
|
864
|
-
|
865
|
-
|
849
|
+
test "Symbol as class level validation message translated as error message" do
|
850
|
+
assert_name_invalid("is broken") do
|
851
|
+
store_translations :errors => {:messages => {:broken => "is broken"}}
|
852
|
+
I18nPerson.validates_presence_of :name, :message => :broken
|
853
|
+
end
|
866
854
|
end
|
867
855
|
|
868
|
-
#
|
869
|
-
|
870
|
-
|
856
|
+
# Strings as class-level validation messages
|
857
|
+
|
858
|
+
test "String as class level validation message translated per attribute (translation on child class)" do
|
859
|
+
assert_name_invalid("is broken") do
|
860
|
+
store_translations :errors => {:models => {:i18n_person => {:attributes => {:name => {"is broken" => "is broken"}}}}}
|
861
|
+
I18nPerson.validates_presence_of :name, :message => "is broken"
|
862
|
+
end
|
871
863
|
end
|
872
864
|
|
873
|
-
|
874
|
-
|
865
|
+
test "String as class level validation message translated per attribute (translation on base class)" do
|
866
|
+
assert_name_invalid("is broken") do
|
867
|
+
store_translations :errors => {:models => {:person => {:attributes => {:name => {"is broken" => "is broken"}}}}}
|
868
|
+
I18nPerson.validates_presence_of :name, :message => "is broken"
|
869
|
+
end
|
875
870
|
end
|
876
871
|
|
877
|
-
|
878
|
-
|
879
|
-
|
872
|
+
test "String as class level validation message translated per model (translation on child class)" do
|
873
|
+
assert_name_invalid("is broken") do
|
874
|
+
store_translations :errors => {:models => {:i18n_person => {"is broken" => "is broken"}}}
|
875
|
+
I18nPerson.validates_presence_of :name, :message => "is broken"
|
876
|
+
end
|
880
877
|
end
|
881
878
|
|
882
|
-
|
883
|
-
|
879
|
+
test "String as class level validation message translated per model (translation on base class)" do
|
880
|
+
assert_name_invalid("is broken") do
|
881
|
+
store_translations :errors => {:models => {:person => {"is broken" => "is broken"}}}
|
882
|
+
I18nPerson.validates_presence_of :name, :message => "is broken"
|
883
|
+
end
|
884
884
|
end
|
885
885
|
|
886
|
-
|
887
|
-
|
888
|
-
|
886
|
+
test "String as class level validation message translated as error message" do
|
887
|
+
assert_name_invalid("is broken") do
|
888
|
+
store_translations :errors => {:messages => {"is broken" => "is broken"}}
|
889
|
+
I18nPerson.validates_presence_of :name, :message => "is broken"
|
890
|
+
end
|
889
891
|
end
|
890
892
|
|
891
|
-
|
892
|
-
|
893
|
+
test "String as class level validation message not translated (uses message as default)" do
|
894
|
+
assert_name_invalid("is broken!") do
|
895
|
+
I18nPerson.validates_presence_of :name, :message => "is broken!"
|
896
|
+
end
|
893
897
|
end
|
898
|
+
end
|
899
|
+
|
900
|
+
class ActiveRecordValidationsI18nFullMessagesFullStackTests < ActiveSupport::TestCase
|
901
|
+
include ActiveRecordValidationsI18nTestHelper
|
894
902
|
|
895
|
-
def
|
896
|
-
|
903
|
+
def setup
|
904
|
+
reset_callbacks(I18nPerson)
|
905
|
+
@old_backend, I18n.backend = I18n.backend, I18n::Backend::Simple.new
|
906
|
+
@person = I18nPerson.new
|
897
907
|
end
|
898
908
|
|
899
|
-
def
|
900
|
-
|
909
|
+
def teardown
|
910
|
+
reset_callbacks(I18nPerson)
|
911
|
+
I18n.backend = @old_backend
|
901
912
|
end
|
902
913
|
|
903
|
-
def
|
904
|
-
|
914
|
+
def assert_full_message(message)
|
915
|
+
yield
|
916
|
+
@person.valid?
|
917
|
+
assert_equal message, @person.errors.full_messages.join
|
905
918
|
end
|
906
919
|
|
907
|
-
|
908
|
-
|
920
|
+
test "full_message format stored per custom error message key" do
|
921
|
+
assert_full_message("Name is broken!") do
|
922
|
+
store_translations :errors => { :messages => { :broken => 'is broken' }, :full_messages => { :broken => '{{attribute}} {{message}}!' } }
|
923
|
+
I18nPerson.validates_presence_of :name, :message => :broken
|
924
|
+
end
|
909
925
|
end
|
910
926
|
|
911
|
-
|
912
|
-
|
927
|
+
test "full_message format stored per error type" do
|
928
|
+
assert_full_message("Name can't be blank!") do
|
929
|
+
store_translations :errors => { :full_messages => { :blank => '{{attribute}} {{message}}!' } }
|
930
|
+
I18nPerson.validates_presence_of :name
|
931
|
+
end
|
913
932
|
end
|
933
|
+
# ActiveRecord#RecordInvalid exception
|
914
934
|
|
935
|
+
test "full_message format stored as default" do
|
936
|
+
assert_full_message("Name: can't be blank") do
|
937
|
+
store_translations :errors => { :full_messages => { :format => '{{attribute}}: {{message}}' } }
|
938
|
+
I18nPerson.validates_presence_of :name
|
939
|
+
end
|
940
|
+
end
|
941
|
+
test "RecordInvalid exception can be localized" do
|
942
|
+
topic = Topic.new
|
943
|
+
topic.errors.add(:title, :invalid)
|
944
|
+
topic.errors.add(:title, :blank)
|
945
|
+
assert_equal "Validation failed: Title is invalid, Title can't be blank", ActiveRecord::RecordInvalid.new(topic).message
|
946
|
+
end
|
915
947
|
end
|