summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2010-02-28 09:43:13 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2010-02-28 09:43:13 +0000
commitc174540a0e39a4d785d9b99535176b0c92cd1958 (patch)
tree46d23c12eb3a519a0be6498bea6e945c7f8b326f
parent02cc0efdd7b9d10e12a9a335befdab4d4458d4a3 (diff)
downloadredmine-c174540a0e39a4d785d9b99535176b0c92cd1958.tar.gz
redmine-c174540a0e39a4d785d9b99535176b0c92cd1958.zip
Adds attachments upload on wiki edit form (#1223).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3500 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/wiki_controller.rb2
-rw-r--r--app/views/wiki/edit.rhtml4
-rw-r--r--test/functional/wiki_controller_test.rb17
3 files changed, 22 insertions, 1 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index 97e1531c0..fb472636b 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -76,6 +76,7 @@ class WikiController < ApplicationController
@content.version = @page.content.version
else
if !@page.new_record? && @content.text == params[:content][:text]
+ attach_files(@page, params[:attachments])
# don't save if text wasn't changed
redirect_to :action => 'index', :id => @project, :page => @page.title
return
@@ -86,6 +87,7 @@ class WikiController < ApplicationController
@content.author = User.current
# if page is new @page.save will also save content, but not if page isn't a new record
if (@page.new_record? ? @page.save : @content.save)
+ attach_files(@page, params[:attachments])
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
redirect_to :action => 'index', :id => @project, :page => @page.title
end
diff --git a/app/views/wiki/edit.rhtml b/app/views/wiki/edit.rhtml
index 6a949e2aa..9b125e994 100644
--- a/app/views/wiki/edit.rhtml
+++ b/app/views/wiki/edit.rhtml
@@ -1,11 +1,13 @@
<h2><%=h @page.pretty_title %></h2>
-<% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:id => 'wiki_form'} do |f| %>
+<% form_for :content, @content, :url => {:action => 'edit', :page => @page.title}, :html => {:multipart => true, :id => 'wiki_form'} do |f| %>
<%= f.hidden_field :version %>
<%= error_messages_for 'content' %>
<p><%= f.text_area :text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %></p>
<p><label><%= l(:field_comments) %></label><br /><%= f.text_field :comments, :size => 120 %></p>
+<p><label><%=l(:label_attachment_plural)%></label><br /><%= render :partial => 'attachments/form' %></p>
+
<p><%= submit_tag l(:button_save) %>
<%= link_to_remote l(:label_preview),
{ :url => { :controller => 'wiki', :action => 'preview', :id => @project, :page => @page.title },
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index cf247db80..3f9ac7eac 100644
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -107,6 +107,23 @@ class WikiControllerTest < ActionController::TestCase
assert_equal 'Created the page', page.content.comments
end
+ def test_create_page_with_attachments
+ @request.session[:user_id] = 2
+ assert_difference 'WikiPage.count' do
+ assert_difference 'Attachment.count' do
+ post :edit, :id => 1,
+ :page => 'New page',
+ :content => {:comments => 'Created the page',
+ :text => "h1. New page\n\nThis is a new page",
+ :version => 0},
+ :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
+ end
+ end
+ page = Project.find(1).wiki.find_page('New page')
+ assert_equal 1, page.attachments.count
+ assert_equal 'testfile.txt', page.attachments.first.filename
+ end
+
def test_preview_routing
assert_routing(
{:method => :post, :path => '/projects/567/wiki/CookBook_documentation/preview'},