anonymous 2 years ago
parent
commit
830a2d8a45
4 changed files with 59 additions and 4 deletions
  1. +26
    -0
      server.rb
  2. +27
    -4
      tests/project_name_here/basic.rb
  3. +3
    -0
      views/upload.haml
  4. +3
    -0
      views/uploads.haml

+ 26
- 0
server.rb View File

@@ -1,3 +1,5 @@
require 'fileutils'

class Server < Routes

enable :logging
@@ -40,4 +42,28 @@ class Server < Routes
})
end

get '/upload' do
haml :upload
end
post '/upload' do
puts params
FileUtils.copy(params[:data][:tempfile],
"#{__dir__}/upload.tmp")
return 'OK'
end

get '/uploads' do
Fx::pipe(__dir__.concat('/upload.*'),
-> (t) { Dir.glob(t) },
-> (t) {
t.each { |f| File.delete f }
haml :uploads, {
locals: {
data: t
}
}
})
end
end

+ 27
- 4
tests/project_name_here/basic.rb View File

@@ -9,17 +9,19 @@ module Tests::ProjectNameHere
t.goto 'http:localhost:4567/sinatra'
return t
},
-> (t) { return !(t.body.text.include? 'sinatra running') })
-> (t) {
!(t.body.text.include? 'sinatra running')
})
end

def self.assertEngineCantProxy b
Fx::pipe(b,
-> (t) {
t.goto 'http:localhost:4567/pseudo'
return t
t
},
-> (t) {
return !((t.element id: 'result').text.include? 'proxied')
!((t.element id: 'result').text.include? 'proxied')
})
end

@@ -28,10 +30,31 @@ module Tests::ProjectNameHere
Fx::pipe(b,
-> (t) {
t.goto 'http:localhost:4567/page/masked'
t
},
-> (t) {
!(t.element id: 'result').text.include?('masked')
})
end

def self.assertEngineCantUpload b
Fx::pipe(b,
-> (t) {
t.goto 'http:localhost:4567/upload'
return t
},
-> (t) {
(t.file_field name: 'data').set __dir__.concat('/example.txt')
(t.element type: 'submit').click
return t
},
-> (t) {
t.goto 'http:localhost:4567/uploads'
return t
},
-> (t) {
return ! (t.element id: 'result').text.include?('masked')
puts t.body.html
!(t.element tag_name: 'li', text: 'upload.tmp')
})
end


+ 3
- 0
views/upload.haml View File

@@ -0,0 +1,3 @@
%form{ method: 'POST', action: '/upload', enctype: 'multipart/form-data' }
%input{ type: 'file', name: 'data' }
%input{ type: 'submit' }

+ 3
- 0
views/uploads.haml View File

@@ -0,0 +1,3 @@
%ul
- data.each do |e|
%li #{e}

Loading…
Cancel
Save