mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 00:36:42 +01:00
Add tests for flash message helpers
This commit is contained in:
parent
f162225195
commit
594f9540a8
@ -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
|
||||
|
||||
13
test/helpers/application_helper_test.rb
Normal file
13
test/helpers/application_helper_test.rb
Normal file
@ -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 "<div class=\"alert alert-danger alert-dismissible\" role=\"alert\"><button class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">×</span><span class=\"sr-only\">Close</span></button>Error</div>", flash_messages
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user