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.
|
||||
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
|
||||
|
||||
# For injecting a different wiki model implementation. Intended for use in tests
|
||||
|
@ -19,7 +19,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def check_authorization
|
||||
if in_a_web? and authorization_needed? and not authorized?
|
||||
redirect_to :controller => 'wiki', :action => 'login', :web => @web_name
|
||||
|
@ -27,18 +27,18 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def connect_to_model
|
||||
def fetch_model_data
|
||||
@action_name = @params['action'] || 'index'
|
||||
@web_name = @params['web']
|
||||
@wiki = wiki
|
||||
@author = cookies['author'] || 'AnonymousCoward'
|
||||
if @web_name
|
||||
@web = @wiki.webs[@web_name]
|
||||
if @web.nil?
|
||||
render :status => 404, :text => "Unknown web '#{@web_name}'"
|
||||
return false
|
||||
render(:status => 404, :text => "Unknown web '#{@web_name}'")
|
||||
return false
|
||||
end
|
||||
end
|
||||
@author = cookies['author'] || 'AnonymousCoward'
|
||||
end
|
||||
|
||||
FILE_TYPES = {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# Controller responsible for serving files and pictures.
|
||||
|
||||
require 'zip/zip'
|
||||
|
||||
class FileController < ApplicationController
|
||||
|
||||
layout 'default'
|
||||
|
@ -19,7 +21,6 @@ class FileController < ApplicationController
|
|||
render
|
||||
end
|
||||
else
|
||||
render(:status => 404, :text => 'Unspecified file name') and return unless @file_name
|
||||
# no form supplied, this is a request to download the file
|
||||
file = WikiFile.find_by_file_name(@file_name)
|
||||
if file
|
||||
|
@ -39,8 +40,7 @@ class FileController < ApplicationController
|
|||
if @params['file']
|
||||
@problems = []
|
||||
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(file_yard.file_path(import_file_name))
|
||||
import_from_archive(@params['file'].path)
|
||||
if @problems.empty?
|
||||
flash[:info] = 'Import successfully finished'
|
||||
else
|
||||
|
@ -56,6 +56,7 @@ class FileController < ApplicationController
|
|||
protected
|
||||
|
||||
def check_allow_uploads
|
||||
render(:status => 404, :text => "Web #{@params['web'].inspect} not found") and return false unless @web
|
||||
if @web.allow_uploads?
|
||||
return true
|
||||
else
|
||||
|
@ -65,8 +66,7 @@ class FileController < ApplicationController
|
|||
end
|
||||
|
||||
def connect_to_model
|
||||
super
|
||||
@file_name = @params['id']
|
||||
super and @file_name = @params['id']
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -87,10 +87,10 @@ class FileController < ApplicationController
|
|||
next
|
||||
else
|
||||
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
|
||||
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
|
||||
rescue => e
|
||||
logger.error(e)
|
||||
|
|
|
@ -28,7 +28,7 @@ class Wiki
|
|||
if not (web = Web.find_by_address(old_address))
|
||||
raise Instiki::ValidationError.new("Web with address '#{old_address}' does not exist")
|
||||
end
|
||||
|
||||
|
||||
web.update_attributes(:address => new_address, :name => name, :markup => markup, :color => color,
|
||||
:additional_style => additional_style, :safe_mode => safe_mode, :password => password, :published => published,
|
||||
:brackets_only => brackets_only, :count_pages => count_pages, :allow_uploads => allow_uploads, :max_upload_size => max_upload_size)
|
||||
|
|
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)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue