1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Check if error is a string to consider it as custom error

This commit is contained in:
Rafael Mendonça França 2014-04-03 18:24:17 -03:00
parent 7141f1b0ba
commit ed7dda96fe
2 changed files with 10 additions and 4 deletions

View file

@ -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

View file

@ -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