diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index e2d6d0d3..ea969158 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -99,7 +99,7 @@ class DmsfFile < ActiveRecord::Base def self.storage_path path = Setting.plugin_redmine_dmsf['dmsf_storage_directory'] if path.blank? - path = Pathname.new('files').join('dmsf').to_s + path = Pathname.new('files').join('dmsf') else pn = Pathname.new(path) return pn if pn.absolute? diff --git a/test/unit/dmsf_file_test.rb b/test/unit/dmsf_file_test.rb index 4a539171..a8958694 100644 --- a/test/unit/dmsf_file_test.rb +++ b/test/unit/dmsf_file_test.rb @@ -251,4 +251,26 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest assert_equal 2, csv.size end + def test_storage_path + # Backup + setting = Setting.plugin_redmine_dmsf['dmsf_storage_directory'] + # Relative path + Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = 'dmsf/files' + sp = DmsfFile.storage_path + assert_kind_of Pathname, sp + assert_equal Rails.root.join(Setting.plugin_redmine_dmsf['dmsf_storage_directory']).to_s, sp.to_s + # Empty + Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = '' + sp = DmsfFile.storage_path + assert_kind_of Pathname, sp + assert_equal Rails.root.join(Pathname.new('files').join('dmsf')).to_s, sp.to_s + # Absolute path + Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = '/opt/redmine' + sp = DmsfFile.storage_path + assert_kind_of Pathname, sp + assert_equal '/opt/redmine', sp.to_s + # Restore + Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = setting + end + end \ No newline at end of file