unit tests fix

This commit is contained in:
karel.picman@lbcfree.net 2020-08-17 09:18:12 +02:00
parent 630c0bffde
commit 76ef7ecb77
3 changed files with 9 additions and 11 deletions

View File

@ -99,18 +99,15 @@ class DmsfFile < ActiveRecord::Base
pn = Pathname.new(path)
return pn if pn.absolute?
end
Rails.root.join(path)
Rails.root.join path
end
def self.find_file_by_name(project, folder, name)
findn_file_by_name(project.id, folder, name)
findn_file_by_name project&.id, folder, name
end
def self.findn_file_by_name(project_id, folder, name)
where(
project_id: project_id,
dmsf_folder_id: folder ? folder.id : nil,
name: name).visible.first
visible.find_by project_id: project_id, dmsf_folder_id: folder&.id, name: name
end
def last_revision

View File

@ -93,8 +93,8 @@ module RedmineDmsf
# Check if current entity is a folder and return DmsfFolder object if found (nil if not)
def folder
unless @folder
@folder = DmsfFolder.visible.where(project_id: project.id, title: basename,
dmsf_folder_id: parent&.folder&.id).first if project
@folder = DmsfFolder.visible.find_by(project_id: project&.id, title: basename,
dmsf_folder_id: parent&.folder&.id)
end
@folder
end
@ -102,7 +102,7 @@ module RedmineDmsf
# Check if the current entity exists as a file (DmsfFile), and returns corresponding object if found (nil otherwise)
def file
unless @file
@file = DmsfFile.find_file_by_name(project, parent&.folder, basename) if project
@file = DmsfFile.find_file_by_name(project, parent&.folder, basename)
end
@file
end
@ -111,14 +111,14 @@ module RedmineDmsf
unless @subproject
if Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names']
if basename =~ / (\d+)$/
@subproject = Project.visible.where(id: $1, parent_id: parent_project&.id).first
@subproject = Project.visible.find_by(id: $1, parent_id: parent_project&.id)
if @subproject
# Check again whether it's really the project and not a folder with a number as a suffix
@subproject = nil unless basename =~ /^#{@subproject.name}/
end
end
else
@subproject = Project.visible.where(parent_id: parent_project.id, identifier: basename).first if parent_project
@subproject = Project.visible.find_by(parent_id: parent_project&.id, identifier: basename)
end
end
@subproject

View File

@ -114,6 +114,7 @@ class DmsfWebdavUnlockTest < RedmineDmsf::Test::IntegrationTest
def test_unlock_folder_wrong_path
log_user 'jsmith', 'jsmith'
l = @folder2.locks.first
# folder1 is missing in the path
process :unlock, "/dmsf/webdav/#{@folder2.project.identifier}/#{@folder2.title}", params: nil,
headers: @jsmith.merge!({ HTTP_DEPTH: 'infinity', HTTP_TIMEOUT: 'Infinite', HTTP_LOCK_TOKEN: l.uuid })
assert_response :not_found