diff --git a/History.txt b/History.txt index 1c99d17a..c70c77a4 100644 --- a/History.txt +++ b/History.txt @@ -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 diff --git a/lib/capybara/driver/rack_test_driver.rb b/lib/capybara/driver/rack_test_driver.rb index da6d4174..09df7e3f 100644 --- a/lib/capybara/driver/rack_test_driver.rb +++ b/lib/capybara/driver/rack_test_driver.rb @@ -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 diff --git a/lib/capybara/spec/session/fill_in_spec.rb b/lib/capybara/spec/session/fill_in_spec.rb index 97f4f7ff..fbed31c1 100644 --- a/lib/capybara/spec/session/fill_in_spec.rb +++ b/lib/capybara/spec/session/fill_in_spec.rb @@ -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') diff --git a/lib/capybara/spec/views/form.erb b/lib/capybara/spec/views/form.erb index bcbbd312..73cf9d9b 100644 --- a/lib/capybara/spec/views/form.erb +++ b/lib/capybara/spec/views/form.erb @@ -109,6 +109,11 @@

+

+ + +

+