Project

General

Profile

Feature #14830 ยป add_rest_api_for_attaching_file_to_WIKI_page_trunk_r15317.patch

Takenori TAKAKI, 2016-04-11 09:02

View differences:

app/controllers/wiki_controller.rb
@content.author = User.current
if @page.save_with_content(@content)
attachments = Attachment.attach_files(@page, params[:attachments])
attachments = Attachment.attach_files(@page, params[:attachments] || (params[:wiki_page] && params[:wiki_page][:uploads]))
render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
test/integration/api_test/wiki_pages_test.rb
assert_nil page.parent
end
test "PUT /projects/:project_id/wiki/:title.json with attachment via params[:attachments]" do
set_tmp_attachments_directory
attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
assert_difference 'WikiPage.count' do
assert_difference 'WikiContent::Version.count' do
put '/projects/ecookbook/wiki/New_page_from_API.json',
{:wiki_page => {:text => 'New content from API with Attachments', :comments => 'API create with Attachments'},
:attachments => [:token => attachment.token, :filename => 'testfile.txt', :content_type => "text/plain"]},
credentials('jsmith')
assert_response 201
end
end
page = WikiPage.order('id DESC').first
assert_equal 'New_page_from_API', page.title
assert_include attachment, page.attachments
assert_equal attachment.filename, page.attachments.first.filename
end
test "PUT /projects/:project_id/wiki/:title.xml with attachment via params[:wiki_page][:uploads]" do
set_tmp_attachments_directory
attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
assert_difference 'WikiPage.count' do
assert_difference 'WikiContent::Version.count' do
put '/projects/ecookbook/wiki/New_page_from_API.xml',
{:wiki_page => {:text => 'New content from API with Attachments', :comments => 'API create with Attachments',
:uploads => [:token => attachment.token, :filename => 'testfile.txt', :content_type => "text/plain"]}},
credentials('jsmith')
assert_response 201
end
end
page = WikiPage.order('id DESC').first
assert_equal 'New_page_from_API', page.title
assert_include attachment, page.attachments
assert_equal attachment.filename, page.attachments.first.filename
end
test "PUT /projects/:project_id/wiki/:title.xml with parent" do
assert_difference 'WikiPage.count' do
assert_difference 'WikiContent::Version.count' do
    (1-1/1)