Permalink
Browse files

Merge pull request #12 from gregoriokusowski/master

New Fix for Issue #7. (Translation being replaced)
  • Loading branch information...
2 parents b87491c + da5ef5c commit be70b56949e3f445c4bb469e24dace55bd68bf23 Tanel Suurhans committed Jul 20, 2011
Showing with 48 additions and 3 deletions.
  1. +3 −1 lib/rails3.rb
  2. +20 −1 test/rails3/validates_existence_test.rb
  3. +20 −1 test/rails31/validates_existence_test.rb
  4. +5 −0 test/shared/locales/pt.yml
View
@@ -48,8 +48,10 @@ def validate_each(record, attribute, value)
errors << (attribute.to_s.ends_with?("_id") ? normalized : foreign_key)
end
+ messages = [:"#{record.class.i18n_scope}.errors.messages.existence", "does not exist"]
+
errors.each do |error|
- record.errors.add(error, options[:message], :message => "does not exist")
+ record.errors.add(error, options[:message], :message => messages)
end
end
end
@@ -91,6 +91,25 @@ def test_save_with_custom_fk
assert_not_nil user.errors[:custom_id]
end
-end
+ def test_message_without_i18n
+ I18n.locale = :en
+
+ user = User.new :name_id => 100
+ user.save
+
+ assert_equal ["does not exist"], user.errors[:name]
+ end
+
+ def test_message_with_i18n
+ I18n.load_path << File.expand_path("./test/shared/locales/pt.yml")
+ I18n.backend.send(:init_translations)
+ I18n.locale = :pt
+ user = User.new :name_id => 100
+ user.save
+
+ assert_equal ["inexistente"], user.errors[:name]
+ end
+
+end
@@ -91,6 +91,25 @@ def test_save_with_custom_fk
assert_not_nil user.errors[:custom_id]
end
-end
+ def test_message_without_i18n
+ I18n.locale = :en
+
+ user = User.new :name_id => 100
+ user.save
+
+ assert_equal ["does not exist"], user.errors[:name]
+ end
+
+ def test_message_with_i18n
+ I18n.load_path << File.expand_path("./test/shared/locales/pt.yml")
+ I18n.backend.send(:init_translations)
+ I18n.locale = :pt
+ user = User.new :name_id => 100
+ user.save
+
+ assert_equal ["inexistente"], user.errors[:name]
+ end
+
+end
@@ -0,0 +1,5 @@
+pt:
+ activerecord:
+ errors:
+ messages:
+ existence: "inexistente"

0 comments on commit be70b56

Please sign in to comment.