From 44eea439400a96e7f5f7fdbe9ead67565416528a Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Sun, 23 Jan 2005 13:42:56 +0000 Subject: [PATCH] uploading pics when not found in the file yard (same as for files) --- app/controllers/application.rb | 2 +- app/controllers/file_controller.rb | 12 +++++++++--- app/models/web.rb | 8 ++++++-- test/functional/file_controller_test.rb | 7 +++++++ test/unit/revision_test.rb | 13 +++++++++++++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index bc303e96..42c1abe2 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -71,7 +71,7 @@ class ApplicationController < ActionController::Base not @web_name.nil? end - @@REMEMBER_NOT = ['locked', 'save', 'back', 'file'] + @@REMEMBER_NOT = ['locked', 'save', 'back', 'file', 'pic'] def remember_location if @response.headers['Status'] == '200 OK' unless @@REMEMBER_NOT.include? action_name or @request.method != :get diff --git a/app/controllers/file_controller.rb b/app/controllers/file_controller.rb index e357830f..349bb287 100644 --- a/app/controllers/file_controller.rb +++ b/app/controllers/file_controller.rb @@ -11,7 +11,7 @@ class FileController < ApplicationController if @params['file'] # form supplied - file_yard.upload(@file_name, @params['file']) + file_yard.upload_file(@file_name, @params['file']) flash[:info] = "File '#{@file_name}' successfully uploaded" return_to_last_remembered elsif file_yard.has_file?(@file_name) @@ -28,10 +28,16 @@ class FileController < ApplicationController def pic check_path - if file_yard.has_file?(@file_name) + if @params['file'] + # form supplied + file_yard.upload_file(@file_name, @params['file']) + flash[:info] = "Image '#{@file_name}' successfully uploaded" + return_to_last_remembered + elsif file_yard.has_file?(@file_name) send_file(file_yard.file_path(@file_name)) else - render_text "Image not found: #{@file_name}", '404 Not Found' + logger.debug("Image not found: #{file_yard.files_path}/#{@file_name}") + render_action 'file' end end diff --git a/app/models/web.rb b/app/models/web.rb index 41de594d..f3115017 100755 --- a/app/models/web.rb +++ b/app/models/web.rb @@ -103,8 +103,12 @@ class Web when :export if has_file?(name) then "\"#{text}\"" else "\"#{text}\"" end - else - "\"#{text}\"" + when :publish + if has_file?(name) then "\"#{text}\"" + else "#{text}" end + else + if has_file?(name) then "\"#{text}\"" + else "#{text}?" end end end diff --git a/test/functional/file_controller_test.rb b/test/functional/file_controller_test.rb index b02d9fc0..6abb4b52 100644 --- a/test/functional/file_controller_test.rb +++ b/test/functional/file_controller_test.rb @@ -56,5 +56,12 @@ class FileControllerTest < Test::Unit::TestCase assert_success assert_equal File.size("#{FILE_AREA}/rails.gif"), r.binary_content.size end + + def test_pic_unknown_pic + r = process 'pic', 'web' => 'wiki1', 'id' => 'non-existant.gif' + + assert_success + assert_rendered_file 'file/file' + end end diff --git a/test/unit/revision_test.rb b/test/unit/revision_test.rb index 68798135..db2a3302 100755 --- a/test/unit/revision_test.rb +++ b/test/unit/revision_test.rb @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' require 'web' require 'revision' +require 'fileutils' class RevisionTest < Test::Unit::TestCase @@ -210,6 +211,7 @@ class RevisionTest < Test::Unit::TestCase end def test_link_to_pic + @wiki.file_yard(@web).upload_file('square.jpg', StringIO.new('')) assert_markup_parsed_as( '

Square

', '[[square.jpg|Square:pic]]') @@ -218,6 +220,17 @@ class RevisionTest < Test::Unit::TestCase '[[square.jpg:pic]]') end + def test_link_to_non_existant_pic + assert_markup_parsed_as( + '

NonExistant?' + + '

', + '[[NonExistant.jpg|NonExistant:pic]]') + assert_markup_parsed_as( + '

NonExistant.jpg?' + + '

', + '[[NonExistant.jpg:pic]]') + end + # TODO Remove the leading underscores from this test when upgrading to RedCloth 3.0.1; # also add a test for the "Unhappy Face" problem (another interesting RedCloth bug) def __test_list_with_tildas