All controller actions are covered by tests [main success scenarios only - not really trying to break it yet]

This commit is contained in:
Alexey Verkhovsky 2005-01-17 20:37:06 +00:00
parent c50dd048e3
commit 8f5ac3440a
3 changed files with 43 additions and 50 deletions

View file

@ -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

View file

@ -80,20 +80,20 @@ class WikiController < ApplicationController
end end
def export_pdf 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 file_path = WikiService.storage_path + file_name
export_web_to_tex "#{file_path}.tex" unless FileTest.exists? "#{file_path}.tex" export_web_to_tex "#{file_path}.tex" unless FileTest.exists? "#{file_path}.tex"
convert_tex_to_pdf "#{file_path}.tex" convert_tex_to_pdf "#{file_path}.tex"
send_export("#{file_name}.tex", "#{file_path}.tex") send_file("#{file_path}.pdf")
end end
def export_tex 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 file_path = WikiService.storage_path + file_name
export_web_to_tex(file_path) unless FileTest.exists?(file_path) export_web_to_tex(file_path) unless FileTest.exists?(file_path)
send_export(file_name, file_path) send_file(file_path)
end end
def feeds def feeds
@ -314,8 +314,8 @@ class WikiController < ApplicationController
end end
def export_web_to_tex(file_path) def export_web_to_tex(file_path)
@tex_content = table_of_contents(web.pages['HomePage'].content.dup, render_tex_web) @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)) } File.open(file_path, 'w') { |f| f.write(render_to_string('wiki/tex_web')) }
end end
def get_page_and_revision def get_page_and_revision

View file

@ -160,7 +160,8 @@ class WikiControllerTest < Test::Unit::TestCase
assert_equal 'application/zip', r.headers['Content-Type'] 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"/, 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'] 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 end
def test_export_markup def test_export_markup
@ -170,10 +171,44 @@ class WikiControllerTest < Test::Unit::TestCase
assert_equal 'application/zip', r.headers['Content-Type'] 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"/, 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'] 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 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 def test_feeds
process('feeds', 'web' => 'wiki1') process('feeds', 'web' => 'wiki1')
end end
@ -280,10 +315,6 @@ class WikiControllerTest < Test::Unit::TestCase
r.headers['Content-Disposition'] r.headers['Content-Disposition']
end 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 end