require File.dirname(__FILE__) + '/../test_helper' require 'textfilter_controller' require 'flickr_mock' # Re-raise errors caught by the controller. class TextfilterController; def rescue_action(e) raise e end; end class ActionController::Base; def rescue_action(e) raise e end; end class TextfilterControllerTest < Test::Unit::TestCase fixtures :text_filters def setup @controller = TextfilterController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @controller.request = @request @controller.response = @response @controller.assigns ||= [] reset_whiteboard get :test_action # set up @url; In Rails 1.0, we can't do url_for without it. # @controller.initialize_current_url #rescue nil end def filter_text(text, filters, filterparams={}, filter_html=false) TextFilter.filter_text(text, @controller, self, filters, filterparams, filter_html) end def whiteboard @whiteboard ||= Hash.new end def reset_whiteboard @whiteboard = nil end def sparklines_available begin Plugins::Textfilters::SparklineController rescue NameError false end end def test_unknown text = filter_text('*foo*',[:unknowndoesnotexist]) assert_equal '*foo*', text end def test_smartypants text = filter_text('"foo"',[:smartypants]) assert_equal '“foo”', text end def test_markdown text = filter_text('*foo*', [:markdown]) assert_equal '
foo
', text text = filter_text("foo\n\nbar",[:markdown]) assert_equal "foo
\n\nbar
", text end def test_filterchain assert_equal '“foo”
', filter_text('*"foo"*',[:markdown,:smartypants]) assert_equal '“foo”
', filter_text('*"foo"*',[:doesntexist1,:markdown,"doesn't exist 2",:smartypants,:nopenotmeeither]) assert_equal 'foo
', filter_text('foo
',[],{},false) assert_equal '<p>foo</p>', filter_text('foo
',[],{},true) end def test_amazon text = filter_text('Rails book', [:amazon], 'amazon-associate-id' => 'scottstuff-20') assert_equal "Rails book", text assert_equal %w{097669400X}, whiteboard[:asins] reset_whiteboard text = filter_text('[Rails book](amazon:097669400X)', [:markdown,:amazon], 'amazon-associate-id' => 'scottstuff-20') assert_equal "", text assert_equal %w{097669400X}, whiteboard[:asins] reset_whiteboard text = filter_text("Foo\n\n[Rails book](amazon:097669400X)", [:markdown,:amazon], 'amazon-associate-id' => 'scottstuff-20') assert_equal "Foo
\n\n", text assert_equal %w{097669400X}, whiteboard[:asins] reset_whiteboard end def test_flickr assert_equal "", filter_text('foo-code
foo-code
foo-code
zzz
class Foo\n def bar\n @a = "zzz"\n end\nend
“foo”
', TextFilter.filter_text_by_name('*"foo"*', @controller, 'markdown smartypants') end def test_code_plus_markup_chain text = <<-EOF *header text here*header text here
class test
def method
"foo"
end
end
footer text here
EOF expects_textile = <<-EOFheader text here
class test
def method
"foo"
end
end
footer text here
EOF assert_equal expects_markdown.strip, TextFilter.filter_text_by_name(text, @controller, 'markdown') assert_equal expects_textile.strip, TextFilter.filter_text_by_name(text, @controller, 'textile') end def test_lightbox assert_equal "", filter_text('