|
|
@ -538,18 +538,14 @@ JJ Abrams</textarea> |
|
|
|
describe 'labels for fields' do |
|
|
|
describe 'labels for fields' do |
|
|
|
let(:options) { {} } |
|
|
|
let(:options) { {} } |
|
|
|
shared_examples_for "generated label" do |
|
|
|
shared_examples_for "generated label" do |
|
|
|
def remove_form_field_container(string) |
|
|
|
def expected_label_like(expected_title, expected_classes = 'form--label') |
|
|
|
string.gsub(/<span class="form--field-container">.+<\/span>/m,'') |
|
|
|
expect(output).to be_html_eql(%{ |
|
|
|
end |
|
|
|
<label class="#{expected_classes}" |
|
|
|
|
|
|
|
|
|
|
|
def expected_label_like(expected_title) |
|
|
|
|
|
|
|
expect(remove_form_field_container(output)).to be_html_eql(%{ |
|
|
|
|
|
|
|
<label class="form--label" |
|
|
|
|
|
|
|
for="user_name" |
|
|
|
for="user_name" |
|
|
|
title="#{expected_title}"> |
|
|
|
title="#{expected_title}"> |
|
|
|
#{expected_title} |
|
|
|
#{expected_title} |
|
|
|
</label> |
|
|
|
</label> |
|
|
|
}) |
|
|
|
}).at_path('label') |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context 'with a label specified as string' do |
|
|
|
context 'with a label specified as string' do |
|
|
@ -598,6 +594,19 @@ JJ Abrams</textarea> |
|
|
|
expected_label_like(User.human_attribute_name(:name)) |
|
|
|
expected_label_like(User.human_attribute_name(:name)) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'when required, with a label specified as symbol' do |
|
|
|
|
|
|
|
let(:text) { :name } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
options[:label] = text |
|
|
|
|
|
|
|
options[:required] = true |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it 'uses the label' do |
|
|
|
|
|
|
|
expected_label_like(I18n.t(:name), 'form--label -required') |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
%w{ text_field |
|
|
|
%w{ text_field |
|
|
|