From db8fbe94ae48b25a8c1af9d6177df95c00c79d61 Mon Sep 17 00:00:00 2001 From: Kai Chen Date: Thu, 19 Jun 2014 16:11:27 +0800 Subject: [PATCH] remove warning of label_text method in wrapper, when replace html label tag to other tag --- lib/simple_form/wrappers/leaf.rb | 4 +++- test/form_builder/label_test.rb | 9 +++++++++ test/support/misc_helpers.rb | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/wrappers/leaf.rb b/lib/simple_form/wrappers/leaf.rb index 3fc9fac0..d2e77018 100644 --- a/lib/simple_form/wrappers/leaf.rb +++ b/lib/simple_form/wrappers/leaf.rb @@ -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 diff --git a/test/form_builder/label_test.rb b/test/form_builder/label_test.rb index 07e4111e..4cf4bc8a 100644 --- a/test/form_builder/label_test.rb +++ b/test/form_builder/label_test.rb @@ -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?' diff --git a/test/support/misc_helpers.rb b/test/support/misc_helpers.rb index 1826bc93..9f9da2da 100644 --- a/test/support/misc_helpers.rb +++ b/test/support/misc_helpers.rb @@ -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