From 71396669265596dffdc729c0f7f6a343100e99c8 Mon Sep 17 00:00:00 2001 From: Geoff Garside Date: Wed, 24 Feb 2010 18:26:05 +0000 Subject: [PATCH 1/2] Add test case to show error_message_on returning incorrect output for a method with no errors --- .../test/template/active_model_helper_test.rb | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/actionpack/test/template/active_model_helper_test.rb b/actionpack/test/template/active_model_helper_test.rb index 3e01ae7..b3c53ab 100644 --- a/actionpack/test/template/active_model_helper_test.rb +++ b/actionpack/test/template/active_model_helper_test.rb @@ -252,6 +252,10 @@ class ActiveModelHelperTest < ActionView::TestCase assert_dom_equal "
beforecan't be emptyafter
", error_message_on(:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after') end + def test_error_message_on_handles_empty_errors + assert_equal "", error_message_on(@post, :tag) + end + def test_error_messages_for_many_objects assert_dom_equal %(

2 errors prohibited this post from being saved

There were problems with the following fields:

), error_messages_for("post", "user") -- 1.6.4.2 From 62344a4d94b0400f3a9ee03815bdf9cec3017f08 Mon Sep 17 00:00:00 2001 From: Geoff Garside Date: Wed, 24 Feb 2010 18:37:36 +0000 Subject: [PATCH 2/2] Correct ActionView::Helpers::ActiveModelHelper#error_messages_on check for errors on method. --- .../lib/action_view/helpers/active_model_helper.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb index 2f309fc..ec62f21 100644 --- a/actionpack/lib/action_view/helpers/active_model_helper.rb +++ b/actionpack/lib/action_view/helpers/active_model_helper.rb @@ -125,7 +125,7 @@ module ActionView object = convert_to_model(object) if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) && - (errors = obj.errors[method]) + (errors = obj.errors[method]) && !errors.empty? content_tag("div", (options[:prepend_text].html_safe << errors.first).safe_concat(options[:append_text]), :class => options[:css_class] -- 1.6.4.2