Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test that RecordInvalid exception's translation falls back to the :er…

…rors namespace
  • Loading branch information...
commit 0eada113c30953f93cf7d7969b10cfd8a7e417ae 1 parent 4da6e1c
@tigrish tigrish authored
View
18 activerecord/test/cases/validations/i18n_generate_message_validation_test.rb
@@ -8,6 +8,15 @@ def setup
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 @@ def test_generate_message_taken_with_custom_message
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
Please sign in to comment.
Something went wrong with that request. Please try again.