diff options
author | Christopher Dell <chris@tigrish.com> | 2012-03-05 18:06:37 +0100 |
---|---|---|
committer | Christopher Dell <chris@tigrish.com> | 2012-03-05 18:06:37 +0100 |
commit | 0eada113c30953f93cf7d7969b10cfd8a7e417ae (patch) | |
tree | 744faf3d507aea35e5723b362626ceb6f3dda0d1 /activerecord | |
parent | 4da6e1cce2833474034fda0cbb67b2cc35e828da (diff) | |
download | rails-0eada113c30953f93cf7d7969b10cfd8a7e417ae.tar.gz rails-0eada113c30953f93cf7d7969b10cfd8a7e417ae.tar.bz2 rails-0eada113c30953f93cf7d7969b10cfd8a7e417ae.zip |
Test that RecordInvalid exception's translation falls back to the :errors namespace
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/validations/i18n_generate_message_validation_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb index 628029f8df..136a336cec 100644 --- a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb +++ b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb @@ -8,6 +8,15 @@ class I18nGenerateMessageValidationTest < ActiveRecord::TestCase I18n.backend = I18n::Backend::Simple.new end + def reset_i18n_load_path(&block) + @old_load_path, @old_backend = I18n.load_path.dup, I18n.backend + I18n.load_path.clear + I18n.backend = I18n::Backend::Simple.new + yield + I18n.load_path.replace @old_load_path + I18n.backend = @old_backend + end + # validates_associated: generate_message(attr_name, :invalid, :message => custom_message, :value => value) def test_generate_message_invalid_with_default_message assert_equal 'is invalid', @topic.errors.generate_message(:title, :invalid, :value => 'title') @@ -35,4 +44,13 @@ class I18nGenerateMessageValidationTest < ActiveRecord::TestCase assert_equal "Validation failed: Title is invalid, Title can't be blank", ActiveRecord::RecordInvalid.new(topic).message end + test "RecordInvalid exception translation falls back to the :errors namespace" do + reset_i18n_load_path do + I18n.backend.store_translations 'en', :errors => {:messages => {:record_invalid => 'fallback message'}} + topic = Topic.new + topic.errors.add(:title, :blank) + assert_equal "fallback message", ActiveRecord::RecordInvalid.new(topic).message + end + end + end |