update the form tag helper to allow for default title in label

pull/2681/head
Florian Kraft 10 years ago
parent 40f6f343b7
commit 178e282576
  1. 1
      lib/open_project/form_tag_helper.rb
  2. 25
      spec/lib/open_project/form_tag_helper_spec.rb

@ -59,6 +59,7 @@ module OpenProject
block_given? && content_or_options.is_a?(Hash) ? content_or_options : (options ||= {}),
'form--label'
)
options[:title] = strip_tags(options[:title] || capture(&block))
label_tag(name, content_or_options, options, &block)
end

@ -93,7 +93,30 @@ describe OpenProject::FormTagHelper, type: :helper do
it 'should output element' do
expect(output).to be_html_eql(%{
<label class="form--label" for="field">Label content</label>
<label class="form--label" for="field" title="Label content">Label content</label>
})
end
it 'should use the title from the options if given' do
label = helper.styled_label_tag 'field', 'Lautrec', title: 'Carim'
expect(label).to be_html_eql(%{
<label for="field" class="form--label" title="Carim">Lautrec</label>
})
end
it 'should prefer the title given in the options over the content' do
label = helper.styled_label_tag('field', nil, title: 'Carim') { 'Lordvessel' }
expect(label).to be_html_eql(%{
<label for="field" class="form--label" title="Carim">Lordvessel</label>
})
end
it 'should strip any given inline HTML from the title tag' do
label = helper.styled_label_tag('field') do
helper.content_tag :span, 'Sif'
end
expect(label).to be_html_eql(%{
<label for="field" class="form--label" title="Sif"><span>Sif</span></label>
})
end
end

Loading…
Cancel
Save