From 8f5ac3440a04e1ea30324f7bbe7b43c6ae4bdc6b Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Mon, 17 Jan 2005 20:37:06 +0000 Subject: [PATCH] All controller actions are covered by tests [main success scenarios only - not really trying to break it yet] --- CONTROLLER_TESTS | 38 ---------------------- app/controllers/wiki_controller.rb | 12 +++---- test/functional/wiki_controller_test.rb | 43 +++++++++++++++++++++---- 3 files changed, 43 insertions(+), 50 deletions(-) delete mode 100755 CONTROLLER_TESTS diff --git a/CONTROLLER_TESTS b/CONTROLLER_TESTS deleted file mode 100755 index e9090097..00000000 --- a/CONTROLLER_TESTS +++ /dev/null @@ -1,38 +0,0 @@ -DONE - -edit -create_system -index -locked -new -new_system -show -recently_revised -save -revision -rollback -search -list -web_list -authenticate -login -create_web -new_web -update_web -authors -remove_orphaned_pages -cancel_edit -print -published -rss_with_content -rss_with_headlines -export_html -export_markup -pdf - -TODO - -tex -export_pdf -export_tex - diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 8f4eb862..b7018133 100755 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -80,20 +80,20 @@ class WikiController < ApplicationController end def export_pdf - file_name = "#{web.address}-tex-#{web.revised_on.strftime('%Y-%m-%d-%H-%M-%S')}" + file_name = "#{@web.address}-tex-#{@web.revised_on.strftime('%Y-%m-%d-%H-%M-%S')}" file_path = WikiService.storage_path + file_name export_web_to_tex "#{file_path}.tex" unless FileTest.exists? "#{file_path}.tex" convert_tex_to_pdf "#{file_path}.tex" - send_export("#{file_name}.tex", "#{file_path}.tex") + send_file("#{file_path}.pdf") end def export_tex - file_name = "#{web.address}-tex-#{web.revised_on.strftime('%Y-%m-%d-%H-%M-%S')}.tex" + file_name = "#{@web.address}-tex-#{@web.revised_on.strftime('%Y-%m-%d-%H-%M-%S')}.tex" file_path = WikiService.storage_path + file_name export_web_to_tex(file_path) unless FileTest.exists?(file_path) - send_export(file_name, file_path) + send_file(file_path) end def feeds @@ -314,8 +314,8 @@ class WikiController < ApplicationController end def export_web_to_tex(file_path) - @tex_content = table_of_contents(web.pages['HomePage'].content.dup, render_tex_web) - File.open(file_path, 'w') { |f| f.write(template_engine('tex_web').result(binding)) } + @tex_content = table_of_contents(@web.pages['HomePage'].content.dup, render_tex_web) + File.open(file_path, 'w') { |f| f.write(render_to_string('wiki/tex_web')) } end def get_page_and_revision diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 18d26a6d..ceb37783 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -160,7 +160,8 @@ class WikiControllerTest < Test::Unit::TestCase assert_equal 'application/zip', r.headers['Content-Type'] assert_match /attachment; filename="wiki1-html-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/, r.headers['Content-Disposition'] - # TODO assert contents of the output file + content = r.binary_content + assert_equal 'PK', content[0..1], 'Content is not a zip file' end def test_export_markup @@ -170,9 +171,43 @@ class WikiControllerTest < Test::Unit::TestCase assert_equal 'application/zip', r.headers['Content-Type'] assert_match /attachment; filename="wiki1-textile-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.zip"/, r.headers['Content-Disposition'] - # TODO assert contents of the output file + content = r.binary_content + assert_equal 'PK', content[0..1], 'Content is not a zip file' + end + + + if ENV['INSTIKI_TEST_LATEX'] or defined? $INSTIKI_TEST_PDFLATEX + + def test_export_pdf + r = process 'export_pdf', 'web' => 'wiki1' + assert_success + assert_equal 'application/octet_stream', r.headers['Content-Type'] + assert_match /attachment; filename="wiki1-tex-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.pdf"/, + r.headers['Content-Disposition'] + content = r.binary_content + assert_equal '%PDF', content[0..3] + assert_equal "EOF\n", content[-4..-1] + end + + else + puts 'Warning: tests involving pdflatex are very slow, therefore they are disable by default.' + puts ' Set environment variable INSTIKI_TEST_PDFLATEX or global Ruby variable' + puts ' $INSTIKI_TEST_PDFLATEX to enable them.' end + + def test_export_tex + setup_wiki_with_three_pages + + r = process 'export_tex', 'web' => 'wiki1' + + assert_success + assert_equal 'application/octet_stream', r.headers['Content-Type'] + assert_match /attachment; filename="wiki1-tex-\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d.tex"/, + r.headers['Content-Disposition'] + content = r.binary_content + assert_equal '\documentclass', content[0..13], 'Content is not a TeX file' + end def test_feeds process('feeds', 'web' => 'wiki1') @@ -280,10 +315,6 @@ class WikiControllerTest < Test::Unit::TestCase r.headers['Content-Disposition'] end - else - puts 'Warning: tests involving pdflatex are very slow, therefore they are disable by default.' - puts ' Set environment variable INSTIKI_TEST_PDFLATEX or global Ruby variable' - puts ' $INSTIKI_TEST_PDFLATEX to enable them.' end