From e2938a4c5645b21d24f78feece34604ad8c4cf1f Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 26 Jan 2012 11:18:28 -0200 Subject: [PATCH] Strip extra spaces from class html attribute for labels --- lib/simple_form/components/labels.rb | 2 +- test/components/label_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/components/labels.rb b/lib/simple_form/components/labels.rb index 2cf4f781..3349554b 100644 --- a/lib/simple_form/components/labels.rb +++ b/lib/simple_form/components/labels.rb @@ -38,7 +38,7 @@ module SimpleForm end def label_html_options - label_options = html_options_for(:label, [input_type, required_class, SimpleForm.label_class]) + label_options = html_options_for(:label, [input_type, required_class, SimpleForm.label_class].compact) label_options[:for] = options[:input_html][:id] if options.key?(:input_html) && options[:input_html].key?(:id) label_options end diff --git a/test/components/label_test.rb b/test/components/label_test.rb index 7cef72f1..87fecf5b 100644 --- a/test/components/label_test.rb +++ b/test/components/label_test.rb @@ -296,4 +296,13 @@ class IsolatedLabelTest < ActionView::TestCase assert_select 'label.my_custom_class' end end + + test 'label strips extra classes even when label_class is nil' do + swap SimpleForm, :label_class => nil do + with_label_for @user, :name, :string + assert_select "label[class='string required']" + assert_no_select "label[class='string required ']" + assert_no_select "label[class=' string required']" + end + end end