remove warning of label_text method in wrapper, when replace html

label tag to other tag
This commit is contained in:
Kai Chen 2014-06-19 16:11:27 +08:00
parent dd95122aee
commit db8fbe94ae
3 changed files with 18 additions and 1 deletions

View File

@ -12,7 +12,9 @@ module SimpleForm
method = input.method(@namespace)
if method.arity == 0
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: @namespace })
if method.name !~ /_text$/
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: @namespace })
end
method.call
else

View File

@ -88,6 +88,15 @@ class LabelTest < ActionView::TestCase
end
end
test 'configuration allow set rewrited label tag for wrappers' do
swap_wrapper :default, self.custom_wrapper_with_custom_label_component do
with_concat_form_for(@user) do |f|
concat f.input :age
end
assert_select "span.integer.user_age", /Age/
end
end
test 'builder allows custom formatting when label is explicitly specified' do
swap SimpleForm, label_text: lambda { |l, r, explicit_label| explicit_label ? l : "#{l.titleize}:" } do
with_label_for @user, :time_zone, 'What is your home time zone?'

View File

@ -156,6 +156,12 @@ module MiscHelpers
end
end
def custom_wrapper_with_custom_label_component
SimpleForm.build tag: :span, class: 'custom_wrapper' do |b|
b.use :label_text
end
end
def custom_form_for(object, *args, &block)
simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
end