diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-04-04 21:25:38 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-04-04 21:37:07 -0400 |
commit | 7a2370f74060b2f065e3602700fe1b33fda4685c (patch) | |
tree | 0c23a588515e857598d5e389cd55aa816d3cfe35 /spec/helpers/form_helper_spec.rb | |
parent | 2ed6cd9e469ffcdb60f21d1738de1eff8c258432 (diff) | |
download | gitlab-ce-7a2370f74060b2f065e3602700fe1b33fda4685c.tar.gz |
Standardize the way we check for and display form errorsrs-form_errors
- 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.
Diffstat (limited to 'spec/helpers/form_helper_spec.rb')
-rw-r--r-- | spec/helpers/form_helper_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/helpers/form_helper_spec.rb b/spec/helpers/form_helper_spec.rb new file mode 100644 index 00000000000..b20373a96fb --- /dev/null +++ b/spec/helpers/form_helper_spec.rb @@ -0,0 +1,46 @@ +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 |