7a2370f740
- Some views had a "Close" button. We've removed this, because we don't want users accidentally hiding the validation errors and not knowing what needs to be fixed. - Some views used `li`, some used `p`, some used `span`. We've standardized on `li`. - Some views only showed the first error. We've standardized on showing all of them. - Some views added an `#error_explanation` div, which we've made standard.
46 lines
1.3 KiB
Ruby
46 lines
1.3 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe FormHelper do
|
|
describe 'form_errors' do
|
|
it 'returns nil when model has no errors' do
|
|
model = double(errors: [])
|
|
|
|
expect(helper.form_errors(model)).to be_nil
|
|
end
|
|
|
|
it 'renders an alert div' do
|
|
model = double(errors: errors_stub('Error 1'))
|
|
|
|
expect(helper.form_errors(model)).
|
|
to include('<div class="alert alert-danger" id="error_explanation">')
|
|
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('<h4>The form contains the following error:')
|
|
expect(helper.form_errors(multi_errors)).
|
|
to include('<h4>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('<li>Error 1</li>')
|
|
expect(errors).to include('<li>Error 2</li>')
|
|
expect(errors).to include('<li>Error 3</li>')
|
|
end
|
|
end
|
|
|
|
def errors_stub(*messages)
|
|
ActiveModel::Errors.new(double).tap do |errors|
|
|
messages.each { |msg| errors.add(:base, msg) }
|
|
end
|
|
end
|
|
end
|
|
end
|