From b4cfb59f42c8e5b9eeda19ba7565b2e359219a34 Mon Sep 17 00:00:00 2001 From: Timm Date: Sat, 14 Sep 2013 13:03:51 +0200 Subject: Moved some tests to scrubbers_test.rb. Added better testing of accessor validation. --- actionview/test/template/sanitizers_test.rb | 9 +++------ actionview/test/template/scrubbers/scrubbers_test.rb | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'actionview/test') diff --git a/actionview/test/template/sanitizers_test.rb b/actionview/test/template/sanitizers_test.rb index 48079bf060..c9e696a972 100644 --- a/actionview/test/template/sanitizers_test.rb +++ b/actionview/test/template/sanitizers_test.rb @@ -218,20 +218,17 @@ class SanitizersTest < ActionController::TestCase def test_should_raise_argument_error_if_tags_is_not_enumerable sanitizer = ActionView::WhiteListSanitizer.new - e = assert_raise(ArgumentError) do + assert_raise(ArgumentError) do sanitizer.sanitize('some html', :tags => 'foo') end - - assert_equal "You should pass :tags as an Enumerable", e.message end def test_should_raise_argument_error_if_attributes_is_not_enumerable sanitizer = ActionView::WhiteListSanitizer.new - e = assert_raise(ArgumentError) do + + assert_raise(ArgumentError) do sanitizer.sanitize('some html', :attributes => 'foo') end - - assert_equal "You should pass :attributes as an Enumerable", e.message end def test_should_not_accept_non_loofah_inheriting_scrubber diff --git a/actionview/test/template/scrubbers/scrubbers_test.rb b/actionview/test/template/scrubbers/scrubbers_test.rb index 15df5b8e22..a4ef36b1fd 100644 --- a/actionview/test/template/scrubbers/scrubbers_test.rb +++ b/actionview/test/template/scrubbers/scrubbers_test.rb @@ -67,6 +67,24 @@ class PermitScrubberTest < ActionView::TestCase assert_node_skipped 'some text' end + def test_tags_accessor_validation + e = assert_raise(ArgumentError) do + @scrubber.tags = 'tag' + end + + assert_equal "You should pass :tags as an Enumerable", e.message + assert_nil @scrubber.tags, "Tags should be nil when validation fails" + end + + def test_attributes_accessor_validation + e = assert_raise(ArgumentError) do + @scrubber.attributes = 'cooler' + end + + assert_equal "You should pass :attributes as an Enumerable", e.message + assert_nil @scrubber.attributes, "Attributes should be nil when validation fails" + end + protected def assert_scrubbed(html, expected = html) output = Loofah.scrub_fragment(html, @scrubber).to_s -- cgit v1.2.3