-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci] Add test for flash_content helper
We added test for flash_content helper and also included Haml::Helpers.
- Loading branch information
David Kang
committed
Oct 18, 2017
1 parent
3faeb2e
commit 3c23ca4
Showing
4 changed files
with
62 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Webui::FlashHelper | ||
def flash_content(flash) | ||
if flash.is_a?(Hash) | ||
capture_haml do | ||
haml_tag(:span, flash.delete(:title)) | ||
haml_tag :ul do | ||
flash.each do |name, messages| | ||
haml_tag(:li, name, class: 'no-bullet') | ||
haml_tag :ul do | ||
messages.each { |message| haml_tag(:li, message) } | ||
end | ||
end | ||
end | ||
end | ||
else | ||
body = flash.gsub(/\\n/, '') | ||
sanitize body, tags: %w(a b ul li br u), attributes: %w(href title) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Webui::FlashHelper do | ||
describe '#flash_content' do | ||
let(:flash_with_hash) do | ||
{ | ||
title: 'example', | ||
'error 1' => ['error 1 content', 'error 1 content 2'], | ||
'error 2' => ['error 2 content', 'error 2 content 2'] | ||
} | ||
end | ||
|
||
let(:result) do | ||
<<-EOF.strip_heredoc | ||
<span>example</span> | ||
<ul> | ||
<li class='no-bullet'>error 1</li> | ||
<ul> | ||
<li>error 1 content</li> | ||
<li>error 1 content 2</li> | ||
</ul> | ||
<li class='no-bullet'>error 2</li> | ||
<ul> | ||
<li>error 2 content</li> | ||
<li>error 2 content 2</li> | ||
</ul> | ||
</ul> | ||
EOF | ||
end | ||
|
||
let(:flash) { "example: \\n<i>error 1</i> <b>content</b>" } | ||
|
||
before do | ||
init_haml_helpers | ||
end | ||
|
||
it { expect(flash_content(flash_with_hash)).to eq(result) } | ||
it { expect(flash_content(flash)).to eq('example: error 1 <b>content</b>') } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters