Skip to content
This repository
Browse code

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

…rors namespace
  • Loading branch information...
commit 0eada113c30953f93cf7d7969b10cfd8a7e417ae 1 parent 4da6e1c
Christopher Dell authored March 05, 2012
18  activerecord/test/cases/validations/i18n_generate_message_validation_test.rb
@@ -8,6 +8,15 @@ def setup
8 8
     I18n.backend = I18n::Backend::Simple.new
9 9
   end
10 10
 
  11
+  def reset_i18n_load_path(&block)
  12
+    @old_load_path, @old_backend = I18n.load_path.dup, I18n.backend
  13
+    I18n.load_path.clear
  14
+    I18n.backend = I18n::Backend::Simple.new
  15
+    yield
  16
+    I18n.load_path.replace @old_load_path
  17
+    I18n.backend = @old_backend
  18
+  end
  19
+
11 20
   # validates_associated: generate_message(attr_name, :invalid, :message => custom_message, :value => value)
12 21
   def test_generate_message_invalid_with_default_message
13 22
     assert_equal 'is invalid', @topic.errors.generate_message(:title, :invalid, :value => 'title')
@@ -35,4 +44,13 @@ def test_generate_message_taken_with_custom_message
35 44
     assert_equal "Validation failed: Title is invalid, Title can't be blank", ActiveRecord::RecordInvalid.new(topic).message
36 45
   end
37 46
 
  47
+  test "RecordInvalid exception translation falls back to the :errors namespace" do
  48
+    reset_i18n_load_path do
  49
+      I18n.backend.store_translations 'en', :errors => {:messages => {:record_invalid => 'fallback message'}}
  50
+      topic = Topic.new
  51
+      topic.errors.add(:title, :blank)
  52
+      assert_equal "fallback message", ActiveRecord::RecordInvalid.new(topic).message
  53
+    end
  54
+  end
  55
+
38 56
 end

0 notes on commit 0eada11

Please sign in to comment.
Something went wrong with that request. Please try again.