From a7bb0474242c84a127999faf7139aecd16bb0468 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Sun, 23 Jan 2005 14:54:41 +0000 Subject: [PATCH] FileController refreshes references to files/pictures after an upload --- app/controllers/file_controller.rb | 2 ++ test/functional/file_controller_test.rb | 37 ++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/controllers/file_controller.rb b/app/controllers/file_controller.rb index 349bb287..bae7b33b 100644 --- a/app/controllers/file_controller.rb +++ b/app/controllers/file_controller.rb @@ -13,6 +13,7 @@ class FileController < ApplicationController # form supplied file_yard.upload_file(@file_name, @params['file']) flash[:info] = "File '#{@file_name}' successfully uploaded" + @web.refresh_pages_with_references(@file_name) return_to_last_remembered elsif file_yard.has_file?(@file_name) send_file(file_yard.file_path(@file_name)) @@ -32,6 +33,7 @@ class FileController < ApplicationController # form supplied file_yard.upload_file(@file_name, @params['file']) flash[:info] = "Image '#{@file_name}' successfully uploaded" + @web.refresh_pages_with_references(@file_name) return_to_last_remembered elsif file_yard.has_file?(@file_name) send_file(file_yard.file_path(@file_name)) diff --git a/test/functional/file_controller_test.rb b/test/functional/file_controller_test.rb index 6556e464..cc60caa2 100644 --- a/test/functional/file_controller_test.rb +++ b/test/functional/file_controller_test.rb @@ -66,7 +66,13 @@ class FileControllerTest < Test::Unit::TestCase end def test_pic_upload_end_to_end - # rails-e2e.gif is unknown to the system + # edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif' + @wiki.revise_page('wiki1', 'HomePage', '[[rails-e2e.gif:pic]]', Time.now, 'AnonymousBrave') + assert_equal "

rails-e2e.gif" + + "?

", + @home.display_content + + # rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form r = process 'pic', 'web' => 'wiki1', 'id' => 'rails-e2e.gif' assert_success assert_rendered_file 'file/file' @@ -77,6 +83,35 @@ class FileControllerTest < Test::Unit::TestCase assert_redirect_url '/' assert @wiki.file_yard(@web).has_file?('rails-e2e.gif') assert_equal(picture, File.read("#{RAILS_ROOT}/storage/test/wiki1/rails-e2e.gif")) + + # this should refresh the page display content (cached) + assert_equal "

\"rails-e2e.gif\"

", + @home.display_content + end + + def test_pic_upload_end_to_end + # edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif' + @wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave') + assert_equal "

instiki-e2e.txt" + + "?

", + @home.display_content + + # rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form + r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt' + assert_success + assert_rendered_file 'file/file' + + # User uploads the picture + file = "abcdefgh\n123" + r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt', 'file' => StringIO.new(file) + assert_redirect_url '/' + assert @wiki.file_yard(@web).has_file?('instiki-e2e.txt') + assert_equal(file, File.read("#{RAILS_ROOT}/storage/test/wiki1/instiki-e2e.txt")) + + # this should refresh the page display content (cached) + assert_equal "

" + + "instiki-e2e.txt

", + @home.display_content end end