From 594f9540a8d487554f8902eba70ca9b2013ce299 Mon Sep 17 00:00:00 2001 From: Philipp Fischbeck Date: Sun, 1 Feb 2015 12:00:49 +0100 Subject: [PATCH] Add tests for flash message helpers --- app/helpers/application_helper.rb | 20 +++++++++++--------- test/helpers/application_helper_test.rb | 13 +++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 test/helpers/application_helper_test.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 781d8fb..fc5c037 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4,15 +4,17 @@ module ApplicationHelper end def flash_messages(opts = {}) - flash.each do |msg_type, message| - concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} alert-dismissible", role: 'alert') do - concat(content_tag(:button, class: 'close', data: { dismiss: 'alert' }) do - concat content_tag(:span, '×'.html_safe, 'aria-hidden' => true) - concat content_tag(:span, 'Close', class: 'sr-only') - end) - concat message - end) + capture do + flash.each do |msg_type, message| + concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} alert-dismissible", role: 'alert') do + concat(content_tag(:button, class: 'close', data: { dismiss: 'alert' }) do + concat content_tag(:span, '×'.html_safe, 'aria-hidden' => true) + concat content_tag(:span, 'Close', class: 'sr-only') + end) + concat message + end) + end + nil end - nil end end diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb new file mode 100644 index 0000000..4a29dc2 --- /dev/null +++ b/test/helpers/application_helper_test.rb @@ -0,0 +1,13 @@ +require 'test_helper' + +class ApplicationHelperTest < ActionView::TestCase + test "bootstrap classes for flash should return correct values" do + assert_equal "alert-danger", bootstrap_class_for(:error) + assert_equal "alert-success", bootstrap_class_for(:success) + end + + test "bootstrap flash messages should work" do + flash[:error] = "Error" + assert_equal "
Error
", flash_messages + end +end