Permalink
Browse files

Internationalization of resource_name in DeviseHelper#devise_error_me…

…ssages!
  • Loading branch information...
1 parent c8077c8 commit e2895239d86f084df27ad2587329ab44b8e01947 @zedtux zedtux committed Jun 27, 2011
Showing with 42 additions and 1 deletion.
  1. +1 −1 app/helpers/devise_helper.rb
  2. +41 −0 test/helpers/devise_helper_test.rb
@@ -11,7 +11,7 @@ def devise_error_messages!
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t("errors.messages.not_saved",
:count => resource.errors.count,
- :resource => resource_name)
+ :resource => resource.class.model_name.human.downcase)
html = <<-HTML
<div id="error_explanation">
@@ -0,0 +1,41 @@
+require 'test_helper'
+
+class DeviseHelperTest < ActionController::IntegrationTest
+ setup do
+ I18n.backend.store_translations :fr,
+ {
+ :errors => { :messages => { :not_saved => {
+ :one => "Erreur lors de l'enregistrement de '%{resource}': 1 erreur.",
+ :other => "Erreur lors de l'enregistrement de '%{resource}': %{count} erreurs."
+ } } },
+ :activerecord => { :models => { :user => "utilisateur" } }
+ }
+
+ I18n.locale = 'fr'
+ end
+
+ test 'test errors.messages.not_saved with single error from i18n' do
+
+ get new_user_registration_path
+
+ fill_in 'password', :with => 'new_user123'
+ fill_in 'password confirmation', :with => 'new_user123'
+ click_button 'Sign up'
+
+ assert_have_selector '#error_explanation'
+ assert_contain "Erreur lors de l'enregistrement de 'utilisateur': 1 erreur"
+ end
+
+ test 'test errors.messages.not_saved with multiple errors from i18n' do
+ get new_user_registration_path
+
+ fill_in 'email', :with => 'invalid_email'
+ fill_in 'password', :with => 'new_user123'
+ fill_in 'password confirmation', :with => 'new_user321'
+ click_button 'Sign up'
+
+ assert_have_selector '#error_explanation'
+ assert_contain "Erreur lors de l'enregistrement de 'utilisateur': 2 erreurs"
+ end
+
+end

0 comments on commit e289523

Please sign in to comment.