Add integration coverage for styled file inputs
Uses example from Quirksmode: http://www.quirksmode.org/dom/inputfile.html
This commit is contained in:
parent
e3a5dfdd4d
commit
0f89db1825
|
@ -10,6 +10,9 @@ end
|
||||||
Capybara::SpecHelper.run_specs TestSessions::Webkit, "webkit"
|
Capybara::SpecHelper.run_specs TestSessions::Webkit, "webkit"
|
||||||
|
|
||||||
describe Capybara::Session do
|
describe Capybara::Session do
|
||||||
|
include AppRunner
|
||||||
|
include Capybara::RSpecMatchers
|
||||||
|
|
||||||
subject { Capybara::Session.new(:reusable_webkit, @app) }
|
subject { Capybara::Session.new(:reusable_webkit, @app) }
|
||||||
after { subject.reset! }
|
after { subject.reset! }
|
||||||
|
|
||||||
|
@ -479,4 +482,62 @@ describe Capybara::Session do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'styled upload app' do
|
||||||
|
let(:session) do
|
||||||
|
session_for_app do
|
||||||
|
get '/render_form' do
|
||||||
|
<<-HTML
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style type="text/css">
|
||||||
|
#wrapper { position: relative; }
|
||||||
|
input[type=file] {
|
||||||
|
position: relative;
|
||||||
|
opacity: 0;
|
||||||
|
z-index: 2;
|
||||||
|
width: 50px;
|
||||||
|
}
|
||||||
|
#styled {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 1;
|
||||||
|
width: 50px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form action="/submit" method="post" enctype="multipart/form-data">
|
||||||
|
<label for="file">File</label>
|
||||||
|
<div id="wrapper">
|
||||||
|
<input type="file" name="file" id="file" />
|
||||||
|
<div id="styled">Upload</div>
|
||||||
|
</div>
|
||||||
|
<input type="submit" value="Go" />
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/submit' do
|
||||||
|
contents = params[:file][:tempfile].read
|
||||||
|
"You uploaded: #{contents}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'attaches uploads' do
|
||||||
|
file = Tempfile.new('example')
|
||||||
|
file.write('Hello')
|
||||||
|
file.flush
|
||||||
|
|
||||||
|
session.visit('/render_form')
|
||||||
|
session.attach_file 'File', file.path
|
||||||
|
session.click_on 'Go'
|
||||||
|
|
||||||
|
session.should have_text('Hello')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,12 @@ module AppRunner
|
||||||
build_driver
|
build_driver
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def session_for_app(&body)
|
||||||
|
app = Class.new(ExampleApp, &body)
|
||||||
|
run_application app
|
||||||
|
Capybara::Session.new(:reusable_webkit, AppRunner.app)
|
||||||
|
end
|
||||||
|
|
||||||
def run_application_for_html(html)
|
def run_application_for_html(html)
|
||||||
run_application lambda { |env|
|
run_application lambda { |env|
|
||||||
[200, { 'Content-Type' => 'text/html', 'Content-Length' => html.size.to_s }, [html]]
|
[200, { 'Content-Type' => 'text/html', 'Content-Length' => html.size.to_s }, [html]]
|
||||||
|
|
Loading…
Reference in New Issue