From 76ef7ecb770855b26efc55f3f1d5c602f05984be Mon Sep 17 00:00:00 2001 From: "karel.picman@lbcfree.net" Date: Mon, 17 Aug 2020 09:18:12 +0200 Subject: [PATCH] unit tests fix --- app/models/dmsf_file.rb | 9 +++------ lib/redmine_dmsf/webdav/dmsf_resource.rb | 10 +++++----- test/integration/webdav/dmsf_webdav_unlock_test.rb | 1 + 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 55f7288f..8476d520 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -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 diff --git a/lib/redmine_dmsf/webdav/dmsf_resource.rb b/lib/redmine_dmsf/webdav/dmsf_resource.rb index d8fffba2..199d0cf4 100644 --- a/lib/redmine_dmsf/webdav/dmsf_resource.rb +++ b/lib/redmine_dmsf/webdav/dmsf_resource.rb @@ -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 diff --git a/test/integration/webdav/dmsf_webdav_unlock_test.rb b/test/integration/webdav/dmsf_webdav_unlock_test.rb index 68eccf4f..be72733c 100644 --- a/test/integration/webdav/dmsf_webdav_unlock_test.rb +++ b/test/integration/webdav/dmsf_webdav_unlock_test.rb @@ -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