Fixing FileController#import; sort of works, but fails on some interesting tests
This commit is contained in:
parent
cb869abf0d
commit
64313ca208
|
@ -2,7 +2,7 @@
|
||||||
# Likewise will all the methods added be available for all controllers.
|
# Likewise will all the methods added be available for all controllers.
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
before_filter :connect_to_model, :check_authorization, :setup_url_generator, :set_content_type_header, :set_robots_metatag
|
before_filter :fetch_model_data, :check_authorization, :setup_url_generator, :set_content_type_header, :set_robots_metatag
|
||||||
after_filter :remember_location, :teardown_url_generator
|
after_filter :remember_location, :teardown_url_generator
|
||||||
|
|
||||||
# For injecting a different wiki model implementation. Intended for use in tests
|
# For injecting a different wiki model implementation. Intended for use in tests
|
||||||
|
@ -27,18 +27,18 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def connect_to_model
|
def fetch_model_data
|
||||||
@action_name = @params['action'] || 'index'
|
@action_name = @params['action'] || 'index'
|
||||||
@web_name = @params['web']
|
@web_name = @params['web']
|
||||||
@wiki = wiki
|
@wiki = wiki
|
||||||
|
@author = cookies['author'] || 'AnonymousCoward'
|
||||||
if @web_name
|
if @web_name
|
||||||
@web = @wiki.webs[@web_name]
|
@web = @wiki.webs[@web_name]
|
||||||
if @web.nil?
|
if @web.nil?
|
||||||
render :status => 404, :text => "Unknown web '#{@web_name}'"
|
render(:status => 404, :text => "Unknown web '#{@web_name}'")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@author = cookies['author'] || 'AnonymousCoward'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
FILE_TYPES = {
|
FILE_TYPES = {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# Controller responsible for serving files and pictures.
|
# Controller responsible for serving files and pictures.
|
||||||
|
|
||||||
|
require 'zip/zip'
|
||||||
|
|
||||||
class FileController < ApplicationController
|
class FileController < ApplicationController
|
||||||
|
|
||||||
layout 'default'
|
layout 'default'
|
||||||
|
@ -19,7 +21,6 @@ class FileController < ApplicationController
|
||||||
render
|
render
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
render(:status => 404, :text => 'Unspecified file name') and return unless @file_name
|
|
||||||
# no form supplied, this is a request to download the file
|
# no form supplied, this is a request to download the file
|
||||||
file = WikiFile.find_by_file_name(@file_name)
|
file = WikiFile.find_by_file_name(@file_name)
|
||||||
if file
|
if file
|
||||||
|
@ -39,8 +40,7 @@ class FileController < ApplicationController
|
||||||
if @params['file']
|
if @params['file']
|
||||||
@problems = []
|
@problems = []
|
||||||
import_file_name = "#{@web.address}-import-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.zip"
|
import_file_name = "#{@web.address}-import-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.zip"
|
||||||
file_yard.upload_file(import_file_name, @params['file'])
|
import_from_archive(@params['file'].path)
|
||||||
import_from_archive(file_yard.file_path(import_file_name))
|
|
||||||
if @problems.empty?
|
if @problems.empty?
|
||||||
flash[:info] = 'Import successfully finished'
|
flash[:info] = 'Import successfully finished'
|
||||||
else
|
else
|
||||||
|
@ -56,6 +56,7 @@ class FileController < ApplicationController
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def check_allow_uploads
|
def check_allow_uploads
|
||||||
|
render(:status => 404, :text => "Web #{@params['web'].inspect} not found") and return false unless @web
|
||||||
if @web.allow_uploads?
|
if @web.allow_uploads?
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
|
@ -65,8 +66,7 @@ class FileController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def connect_to_model
|
def connect_to_model
|
||||||
super
|
super and @file_name = @params['id']
|
||||||
@file_name = @params['id']
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -87,10 +87,10 @@ class FileController < ApplicationController
|
||||||
next
|
next
|
||||||
else
|
else
|
||||||
logger.info "Page '#{page_name}' already exists. Adding a new revision to it."
|
logger.info "Page '#{page_name}' already exists. Adding a new revision to it."
|
||||||
wiki.revise_page(@web.address, page_name, page_content, Time.now, @author)
|
wiki.revise_page(@web.address, page_name, page_content, Time.now, @author, PageRenderer.new)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
wiki.write_page(@web.address, page_name, page_content, Time.now, @author)
|
wiki.write_page(@web.address, page_name, page_content, Time.now, @author, PageRenderer.new)
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
BIN
test/fixtures/exported_markup.zip
vendored
Normal file
BIN
test/fixtures/exported_markup.zip
vendored
Normal file
Binary file not shown.
|
@ -93,4 +93,22 @@ class FileControllerTest < Test::Unit::TestCase
|
||||||
assert_equal(picture, WikiFile.find_by_file_name('rails-e2e.gif').content)
|
assert_equal(picture, WikiFile.find_by_file_name('rails-e2e.gif').content)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_import
|
||||||
|
r = post :import, :web => 'wiki1', :file => uploaded_file("#{RAILS_ROOT}/test/fixtures/exported_markup.zip")
|
||||||
|
assert_redirect
|
||||||
|
assert @web.has_page?('ImportedPage')
|
||||||
|
end
|
||||||
|
|
||||||
|
def uploaded_file(path, content_type="application/octet-stream", filename=nil)
|
||||||
|
filename ||= File.basename(path)
|
||||||
|
t = Tempfile.new(filename)
|
||||||
|
FileUtils.copy_file(path, t.path)
|
||||||
|
(class << t; self; end;).class_eval do
|
||||||
|
alias local_path path
|
||||||
|
define_method(:original_filename) { filename }
|
||||||
|
define_method(:content_type) { content_type }
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue