Unescape the values passed to the sinatra test helpers
This commit is contained in:
parent
34ea3e64b8
commit
4565a3cea6
@ -20,6 +20,7 @@ module Webrat
|
|||||||
%w(get head post put delete).each do |verb|
|
%w(get head post put delete).each do |verb|
|
||||||
define_method(verb) do |*args| # (path, data, headers = nil)
|
define_method(verb) do |*args| # (path, data, headers = nil)
|
||||||
path, data, headers = *args
|
path, data, headers = *args
|
||||||
|
data = data.inject({}) {|data, (key,value)| data[key] = Rack::Utils.unescape(value); data }
|
||||||
params = data.merge(:env => headers || {})
|
params = data.merge(:env => headers || {})
|
||||||
self.__send__("#{verb}_it", path, params)
|
self.__send__("#{verb}_it", path, params)
|
||||||
end
|
end
|
||||||
|
@ -17,6 +17,7 @@ end
|
|||||||
|
|
||||||
post "/go" do
|
post "/go" do
|
||||||
@user = params[:name]
|
@user = params[:name]
|
||||||
|
@email = params[:email]
|
||||||
erb :hello
|
erb :hello
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,10 +37,17 @@ __END__
|
|||||||
|
|
||||||
@@ go
|
@@ go
|
||||||
<form method="post" action="/go">
|
<form method="post" action="/go">
|
||||||
<label for="name">Name</label>
|
<div>
|
||||||
<input type="text" name="name" id="name">
|
<label for="name">Name</label>
|
||||||
|
<input type="text" name="name" id="name">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="email">Email</label>
|
||||||
|
<input type="text" name="email" id="email">
|
||||||
|
</div>
|
||||||
<input type="submit" value="Submit" />
|
<input type="submit" value="Submit" />
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@@ hello
|
@@ hello
|
||||||
<p>Hello, <%= @user %></p>
|
<p>Hello, <%= @user %></p>
|
||||||
|
<p>Your email is: <%= @email %></p>
|
@ -12,9 +12,11 @@ class WebratTest < Test::Unit::TestCase
|
|||||||
def test_submits_form
|
def test_submits_form
|
||||||
visit "/go"
|
visit "/go"
|
||||||
fill_in "Name", :with => "World"
|
fill_in "Name", :with => "World"
|
||||||
|
fill_in "Email", :with => "world@example.org"
|
||||||
click_button "Submit"
|
click_button "Submit"
|
||||||
|
|
||||||
assert response_body.include?("Hello, World")
|
assert response_body.include?("Hello, World")
|
||||||
|
assert response_body.include?("Your email is: world@example.org")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_follows_redirects
|
def test_follows_redirects
|
||||||
|
Loading…
Reference in New Issue
Block a user