diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index a8ce9c66..f83846d2 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -260,13 +260,8 @@ class WikiController < ApplicationController # add an index file, if exporting to HTML if file_type.to_s.downcase == 'html' zip_out.put_next_entry 'index.html' - zip_out.puts <<-EOL - - - - - - EOL + zip_out.puts "" + + "" end end FileUtils.rm_rf(Dir[File.join(@wiki.storage_path, file_prefix + '*.zip')]) @@ -338,9 +333,12 @@ class WikiController < ApplicationController def render_to_string(template_name, with_layout = false) add_variables_to_assigns - @content_for_layout = @template.render_file(template_name) - if with_layout then @template.render_file('layouts/default'); - else @content_for_layout; end + self.assigns['content_for_layout'] = @template.render_file(template_name) + if with_layout + @template.render_file('layouts/default') + else + self.assigns['content_for_layout'] + end end def rss_with_content_allowed? diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index cb844d46..9b0cafdc 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -7,6 +7,8 @@ require File.dirname(__FILE__) + '/../test_helper' require 'wiki_controller' require 'rexml/document' +require 'tempfile' +require 'zip/zipfilesystem' # Raise errors beyond the default web-based presentation class WikiController; def rescue_action(e) logger.error(e); raise e end; end @@ -115,6 +117,24 @@ class WikiControllerTest < Test::Unit::TestCase content = r.binary_content assert_equal 'PK', content[0..1], 'Content is not a zip file' assert_equal :export, r.template_objects['link_mode'] + + # Tempfile doesn't know how to open files with binary flag, hence the two-step process + Tempfile.open('instiki_export_file') { |f| @tempfile_path = f.path } + begin + File.open(@tempfile_path, 'wb') { |f| f.write(content); @exported_file = f.path } + Zip::ZipFile.open(@exported_file) do |zip| + assert_equal %w(Elephant.html HomePage.html Oak.html index.html), zip.dir.entries('.').sort + assert_match /.*/, + zip.file.read('Elephant.html').gsub(/\s+/, ' ') + assert_match /.*/, + zip.file.read('Oak.html').gsub(/\s+/, ' ') + assert_match /.*/, + zip.file.read('HomePage.html').gsub(/\s+/, ' ') + assert_equal ' ', zip.file.read('index.html').gsub(/\s+/, ' ') + end + ensure + File.delete(@tempfile_path) if File.exist?(@tempfile_path) + end end def test_export_html_no_layout