Commit bb494203d263104e9f2ac13d18c438798f7a99f8
1 parent
898e2acd
Exists in
master
and in
4 other branches
Cover the simple_sanitize helper
Showing
2 changed files
with
18 additions
and
1 deletions
Show diff stats
app/helpers/application_helper.rb
| @@ -192,7 +192,7 @@ module ApplicationHelper | @@ -192,7 +192,7 @@ module ApplicationHelper | ||
| 192 | alt: "Sign in with #{provider.to_s.titleize}") | 192 | alt: "Sign in with #{provider.to_s.titleize}") |
| 193 | end | 193 | end |
| 194 | 194 | ||
| 195 | - def simple_sanitize str | 195 | + def simple_sanitize(str) |
| 196 | sanitize(str, tags: %w(a span)) | 196 | sanitize(str, tags: %w(a span)) |
| 197 | end | 197 | end |
| 198 | 198 |
spec/helpers/application_helper_spec.rb
| @@ -123,4 +123,21 @@ describe ApplicationHelper do | @@ -123,4 +123,21 @@ describe ApplicationHelper do | ||
| 123 | end | 123 | end |
| 124 | end | 124 | end |
| 125 | 125 | ||
| 126 | + describe "simple_sanitize" do | ||
| 127 | + let(:a_tag) { '<a href="#">Foo</a>' } | ||
| 128 | + | ||
| 129 | + it "allows the a tag" do | ||
| 130 | + simple_sanitize(a_tag).should == a_tag | ||
| 131 | + end | ||
| 132 | + | ||
| 133 | + it "allows the span tag" do | ||
| 134 | + input = '<span class="foo">Bar</span>' | ||
| 135 | + simple_sanitize(input).should == input | ||
| 136 | + end | ||
| 137 | + | ||
| 138 | + it "disallows other tags" do | ||
| 139 | + input = "<strike><b>#{a_tag}</b></strike>" | ||
| 140 | + simple_sanitize(input).should == a_tag | ||
| 141 | + end | ||
| 142 | + end | ||
| 126 | end | 143 | end |