Strip extra spaces from class html attribute for labels

This commit is contained in:
Carlos Antonio da Silva 2012-01-26 11:18:28 -02:00
parent dbf11d94ac
commit e2938a4c56
2 changed files with 10 additions and 1 deletions

View File

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

View File

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