')
expect(helper.form_errors(model, pajamas_alert: true))
.to include(
'
'
)
end
it 'contains a summary message' do
single_error = double(errors: errors_stub('A'))
multi_errors = double(errors: errors_stub('A', 'B', 'C'))
expect(helper.form_errors(single_error))
.to include('The form contains the following error:')
expect(helper.form_errors(multi_errors))
.to include('The form contains the following errors:')
end
it 'renders each message' do
model = double(errors: errors_stub('Error 1', 'Error 2', 'Error 3'))
errors = helper.form_errors(model)
aggregate_failures do
expect(errors).to include('
Error 1')
expect(errors).to include('
Error 2')
expect(errors).to include('
Error 3')
end
end
it 'renders messages truncated if requested' do
model = double(errors: errors_stub('Error 1', 'Error 2'))
model.errors.add(:title, 'is truncated')
model.errors.add(:base, 'Error 3')
expect(model.class).to receive(:human_attribute_name) do |attribute|
attribute.to_s.capitalize
end
errors = helper.form_errors(model, truncate: :title)
aggregate_failures do
expect(errors).to include('
Error 1')
expect(errors).to include('
Error 2')
expect(errors).to include('
Title is truncated')
expect(errors).to include('
Error 3')
end
end
it 'renders help page links' do
stubbed_errors = ActiveModel::Errors.new(double).tap do |errors|
errors.add(:base, 'No text.', help_page_url: 'http://localhost/doc/user/index.html')
errors.add(
:base,
'With text.',
help_link_text: 'Documentation page title.',
help_page_url: 'http://localhost/doc/administration/index.html'
)
errors.add(
:base,
'With HTML text.',
help_link_text: '
',
help_page_url: 'http://localhost/doc/security/index.html'
)
end
model = double(errors: stubbed_errors)
errors = helper.form_errors(model)
aggregate_failures do
expect(errors).to include(
'No text. Learn more.'
)
expect(errors).to include(
'With text. Documentation page title.'
)
expect(errors).to include(
'With HTML text. <foo>'
)
end
end
def errors_stub(*messages)
ActiveModel::Errors.new(double).tap do |errors|
messages.each { |msg| errors.add(:base, msg) }
end
end
end
end