diff --git a/models/site_file.rb b/models/site_file.rb index 6faded0f..28136ed1 100644 --- a/models/site_file.rb +++ b/models/site_file.rb @@ -44,6 +44,10 @@ class SiteFile < Sequel::Model current_path = self.path new_path = site.scrubbed_path new_path + if new_path == '' + return false, 'cannot rename to empty path' + end + if current_path == 'index.html' return false, 'cannot rename or move root index.html' end diff --git a/tests/site_file_tests.rb b/tests/site_file_tests.rb index fad72060..77e1b5fd 100644 --- a/tests/site_file_tests.rb +++ b/tests/site_file_tests.rb @@ -81,6 +81,17 @@ describe 'site_files' do PurgeCacheWorker.jobs.last['args'].last.must_equal 'dasharezone' end + it 'wont set an empty directory' do + @site.create_directory 'dirone' + @site.site_files.select {|sf| sf.path == 'dirone'}.length.must_equal 1 + + dirone = @site.site_files_dataset.where(path: 'dirone').first + res = dirone.rename('') + @site.site_files_dataset.where(path: '').count.must_equal 0 + res.must_equal [false, 'cannot rename to empty path'] + @site.site_files_dataset.where(path: '').count.wont_equal 1 + end + it 'changes path of files and dirs within directory when changed' do upload( 'dir' => 'test',