diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-04-12 00:33:50 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-04-12 00:33:50 +0300 |
commit | 52be9e20f9e2382f01a778d7b348283e7dd757e6 (patch) | |
tree | 2a22a5575f62c0ffada22ac27121c648544a4822 /spec/helpers | |
parent | af7214d0f077f738ed57194feb0cd468c43d4310 (diff) | |
parent | 7998725e3c2557c04ceece028dd73a316a3a746c (diff) |
Merge remote-tracking branch 'origin/master' into ci-commit-as-pipeline
# Conflicts:
# app/views/projects/commits/_commit.html.haml
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 |