1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Added tests for TargetScrubber.

This commit is contained in:
Timm 2013-09-14 14:32:10 +02:00
parent 15382e9793
commit af05b01505

View file

@ -167,4 +167,35 @@ class PermitScrubberTest < ScrubberTest
assert_equal Loofah::Scrubber::STOP, scrubbing
end
end
class TargetScrubberTest < ScrubberTest
def setup
@scrubber = TargetScrubber.new
end
def test_targeting_tags_removes_only_them
@scrubber.tags = %w(a h1)
html = '<script></script><a></a><h1></h1>'
assert_scrubbed html, '<script></script>'
end
def test_targeting_tags_removes_only_them_nested
@scrubber.tags = %w(a)
html = '<tag><a><tag><a></a></tag></a></tag>'
assert_scrubbed html, '<tag><tag></tag></tag>'
end
def test_targeting_attributes_removes_only_them
@scrubber.attributes = %w(class id)
html = '<a class="a" id="b" onclick="c"></a>'
assert_scrubbed html, '<a onclick="c"></a>'
end
def test_targeting_tags_and_attributes_removes_only_them
@scrubber.tags = %w(tag)
@scrubber.attributes = %w(remove)
html = '<tag remove="" other=""></tag><a remove="" other=""></a>'
assert_scrubbed html, '<a other=""></a>'
end
end