Sub Folder creation via REST API #1255

This commit is contained in:
karel.picman@lbcfree.net 2021-05-24 13:19:24 +02:00
parent facc4e25a6
commit 2a16856b1b
2 changed files with 21 additions and 2 deletions

View File

@ -468,7 +468,7 @@ class DmsfFolder < ActiveRecord::Base
# Attributes
self.title = params[:dmsf_folder][:title].strip
self.description = params[:dmsf_folder][:description].strip
self.dmsf_folder_id = params[:parent_id]
self.dmsf_folder_id = params[:dmsf_folder][:dmsf_folder_id]
# Custom fields
if params[:dmsf_folder][:custom_field_values].present?
i = 0

View File

@ -116,6 +116,25 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
assert_select 'dmsf_folder > title', text: 'rest_api'
end
def test_create_subfolder
# curl -v -H "Content-Type: application/xml" -X POST --data "@folder.xml" -u ${1}:${2} http://localhost:3000/projects/12/dmsf/create.xml
payload = %{<?xml version="1.0" encoding="utf-8" ?>
<dmsf_folder>
<title>rest_api</title>
<description>A folder created via REST API</description>
<dmsf_folder_id>#{@folder1.id}</dmsf_folder_id>
</dmsf_folder>}
post "/projects/#{@project1.identifier}/dmsf/create.xml?key=#{@token.value}", params: payload, headers: { 'CONTENT_TYPE' => 'application/xml' }
assert_response :success
# <?xml version="1.0" encoding="UTF-8"?>
# <dmsf_folder>
# <id>8</id>
# <title>rest_api</title>
# </dmsf_folder>
assert_select 'dmsf_folder > title', text: 'rest_api'
assert @folder1.dmsf_folders.where(title: 'rest_api').exists?
end
def test_find_folder_by_title
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/projects/1/dmsf.json?folder_title=Updated%20title
get "/projects/#{@project1.identifier}/dmsf.xml?key=#{@token.value}&folder_title=#{@folder1.title}"