From ed7dda96fe35750379fef1f9c5c7bf104cc6a58a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 3 Apr 2014 18:24:17 -0300 Subject: [PATCH] Check if error is a string to consider it as custom error --- lib/simple_form/components/errors.rb | 8 ++++---- test/form_builder/error_test.rb | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/simple_form/components/errors.rb b/lib/simple_form/components/errors.rb index d2d8f689..2f9dabe4 100644 --- a/lib/simple_form/components/errors.rb +++ b/lib/simple_form/components/errors.rb @@ -16,13 +16,13 @@ module SimpleForm protected def error_text - text = has_error_in_options? ? options[:error] : errors.send(error_method) + text = has_custom_error? ? options[:error] : errors.send(error_method) "#{html_escape(options[:error_prefix])} #{text}".lstrip.html_safe end def full_error_text - text = has_error_in_options? ? options[:error] : full_errors.send(error_method) + text = has_custom_error? ? options[:error] : full_errors.send(error_method) text.html_safe end @@ -54,8 +54,8 @@ module SimpleForm reflection ? object.full_messages_for(reflection.name) : [] end - def has_error_in_options? - options[:error] && !options[:error].nil? + def has_custom_error? + options[:error].is_a?(String) end end end diff --git a/test/form_builder/error_test.rb b/test/form_builder/error_test.rb index 5b5622ae..d69303e6 100644 --- a/test/form_builder/error_test.rb +++ b/test/form_builder/error_test.rb @@ -156,6 +156,12 @@ class ErrorTest < ActionView::TestCase assert_select 'span.error', error_text end + test 'input with custom error works 1' do + with_form_for @user, :name, error: true + + assert_select 'span.error', "can't be blank" + end + test 'input with custom error does not generate the error if there is no error on the attribute' do error_text = "Super User Active! can't be blank" with_form_for @user, :active, error: error_text