diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-04-11 15:01:50 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-04-11 15:01:50 +0300 |
commit | 5999fec7a3aa7f663d0ade254e37fda3391fa17a (patch) | |
tree | 11ab4556b1e36b9820f860046929ef3164daa48d /spec/helpers | |
parent | 1794e934ce44b5058be598c2da43172bf80aac16 (diff) | |
parent | 7a2370f74060b2f065e3602700fe1b33fda4685c (diff) |
Merge branch 'rs-form_errors' into 'master'
Standardize the way we check for and display 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.
See merge request !3531
Diffstat (limited to 'spec/helpers')
-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 |