From 312796b1ee8c5516e1256a152fcc98733b34f8c6 Mon Sep 17 00:00:00 2001 From: Edison Date: Sat, 11 Feb 2012 05:30:58 -0200 Subject: [PATCH 1/3] appended `html_safe` for inline error messages --- lib/simple_form/components/errors.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simple_form/components/errors.rb b/lib/simple_form/components/errors.rb index b416bce2..74d6f5ee 100644 --- a/lib/simple_form/components/errors.rb +++ b/lib/simple_form/components/errors.rb @@ -12,7 +12,7 @@ module SimpleForm protected def error_text - "#{options[:error_prefix]} #{errors.send(error_method)}".lstrip + "#{options[:error_prefix]} #{errors.send(error_method)}".lstrip.html_safe end def error_method From 18b73ddba4adfd3bd56e9bcf75f427b3b63069a0 Mon Sep 17 00:00:00 2001 From: Edison Date: Thu, 16 Feb 2012 15:07:03 -0200 Subject: [PATCH 2/3] test for errors messages with HTML tags --- test/form_builder/error_test.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/form_builder/error_test.rb b/test/form_builder/error_test.rb index ecbe8827..4a370c3d 100644 --- a/test/form_builder/error_test.rb +++ b/test/form_builder/error_test.rb @@ -73,6 +73,12 @@ class ErrorTest < ActionView::TestCase assert_no_select 'p.error[error_method]' end + test 'error should generate an error message with raw HTML tags' do + with_error_for @user, :name, :error_prefix => 'Name' + assert_select 'span.error', "Name can't be blank" + assert_select 'span.error b', "Name" + end + # FULL ERRORS test 'full error should generate an full error tag for the attribute' do From 9dfff667a778416e0ccf2a10f7010a8a53f7058f Mon Sep 17 00:00:00 2001 From: Edison Date: Thu, 16 Feb 2012 15:07:52 -0200 Subject: [PATCH 3/3] allow HTML tags in error notifications messages --- lib/simple_form/error_notification.rb | 2 +- test/form_builder/error_notification_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/error_notification.rb b/lib/simple_form/error_notification.rb index a5ee84f3..0cd0c63d 100644 --- a/lib/simple_form/error_notification.rb +++ b/lib/simple_form/error_notification.rb @@ -25,7 +25,7 @@ module SimpleForm end def error_message - @message || translate_error_notification + (@message || translate_error_notification).html_safe end def error_notification_tag diff --git a/test/form_builder/error_notification_test.rb b/test/form_builder/error_notification_test.rb index 2fb1cd36..d71d3a81 100644 --- a/test/form_builder/error_notification_test.rb +++ b/test/form_builder/error_notification_test.rb @@ -60,4 +60,10 @@ class ErrorNotificationTest < ActionView::TestCase assert_select 'div.error_notification' end end + + test 'error notification should contain HTML tags' do + with_error_notification_for @user, :message => 'Erro encontrado ao criar usuario' + assert_select 'p.error_notification', 'Erro encontrado ao criar usuario' + assert_select 'p.error_notification b', 'usuario' + end end