Made rack test driver honour maxlength constraints on text and password fields. Closes #210.

This commit is contained in:
Guilherme Carvalho 2011-02-20 16:23:11 -03:00 committed by Jo Liss
parent 4ef81348a4
commit e61373fdc6
4 changed files with 18 additions and 0 deletions

View File

@ -11,6 +11,10 @@ Release date:
* Capybara now prefers visible elements over hidden elements, disable by setting Capybara.prefer_visible_elements = false [Jonas Nicklas and Nicklas Ramhöj]
## Fixed
* The Rack::Test driver now respects maxlength on text fields [Guilherme Carvalho]
# Version 0.4.1
Release date: 2011-01-21

View File

@ -30,6 +30,9 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
native.remove_attribute('checked')
end
elsif tag_name == 'input'
if (type == 'text' || type == 'password') && self[:maxlength]
value = value[0...self[:maxlength].to_i]
end
native['value'] = value.to_s
elsif tag_name == "textarea"
native.content = value.to_s

View File

@ -70,6 +70,12 @@ shared_examples_for "fill_in" do
extract_results(@session)['phone'].should == '+1 555 7022'
end
it "should fill in a text field respecting its maxlength attribute" do
@session.fill_in('Zipcode', :with => '52071350')
@session.click_button('awesome')
extract_results(@session)['zipcode'].should == '52071'
end
it "should fill in a password field by name" do
@session.fill_in('form[password]', :with => 'supasikrit')
@session.click_button('awesome')

View File

@ -109,6 +109,11 @@
</select>
</p>
<p>
<label for="form_zipcode">Zipcode</label>
<input type="text" maxlength="5" name="form[zipcode]" id="form_zipcode" />
</p>
<p>
<label for="form_tendency">Tendency</label>
<select name="form[tendency]" id="form_tendency"></select>