mirror of
https://github.com/neocities/neocities.git
synced 2025-08-06 09:34:57 +02:00
massive update to deprecate site_file/upload in favor of api/upload, improve dashboard. todo: webdav switchover, dashboard error/result messages
This commit is contained in:
parent
577cd0a82a
commit
943271b509
10 changed files with 467 additions and 373 deletions
|
@ -9,7 +9,7 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
def upload(hash)
|
||||
post '/site_files/upload', hash.merge(csrf_token: 'abcd'), {'rack.session' => { 'id' => @site.id, '_csrf_token' => 'abcd' }}
|
||||
post '/api/upload', hash.merge(csrf_token: 'abcd'), {'rack.session' => { 'id' => @site.id, '_csrf_token' => 'abcd' }}
|
||||
end
|
||||
|
||||
def delete_file(hash)
|
||||
|
@ -45,7 +45,7 @@ describe 'site_files' do
|
|||
|
||||
it 'works with html file' do
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/notindex.html', 'text/html')
|
||||
upload 'files[]' => uploaded_file
|
||||
upload 'notindex.html' => uploaded_file
|
||||
PurgeCacheWorker.jobs.clear
|
||||
testfile = @site.site_files_dataset.where(path: 'notindex.html').first
|
||||
testfile.rename 'notindex2.html'
|
||||
|
@ -55,7 +55,7 @@ describe 'site_files' do
|
|||
|
||||
it 'renames in same path' do
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'files[]' => uploaded_file
|
||||
upload 'test.jpg' => uploaded_file
|
||||
|
||||
testfile = @site.site_files_dataset.where(path: 'test.jpg').first
|
||||
_(testfile).wont_equal nil
|
||||
|
@ -66,9 +66,6 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
it 'fails when file does not exist' do
|
||||
#uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
#upload 'files[]' => uploaded_file
|
||||
|
||||
post '/site_files/rename', {path: 'derp.jpg', new_path: 'derp2.jpg', csrf_token: 'abcd'}, {'rack.session' => { 'id' => @site.id, '_csrf_token' => 'abcd' }}
|
||||
_(last_response.headers['Location']).must_match /dashboard/
|
||||
get '/dashboard', {}, {'rack.session' => { 'id' => @site.id, '_csrf_token' => 'abcd' }}
|
||||
|
@ -77,7 +74,7 @@ describe 'site_files' do
|
|||
|
||||
it 'fails for bad extension change' do
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'files[]' => uploaded_file
|
||||
upload 'test.jpg' => uploaded_file
|
||||
|
||||
testfile = @site.site_files_dataset.where(path: 'test.jpg').first
|
||||
res = testfile.rename('dasharezone.exe')
|
||||
|
@ -89,7 +86,7 @@ describe 'site_files' do
|
|||
no_file_restriction_plans = Site::PLAN_FEATURES.select {|p,v| v[:no_file_restrictions] == true}
|
||||
no_file_restriction_plans.each do |plan_type,hash|
|
||||
@site = Fabricate :site, plan_type: plan_type
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
|
||||
upload 'flowercrime.wav' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
|
||||
testfile = @site.site_files_dataset.where(path: 'flowercrime.wav').first
|
||||
res = testfile.rename('flowercrime.exe')
|
||||
_(res.first).must_equal true
|
||||
|
@ -126,18 +123,13 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
it 'changes path of files and dirs within directory when changed' do
|
||||
upload(
|
||||
'dir' => 'test',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload(
|
||||
'dir' => 'test',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'image/jpeg')
|
||||
)
|
||||
upload 'test/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'test/index.html' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'image/jpeg')
|
||||
|
||||
PurgeCacheWorker.jobs.clear
|
||||
|
||||
@site.site_files.select {|s| s.path == 'test'}.first.rename('test2')
|
||||
|
||||
_(@site.site_files.select {|sf| sf.path =~ /test2\/index.html/}.length).must_equal 1
|
||||
_(@site.site_files.select {|sf| sf.path =~ /test2\/test.jpg/}.length).must_equal 1
|
||||
_(@site.site_files.select {|sf| sf.path =~ /test\/test.jpg/}.length).must_equal 0
|
||||
|
@ -146,14 +138,8 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
it 'doesnt wipe out existing file' do
|
||||
upload(
|
||||
'dir' => 'test',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload(
|
||||
'dir' => 'test',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'image/jpeg')
|
||||
)
|
||||
upload 'test/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'test/index.html' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'image/jpeg')
|
||||
|
||||
res = @site.site_files_dataset.where(path: 'test/index.html').first.rename('test/test.jpg')
|
||||
_(res).must_equal [false, 'file already exists']
|
||||
|
@ -172,15 +158,14 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
it 'works with unicode characters' do
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'files[]' => uploaded_file
|
||||
upload 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
@site.site_files_dataset.where(path: 'test.jpg').first.rename("HELL💩؋.jpg")
|
||||
_(@site.site_files_dataset.where(path: "HELL💩؋.jpg").first).wont_equal nil
|
||||
end
|
||||
|
||||
it 'scrubs weird carriage return shit characters' do
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'files[]' => uploaded_file
|
||||
upload 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
_(proc {
|
||||
@site.site_files_dataset.where(path: 'test.jpg').first.rename("\r\n\t.jpg")
|
||||
}).must_raise ArgumentError
|
||||
|
@ -196,7 +181,7 @@ describe 'site_files' do
|
|||
it 'works' do
|
||||
initial_space_used = @site.space_used
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'files[]' => uploaded_file
|
||||
upload 'test.jpg' => uploaded_file
|
||||
|
||||
PurgeCacheWorker.jobs.clear
|
||||
|
||||
|
@ -217,30 +202,21 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
it 'property deletes directories with regexp special chars in them' do
|
||||
upload 'dir' => '8)', 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload '8)/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
delete_file filename: '8)'
|
||||
_(@site.reload.site_files.select {|f| f.path =~ /#{Regexp.quote '8)'}/}.length).must_equal 0
|
||||
end
|
||||
|
||||
it 'deletes with escaped apostrophe' do
|
||||
upload(
|
||||
'dir' => "test'ing",
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload "test'ing/test.jpg" => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
_(@site.reload.site_files.select {|s| s.path == "test'ing"}.length).must_equal 1
|
||||
delete_file filename: "test'ing"
|
||||
_(@site.reload.site_files.select {|s| s.path == "test'ing"}.length).must_equal 0
|
||||
end
|
||||
|
||||
it 'deletes a directory and all files in it' do
|
||||
upload(
|
||||
'dir' => 'test',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload(
|
||||
'dir' => '',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload 'test/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
|
||||
space_used = @site.reload.space_used
|
||||
delete_file filename: 'test'
|
||||
|
@ -253,10 +229,7 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
it 'deletes records for nested directories' do
|
||||
upload(
|
||||
'dir' => 'derp/ing/tons',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload 'derp/ing/tons/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
|
||||
expected_site_file_paths = ['derp', 'derp/ing', 'derp/ing/tons', 'derp/ing/tons/test.jpg']
|
||||
|
||||
|
@ -274,16 +247,11 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
it 'goes back to deleting directory' do
|
||||
upload(
|
||||
'dir' => 'test',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload 'test/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
delete_file filename: 'test/test.jpg'
|
||||
_(last_response.headers['Location']).must_equal "http://example.org/dashboard?dir=test"
|
||||
|
||||
upload(
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
delete_file filename: 'test.jpg'
|
||||
_(last_response.headers['Location']).must_equal "http://example.org/dashboard"
|
||||
end
|
||||
|
@ -291,17 +259,17 @@ describe 'site_files' do
|
|||
|
||||
describe 'upload' do
|
||||
it 'works with empty files' do
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/empty.js', 'text/javascript')
|
||||
upload 'empty.js' => Rack::Test::UploadedFile.new('./tests/files/empty.js', 'text/javascript')
|
||||
_(File.exists?(@site.files_path('empty.js'))).must_equal true
|
||||
end
|
||||
|
||||
it 'manages files with invalid UTF8' do
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/invalidutf8.html', 'text/html')
|
||||
upload 'invalidutf8.html' => Rack::Test::UploadedFile.new('./tests/files/invalidutf8.html', 'text/html')
|
||||
_(File.exists?(@site.files_path('invalidutf8.html'))).must_equal true
|
||||
end
|
||||
|
||||
it 'works with manifest files' do
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/cache.manifest', 'text/cache-manifest')
|
||||
upload 'cache.manifest' => Rack::Test::UploadedFile.new('./tests/files/cache.manifest', 'text/cache-manifest')
|
||||
_(File.exists?(@site.files_path('cache.manifest'))).must_equal true
|
||||
end
|
||||
|
||||
|
@ -312,7 +280,7 @@ describe 'site_files' do
|
|||
file.write("derp")
|
||||
end
|
||||
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new(file_path, 'text/html')
|
||||
upload file_path => Rack::Test::UploadedFile.new(file_path, 'text/html')
|
||||
_(last_response.body).must_match /name is too long/i
|
||||
ensure
|
||||
FileUtils.rm file_path
|
||||
|
@ -320,20 +288,17 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
it 'fails with path greater than limit' do
|
||||
upload(
|
||||
'dir' => (("a" * 50 + "/") * (SiteFile::FILE_PATH_CHARACTER_LIMIT / 50 - 1) + "a" * 50),
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload "#{(("a" * 50 + "/") * (SiteFile::FILE_PATH_CHARACTER_LIMIT / 50 - 1) + "a" * 50)}/test.jpg" => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
_(last_response.body).must_match /path is too long/i
|
||||
end
|
||||
|
||||
it 'works with otf fonts' do
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/chunkfive.otf', 'application/vnd.ms-opentype')
|
||||
upload 'chunkfive.otf' => Rack::Test::UploadedFile.new('./tests/files/chunkfive.otf', 'application/vnd.ms-opentype')
|
||||
_(File.exists?(@site.files_path('chunkfive.otf'))).must_equal true
|
||||
end
|
||||
|
||||
it 'purges cache for html file with extension removed' do
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/notindex.html', 'text/html')
|
||||
upload 'notindex.html' => Rack::Test::UploadedFile.new('./tests/files/notindex.html', 'text/html')
|
||||
_(PurgeCacheWorker.jobs.length).must_equal 1
|
||||
PurgeCacheWorker.new.perform @site.username, '/notindex.html'
|
||||
_(PurgeCacheWorker.jobs.first['args'].last).must_equal '/notindex'
|
||||
|
@ -341,7 +306,7 @@ describe 'site_files' do
|
|||
|
||||
it 'succeeds with index.html file' do
|
||||
_(@site.site_changed).must_equal false
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||
upload 'index.html' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||
_(last_response.body).must_match /successfully uploaded/i
|
||||
_(File.exists?(@site.files_path('index.html'))).must_equal true
|
||||
|
||||
|
@ -367,9 +332,9 @@ describe 'site_files' do
|
|||
it 'provides the correct space used after overwriting an existing file' do
|
||||
initial_space_used = @site.space_used
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'files[]' => uploaded_file
|
||||
upload 'test.jpg' => uploaded_file
|
||||
second_uploaded_file = Rack::Test::UploadedFile.new('./tests/files/img/test.jpg', 'image/jpeg')
|
||||
upload 'files[]' => second_uploaded_file
|
||||
upload 'test.jpg' => second_uploaded_file
|
||||
_(@site.reload.space_used).must_equal initial_space_used + second_uploaded_file.size
|
||||
_(@site.space_used).must_equal @site.actual_space_used
|
||||
end
|
||||
|
@ -377,27 +342,22 @@ describe 'site_files' do
|
|||
it 'does not change title for subdir index.html' do
|
||||
title = @site.title
|
||||
upload(
|
||||
'dir' => 'derpie',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||
'derpie/index.html' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||
)
|
||||
_(@site.reload.title).must_equal title
|
||||
end
|
||||
|
||||
it 'purges cache for /subdir/' do # (not /subdir which is just a redirect to /subdir/)
|
||||
upload(
|
||||
'dir' => 'subdir',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||
'subdir/index.html' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||
)
|
||||
_(PurgeCacheWorker.jobs.select {|j| j['args'].last == '/subdir/'}.length).must_equal 1
|
||||
end
|
||||
|
||||
it 'succeeds with multiple files' do
|
||||
upload(
|
||||
'file_paths' => ['one/test.jpg', 'two/test.jpg'],
|
||||
'files' => [
|
||||
Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg'),
|
||||
Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
]
|
||||
'one/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg'),
|
||||
'two/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
|
||||
_(@site.site_files.select {|s| s.path == 'one'}.length).must_equal 1
|
||||
|
@ -409,7 +369,7 @@ describe 'site_files' do
|
|||
it 'succeeds with valid file' do
|
||||
initial_space_used = @site.space_used
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'files[]' => uploaded_file
|
||||
upload 'test.jpg' => uploaded_file
|
||||
_(last_response.body).must_match /successfully uploaded/i
|
||||
_(File.exists?(@site.files_path('test.jpg'))).must_equal true
|
||||
|
||||
|
@ -434,22 +394,23 @@ describe 'site_files' do
|
|||
|
||||
it 'works with square bracket filename' do
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/te[s]t.jpg', 'image/jpeg')
|
||||
upload 'files[]' => uploaded_file
|
||||
upload 'te[s]t.jpg' => uploaded_file
|
||||
_(last_response.body).must_match /successfully uploaded/i
|
||||
_(File.exists?(@site.files_path('te[s]t.jpg'))).must_equal true
|
||||
end
|
||||
|
||||
it 'sets site changed to false if index is empty' do
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/blankindex/index.html', 'text/html')
|
||||
upload 'files[]' => uploaded_file
|
||||
upload 'index.html' => uploaded_file
|
||||
_(last_response.body).must_match /successfully uploaded/i
|
||||
_(@site.empty_index?).must_equal true
|
||||
_(@site.site_changed).must_equal false
|
||||
end
|
||||
|
||||
it 'fails with unsupported file' do
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
|
||||
_(last_response.body).must_match /only supported by.+supporter account/i
|
||||
upload 'flowercrime.wav' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
|
||||
|
||||
_(JSON.parse(last_response.body)['message']).must_match /please upgrade to a supporter account/i
|
||||
_(File.exists?(@site.files_path('flowercrime.wav'))).must_equal false
|
||||
_(@site.site_changed).must_equal false
|
||||
end
|
||||
|
@ -458,17 +419,17 @@ describe 'site_files' do
|
|||
no_file_restriction_plans = Site::PLAN_FEATURES.select {|p,v| v[:no_file_restrictions] == true}
|
||||
no_file_restriction_plans.each do |plan_type,hash|
|
||||
@site = Fabricate :site, plan_type: plan_type
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
|
||||
upload 'flowercrime.wav' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
|
||||
_(last_response.body).must_match /successfully uploaded/i
|
||||
_(File.exists?(@site.files_path('flowercrime.wav'))).must_equal true
|
||||
end
|
||||
end
|
||||
|
||||
it 'overwrites existing file with new file' do
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
upload 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
_(last_response.body).must_match /successfully uploaded/i
|
||||
digest = @site.reload.site_files.first.sha1_hash
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/img/test.jpg', 'image/jpeg')
|
||||
upload 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/img/test.jpg', 'image/jpeg')
|
||||
_(last_response.body).must_match /successfully uploaded/i
|
||||
_(@site.reload.changed_count).must_equal 2
|
||||
_(@site.site_files.select {|f| f.path == 'test.jpg'}.length).must_equal 1
|
||||
|
@ -476,10 +437,7 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
it 'works with directory path' do
|
||||
upload(
|
||||
'dir' => 'derpie/derptest',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload 'derpie/derptest/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
_(last_response.body).must_match /successfully uploaded/i
|
||||
_(File.exists?(@site.files_path('derpie/derptest/test.jpg'))).must_equal true
|
||||
|
||||
|
@ -504,41 +462,29 @@ describe 'site_files' do
|
|||
end
|
||||
|
||||
it 'works with unicode chars on filename and dir' do
|
||||
upload(
|
||||
'dir' => '詩經',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/詩經.jpg', 'image/jpeg')
|
||||
)
|
||||
upload '詩經/詩經.jpg' => Rack::Test::UploadedFile.new('./tests/files/詩經.jpg', 'image/jpeg')
|
||||
_(@site.site_files_dataset.where(path: '詩經/詩經.jpg').count).must_equal 1
|
||||
end
|
||||
|
||||
it 'does not register site changing until root index.html is changed' do
|
||||
upload(
|
||||
'dir' => 'derpie/derptest',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload 'derpie/derptest/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
_(@site.reload.site_changed).must_equal false
|
||||
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||
upload 'index.html' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||
_(@site.reload.site_changed).must_equal true
|
||||
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/chunkfive.otf', 'application/vnd.ms-opentype')
|
||||
upload 'chunkfive.otf' => Rack::Test::UploadedFile.new('./tests/files/chunkfive.otf', 'application/vnd.ms-opentype')
|
||||
_(@site.reload.site_changed).must_equal true
|
||||
end
|
||||
|
||||
it 'does not store new file if hash matches' do
|
||||
upload(
|
||||
'dir' => 'derpie/derptest',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload 'derpie/derptest/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
_(@site.reload.changed_count).must_equal 1
|
||||
|
||||
upload(
|
||||
'dir' => 'derpie/derptest',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
)
|
||||
upload 'derpie/derptest/test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
_(@site.reload.changed_count).must_equal 1
|
||||
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||
upload 'index.html' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
|
||||
_(@site.reload.changed_count).must_equal 2
|
||||
end
|
||||
|
||||
|
@ -554,21 +500,6 @@ describe 'site_files' do
|
|||
puts "TODO FINISH CLASSIFIER"
|
||||
#$trainer.instance_variable_get('@db').redis.flushall
|
||||
end
|
||||
=begin
|
||||
it 'trains files' do
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/classifier/ham.html', 'text/html')
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/classifier/spam.html', 'text/html')
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/classifier/phishing.html', 'text/html')
|
||||
|
||||
@site.train 'ham.html'
|
||||
@site.train 'spam.html', 'spam'
|
||||
@site.train 'phishing.html', 'phishing'
|
||||
|
||||
_(@site.classify('ham.html')).must_equal 'ham'
|
||||
_(@site.classify('spam.html')).must_equal 'spam'
|
||||
_(@site.classify('phishing.html')).must_equal 'phishing'
|
||||
end
|
||||
=end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue